mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Partial support for storing the cover information in the DB. Work in progress.
This commit is contained in:
parent
0c303e6ea3
commit
69395398e1
@ -3,6 +3,7 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include "library_creator.h"
|
#include "library_creator.h"
|
||||||
#include "check_new_version.h"
|
#include "check_new_version.h"
|
||||||
|
#include "db_helper.h"
|
||||||
|
|
||||||
|
|
||||||
static QString fields = "title ,"
|
static QString fields = "title ,"
|
||||||
@ -181,7 +182,8 @@ bool DataBaseManagement::createTables(QSqlDatabase & database)
|
|||||||
//new 7.1 fields
|
//new 7.1 fields
|
||||||
"comicVineID TEXT,"
|
"comicVineID TEXT,"
|
||||||
//new 8.6 fields
|
//new 8.6 fields
|
||||||
"lastTimeOpened INTEGER"
|
"lastTimeOpened INTEGER,"
|
||||||
|
"coverSizeRatio REAL" //h/w
|
||||||
|
|
||||||
")");
|
")");
|
||||||
success = success && queryComicInfo.exec();
|
success = success && queryComicInfo.exec();
|
||||||
@ -421,7 +423,9 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
|||||||
|
|
||||||
"comicVineID = :comicVineID,"
|
"comicVineID = :comicVineID,"
|
||||||
|
|
||||||
"lastTimeOpened = :lastTimeOpened"
|
"lastTimeOpened = :lastTimeOpened,"
|
||||||
|
|
||||||
|
"coverSizeRatio = :coverSizeRatio"
|
||||||
|
|
||||||
" WHERE hash = :hash ");
|
" WHERE hash = :hash ");
|
||||||
|
|
||||||
@ -456,6 +460,7 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
|||||||
"edited,"
|
"edited,"
|
||||||
"comicVineID,"
|
"comicVineID,"
|
||||||
"lastTimeOpened,"
|
"lastTimeOpened,"
|
||||||
|
"coverSizeRatio,"
|
||||||
"hash)"
|
"hash)"
|
||||||
|
|
||||||
"VALUES (:title,"
|
"VALUES (:title,"
|
||||||
@ -495,6 +500,8 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
|||||||
|
|
||||||
":lastTimeOpened,"
|
":lastTimeOpened,"
|
||||||
|
|
||||||
|
":coverSizeRatio,"
|
||||||
|
|
||||||
":hash )");
|
":hash )");
|
||||||
|
|
||||||
QSqlRecord record = newInfo.record();
|
QSqlRecord record = newInfo.record();
|
||||||
@ -607,6 +614,8 @@ void DataBaseManagement::bindValuesFromRecord(const QSqlRecord & record, QSqlQue
|
|||||||
|
|
||||||
bindString("lastTimeOpened",record,query);
|
bindString("lastTimeOpened",record,query);
|
||||||
|
|
||||||
|
bindDouble("coverSizeRatio",record,query);
|
||||||
|
|
||||||
bindString("hash",record,query);
|
bindString("hash",record,query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,6 +664,14 @@ void DataBaseManagement::bindInt(const QString & name, const QSqlRecord & record
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataBaseManagement::bindDouble(const QString & name, const QSqlRecord & record, QSqlQuery & query)
|
||||||
|
{
|
||||||
|
if(!record.value(name).isNull())
|
||||||
|
{
|
||||||
|
query.bindValue(":"+name,record.value(name).toDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString DataBaseManagement::checkValidDB(const QString & fullPath)
|
QString DataBaseManagement::checkValidDB(const QString & fullPath)
|
||||||
{
|
{
|
||||||
QSqlDatabase db = loadDatabaseFromFile(fullPath);
|
QSqlDatabase db = loadDatabaseFromFile(fullPath);
|
||||||
@ -787,11 +804,22 @@ bool DataBaseManagement::updateToCurrentVersion(const QString & fullPath)
|
|||||||
{//comic_info
|
{//comic_info
|
||||||
QStringList columnDefs;
|
QStringList columnDefs;
|
||||||
columnDefs << "lastTimeOpened INTEGER";
|
columnDefs << "lastTimeOpened INTEGER";
|
||||||
|
columnDefs << "coverSizeRatio REAL";
|
||||||
returnValue = returnValue && addColumns("comic_info", columnDefs, db);
|
returnValue = returnValue && addColumns("comic_info", columnDefs, db);
|
||||||
|
|
||||||
QSqlQuery queryIndexLastTimeOpened(db);
|
QSqlQuery queryIndexLastTimeOpened(db);
|
||||||
returnValue = returnValue && queryIndexLastTimeOpened.exec("CREATE INDEX last_time_opened_index ON comic_info (lastTimeOpened)");
|
returnValue = returnValue && queryIndexLastTimeOpened.exec("CREATE INDEX last_time_opened_index ON comic_info (lastTimeOpened)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update folders info
|
||||||
|
{
|
||||||
|
DBHelper::updateChildrenInfo(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO udate covers info
|
||||||
|
{
|
||||||
|
//cover sizes...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ private:
|
|||||||
QList<QString> dataBasesList;
|
QList<QString> dataBasesList;
|
||||||
static void bindString(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
static void bindString(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
||||||
static void bindInt(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
static void bindInt(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
||||||
|
static void bindDouble(const QString & name, const QSqlRecord & record, QSqlQuery & query);
|
||||||
static void bindValuesFromRecord(const QSqlRecord & record, QSqlQuery & query);
|
static void bindValuesFromRecord(const QSqlRecord & record, QSqlQuery & query);
|
||||||
|
|
||||||
static bool addColumns(const QString & tableName, const QStringList & columnDefs, const QSqlDatabase & db);
|
static bool addColumns(const QString & tableName, const QStringList & columnDefs, const QSqlDatabase & db);
|
||||||
|
@ -309,12 +309,14 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo &
|
|||||||
QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
|
QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
|
||||||
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(),relativePath,hash,_database);
|
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(),relativePath,hash,_database);
|
||||||
int numPages = 0;
|
int numPages = 0;
|
||||||
|
QPair<int,int> originalCoverSize = {0,0};
|
||||||
bool exists = checkCover(hash);
|
bool exists = checkCover(hash);
|
||||||
if(! ( comic.hasCover() && exists))
|
if(! ( comic.hasCover() && exists))
|
||||||
{
|
{
|
||||||
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg",comic.info.coverPage.toInt());
|
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg",comic.info.coverPage.toInt());
|
||||||
tc.create();
|
tc.create();
|
||||||
numPages = tc.getNumPages();
|
numPages = tc.getNumPages();
|
||||||
|
originalCoverSize = tc.getOriginalCoverSize();
|
||||||
if (numPages > 0)
|
if (numPages > 0)
|
||||||
{
|
{
|
||||||
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
||||||
@ -326,6 +328,12 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo &
|
|||||||
//en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos
|
//en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos
|
||||||
insertFolders();
|
insertFolders();
|
||||||
comic.info.numPages = numPages;
|
comic.info.numPages = numPages;
|
||||||
|
if(originalCoverSize.first > 0)
|
||||||
|
{
|
||||||
|
comic.info.originalCoverSize = QString("%1x%2").arg(originalCoverSize.first, originalCoverSize.second);
|
||||||
|
comic.info.coverSizeRatio = static_cast<float>(originalCoverSize.first) / originalCoverSize.second;
|
||||||
|
}
|
||||||
|
|
||||||
comic.parentId = _currentPathFolders.last().id;
|
comic.parentId = _currentPathFolders.last().id;
|
||||||
DBHelper::insert(&comic,_database);
|
DBHelper::insert(&comic,_database);
|
||||||
}
|
}
|
||||||
@ -640,6 +648,7 @@ void ThumbnailCreator::create()
|
|||||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||||
#endif //
|
#endif //
|
||||||
_cover = p;
|
_cover = p;
|
||||||
|
_coverSize = QPair<int,int>(p.width(), p.height());
|
||||||
if(_target!="")
|
if(_target!="")
|
||||||
{
|
{
|
||||||
QImage scaled;
|
QImage scaled;
|
||||||
@ -651,7 +660,7 @@ void ThumbnailCreator::create()
|
|||||||
{
|
{
|
||||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||||
}
|
}
|
||||||
scaled.save(_target,0,75);
|
scaled.save(_target,0,75);
|
||||||
}
|
}
|
||||||
else if(_target!="")
|
else if(_target!="")
|
||||||
{
|
{
|
||||||
@ -717,6 +726,7 @@ void ThumbnailCreator::create()
|
|||||||
QImage p;
|
QImage p;
|
||||||
if(p.loadFromData(archive.getRawDataAtIndex(index)))
|
if(p.loadFromData(archive.getRawDataAtIndex(index)))
|
||||||
{
|
{
|
||||||
|
_coverSize = QPair<int,int>(p.width(), p.height());
|
||||||
QImage scaled;
|
QImage scaled;
|
||||||
if(p.width()>p.height()) //landscape??
|
if(p.width()>p.height()) //landscape??
|
||||||
{
|
{
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
QString _target;
|
QString _target;
|
||||||
QString _currentName;
|
QString _currentName;
|
||||||
int _numPages;
|
int _numPages;
|
||||||
|
QPair<int,int> _coverSize;
|
||||||
QImage _cover;
|
QImage _cover;
|
||||||
int _coverPage;
|
int _coverPage;
|
||||||
static bool crash;
|
static bool crash;
|
||||||
@ -86,6 +87,7 @@
|
|||||||
void create();
|
void create();
|
||||||
int getNumPages(){return _numPages;}
|
int getNumPages(){return _numPages;}
|
||||||
QPixmap getCover(){return QPixmap::fromImage(_cover);}
|
QPixmap getCover(){return QPixmap::fromImage(_cover);}
|
||||||
|
QPair<int,int> getOriginalCoverSize(){return _coverSize;}
|
||||||
signals:
|
signals:
|
||||||
void openingError(QProcess::ProcessError error);
|
void openingError(QProcess::ProcessError error);
|
||||||
|
|
||||||
|
@ -237,6 +237,9 @@ ComicInfo & ComicInfo::operator=(const ComicInfo & comicInfo)
|
|||||||
|
|
||||||
lastTimeOpened = comicInfo.lastTimeOpened;
|
lastTimeOpened = comicInfo.lastTimeOpened;
|
||||||
|
|
||||||
|
coverSizeRatio = comicInfo.coverSizeRatio;
|
||||||
|
originalCoverSize = comicInfo.originalCoverSize;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,6 +554,9 @@ QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo)
|
|||||||
|
|
||||||
stream << comicInfo.lastTimeOpened;
|
stream << comicInfo.lastTimeOpened;
|
||||||
|
|
||||||
|
stream << comicInfo.coverSizeRatio;
|
||||||
|
stream << comicInfo.originalCoverSize;
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,6 +614,9 @@ QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo)
|
|||||||
stream >> comicInfo.comicVineID;
|
stream >> comicInfo.comicVineID;
|
||||||
|
|
||||||
stream >> comicInfo.lastTimeOpened;
|
stream >> comicInfo.lastTimeOpened;
|
||||||
|
|
||||||
|
stream >> comicInfo.coverSizeRatio;
|
||||||
|
stream >> comicInfo.originalCoverSize;
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,8 @@ public:
|
|||||||
QImage cover;
|
QImage cover;
|
||||||
|
|
||||||
QVariant lastTimeOpened;//integer/date
|
QVariant lastTimeOpened;//integer/date
|
||||||
|
QVariant coverSizeRatio;//h/w
|
||||||
|
QVariant originalCoverSize; //string "WxH"
|
||||||
|
|
||||||
/*void setTitle(QVariant value);
|
/*void setTitle(QVariant value);
|
||||||
|
|
||||||
@ -190,6 +192,9 @@ public:
|
|||||||
|
|
||||||
Q_PROPERTY(QVariant lastTimeOpened MEMBER lastTimeOpened CONSTANT)
|
Q_PROPERTY(QVariant lastTimeOpened MEMBER lastTimeOpened CONSTANT)
|
||||||
|
|
||||||
|
Q_PROPERTY(QVariant coverSizeRatio MEMBER coverSizeRatio CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant originalCoverSize MEMBER originalCoverSize CONSTANT)
|
||||||
|
|
||||||
//-new properties, not loaded from the DB automatically
|
//-new properties, not loaded from the DB automatically
|
||||||
bool isFavorite;
|
bool isFavorite;
|
||||||
Q_PROPERTY(bool isFavorite MEMBER isFavorite WRITE setFavorite NOTIFY favoriteChanged)
|
Q_PROPERTY(bool isFavorite MEMBER isFavorite WRITE setFavorite NOTIFY favoriteChanged)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user