mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Add Recent
list.
This commit is contained in:
@ -623,6 +623,36 @@ void ComicModel::setupReadingModelData(const QString &databasePath)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ComicModel::setupRecentModelData(const QString &databasePath)
|
||||
{
|
||||
enableResorting = false;
|
||||
mode = Recent;
|
||||
sourceId = -1;
|
||||
|
||||
beginResetModel();
|
||||
qDeleteAll(_data);
|
||||
_data.clear();
|
||||
|
||||
_databasePath = databasePath;
|
||||
|
||||
QString connectionName = "";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||
QSqlQuery selectQuery(db);
|
||||
selectQuery.prepare("SELECT " COMIC_MODEL_QUERY_FIELDS " "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"WHERE ci.added > :limit "
|
||||
"ORDER BY ci.added DESC");
|
||||
selectQuery.bindValue(":limit", QDateTime::currentDateTime().addDays(-recentDays).toSecsSinceEpoch());
|
||||
selectQuery.exec();
|
||||
|
||||
setupModelDataForList(selectQuery);
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ComicModel::setModelData(QList<ComicItem *> *data, const QString &databasePath)
|
||||
{
|
||||
_databasePath = databasePath;
|
||||
@ -923,6 +953,9 @@ void ComicModel::reload()
|
||||
case Reading:
|
||||
setupReadingModelData(_databasePath);
|
||||
break;
|
||||
case Recent:
|
||||
setupRecentModelData(_databasePath);
|
||||
break;
|
||||
case Label:
|
||||
setupLabelModelData(sourceId, _databasePath);
|
||||
break;
|
||||
@ -1155,6 +1188,9 @@ void ComicModel::setRecentRange(int days)
|
||||
this->recentDays = days;
|
||||
|
||||
emit dataChanged(index(0, 0), index(rowCount() - 1, 0), { ComicModel::RecentRangeRole });
|
||||
|
||||
if (mode == ComicModel::Recent)
|
||||
reload();
|
||||
}
|
||||
|
||||
void ComicModel::updateRating(int rating, QModelIndex mi)
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
Folder,
|
||||
Favorites,
|
||||
Reading,
|
||||
Recent,
|
||||
Label,
|
||||
ReadingList
|
||||
};
|
||||
@ -96,6 +97,7 @@ public:
|
||||
void setupReadingListModelData(unsigned long long int parentReadingList, const QString &databasePath);
|
||||
void setupFavoritesModelData(const QString &databasePath);
|
||||
void setupReadingModelData(const QString &databasePath);
|
||||
void setupRecentModelData(const QString &databasePath);
|
||||
|
||||
// Métodos de conveniencia
|
||||
QStringList getPaths(const QString &_source);
|
||||
|
@ -82,7 +82,7 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
if (role == ReadingListModel::SpecialListTypeRole && typeid(*item) == typeid(SpecialListItem)) {
|
||||
auto specialListItem = static_cast<SpecialListItem *>(item);
|
||||
return QVariant(specialListItem->getType());
|
||||
return QVariant::fromValue(specialListItem->getType());
|
||||
}
|
||||
|
||||
if (typeid(*item) == typeid(ReadingListSeparatorItem))
|
||||
@ -196,7 +196,10 @@ bool ReadingListModel::canDropMimeData(const QMimeData *data, Qt::DropAction act
|
||||
if (row == -1) // no list
|
||||
return false;
|
||||
|
||||
if (row == 1) // reading is just an smart list
|
||||
if (row == 1) // reading is just a smart list
|
||||
return false;
|
||||
|
||||
if (row == 2) // recent is just a smart list
|
||||
return false;
|
||||
|
||||
if (rowIsSeparator(row, parent))
|
||||
@ -609,8 +612,8 @@ QList<SpecialListItem *> ReadingListModel::setupSpecialLists(QSqlDatabase &db)
|
||||
<< selectQuery.value(id));
|
||||
}
|
||||
|
||||
// Reading after Favorites, Why? Because I want to :P
|
||||
list.insert(1, new SpecialListItem(QList<QVariant>() << "Reading" << 0));
|
||||
list.insert(2, new SpecialListItem(QList<QVariant>() << "Recent" << 2));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
@ -69,9 +69,10 @@ public:
|
||||
Separator
|
||||
};
|
||||
|
||||
enum TypeSpecialList {
|
||||
Reading,
|
||||
Favorites
|
||||
enum class TypeSpecialList : int {
|
||||
Reading = 0,
|
||||
Favorites,
|
||||
Recent,
|
||||
};
|
||||
|
||||
signals:
|
||||
|
@ -96,6 +96,8 @@
|
||||
|
||||
<file>../images/lists/default_0.svg</file>
|
||||
<file>../images/lists/default_1.svg</file>
|
||||
<file>../images/lists/default_2.svg</file>
|
||||
|
||||
<file>../images/lists/label_blue.svg</file>
|
||||
<file>../images/lists/label_cyan.svg</file>
|
||||
<file>../images/lists/label_dark.svg</file>
|
||||
|
@ -102,12 +102,15 @@ void YACReaderNavigationController::loadSpecialListInfo(const QModelIndex &model
|
||||
ReadingListModel::TypeSpecialList type = (ReadingListModel::TypeSpecialList)modelIndex.data(ReadingListModel::SpecialListTypeRole).toInt();
|
||||
|
||||
switch (type) {
|
||||
case ReadingListModel::Favorites:
|
||||
case ReadingListModel::TypeSpecialList::Favorites:
|
||||
libraryWindow->comicsModel->setupFavoritesModelData(libraryWindow->foldersModel->getDatabase());
|
||||
break;
|
||||
case ReadingListModel::Reading:
|
||||
case ReadingListModel::TypeSpecialList::Reading:
|
||||
libraryWindow->comicsModel->setupReadingModelData(libraryWindow->foldersModel->getDatabase());
|
||||
break;
|
||||
case ReadingListModel::TypeSpecialList::Recent:
|
||||
libraryWindow->comicsModel->setupRecentModelData(libraryWindow->foldersModel->getDatabase());
|
||||
break;
|
||||
}
|
||||
|
||||
contentViewsManager->comicsView->setModel(libraryWindow->comicsModel);
|
||||
@ -118,14 +121,18 @@ void YACReaderNavigationController::loadSpecialListInfo(const QModelIndex &model
|
||||
} else {
|
||||
// setup empty special list widget
|
||||
switch (type) {
|
||||
case ReadingListModel::Favorites:
|
||||
case ReadingListModel::TypeSpecialList::Favorites:
|
||||
contentViewsManager->emptySpecialList->setPixmap(QPixmap(":/images/empty_favorites.png"));
|
||||
contentViewsManager->emptySpecialList->setText(tr("No favorites"));
|
||||
break;
|
||||
case ReadingListModel::Reading:
|
||||
case ReadingListModel::TypeSpecialList::Reading:
|
||||
contentViewsManager->emptySpecialList->setPixmap(QPixmap(":/images/empty_current_readings.png"));
|
||||
contentViewsManager->emptySpecialList->setText(tr("You are not reading anything yet, come on!!"));
|
||||
break;
|
||||
case ReadingListModel::TypeSpecialList::Recent:
|
||||
contentViewsManager->emptySpecialList->setPixmap(QPixmap());
|
||||
contentViewsManager->emptySpecialList->setText(tr("There are no recent comics!"));
|
||||
break;
|
||||
}
|
||||
|
||||
contentViewsManager->showEmptySpecialList();
|
||||
|
Reference in New Issue
Block a user