mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Added new methods for getting reading lists and comics in a reading list. Fixed DBHelper for not using GUI related classes (reading_list_item).
This commit is contained in:
parent
d20277736d
commit
85fba7e8f5
@ -14,7 +14,7 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "reading_list_item.h"
|
||||
#include "reading_list.h"
|
||||
#include "library_item.h"
|
||||
#include "comic_db.h"
|
||||
#include "data_base_management.h"
|
||||
@ -286,6 +286,94 @@ QList<ComicDB> DBHelper::getReading(qulonglong libraryId)
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<ReadingList> DBHelper::getReadingLists(qulonglong libraryId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<ReadingList> list;
|
||||
|
||||
QSqlQuery selectQuery("SELECT * from reading_list WHERE parentId IS NULL ORDER BY name DESC",db);
|
||||
|
||||
selectQuery.exec();
|
||||
|
||||
while (selectQuery.next())
|
||||
{
|
||||
QSqlRecord record = selectQuery.record();
|
||||
|
||||
ReadingList item(record.value("name").toString(), record.value("id").toLongLong(),record.value("ordering").toInt());
|
||||
|
||||
if(list.isEmpty())
|
||||
{
|
||||
list.append(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i= 0;
|
||||
while(i<list.length() && naturalSortLessThanCI(list.at(i).getName(),item.getName()))
|
||||
i++;
|
||||
list.insert(i,item);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<ComicDB> DBHelper::getReadingListFullContent(qulonglong libraryId, qulonglong readingListId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<ComicDB> list;
|
||||
|
||||
{
|
||||
QList<qulonglong> ids;
|
||||
ids << readingListId;
|
||||
|
||||
QSqlQuery subfolders(db);
|
||||
subfolders.prepare("SELECT id "
|
||||
"FROM reading_list "
|
||||
"WHERE parentId = :parentId "
|
||||
"ORDER BY ordering ASC");
|
||||
subfolders.bindValue(":parentId", readingListId);
|
||||
subfolders.exec();
|
||||
while(subfolders.next())
|
||||
ids << subfolders.record().value(0).toULongLong();
|
||||
|
||||
foreach(qulonglong id, ids)
|
||||
{
|
||||
QSqlQuery selectQuery(db);
|
||||
selectQuery.prepare("SELECT c.id,c.parentId,c.fileName,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) "
|
||||
"WHERE crl.reading_list_id = :parentReadingList "
|
||||
"ORDER BY crl.ordering");
|
||||
selectQuery.bindValue(":parentReadingList", id);
|
||||
selectQuery.exec();
|
||||
|
||||
while (selectQuery.next())
|
||||
{
|
||||
ComicDB comic;
|
||||
|
||||
QSqlRecord record = selectQuery.record();
|
||||
|
||||
comic.id = record.value(0).toULongLong();
|
||||
comic.parentId = record.value(1).toULongLong();
|
||||
comic.name = record.value(2).toString();
|
||||
comic.info.title = record.value(3).toString();
|
||||
comic.info.currentPage = record.value(4).toInt();
|
||||
comic.info.numPages = record.value(5).toInt();
|
||||
comic.info.hash = record.value(6).toString();
|
||||
comic.info.read = record.value(7).toBool();
|
||||
|
||||
list.append(comic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
//objects management
|
||||
//deletes
|
||||
void DBHelper::removeFromDB(LibraryItem * item, QSqlDatabase & db)
|
||||
@ -935,7 +1023,7 @@ QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDat
|
||||
QList<LibraryItem *>::iterator i;
|
||||
i = list.end();
|
||||
i--;
|
||||
while ((0 > (lessThan = naturalSortLessThanCI(nameCurrent,nameLast))) && i != list.begin())
|
||||
while ((0 > (lessThan = naturalCompare(nameCurrent,nameLast,Qt::CaseInsensitive))) && i != list.begin())
|
||||
{
|
||||
i--;
|
||||
nameLast = (*i)->name;
|
||||
@ -1098,22 +1186,18 @@ QList<LibraryItem *> DBHelper::getComicsFromParent(qulonglong parentId, QSqlData
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<LabelItem *> DBHelper::getLabelItems(qulonglong libraryId)
|
||||
QList<Label> DBHelper::getLabels(qulonglong libraryId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name",db); //TODO add some kind of
|
||||
QList<LabelItem *> labels;
|
||||
QList<Label> labels;
|
||||
|
||||
while(selectQuery.next())
|
||||
{
|
||||
QSqlRecord record = selectQuery.record();
|
||||
LabelItem *item = new LabelItem(QList<QVariant>()
|
||||
<< record.value("name")
|
||||
<< record.value("color")
|
||||
<< record.value("id")
|
||||
<< record.value("ordering"));
|
||||
Label item(record.value("name").toString(), record.value("id").toLongLong(), static_cast<YACReader::LabelColors>(record.value("color").toInt()));
|
||||
|
||||
if(labels.isEmpty())
|
||||
{
|
||||
@ -1123,14 +1207,14 @@ QList<LabelItem *> DBHelper::getLabelItems(qulonglong libraryId)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < labels.count() && (labels.at(i)->colorid() < item->colorid()) )
|
||||
while (i < labels.count() && (labels.at(i).getColorID() < item.getColorID()) )
|
||||
i++;
|
||||
|
||||
if(i < labels.count())
|
||||
{
|
||||
if(labels.at(i)->colorid() == item->colorid()) //sort by name
|
||||
if(labels.at(i).getColorID() == item.getColorID()) //sort by name
|
||||
{
|
||||
while( i < labels.count() && labels.at(i)->colorid() == item->colorid() && naturalSortLessThanCI(labels.at(i)->name(),item->name()))
|
||||
while( i < labels.count() && labels.at(i).getColorID() == item.getColorID() && naturalSortLessThanCI(labels.at(i).getName(),item.getName()))
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ class QString;
|
||||
class ComicDB;
|
||||
class Folder;
|
||||
class LibraryItem;
|
||||
class LabelItem;
|
||||
class Label;
|
||||
class QSqlDatabase;
|
||||
class ComicInfo;
|
||||
class QSqlRecord;
|
||||
class QSqlQuery;
|
||||
class YACReaderLibraries;
|
||||
class ReadingList;
|
||||
|
||||
class DBHelper
|
||||
{
|
||||
@ -34,6 +35,8 @@ public:
|
||||
static QList<ComicDB> getLabelComics(qulonglong libraryId, qulonglong labelId);
|
||||
static QList<ComicDB> getFavorites(qulonglong libraryId);
|
||||
static QList<ComicDB> getReading(qulonglong libraryId);
|
||||
static QList<ReadingList> getReadingLists(qulonglong libraryId);
|
||||
static QList<ComicDB> getReadingListFullContent(qulonglong libraryId, qulonglong readingListId);
|
||||
|
||||
//objects management
|
||||
//deletes
|
||||
@ -77,7 +80,7 @@ public:
|
||||
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||
static QList<ComicDB> getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db);
|
||||
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||
static QList<LabelItem *> getLabelItems(qulonglong libraryId);
|
||||
static QList<Label> getLabels(qulonglong libraryId);
|
||||
|
||||
//load
|
||||
static Folder loadFolder(qulonglong id, QSqlDatabase & db);
|
||||
|
Loading…
Reference in New Issue
Block a user