This commit is contained in:
Luis Ángel San Martín 2017-08-28 18:52:24 +02:00
commit 9ed1f0f306
14 changed files with 328 additions and 87 deletions

View File

@ -146,7 +146,8 @@ HEADERS += comic_flow.h \
yacreader_comics_views_manager.h \
info_comics_view.h \
yacreader_comics_selection_helper.h \
yacreader_comic_info_helper.h
yacreader_comic_info_helper.h \
db/reading_list.cpp
!CONFIG(no_opengl) {
CONFIG(legacy_gl_widget) {
@ -220,7 +221,8 @@ SOURCES += comic_flow.cpp \
yacreader_comics_views_manager.cpp \
info_comics_view.cpp \
yacreader_comics_selection_helper.cpp \
yacreader_comic_info_helper.cpp
yacreader_comic_info_helper.cpp \
db/reading_list.cpp
!CONFIG(no_opengl) {
CONFIG(legacy_gl_widget) {

View File

@ -0,0 +1,44 @@
#include "reading_list.h"
ReadingList::ReadingList(const QString &name, qulonglong id, int ordering)
:name(name), id(id), ordering(ordering)
{
}
qulonglong ReadingList::getId() const
{
return id;
}
QString ReadingList::getName() const
{
return name;
}
int ReadingList::getOrdering() const
{
return ordering;
}
Label::Label(const QString &name, qulonglong id, YACReader::LabelColors colorid)
:name(name), id(id), colorid(colorid)
{
}
YACReader::LabelColors Label::getColorID() const
{
return colorid;
}
QString Label::getName() const
{
return name;
}
qulonglong Label::getId() const
{
return id;
}

View File

@ -0,0 +1,36 @@
#ifndef READING_LIST_H
#define READING_LIST_H
#include "yacreader_global.h"
class ReadingList
{
public:
ReadingList(const QString &name, qulonglong id, int ordering);
qulonglong getId() const;
QString getName() const;
int getOrdering() const;
private:
QString name;
qulonglong id;
int ordering;
};
class Label
{
public:
Label(const QString &name, qulonglong id, YACReader::LabelColors colorid);
YACReader::LabelColors getColorID() const;
QString getName() const;
qulonglong getId() const;
private:
QString name;
qulonglong id;
YACReader::LabelColors colorid;
};
#endif // READING_LIST_H

View File

@ -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"
@ -276,6 +276,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)
@ -930,7 +1018,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;
@ -1138,13 +1226,13 @@ 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;
QSqlRecord record = selectQuery.record();
@ -1155,11 +1243,9 @@ QList<LabelItem *> DBHelper::getLabelItems(qulonglong libraryId)
while(selectQuery.next())
{
LabelItem *item = new LabelItem(QList<QVariant>()
<< selectQuery.value(name)
<< selectQuery.value(color)
<< selectQuery.value(id)
<< selectQuery.value(ordering));
Label item(selectQuery.value(name).toString(),
selectQuery.value(id).toLongLong(),
static_cast<YACReader::LabelColors>(selectQuery.value(color).toInt()));
if(labels.isEmpty())
{
@ -1169,14 +1255,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++;
}
}

View File

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

View File

@ -0,0 +1,35 @@
#include "readinglistcontentcontroller.h"
#include "db_helper.h"
#include "comic_db.h"
#include "yacreader_server_data_helper.h"
ReadingListContentController::ReadingListContentController()
{
}
void ReadingListContentController::service(HttpRequest &request, HttpResponse &response)
{
response.setHeader("Content-Type", "text/plain; charset=utf-8");
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
int libraryId = pathElements.at(2).toInt();
qulonglong readingListId = pathElements.at(4).toULongLong();
serviceContent(libraryId, readingListId, response);
response.write("",true);
}
void ReadingListContentController::serviceContent(const int &library, const qulonglong &readingListId, HttpResponse &response)
{
QList<ComicDB> comics = DBHelper::getReadingListFullContent(library, readingListId);
for(const ComicDB &comic : comics)
{
response.write(YACReaderServerDataHelper::comicToYSFormat(library, comic).toUtf8());
}
}

View File

@ -0,0 +1,20 @@
#ifndef READINGLISTCONTENTCONTROLLER_H
#define READINGLISTCONTENTCONTROLLER_H
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class ReadingListContentController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(ReadingListContentController)
public:
ReadingListContentController();
void service(HttpRequest& request, HttpResponse& response);
private:
void serviceContent(const int &library, const qulonglong &readingListId, HttpResponse &response);
};
#endif // READINGLISTCONTENTCONTROLLER_H

View File

@ -1,5 +1,8 @@
#include "readinglistscontroller.h"
#include "db_helper.h"
#include "reading_list.h"
ReadingListsController::ReadingListsController()
{
@ -20,5 +23,10 @@ void ReadingListsController::service(HttpRequest &request, HttpResponse &respons
void ReadingListsController::serviceContent(const int library, HttpResponse &response)
{
QList<ReadingList> readingLists = DBHelper::getReadingLists(library);
foreach(const ReadingList &item, readingLists)
{
response.write(QString("%1\t%2\t%3\r\n").arg(library).arg(item.getId()).arg(item.getName()).toUtf8());
}
}

View File

@ -3,7 +3,7 @@
#include "db_helper.h"
#include "yacreader_libraries.h"
#include "reading_list_item.h"
#include "reading_list.h"
#include "../static.h"
#include "yacreader_global.h"
@ -19,11 +19,11 @@ void TagsController::service(HttpRequest& request, HttpResponse& response)
QStringList pathElements = path.split('/');
int libraryId = pathElements.at(2).toInt();
QList<LabelItem *> tags = DBHelper::getLabelItems(libraryId);
QList<Label> tags = DBHelper::getLabels(libraryId);
foreach(LabelItem * tag, tags)
foreach(const Label &tag, tags)
{
response.write(QString("%1\t%2\t%3\r\n").arg(tag->getId()).arg(tag->name()).arg(labelColorToRGBString(tag->colorid())).toUtf8());
response.write(QString("%1\t%2\t%3\t%4\r\n").arg(libraryId).arg(tag.getId()).arg(tag.getName()).arg(labelColorToRGBString(tag.getColorID())).toUtf8());
}
response.write("",true);

View File

@ -28,6 +28,8 @@
#include "controllers/tagcontentcontroller.h"
#include "controllers/favoritescontroller.h"
#include "controllers/readingcomicscontroller.h"
#include "controllers/readinglistscontroller.h"
#include "controllers/readinglistcontentcontroller.h"
#include "db_helper.h"
#include "yacreader_libraries.h"
@ -211,11 +213,11 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
}
else if(readingLists.exactMatch(path))
{
//ReadingListsController().service(request, response);
ReadingListsController().service(request, response);
}
else if(readingListContent.exactMatch(path))
{
//ReadingListContentController().service(request, response);
ReadingListContentController().service(request, response);
}
}
else

View File

@ -1,62 +1,64 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += \
$$PWD/static.h \
$$PWD/startup.h \
$$PWD/requestmapper.h \
$$PWD/controllers/comiccontroller.h \
$$PWD/controllers/errorcontroller.h \
$$PWD/controllers/foldercontroller.h \
$$PWD/controllers/folderinfocontroller.h \
$$PWD/controllers/librariescontroller.h \
$$PWD/controllers/pagecontroller.h \
$$PWD/controllers/sessionmanager.h \
$$PWD/controllers/covercontroller.h \
$$PWD/controllers/updatecomiccontroller.h \
$$PWD/controllers/comicdownloadinfocontroller.h \
$$PWD/controllers/synccontroller.h \
#v2
$$PWD/controllers/versioncontroller.h \
$$PWD/controllers/foldercontentcontroller.h \
$$PWD/controllers/tagscontroller.h \
$$PWD/yacreader_http_session.h \
$$PWD/yacreader_http_session_store.h \
$$PWD/controllers/tagcontentcontroller.h \
$$PWD/yacreader_server_data_helper.h \
$$PWD/controllers/favoritescontroller.h \
$$PWD/controllers/readingcomicscontroller.h \
$$PWD/controllers/readinglistscontroller.h
SOURCES += \
$$PWD/static.cpp \
$$PWD/startup.cpp \
$$PWD/requestmapper.cpp \
$$PWD/controllers/comiccontroller.cpp \
$$PWD/controllers/errorcontroller.cpp \
$$PWD/controllers/foldercontroller.cpp \
$$PWD/controllers/folderinfocontroller.cpp \
$$PWD/controllers/librariescontroller.cpp \
$$PWD/controllers/pagecontroller.cpp \
$$PWD/controllers/sessionmanager.cpp \
$$PWD/controllers/covercontroller.cpp \
$$PWD/controllers/updatecomiccontroller.cpp \
$$PWD/controllers/comicdownloadinfocontroller.cpp \
$$PWD/controllers/synccontroller.cpp \
#v2
$$PWD/controllers/versioncontroller.cpp \
$$PWD/controllers/foldercontentcontroller.cpp \
$$PWD/controllers/tagscontroller.cpp \
$$PWD/yacreader_http_session.cpp \
$$PWD/yacreader_http_session_store.cpp \
$$PWD/controllers/tagcontentcontroller.cpp \
$$PWD/yacreader_server_data_helper.cpp \
$$PWD/controllers/favoritescontroller.cpp \
$$PWD/controllers/readingcomicscontroller.cpp \
$$PWD/controllers/readinglistscontroller.cpp
include(lib/logging/logging.pri)
include(lib/httpserver/httpserver.pri)
include(lib/templateengine/templateengine.pri)
DEFINES += SERVER_VERSION_NUMBER=\\\"2.0\\\"
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += \
$$PWD/static.h \
$$PWD/startup.h \
$$PWD/requestmapper.h \
$$PWD/controllers/comiccontroller.h \
$$PWD/controllers/errorcontroller.h \
$$PWD/controllers/foldercontroller.h \
$$PWD/controllers/folderinfocontroller.h \
$$PWD/controllers/librariescontroller.h \
$$PWD/controllers/pagecontroller.h \
$$PWD/controllers/sessionmanager.h \
$$PWD/controllers/covercontroller.h \
$$PWD/controllers/updatecomiccontroller.h \
$$PWD/controllers/comicdownloadinfocontroller.h \
$$PWD/controllers/synccontroller.h \
#v2
$$PWD/controllers/versioncontroller.h \
$$PWD/controllers/foldercontentcontroller.h \
$$PWD/controllers/tagscontroller.h \
$$PWD/yacreader_http_session.h \
$$PWD/yacreader_http_session_store.h \
$$PWD/controllers/tagcontentcontroller.h \
$$PWD/yacreader_server_data_helper.h \
$$PWD/controllers/favoritescontroller.h \
$$PWD/controllers/readingcomicscontroller.h \
$$PWD/controllers/readinglistscontroller.h \
$$PWD/controllers/readinglistcontentcontroller.h
SOURCES += \
$$PWD/static.cpp \
$$PWD/startup.cpp \
$$PWD/requestmapper.cpp \
$$PWD/controllers/comiccontroller.cpp \
$$PWD/controllers/errorcontroller.cpp \
$$PWD/controllers/foldercontroller.cpp \
$$PWD/controllers/folderinfocontroller.cpp \
$$PWD/controllers/librariescontroller.cpp \
$$PWD/controllers/pagecontroller.cpp \
$$PWD/controllers/sessionmanager.cpp \
$$PWD/controllers/covercontroller.cpp \
$$PWD/controllers/updatecomiccontroller.cpp \
$$PWD/controllers/comicdownloadinfocontroller.cpp \
$$PWD/controllers/synccontroller.cpp \
#v2
$$PWD/controllers/versioncontroller.cpp \
$$PWD/controllers/foldercontentcontroller.cpp \
$$PWD/controllers/tagscontroller.cpp \
$$PWD/yacreader_http_session.cpp \
$$PWD/yacreader_http_session_store.cpp \
$$PWD/controllers/tagcontentcontroller.cpp \
$$PWD/yacreader_server_data_helper.cpp \
$$PWD/controllers/favoritescontroller.cpp \
$$PWD/controllers/readingcomicscontroller.cpp \
$$PWD/controllers/readinglistscontroller.cpp \
$$PWD/controllers/readinglistcontentcontroller.cpp
include(lib/logging/logging.pri)
include(lib/httpserver/httpserver.pri)
include(lib/templateengine/templateengine.pri)
DEFINES += SERVER_VERSION_NUMBER=\\\"2.0\\\"

View File

@ -60,7 +60,8 @@ HEADERS += ../YACReaderLibrary/library_creator.h \
../common/http_worker.h \
../YACReaderLibrary/yacreader_libraries.h \
../YACReaderLibrary/comic_files_manager.h \
console_ui_library_creator.h
console_ui_library_creator.h \
../YACReaderLibrary/db/reading_list.h
SOURCES += ../YACReaderLibrary/library_creator.cpp \
@ -81,6 +82,7 @@ SOURCES += ../YACReaderLibrary/library_creator.cpp \
../YACReaderLibrary/yacreader_libraries.cpp \
../YACReaderLibrary/comic_files_manager.cpp \
console_ui_library_creator.cpp \
../YACReaderLibrary/db/reading_list.cpp \
main.cpp
include(../YACReaderLibrary/server/server.pri)
@ -151,4 +153,4 @@ translation.files = ../release/languages/yacreaderlibrary_*
#manpage.path = $$DATADIR/man/man1
#manpage.files = ../YACReaderLibrary.1
}
}

View File

@ -7,6 +7,7 @@
#include <QFileInfo>
#include "library_item.h"
int naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity caseSensitivity);
bool naturalSortLessThanCS( const QString &left, const QString &right );
bool naturalSortLessThanCI( const QString &left, const QString &right );
bool naturalSortLessThanCIFileInfo(const QFileInfo & left,const QFileInfo & right);

View File

@ -10,7 +10,7 @@ extern"C" {
}
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
QObject(parent),valid(false),tools(true),numFiles(0),ar(NULL),stream(NULL)
QObject(parent),tools(true),valid(false),numFiles(0),ar(NULL),stream(NULL)
{
//open file
stream = ar_open_file(filePath.toStdString().c_str());