mirror of
https://github.com/YACReader/yacreader
synced 2025-07-17 20:44:32 -04:00
Corregido bug relacionado con la comunicaci?n entre ComicFlowGL y la TableView
Modificados los .pro para a?adir las opciones de compilaci?n para VisualStudio A?adida la clase DBHelper para aislar el servidor web de la UI
This commit is contained in:
@ -11,6 +11,9 @@ INCLUDEPATH += ../common
|
||||
win32 {
|
||||
INCLUDEPATH += ../dependencies/poppler/include
|
||||
LIBS += -L../dependencies/poppler/lib -lpoppler-qt4
|
||||
QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
|
||||
QMAKE_LFLAGS_RELEASE += /LTCG
|
||||
CONFIG -= embed_manifest_exe
|
||||
}
|
||||
|
||||
unix:!macx{
|
||||
|
@ -10,10 +10,15 @@ INCLUDEPATH += ../common \
|
||||
./server \
|
||||
./db \
|
||||
../YACReader
|
||||
|
||||
DEFINES += SERVER_RELEASE
|
||||
|
||||
win32 {
|
||||
INCLUDEPATH += ../dependencies/poppler/include
|
||||
LIBS += -L../dependencies/poppler/lib -lpoppler-qt4
|
||||
QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
|
||||
QMAKE_LFLAGS_RELEASE += /LTCG
|
||||
CONFIG -= embed_manifest_exe
|
||||
}
|
||||
|
||||
unix:!macx{
|
||||
@ -51,6 +56,7 @@ HEADERS += comic_flow.h \
|
||||
import_comics_info_dialog.h \
|
||||
server_config_dialog.h \
|
||||
comic_flow_widget.h \
|
||||
db_helper.h \
|
||||
./db/data_base_management.h \
|
||||
./db/treeitem.h \
|
||||
./db/treemodel.h \
|
||||
@ -85,6 +91,7 @@ SOURCES += comic_flow.cpp \
|
||||
import_comics_info_dialog.cpp \
|
||||
server_config_dialog.cpp \
|
||||
comic_flow_widget.cpp \
|
||||
db_helper.cpp \
|
||||
./db/data_base_management.cpp \
|
||||
./db/treeitem.cpp \
|
||||
./db/treemodel.cpp \
|
||||
|
123
YACReaderLibrary/db_helper.cpp
Normal file
123
YACReaderLibrary/db_helper.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
#include "db_helper.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QCoreApplication>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "library_item.h"
|
||||
#include "comic_db.h"
|
||||
#include "data_base_management.h"
|
||||
#include "folder.h"
|
||||
|
||||
//server
|
||||
|
||||
//TODO optimizar, evitar que se tenga que leer en cada petición el archivo
|
||||
//conservar un QDateTime stático que compruebe si libraries.yacr ha sido modificado
|
||||
//libraries debe ser una variable estática
|
||||
static QDateTime lastModified;
|
||||
static QMap<QString,QString> libraries;
|
||||
|
||||
QMap<QString,QString> DBHelper::getLibraries()
|
||||
{
|
||||
QFileInfo fi(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
if(fi.lastModified() == lastModified)
|
||||
return libraries;
|
||||
|
||||
lastModified = fi.lastModified();
|
||||
libraries.clear();
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QTextStream txtS(&f);
|
||||
QString content = txtS.readAll();
|
||||
QStringList lines = content.split('\n');
|
||||
QString line,name;
|
||||
int i=0;
|
||||
foreach(line,lines)
|
||||
{
|
||||
if((i%2)==0)
|
||||
{
|
||||
name = line;
|
||||
}
|
||||
else
|
||||
{
|
||||
libraries.insert(name.trimmed(),line.trimmed());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
f.close();
|
||||
return libraries;
|
||||
}
|
||||
QList<LibraryItem *> DBHelper::getFolderContentFromLibrary(const QString & libraryName, qulonglong folderId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<LibraryItem *> list = Folder::getFoldersFromParent(folderId,db,false);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
return list;
|
||||
}
|
||||
QList<LibraryItem *> DBHelper::getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<LibraryItem *> list = ComicDB::getComicsFromParent(folderId,db,false);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
return list;
|
||||
}
|
||||
qulonglong DBHelper::getParentFromComicFolderId(const QString & libraryName, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
Folder f(id,db);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
return f.parentId;
|
||||
}
|
||||
ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
ComicDB comic;
|
||||
comic.load(id,db);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
return comic;
|
||||
}
|
||||
QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QString name="";
|
||||
|
||||
{
|
||||
QSqlQuery selectQuery(db); //TODO check
|
||||
selectQuery.prepare("SELECT name FROM folder WHERE id = :id");
|
||||
selectQuery.bindValue(":id", id);
|
||||
selectQuery.exec();
|
||||
|
||||
if(selectQuery.next())
|
||||
{
|
||||
QSqlRecord record = selectQuery.record();
|
||||
name = record.value(0).toString();
|
||||
}
|
||||
}
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
return name;
|
||||
}
|
22
YACReaderLibrary/db_helper.h
Normal file
22
YACReaderLibrary/db_helper.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef DB_HELPER_H
|
||||
#define DB_HELPER_H
|
||||
|
||||
class QString;
|
||||
class LibraryItem;
|
||||
class ComicDB;
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
|
||||
class DBHelper
|
||||
{
|
||||
public:
|
||||
//server
|
||||
static QMap<QString,QString> getLibraries();
|
||||
static QList<LibraryItem *> getFolderContentFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
||||
static ComicDB getComicInfo(const QString & libraryName, qulonglong id);
|
||||
static QString getFolderName(const QString & libraryName, qulonglong id);
|
||||
};
|
||||
|
||||
#endif
|
@ -843,17 +843,21 @@ void LibraryWindow::reloadCovers()
|
||||
|
||||
void LibraryWindow::centerComicFlow(const QModelIndex & mi)
|
||||
{
|
||||
int distance = comicFlow->centerIndex()-mi.row();
|
||||
if(abs(distance)>10)
|
||||
//TODO corregir el comportamiento de ComicFlowWidgetSW para evitar skip
|
||||
if(typeid(comicFlow) == typeid(ComicFlowWidgetSW))
|
||||
{
|
||||
if(distance<0)
|
||||
comicFlow->setCenterIndex(comicFlow->centerIndex()+(-distance)-10);
|
||||
int distance = comicFlow->centerIndex()-mi.row();
|
||||
if(abs(distance)>10)
|
||||
{
|
||||
if(distance<0)
|
||||
comicFlow->setCenterIndex(comicFlow->centerIndex()+(-distance)-10);
|
||||
else
|
||||
comicFlow->setCenterIndex(comicFlow->centerIndex()-distance+10);
|
||||
skip = 10;
|
||||
}
|
||||
else
|
||||
comicFlow->setCenterIndex(comicFlow->centerIndex()-distance+10);
|
||||
skip = 10;
|
||||
skip = abs(comicFlow->centerIndex()-mi.row());
|
||||
}
|
||||
else
|
||||
skip = abs(comicFlow->centerIndex()-mi.row());
|
||||
comicFlow->showSlide(mi.row());
|
||||
comicFlow->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
|
@ -5,11 +5,8 @@
|
||||
#define PICTUREFLOW_QT4 1
|
||||
|
||||
//interfaz al servidor
|
||||
LibraryWindow * mw;
|
||||
Startup * s;
|
||||
|
||||
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
@ -25,11 +22,9 @@ int main( int argc, char ** argv )
|
||||
s->start();
|
||||
#endif
|
||||
|
||||
mw = new LibraryWindow();
|
||||
LibraryWindow * mw = new LibraryWindow();
|
||||
mw->resize(800,480);
|
||||
mw->showMaximized();
|
||||
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "comiccontroller.h"
|
||||
|
||||
#include "library_window.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
#include "db_helper.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
@ -33,12 +31,17 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
// response.write("",true);
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
|
||||
QMap<QString,QString> libraries = mw->getLibraries();
|
||||
//Aplicar a todos los controladores
|
||||
//TODO usar LibraryWindow para acceder a informaci<63>n de las bases de datos est<73> mal, hay
|
||||
//que crear una clase que se encargue de estas cosas
|
||||
//<2F>Se est<73> accediendo a la UI desde un hilo?
|
||||
|
||||
QMap<QString,QString> libraries = DBHelper::getLibraries();
|
||||
|
||||
|
||||
ComicDB comic = mw->getComicInfo(libraryName, comicId);
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryName, comicId);
|
||||
|
||||
session.setDownloadedComic(comic.info.hash);
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
#include "covercontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
CoverController::CoverController() {}
|
||||
|
||||
void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||
@ -17,7 +15,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||
response.setHeader("Connection","close");
|
||||
//response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
|
||||
QMap<QString,QString> libraries = mw->getLibraries();
|
||||
QMap<QString,QString> libraries = DBHelper::getLibraries();
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||
QStringList pathElements = path.split('/');
|
||||
@ -55,5 +53,11 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||
img.save(&buffer, "JPG");
|
||||
response.write(ba,true);
|
||||
}
|
||||
//DONE else, hay que devolver un 404
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
#include "errorcontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
ErrorController::ErrorController(int errorCode)
|
||||
:error(errorCode)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "foldercontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "folder.h"
|
||||
|
||||
@ -16,8 +17,6 @@ struct LibraryItemSorter
|
||||
}
|
||||
};
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
FolderController::FolderController() {}
|
||||
|
||||
void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
@ -36,13 +35,13 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = pathElements.at(2);
|
||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||
QString folderName = mw->getFolderName(libraryName,parentId);
|
||||
QString folderName = DBHelper::getFolderName(libraryName,parentId);
|
||||
if(parentId!=1)
|
||||
t.setVariable("folder.name",folderName);
|
||||
else
|
||||
t.setVariable("folder.name",libraryName);
|
||||
QList<LibraryItem *> folderContent = mw->getFolderContentFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderComics = mw->getFolderComicsFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderContentFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryName,parentId);
|
||||
|
||||
//response.writeText(libraryName);
|
||||
|
||||
@ -51,7 +50,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter());
|
||||
folderComics.clear();
|
||||
|
||||
qulonglong backId = mw->getParentFromComicFolderId(libraryName,parentId);
|
||||
qulonglong backId = DBHelper::getParentFromComicFolderId(libraryName,parentId);
|
||||
|
||||
int page = 0;
|
||||
QByteArray p = request.getParameter("page");
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "folderinfocontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "folder.h"
|
||||
#include "comic_db.h"
|
||||
@ -7,7 +7,6 @@
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
FolderInfoController::FolderInfoController() {}
|
||||
|
||||
@ -19,8 +18,8 @@ void FolderInfoController::service(HttpRequest& request, HttpResponse& response)
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = pathElements.at(2);
|
||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||
QList<LibraryItem *> folderContent = mw->getFolderContentFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderComics = mw->getFolderComicsFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderContentFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryName,parentId);
|
||||
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
|
@ -1,11 +1,9 @@
|
||||
#include "librariescontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
LibrariesController::LibrariesController() {}
|
||||
|
||||
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
@ -40,7 +38,7 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
|
||||
QMap<QString,QString> libraries = mw->getLibraries();
|
||||
QMap<QString,QString> libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = libraries.keys();
|
||||
|
||||
t.loop("library",names.length());
|
||||
|
@ -20,9 +20,7 @@
|
||||
#include "controllers/pagecontroller.h"
|
||||
#include "controllers/errorcontroller.h"
|
||||
|
||||
#include "library_window.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
#include "db_helper.h"
|
||||
|
||||
RequestMapper::RequestMapper(QObject* parent)
|
||||
:HttpRequestHandler(parent) {}
|
||||
@ -55,7 +53,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
if(!session.isNull() && session.contains("ySession"))
|
||||
{
|
||||
if(library.indexIn(path)!=-1 && mw->getLibraries().contains(library.cap(1)) )
|
||||
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1)) )
|
||||
{
|
||||
//listar el contenido del folder
|
||||
if(folder.exactMatch(path))
|
||||
|
Reference in New Issue
Block a user