From fa29a3099fca14f8d3b9d9ae3047c628236cd078 Mon Sep 17 00:00:00 2001 From: Simounet Date: Sat, 2 May 2020 17:14:09 +0200 Subject: [PATCH 1/2] utils namespace added --- src/application.cpp | 20 +++----------------- src/utils.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 src/utils.cpp diff --git a/src/application.cpp b/src/application.cpp index 8ce888a..e46d026 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1,20 +1,6 @@ #include "application.h" #include "log.h" - - -#include -#include - -namespace patch -{ - template < typename T > std::string to_string( const T& n ) - { - std::ostringstream stm ; - stm << n ; - return stm.str() ; - } -} - +#include "utils.cpp" void Application::init() @@ -499,8 +485,8 @@ void Application::restoreModeAndPage() void Application::saveModeAndPage() { - getDb().saveInternal("gui.pageNum", patch::to_string(pageNum)); - getDb().saveInternal("gui.mode", patch::to_string(mode)); + getDb().saveInternal("gui.pageNum", utils::to_string(pageNum)); + getDb().saveInternal("gui.mode", utils::to_string(mode)); } diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..e280a7c --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,12 @@ +#include +#include + +namespace utils +{ + template < typename T > std::string to_string( const T& n ) + { + std::ostringstream stm ; + stm << n ; + return stm.str() ; + } +} From eac6893ea6e615f19b1edd062f094ea267bdcbd7 Mon Sep 17 00:00:00 2001 From: Simounet Date: Sat, 2 May 2020 17:16:03 +0200 Subject: [PATCH 2/2] Long entries filter added --- src/application.cpp | 6 +++++ src/application.h | 2 +- src/gui/gui.cpp | 14 +++++++++++ src/repositories/entry_repository.cpp | 35 +++++++++++++++++++++------ src/repositories/entry_repository.h | 6 +++-- src/translate.h | 10 ++++++++ 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index e46d026..010157f 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -386,6 +386,9 @@ int Application::countEntriesForCurrentMode() if (mode == MODE_STARRED) { return entryRepository.countStarred(); } + if (mode == MODE_LONG) { + return entryRepository.countLong(); + } return 0; } @@ -401,6 +404,9 @@ void Application::listEntriesForCurrentMode(std::vector &entries) else if (mode == MODE_STARRED) { entryRepository.listStarred(entries, numPerPage, (pageNum-1) * numPerPage); } + else if (mode == MODE_LONG) { + entryRepository.listLong(entries, numPerPage, (pageNum-1) * numPerPage); + } } diff --git a/src/application.h b/src/application.h index 17c8f3e..dbc14fe 100644 --- a/src/application.h +++ b/src/application.h @@ -27,7 +27,7 @@ class Application { public: - enum entries_mode {MODE_UNREAD=1, MODE_ARCHIVED, MODE_STARRED}; + enum entries_mode {MODE_UNREAD=1, MODE_ARCHIVED, MODE_STARRED, MODE_LONG}; enum reading_format {FORMAT_HTML=1, FORMAT_EPUB}; Application() : entryRepository(db), epubDownloadQueueRepository(db), gui(*this) { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index abf43ee..6073476 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -125,6 +125,9 @@ void Gui::show(int numPage, int numberOfPages, int countAllEntries, std::vector< else if (mode == 3) { snprintf(buffer, sizeof(buffer), PLOP_APPLICATION_FULLNAME " - %s", LBL_HEADER_STARRED_ENTRIES); } + else if (mode == 4) { + snprintf(buffer, sizeof(buffer), PLOP_APPLICATION_FULLNAME " - %s", LBL_HEADER_LONG_ENTRIES); + } else { snprintf(buffer, sizeof(buffer), PLOP_APPLICATION_FULLNAME); } @@ -231,6 +234,7 @@ void Gui::displayMainMenu() const char *str3 = LBL_MAINMENU_MODE_STARRED_ENTRIES; const char *str_reset = LBL_MAINMENU_DELETE_ALL_LOCAL_DATA; const char *str4 = LBL_MAINMENU_ABOUT; + const char *str5 = LBL_MAINMENU_MODE_LONG_ENTRIES; menu = (imenuex *)calloc(7, sizeof(imenuex)); @@ -276,6 +280,13 @@ void Gui::displayMainMenu() menu[5].font = NULL; menu[5].submenu = NULL; + menu[6].type = 2; + menu[6].index = 6; + menu[6].text = (char *)str5; + menu[6].icon = NULL; + menu[6].font = NULL; + menu[6].submenu = &menu[5]; + auto callback = [](int index) { free(menu); @@ -329,6 +340,9 @@ void Gui::displayMainMenu() app.getGui().statusBarText(LBL_STATUSBAR_DELETEALL_CANCELED); } } + else if (index == 6) { + app.setMode(Application::MODE_LONG); + } }; statusBarText(LBL_STATUSBAR_MAINMENU); diff --git a/src/repositories/entry_repository.cpp b/src/repositories/entry_repository.cpp index ec7afd0..3e1b36a 100644 --- a/src/repositories/entry_repository.cpp +++ b/src/repositories/entry_repository.cpp @@ -1,5 +1,6 @@ #include "entry_repository.h" +#include "../utils.cpp" // TODO a lot of error-handling around database manipulations @@ -208,24 +209,29 @@ void EntryRepository::deleteAll() void EntryRepository::listUnread(std::vector &entries, int limit, int offset) { - return list(entries, limit, offset, 0, 1); + return list(entries, limit, offset, 0, 1, -1); } void EntryRepository::listArchived(std::vector &entries, int limit, int offset) { - return list(entries, limit, offset, 2, 1); + return list(entries, limit, offset, 2, 1, -1); } void EntryRepository::listStarred(std::vector &entries, int limit, int offset) { - return list(entries, limit, offset, 1, 2); + return list(entries, limit, offset, 1, 2, -1); +} + +void EntryRepository::listLong(std::vector &entries, int limit, int offset) +{ + return list(entries, limit, offset, 0, 1, 600); } void EntryRepository::list(std::vector &entries, int limit, int offset, - int archived, int starred + int archived, int starred, int reading_time = -1 ) { entries.clear(); @@ -253,6 +259,10 @@ void EntryRepository::list(std::vector &entries, int limit, int offset, conditions.push_back("local_is_starred = 1"); } + if (reading_time != -1) { + conditions.push_back("reading_time >= " + utils::to_string(reading_time)); + } + //conditions.push_back("is_empty = 0"); const char *sqlTemplate = R"sql( @@ -351,21 +361,26 @@ offset :offset int EntryRepository::countUnread() { - return count(0, 1); + return count(0, 1, -1); } int EntryRepository::countArchived() { - return count(2, 1); + return count(2, 1, -1); } int EntryRepository::countStarred() { - return count(1, 2); + return count(1, 2, -1); } +int EntryRepository::countLong() +{ + return count(0, 1, 600); +} -int EntryRepository::count(int archived, int starred) + +int EntryRepository::count(int archived, int starred, int reading_time = -1) { std::vector conditions; @@ -389,6 +404,10 @@ int EntryRepository::count(int archived, int starred) conditions.push_back("local_is_starred = 1"); } + if (reading_time != -1) { + conditions.push_back("reading_time >= " + utils::to_string(reading_time)); + } + const char *sqlTemplate = "select count(*) from entries %s"; char sql[2048]; diff --git a/src/repositories/entry_repository.h b/src/repositories/entry_repository.h index ed68f44..399d6ac 100644 --- a/src/repositories/entry_repository.h +++ b/src/repositories/entry_repository.h @@ -18,18 +18,20 @@ class EntryRepository void deleteAll(); void list(std::vector &entries, int limit, int offset, - int archived, int starred); + int archived, int starred, int reading_time); int countAllEntries(); int countUnread(); int countArchived(); int countStarred(); - int count(int archived, int starred); + int countLong(); + int count(int archived, int starred, int reading_time); void listUnread(std::vector &entries, int limit, int offset); void listArchived(std::vector &entries, int limit, int offset); void listStarred(std::vector &entries, int limit, int offset); + void listLong(std::vector &entries, int limit, int offset); Entry get(int entryId); Entry findByRemoteId(int remoteId); diff --git a/src/translate.h b/src/translate.h index c7f6b99..359b7e2 100644 --- a/src/translate.h +++ b/src/translate.h @@ -23,6 +23,11 @@ extern int global_lang; : "starred entries" \ ) +#define LBL_HEADER_LONG_ENTRIES (IS_LANG_FR \ + ? "Longs articles" \ + : "Long entries" \ +) + #define LBL_HEADER_PAGE_NUM (IS_LANG_FR \ ? "Page %1$d / %2$d (%3$d entrées)" \ : "Page %1$d / %2$d (%3$d entries)" \ @@ -63,6 +68,11 @@ extern int global_lang; : "Display starred entries" \ ) +#define LBL_MAINMENU_MODE_LONG_ENTRIES (IS_LANG_FR \ + ? "Lecture > 10 min" \ + : "Reading > 10mn" \ +) + #define LBL_MAINMENU_DELETE_ALL_LOCAL_DATA (IS_LANG_FR \ ? "Supprimer toutes les données locales" \ : "Delete all local data" \