mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -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 "library_creator.h"
|
||||
#include "check_new_version.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
|
||||
static QString fields = "title ,"
|
||||
@ -181,7 +182,8 @@ bool DataBaseManagement::createTables(QSqlDatabase & database)
|
||||
//new 7.1 fields
|
||||
"comicVineID TEXT,"
|
||||
//new 8.6 fields
|
||||
"lastTimeOpened INTEGER"
|
||||
"lastTimeOpened INTEGER,"
|
||||
"coverSizeRatio REAL" //h/w
|
||||
|
||||
")");
|
||||
success = success && queryComicInfo.exec();
|
||||
@ -421,7 +423,9 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
||||
|
||||
"comicVineID = :comicVineID,"
|
||||
|
||||
"lastTimeOpened = :lastTimeOpened"
|
||||
"lastTimeOpened = :lastTimeOpened,"
|
||||
|
||||
"coverSizeRatio = :coverSizeRatio"
|
||||
|
||||
" WHERE hash = :hash ");
|
||||
|
||||
@ -456,6 +460,7 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
||||
"edited,"
|
||||
"comicVineID,"
|
||||
"lastTimeOpened,"
|
||||
"coverSizeRatio,"
|
||||
"hash)"
|
||||
|
||||
"VALUES (:title,"
|
||||
@ -495,6 +500,8 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
||||
|
||||
":lastTimeOpened,"
|
||||
|
||||
":coverSizeRatio,"
|
||||
|
||||
":hash )");
|
||||
|
||||
QSqlRecord record = newInfo.record();
|
||||
@ -607,6 +614,8 @@ void DataBaseManagement::bindValuesFromRecord(const QSqlRecord & record, QSqlQue
|
||||
|
||||
bindString("lastTimeOpened",record,query);
|
||||
|
||||
bindDouble("coverSizeRatio",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)
|
||||
{
|
||||
QSqlDatabase db = loadDatabaseFromFile(fullPath);
|
||||
@ -787,11 +804,22 @@ bool DataBaseManagement::updateToCurrentVersion(const QString & fullPath)
|
||||
{//comic_info
|
||||
QStringList columnDefs;
|
||||
columnDefs << "lastTimeOpened INTEGER";
|
||||
columnDefs << "coverSizeRatio REAL";
|
||||
returnValue = returnValue && addColumns("comic_info", columnDefs, db);
|
||||
|
||||
QSqlQuery queryIndexLastTimeOpened(db);
|
||||
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;
|
||||
static void bindString(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 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());
|
||||
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(),relativePath,hash,_database);
|
||||
int numPages = 0;
|
||||
QPair<int,int> originalCoverSize = {0,0};
|
||||
bool exists = checkCover(hash);
|
||||
if(! ( comic.hasCover() && exists))
|
||||
{
|
||||
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg",comic.info.coverPage.toInt());
|
||||
tc.create();
|
||||
numPages = tc.getNumPages();
|
||||
originalCoverSize = tc.getOriginalCoverSize();
|
||||
if (numPages > 0)
|
||||
{
|
||||
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
|
||||
insertFolders();
|
||||
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;
|
||||
DBHelper::insert(&comic,_database);
|
||||
}
|
||||
@ -640,6 +648,7 @@ void ThumbnailCreator::create()
|
||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||
#endif //
|
||||
_cover = p;
|
||||
_coverSize = QPair<int,int>(p.width(), p.height());
|
||||
if(_target!="")
|
||||
{
|
||||
QImage scaled;
|
||||
@ -651,7 +660,7 @@ void ThumbnailCreator::create()
|
||||
{
|
||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||
}
|
||||
scaled.save(_target,0,75);
|
||||
scaled.save(_target,0,75);
|
||||
}
|
||||
else if(_target!="")
|
||||
{
|
||||
@ -717,6 +726,7 @@ void ThumbnailCreator::create()
|
||||
QImage p;
|
||||
if(p.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
{
|
||||
_coverSize = QPair<int,int>(p.width(), p.height());
|
||||
QImage scaled;
|
||||
if(p.width()>p.height()) //landscape??
|
||||
{
|
||||
|
@ -78,6 +78,7 @@
|
||||
QString _target;
|
||||
QString _currentName;
|
||||
int _numPages;
|
||||
QPair<int,int> _coverSize;
|
||||
QImage _cover;
|
||||
int _coverPage;
|
||||
static bool crash;
|
||||
@ -86,6 +87,7 @@
|
||||
void create();
|
||||
int getNumPages(){return _numPages;}
|
||||
QPixmap getCover(){return QPixmap::fromImage(_cover);}
|
||||
QPair<int,int> getOriginalCoverSize(){return _coverSize;}
|
||||
signals:
|
||||
void openingError(QProcess::ProcessError error);
|
||||
|
||||
|
@ -237,6 +237,9 @@ ComicInfo & ComicInfo::operator=(const ComicInfo & comicInfo)
|
||||
|
||||
lastTimeOpened = comicInfo.lastTimeOpened;
|
||||
|
||||
coverSizeRatio = comicInfo.coverSizeRatio;
|
||||
originalCoverSize = comicInfo.originalCoverSize;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -551,6 +554,9 @@ QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo)
|
||||
|
||||
stream << comicInfo.lastTimeOpened;
|
||||
|
||||
stream << comicInfo.coverSizeRatio;
|
||||
stream << comicInfo.originalCoverSize;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
@ -608,6 +614,9 @@ QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo)
|
||||
stream >> comicInfo.comicVineID;
|
||||
|
||||
stream >> comicInfo.lastTimeOpened;
|
||||
|
||||
stream >> comicInfo.coverSizeRatio;
|
||||
stream >> comicInfo.originalCoverSize;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ public:
|
||||
QImage cover;
|
||||
|
||||
QVariant lastTimeOpened;//integer/date
|
||||
QVariant coverSizeRatio;//h/w
|
||||
QVariant originalCoverSize; //string "WxH"
|
||||
|
||||
/*void setTitle(QVariant value);
|
||||
|
||||
@ -190,6 +192,9 @@ public:
|
||||
|
||||
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
|
||||
bool isFavorite;
|
||||
Q_PROPERTY(bool isFavorite MEMBER isFavorite WRITE setFavorite NOTIFY favoriteChanged)
|
||||
|
Loading…
Reference in New Issue
Block a user