diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | src/Storage.cpp | 7 | ||||
-rw-r--r-- | src/plugins/LocalManga.cpp | 46 |
4 files changed, 55 insertions, 2 deletions
@@ -135,7 +135,7 @@ Type text and then wait and QuickMedia will automatically search.\ `I`: Start typing a message, `Esc` to cancel.\ `Enter`: Post message (when typing a message).\ `R`: Add the selected post as a reply to the message.\ -`U`: Bring up file manager to choose which file should be uploaded, `Esc` to cancel.\ +`U`: Select a file to upload by selecting a file with the file manager, `Esc` to cancel.\ `Ctrl+D`: Remove the selected file from the post.\ `Ctrl+I`: Reverse image search the selected image or select an url to open in the browser.\ `Arrow left/right`: Move captcha slider left/right.\ @@ -214,7 +214,7 @@ Use std::move(string) for all places where text.set_string is called. Use reference for text.get_string() in all places. Cleanup font sizes that are not visible (or not used for a while). Also do the same for character ranges font texture. Show video upload date in video description on youtube. -Add latest read chapter name to manga progress, to easily see from manga list page how we have progressed in the manga. +Add latest read chapter name to manga progress, to easily see from manga list page how we have progressed in the manga and also if the last chapter has been read then mark it as read. Allow changing manga sorting in gui (especially for local manga). Allow using ~ and $HOME in config file. Save manga "I" mode to file and load it on startup.
\ No newline at end of file diff --git a/src/Storage.cpp b/src/Storage.cpp index a0f20e4..f4732b8 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -163,6 +163,13 @@ namespace QuickMedia { FILE *file = fopen_eintr(path.data.c_str(), "rb"); if(!file) return -errno; + + int fd = fileno(file); + struct stat s; + if(fstat(fd, &s) == -1 || !S_ISREG(s.st_mode)) { + fclose(file); + return -1; + } fseek_eintr(file, 0, SEEK_END); long file_size = ftell(file); diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp index 4deb229..3ad4ffa 100644 --- a/src/plugins/LocalManga.cpp +++ b/src/plugins/LocalManga.cpp @@ -4,6 +4,7 @@ #include "../../include/Theme.hpp" #include "../../include/StringUtils.hpp" #include "../../include/Storage.hpp" +#include <unordered_set> namespace QuickMedia { // Pages are sorted from 1.png to n.png @@ -155,6 +156,47 @@ namespace QuickMedia { return PluginResult::OK; } + static std::unordered_set<std::string> get_lines_in_file(const Path &filepath) { + std::unordered_set<std::string> lines; + + std::string file_content; + if(file_get_content(filepath, file_content) != 0) + return lines; + + string_split(file_content, '\n', [&lines](const char *str_part, size_t size) { + lines.insert(std::string(str_part, size)); + return true; + }); + + return lines; + } + + static bool append_seen_manga_to_automedia_seen(const std::string &manga_chapter_name) { + Path automedia_config_dir = get_home_dir().join(".config").join("automedia"); + if(create_directory_recursive(automedia_config_dir) != 0) { + fprintf(stderr, "Warning: failed to create directory: %s\n", automedia_config_dir.data.c_str()); + return false; + } + + Path automedia_seen_filepath = automedia_config_dir; + automedia_seen_filepath.join("seen"); + + std::unordered_set<std::string> lines = get_lines_in_file(automedia_seen_filepath); + if(lines.find(manga_chapter_name) != lines.end()) + return true; // Already seen + + FILE *file = fopen(automedia_seen_filepath.data.c_str(), "ab"); + if(!file) { + fprintf(stderr, "Warning: failed to open automedia seen file %s\n", automedia_seen_filepath.data.c_str()); + return false; + } + + std::string new_line_data = manga_chapter_name + "\n"; + fwrite(new_line_data.data(), 1, new_line_data.size(), file); + fclose(file); + return true; + } + PluginResult LocalMangaChaptersPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) { if(get_config().local_manga_directory.empty()) { show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL); @@ -169,6 +211,10 @@ namespace QuickMedia { Path chapter_url = Path(get_config().local_manga_directory).join(content_url).join(args.url); std::vector<LocalMangaPage> pages = get_images_in_manga(chapter_url); result_tabs.push_back(Tab{nullptr, std::make_unique<LocalMangaImagesPage>(program, content_title, args.title, args.url, thumbnail_url, std::move(pages)), nullptr}); + + if(is_program_executable_by_name("automedia")) + append_seen_manga_to_automedia_seen(content_url + "/" + args.url); + return PluginResult::OK; } |