From d7a681b69153ea99f03c128fce5d297ff1f635f6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 5 Jun 2021 17:36:54 +0200 Subject: Fix incorrect times, add time to manga history --- src/QuickMedia.cpp | 59 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'src/QuickMedia.cpp') 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; }); } -- cgit v1.2.3