aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp59
1 files changed, 35 insertions, 24 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 48d73d5..dccdf11 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1286,7 +1286,6 @@ namespace QuickMedia {
return std::to_string(seconds) + " second" + (seconds == 1 ? "" : "s") + " ago";
}
- // TODO: Make asynchronous
static void fill_history_items_from_json(const Json::Value &history_json, BodyItems &history_items) {
assert(history_json.isArray());
@@ -1355,8 +1354,9 @@ namespace QuickMedia {
show_notification("QuickMedia", "Failed to create directory: " + content_storage_dir.data, Urgency::CRITICAL);
exit(1);
}
- // TODO: Make asynchronous
- for_files_in_dir_sort_last_modified(content_storage_dir, [&history_items, plugin_name](const std::filesystem::path &filepath) {
+
+ time_t now = time(NULL);
+ for_files_in_dir_sort_last_modified(content_storage_dir, [&history_items, plugin_name, now](const std::filesystem::path &filepath) {
// This can happen when QuickMedia crashes/is killed while writing to storage.
// In that case, the storage wont be corrupt but there will be .tmp files.
// TODO: Remove these .tmp files if they exist during startup
@@ -1373,28 +1373,39 @@ namespace QuickMedia {
// TODO: Manga combined
auto filename = filepath.filename();
+ if(filename.empty())
+ return true;
+
const Json::Value &manga_name = body["name"];
- if(!filename.empty() && manga_name.isString()) {
- // TODO: Add thumbnail
- auto body_item = BodyItem::create(manga_name.asString());
- if(strcmp(plugin_name, "manganelo") == 0)
- body_item->url = "https://manganelo.com/manga/" + base64_decode(filename.string());
- else if(strcmp(plugin_name, "manganelos") == 0)
- body_item->url = "http://manganelos.com/manga/" + base64_decode(filename.string());
- else if(strcmp(plugin_name, "mangadex") == 0)
- body_item->url = base64_decode(filename.string());
- else if(strcmp(plugin_name, "mangatown") == 0)
- body_item->url = "https://mangatown.com/manga/" + base64_decode(filename.string());
- else if(strcmp(plugin_name, "mangakatana") == 0)
- body_item->url = "https://mangakatana.com/manga/" + base64_decode(filename.string());
- else if(strcmp(plugin_name, "onimanga") == 0)
- body_item->url = "https://onimanga.com/" + base64_decode(filename.string());
- else if(strcmp(plugin_name, "readm") == 0)
- body_item->url = "https://readm.org/manga/" + base64_decode(filename.string());
- else
- fprintf(stderr, "Error: Not implemented: filename to manga chapter list\n");
- history_items.push_back(std::move(body_item));
- }
+ if(!manga_name.isString())
+ return true;
+
+ time_t last_modified_time = 0;
+ file_get_last_modified_time_seconds(filepath.c_str(), &last_modified_time);
+
+ // TODO: Add thumbnail
+ auto body_item = BodyItem::create(manga_name.asString());
+ body_item->set_description("Last read " + seconds_to_relative_time_str(now - last_modified_time));
+ body_item->set_description_color(sf::Color(179, 179, 179));
+
+ if(strcmp(plugin_name, "manganelo") == 0)
+ body_item->url = "https://manganelo.com/manga/" + base64_decode(filename.string());
+ else if(strcmp(plugin_name, "manganelos") == 0)
+ body_item->url = "http://manganelos.com/manga/" + base64_decode(filename.string());
+ else if(strcmp(plugin_name, "mangadex") == 0)
+ body_item->url = base64_decode(filename.string());
+ else if(strcmp(plugin_name, "mangatown") == 0)
+ body_item->url = "https://mangatown.com/manga/" + base64_decode(filename.string());
+ else if(strcmp(plugin_name, "mangakatana") == 0)
+ body_item->url = "https://mangakatana.com/manga/" + base64_decode(filename.string());
+ else if(strcmp(plugin_name, "onimanga") == 0)
+ body_item->url = "https://onimanga.com/" + base64_decode(filename.string());
+ else if(strcmp(plugin_name, "readm") == 0)
+ body_item->url = "https://readm.org/manga/" + base64_decode(filename.string());
+ else
+ fprintf(stderr, "Error: Not implemented: filename to manga chapter list\n");
+
+ history_items.push_back(std::move(body_item));
return true;
});
}