Add setting to control what "recent" is considered.

This commit is contained in:
Luis Ángel San Martín 2023-05-20 17:43:38 +02:00
parent 6a6a239cc7
commit 45af72520b
17 changed files with 86 additions and 14 deletions

View File

@ -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<int, QByteArray> 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);

View File

@ -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<int, QByteArray> roleNames() const override;
@ -172,6 +174,7 @@ private:
QString localizedDate(const QString &dbDate) const;
bool showRecent;
qlonglong recentDays;
signals:
void isEmpty();

View File

@ -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<QVariant> rootData;
rootData << "root"; // id 1, parent 1, title "root"
@ -100,6 +100,7 @@ QHash<int, QByteArray> 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());

View File

@ -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

View File

@ -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);

View File

@ -24,6 +24,7 @@ public:
void setContinueReadingModel(ComicModel *model);
void reloadContinueReadingModel();
void setShowRecent(bool visible);
void setRecentRange(int days);
FolderModel *currentFolderModel() { return folderModel; }
signals:

View File

@ -2756,6 +2756,8 @@ void LibraryWindow::reloadOptions()
contentViewsManager->comicsView->updateConfig(settings);
trayIconController->updateIconVisibility();
recentVisibilityCoordinator->updateTimeRange();
}
QString LibraryWindow::currentPath()

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -16,7 +16,7 @@ public:
public slots:
void toggleVisibility(bool visibility);
void setTimeRangeInDays(int days);
void updateTimeRange();
private:
QSettings *settings;

View File

@ -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)));

View File

@ -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 {