From 45af72520b78a0e5c8b03fe4924335db9662e281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 20 May 2023 17:43:38 +0200 Subject: [PATCH] Add setting to control what "recent" is considered. --- YACReaderLibrary/db/comic_model.cpp | 17 ++++++++++-- YACReaderLibrary/db/comic_model.h | 3 +++ YACReaderLibrary/db/folder_model.cpp | 18 +++++++++++-- YACReaderLibrary/db/folder_model.h | 3 +++ YACReaderLibrary/folder_content_view.cpp | 5 ++++ YACReaderLibrary/folder_content_view.h | 1 + YACReaderLibrary/library_window.cpp | 2 ++ YACReaderLibrary/options_dialog.cpp | 26 +++++++++++++++++-- YACReaderLibrary/options_dialog.h | 3 +++ YACReaderLibrary/qml/FolderContentView.qml | 2 +- YACReaderLibrary/qml/FolderContentView6.qml | 2 +- YACReaderLibrary/qml/GridComicsView.qml | 2 +- YACReaderLibrary/qml/GridComicsView6.qml | 2 +- .../recent_visibility_coordinator.cpp | 7 ++++- .../recent_visibility_coordinator.h | 2 +- YACReaderLibrary/yacreader_folders_view.cpp | 4 +-- common/yacreader_global_gui.h | 1 + 17 files changed, 86 insertions(+), 14 deletions(-) diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 08216740..844bcbeb 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -17,13 +17,13 @@ #include "QsLog.h" ComicModel::ComicModel(QObject *parent) - : QAbstractItemModel(parent), showRecent(false) + : QAbstractItemModel(parent), showRecent(false), recentDays(1) { } ComicModel::ComicModel(QSqlQuery &sqlquery, QObject *parent) - : QAbstractItemModel(parent), showRecent(false) + : QAbstractItemModel(parent), showRecent(false), recentDays(1) { setupModelData(sqlquery); } @@ -243,6 +243,7 @@ QHash ComicModel::roleNames() const roles[AddedRole] = "added_date"; roles[TypeRole] = "type"; roles[ShowRecentRole] = "show_recent"; + roles[RecentRangeRole] = "recent_range"; return roles; } @@ -311,6 +312,8 @@ QVariant ComicModel::data(const QModelIndex &index, int role) const return item->data(Type); else if (role == ShowRecentRole) return showRecent; + else if (role == ComicModel::RecentRangeRole) + return recentDays * 86400; if (role != Qt::DisplayRole) return QVariant(); @@ -1144,6 +1147,16 @@ void ComicModel::setShowRecent(bool showRecent) emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { ComicModel::ShowRecentRole }); } +void ComicModel::setRecentRange(int days) +{ + if (this->recentDays == days) + return; + + this->recentDays = days; + + emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { ComicModel::RecentRangeRole }); +} + void ComicModel::updateRating(int rating, QModelIndex mi) { ComicDB comic = getComic(mi); diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index 62e582d0..b7b6f854 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -60,6 +60,7 @@ public: AddedRole, TypeRole, ShowRecentRole, + RecentRangeRole, }; enum Mode { @@ -141,6 +142,7 @@ public: unsigned long long int getSourceId() { return sourceId; } void setShowRecent(bool visible); + void setRecentRange(int days); QHash roleNames() const override; @@ -172,6 +174,7 @@ private: QString localizedDate(const QString &dbDate) const; bool showRecent; + qlonglong recentDays; signals: void isEmpty(); diff --git a/YACReaderLibrary/db/folder_model.cpp b/YACReaderLibrary/db/folder_model.cpp index 73bd9a88..28c19634 100644 --- a/YACReaderLibrary/db/folder_model.cpp +++ b/YACReaderLibrary/db/folder_model.cpp @@ -52,12 +52,12 @@ void drawMacOSXFinishedFolderIcon() #define ROOT 1 FolderModel::FolderModel(QObject *parent) - : QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), folderIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder.svg")), folderFinishedIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.svg")), showRecent(false) + : QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), folderIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder.svg")), folderFinishedIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.svg")), showRecent(false), recentDays(1) { } FolderModel::FolderModel(QSqlQuery &sqlquery, QObject *parent) - : QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), showRecent(false) + : QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), showRecent(false), recentDays(1) { QList rootData; rootData << "root"; // id 1, parent 1, title "root" @@ -100,6 +100,7 @@ QHash FolderModel::roleNames() const roles[AddedRole] = "added"; roles[UpdatedRole] = "updated"; roles[ShowRecentRole] = "show_recent"; + roles[RecentRangeRole] = "recent_range"; return roles; } @@ -185,6 +186,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const if (role == FolderModel::ShowRecentRole) return showRecent; + if (role == FolderModel::RecentRangeRole) + return recentDays * 86400; + if (role != Qt::DisplayRole) return QVariant(); @@ -655,6 +659,16 @@ void FolderModel::setShowRecent(bool showRecent) emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { FolderModel::ShowRecentRole }); } +void FolderModel::setRecentRange(int days) +{ + if (this->recentDays == days) + return; + + this->recentDays = days; + + emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { FolderModel::RecentRangeRole }); +} + void FolderModel::deleteFolder(const QModelIndex &mi) { beginRemoveRows(mi.parent(), mi.row(), mi.row()); diff --git a/YACReaderLibrary/db/folder_model.h b/YACReaderLibrary/db/folder_model.h index 11238b0c..c8e286e7 100644 --- a/YACReaderLibrary/db/folder_model.h +++ b/YACReaderLibrary/db/folder_model.h @@ -82,6 +82,7 @@ public: Q_INVOKABLE QUrl getCoverUrlPathForComicHash(const QString &hash) const; void setShowRecent(bool showRecent); + void setRecentRange(int days); enum Columns { Name = 0, @@ -109,6 +110,7 @@ public: AddedRole, UpdatedRole, ShowRecentRole, + RecentRangeRole, }; bool isSubfolder; @@ -130,6 +132,7 @@ private: QIcon folderFinishedIcon; bool showRecent; + qlonglong recentDays; }; #endif diff --git a/YACReaderLibrary/folder_content_view.cpp b/YACReaderLibrary/folder_content_view.cpp index 69e31770..e474941d 100644 --- a/YACReaderLibrary/folder_content_view.cpp +++ b/YACReaderLibrary/folder_content_view.cpp @@ -212,6 +212,11 @@ void FolderContentView::setShowRecent(bool visible) folderModel->setShowRecent(visible); } +void FolderContentView::setRecentRange(int days) +{ + folderModel->setRecentRange(days); +} + void FolderContentView::openFolder(int index) { emit subfolderSelected(this->parent, index); diff --git a/YACReaderLibrary/folder_content_view.h b/YACReaderLibrary/folder_content_view.h index 865534aa..cebb548a 100644 --- a/YACReaderLibrary/folder_content_view.h +++ b/YACReaderLibrary/folder_content_view.h @@ -24,6 +24,7 @@ public: void setContinueReadingModel(ComicModel *model); void reloadContinueReadingModel(); void setShowRecent(bool visible); + void setRecentRange(int days); FolderModel *currentFolderModel() { return folderModel; } signals: diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index d5cd63a2..d149d1cd 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -2756,6 +2756,8 @@ void LibraryWindow::reloadOptions() contentViewsManager->comicsView->updateConfig(settings); trayIconController->updateIconVisibility(); + + recentVisibilityCoordinator->updateTimeRange(); } QString LibraryWindow::currentPath() diff --git a/YACReaderLibrary/options_dialog.cpp b/YACReaderLibrary/options_dialog.cpp index 2e629215..e155ff72 100644 --- a/YACReaderLibrary/options_dialog.cpp +++ b/YACReaderLibrary/options_dialog.cpp @@ -86,6 +86,18 @@ OptionsDialog::OptionsDialog(QWidget *parent) comicInfoXMLBoxLayout->addWidget(comicInfoXMLCheckbox); comicInfoXMLBox->setLayout(comicInfoXMLBoxLayout); + auto recentlyAddedBox = new QGroupBox(tr("Consider 'recent' items added or updated since X days ago")); + recentIntervalSlider = new QSlider(Qt::Horizontal); + recentIntervalSlider->setRange(1, 30); + auto recentlyAddedLayout = new QHBoxLayout(); + numDaysLabel = new QLabel(); + numDaysLabel->setMidLineWidth(50); + recentlyAddedLayout->addWidget(numDaysLabel); + recentlyAddedLayout->addWidget(recentIntervalSlider); + recentlyAddedBox->setLayout(recentlyAddedLayout); + + connect(recentIntervalSlider, &QAbstractSlider::valueChanged, this, &OptionsDialog::numDaysToConsiderRecentChanged); + // grid view background config useBackgroundImageCheck = new QCheckBox(tr("Enable background image")); @@ -152,6 +164,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) generalLayout->addWidget(shortcutsBox); generalLayout->addWidget(apiKeyBox); generalLayout->addWidget(comicInfoXMLBox); + generalLayout->addWidget(recentlyAddedBox); generalLayout->addStretch(); tabWidget->addTab(generalW, tr("General")); @@ -163,8 +176,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) layout->addWidget(tabWidget); layout->addLayout(buttons); setLayout(layout); - // restoreOptions(settings); //load options - // resize(200,0); setModal(true); setWindowTitle(tr("Options")); @@ -187,6 +198,8 @@ void OptionsDialog::restoreOptions(QSettings *settings) comicInfoXMLCheckbox->setChecked(settings->value(IMPORT_COMIC_INFO_XML_METADATA, false).toBool()); + recentIntervalSlider->setValue(settings->value(NUM_DAYS_TO_CONSIDER_RECENT, 1).toInt()); + bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool(); useBackgroundImageCheck->setChecked(useBackgroundImage); @@ -237,6 +250,15 @@ void OptionsDialog::useCurrentComicCoverCheckClicked(bool checked) emit optionsChanged(); } +void OptionsDialog::numDaysToConsiderRecentChanged(int value) +{ + settings->setValue(NUM_DAYS_TO_CONSIDER_RECENT, value); + + numDaysLabel->setText(QString("%1").arg(value)); + + emit optionsChanged(); +} + void OptionsDialog::resetToDefaults() { settings->setValue(OPACITY_BACKGROUND_IMAGE_IN_GRID_VIEW, 0.2); diff --git a/YACReaderLibrary/options_dialog.h b/YACReaderLibrary/options_dialog.h index c65500ac..84466a24 100644 --- a/YACReaderLibrary/options_dialog.h +++ b/YACReaderLibrary/options_dialog.h @@ -24,6 +24,7 @@ private slots: void backgroundImageOpacitySliderChanged(int value); void backgroundImageBlurRadiusSliderChanged(int value); void useCurrentComicCoverCheckClicked(bool checked); + void numDaysToConsiderRecentChanged(int value); void resetToDefaults(); private: @@ -38,6 +39,8 @@ private: QCheckBox *trayIconCheckbox; QCheckBox *startToTrayCheckbox; QCheckBox *comicInfoXMLCheckbox; + QSlider *recentIntervalSlider; + QLabel *numDaysLabel; }; #endif diff --git a/YACReaderLibrary/qml/FolderContentView.qml b/YACReaderLibrary/qml/FolderContentView.qml index 47aadd51..f73352e4 100644 --- a/YACReaderLibrary/qml/FolderContentView.qml +++ b/YACReaderLibrary/qml/FolderContentView.qml @@ -138,7 +138,7 @@ Rectangle { radius: 5 anchors { left: coverElement.left; top: coverElement.top; topMargin: 10; leftMargin: 10; } color: "#FFFFCC00" - visible: (((new Date() / 1000) - added) < 86400 || ((new Date() / 1000) - updated) < 86400) && show_recent + visible: (((new Date() / 1000) - added) < recent_range || ((new Date() / 1000) - updated) < recent_range) && show_recent } //border diff --git a/YACReaderLibrary/qml/FolderContentView6.qml b/YACReaderLibrary/qml/FolderContentView6.qml index 1e925c08..89a88b08 100644 --- a/YACReaderLibrary/qml/FolderContentView6.qml +++ b/YACReaderLibrary/qml/FolderContentView6.qml @@ -140,7 +140,7 @@ Rectangle { radius: 5 anchors { left: coverElement.left; top: coverElement.top; topMargin: 10; leftMargin: 10; } color: "#FFFFCC00" - visible: (((new Date() / 1000) - added) < 86400 || ((new Date() / 1000) - updated) < 86400) && show_recent + visible: (((new Date() / 1000) - added) < recent_range || ((new Date() / 1000) - updated) < recent_range) && show_recent } //border diff --git a/YACReaderLibrary/qml/GridComicsView.qml b/YACReaderLibrary/qml/GridComicsView.qml index d5ec996c..8de717fd 100644 --- a/YACReaderLibrary/qml/GridComicsView.qml +++ b/YACReaderLibrary/qml/GridComicsView.qml @@ -287,7 +287,7 @@ SplitView { radius: 5 anchors { left: coverElement.left; top: coverElement.top; topMargin: 5; leftMargin: 5; } color: "#FFFFCC00" - visible: (((new Date() / 1000) - added_date) < 86400) && show_recent + visible: (((new Date() / 1000) - added_date) < recent_range) && show_recent } //border diff --git a/YACReaderLibrary/qml/GridComicsView6.qml b/YACReaderLibrary/qml/GridComicsView6.qml index d410a9fb..8e0d63d7 100644 --- a/YACReaderLibrary/qml/GridComicsView6.qml +++ b/YACReaderLibrary/qml/GridComicsView6.qml @@ -290,7 +290,7 @@ SplitView { radius: 5 anchors { left: coverElement.left; top: coverElement.top; topMargin: 5; leftMargin: 5; } color: "#FFFFCC00" - visible: (((new Date() / 1000) - added_date) < 86400) && show_recent + visible: (((new Date() / 1000) - added_date) < recent_range) && show_recent } //border diff --git a/YACReaderLibrary/recent_visibility_coordinator.cpp b/YACReaderLibrary/recent_visibility_coordinator.cpp index 6670224f..f62979e2 100644 --- a/YACReaderLibrary/recent_visibility_coordinator.cpp +++ b/YACReaderLibrary/recent_visibility_coordinator.cpp @@ -7,6 +7,7 @@ RecentVisibilityCoordinator::RecentVisibilityCoordinator(QSettings *settings, Fo : QObject(), settings(settings), folderModel(folderModel), folderContentView(folderContentView), comicModel(comicModel) { updateVisibility(); + updateTimeRange(); } void RecentVisibilityCoordinator::toggleVisibility(bool visibility) @@ -16,8 +17,12 @@ void RecentVisibilityCoordinator::toggleVisibility(bool visibility) updateVisibility(); } -void RecentVisibilityCoordinator::setTimeRangeInDays(int days) +void RecentVisibilityCoordinator::updateTimeRange() { + auto days = settings->value(NUM_DAYS_TO_CONSIDER_RECENT, 1).toInt(); + folderModel->setRecentRange(days); + folderContentView->setRecentRange(days); + comicModel->setRecentRange(days); } void RecentVisibilityCoordinator::updateVisibility() diff --git a/YACReaderLibrary/recent_visibility_coordinator.h b/YACReaderLibrary/recent_visibility_coordinator.h index b1254953..22fb1db4 100644 --- a/YACReaderLibrary/recent_visibility_coordinator.h +++ b/YACReaderLibrary/recent_visibility_coordinator.h @@ -16,7 +16,7 @@ public: public slots: void toggleVisibility(bool visibility); - void setTimeRangeInDays(int days); + void updateTimeRange(); private: QSettings *settings; diff --git a/YACReaderLibrary/yacreader_folders_view.cpp b/YACReaderLibrary/yacreader_folders_view.cpp index f4f6ee92..333ebaa5 100644 --- a/YACReaderLibrary/yacreader_folders_view.cpp +++ b/YACReaderLibrary/yacreader_folders_view.cpp @@ -98,9 +98,9 @@ void YACReaderFoldersViewItemDeletegate::paint(QPainter *painter, const QStyleOp auto now = QDateTime::currentSecsSinceEpoch(); auto added = index.data(FolderModel::AddedRole).toLongLong(); auto updated = index.data(FolderModel::UpdatedRole).toLongLong(); - auto dayInSeconds = 86400; + auto daysInSeconds = index.data(FolderModel::RecentRangeRole).toLongLong(); - if (now - added < dayInSeconds || now - updated < dayInSeconds) { + if (now - added < daysInSeconds || now - updated < daysInSeconds) { painter->save(); #ifdef Q_OS_MAC painter->setBrush(QBrush(QColor(85, 95, 127))); diff --git a/common/yacreader_global_gui.h b/common/yacreader_global_gui.h index 9aed6620..00905095 100644 --- a/common/yacreader_global_gui.h +++ b/common/yacreader_global_gui.h @@ -72,6 +72,7 @@ #define USE_SELECTED_COMIC_COVER_AS_BACKGROUND_IMAGE_IN_GRID_VIEW "USE_SELECTED_COMIC_COVER_AS_BACKGROUND_IMAGE_IN_GRID_VIEW" #define DISPLAY_CONTINUE_READING_IN_GRID_VIEW "DISPLAY_CONTINUE_READING_IN_GRID_VIEW" #define DISPLAY_RECENTLY_INDICATOR "DISPLAY_RECENTLY_INDICATOR" +#define NUM_DAYS_TO_CONSIDER_RECENT "NUM_DAYS_TO_CONSIDER_RECENT" namespace YACReader {