diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 79e18b7f..77e8311e 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -418,7 +418,9 @@ void ComicVineDialog::getComicsInfo(QList > & matchingIn QByteArray result = comicVineClient->getComicDetail(p.second,error,timeout); //TODO check timeOut or Connection error if(error || timeout) continue; //TODO - comics.push_back(parseComicInfo(p.first,result,count,publisher)); //TODO check result error + ComicDB comic = parseComicInfo(p.first,result,count,publisher);//TODO check result error + comic.info.comicVineID = p.second; + comics.push_back(comic); setLoadingMessage(tr("Retrieving tags for : %1").arg(p.first.getFileName())); } @@ -459,7 +461,7 @@ void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QStr } ComicDB comic = parseComicInfo(comics[currentIndex],result,count,publisher); //TODO check result error - + comic.info.comicVineID = comicId; setLoadingMessage(tr("Retrieving tags for : %1").arg(comics[currentIndex].getFileName())); QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index 5f6d9901..3b5e193e 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -37,6 +37,8 @@ static QString fields = "title ," "characters," "notes," + "comicVineID," + "hash" ; @@ -179,8 +181,11 @@ bool DataBaseManagement::createTables(QSqlDatabase & database) "bookmark3 INTEGER DEFAULT -1, " "brightness INTEGER DEFAULT -1, " "contrast INTEGER DEFAULT -1, " - "gamma INTEGER DEFAULT -1 " - ")"); + "gamma INTEGER DEFAULT -1, " +//new 7.1 fields + "comicVineID TEXT" + + ")"); success = success && queryComicInfo.exec(); //queryComicInfo.finish(); @@ -304,7 +309,9 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest) "characters = :characters," "notes = :notes," - "edited = :edited" + "edited = :edited," + + "comicVineID = :comicVineID" " WHERE hash = :hash "); @@ -337,6 +344,7 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest) "notes," "read," "edited," + "comicVineID," "hash)" "VALUES (:title," @@ -372,6 +380,7 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest) ":read," ":edited," + ":comicVineID," ":hash )"); @@ -445,7 +454,7 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest) return b; } - +//TODO fix these bindings void DataBaseManagement::bindValuesFromRecord(const QSqlRecord & record, QSqlQuery & query) { bindString("title",record,query); @@ -481,7 +490,22 @@ void DataBaseManagement::bindValuesFromRecord(const QSqlRecord & record, QSqlQue bindString("characters",record,query); bindString("notes",record,query); - bindString("hash",record,query); + bindString("comicVineID",record,query); + + bindString("hash",record,query); +} + +bool DataBaseManagement::addColumns(const QString &tableName, const QStringList &columnDefs, const QSqlDatabase &db) +{ + QString sql = "ALTER TABLE %1 ADD COLUMN %2"; + foreach(QString columnDef, columnDefs) + { + QSqlQuery alterTableComicInfo(db); + alterTableComicInfo.prepare(sql.arg(tableName).arg(columnDef)); + //alterTableComicInfo.bindValue(":column_def",columnDef); + alterTableComicInfo.exec(); + return (alterTableComicInfo.numRowsAffected() > 0); + } } void DataBaseManagement::bindString(const QString & name, const QSqlRecord & record, QSqlQuery & query) @@ -552,8 +576,11 @@ int DataBaseManagement::compareVersions(const QString & v1, const QString v2) bool DataBaseManagement::updateToCurrentVersion(const QString & fullPath) { bool pre7 = false; + bool pre7_1 = false; if(compareVersions(DataBaseManagement::checkValidDB(fullPath),"7.0.0")<0) pre7 = true; + if(compareVersions(DataBaseManagement::checkValidDB(fullPath),"7.0.3")<0) + pre7_1 = true; QSqlDatabase db = loadDatabaseFromFile(fullPath); bool returnValue = false; @@ -581,17 +608,17 @@ bool DataBaseManagement::updateToCurrentVersion(const QString & fullPath) << "brightness INTEGER DEFAULT -1" << "contrast INTEGER DEFAULT -1" << "gamma INTEGER DEFAULT -1"; - QString sql = "ALTER TABLE comic_info ADD COLUMN %1"; - foreach(QString columnDef, columnDefs) - { - QSqlQuery alterTableComicInfo(db); - alterTableComicInfo.prepare(sql.arg(columnDef)); - //alterTableComicInfo.bindValue(":column_def",columnDef); - alterTableComicInfo.exec(); - returnValue = returnValue && (alterTableComicInfo.numRowsAffected() > 0); - } + + returnValue = returnValue && addColumns("comic_info", columnDefs, db); } //TODO update hasBeenOpened value + + if(pre7_1) + { + QStringList columnDefs; + columnDefs << "comicVineID TEXT DEFAULT NULL"; + returnValue = returnValue && addColumns("comic_info", columnDefs, db); + } } db.close(); diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h index f7a49dbb..ebb8aab4 100644 --- a/YACReaderLibrary/db/data_base_management.h +++ b/YACReaderLibrary/db/data_base_management.h @@ -37,6 +37,8 @@ private: static void bindInt(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); + public: DataBaseManagement(); //TreeModel * newTreeModel(QString path); @@ -56,4 +58,4 @@ public: static bool updateToCurrentVersion(const QString & path); }; -#endif \ No newline at end of file +#endif diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index f0f12a89..54bcbc0f 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -212,7 +212,10 @@ void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) "brightness = :brightness," "contrast = :contrast, " "gamma = :gamma," - "rating = :rating" + "rating = :rating," + + //new 7.1 fields + "comicVineID = :comicVineID" //-- " WHERE id = :id "); @@ -263,6 +266,8 @@ void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) updateComicInfo.bindValue(":gamma", comicInfo->gamma); updateComicInfo.bindValue(":rating", comicInfo->rating); + updateComicInfo.bindValue(":comicVineID", comicInfo->comicVineID); + updateComicInfo.exec(); } @@ -641,6 +646,8 @@ ComicInfo DBHelper::loadComicInfo(QString hash, QSqlDatabase & db) comicInfo.characters = record.value("characters"); comicInfo.notes = record.value("notes"); + comicInfo.comicVineID = record.value("comicVineID"); + comicInfo.existOnDb = true; } else diff --git a/YACReaderLibrary/properties_dialog.cpp b/YACReaderLibrary/properties_dialog.cpp index 102e9203..4f3cd5ed 100644 --- a/YACReaderLibrary/properties_dialog.cpp +++ b/YACReaderLibrary/properties_dialog.cpp @@ -181,7 +181,16 @@ void PropertiesDialog::createGeneralInfoBox() generalInfoLayout->addRow(tr("Size:"), size = new QLabel("size")); - generalInfoBox->setLayout(generalInfoLayout); + //generalInfoLayout->addRow(tr("Comic Vine link:"), comicVineLink = new QLabel("...")); + //generalInfoLayout->addRow(bottom); + + QVBoxLayout * main = new QVBoxLayout; + main->addLayout(generalInfoLayout); + main->addStretch(); + main->addWidget(comicVineLink = new QLabel("Comic Vine link : ...")); + comicVineLink->setOpenExternalLinks(true); + + generalInfoBox->setLayout(main); } void PropertiesDialog::createAuthorsBox() @@ -373,6 +382,13 @@ void PropertiesDialog::setComics(QList comics) if(!comic.info.title.isNull()) title->setText(comic.info.title.toString()); + if(!comic.info.comicVineID.isNull()) + { + comicVineLink->setHidden(false); + comicVineLink->setText(QString(tr("Comic Vine link: view ").arg(comic.info.comicVineID.toString()))); + } + else + comicVineLink->setHidden(true); if(comics.length()==1 && !comic.info.coverPage.isNull()) { diff --git a/YACReaderLibrary/properties_dialog.h b/YACReaderLibrary/properties_dialog.h index c732ba54..a3088b1d 100644 --- a/YACReaderLibrary/properties_dialog.h +++ b/YACReaderLibrary/properties_dialog.h @@ -39,6 +39,7 @@ class QToolButton; YACReaderFieldEdit * title; YACReaderFieldEdit * numPagesEdit; QLabel * size; + QLabel * comicVineLink; YACReaderFieldEdit * coverPageEdit; QIntValidator coverPageValidator; diff --git a/common/comic_db.cpp b/common/comic_db.cpp index 995ac44d..119dd9a6 100644 --- a/common/comic_db.cpp +++ b/common/comic_db.cpp @@ -201,7 +201,7 @@ ComicInfo & ComicInfo::operator=(const ComicInfo & comicInfo) synopsis = comicInfo.synopsis; characters = comicInfo.characters; notes = comicInfo.notes; - comicVineURL = comicInfo.comicVineURL; + comicVineID = comicInfo.comicVineID; return *this; } @@ -414,6 +414,9 @@ QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo) stream << comicInfo.synopsis; stream << comicInfo.characters; stream << comicInfo.notes; + + stream << comicInfo.comicVineID; + return stream; } @@ -467,6 +470,8 @@ QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo) stream >> comicInfo.synopsis; stream >> comicInfo.characters; stream >> comicInfo.notes; + + stream >> comicInfo.comicVineID; return stream; } diff --git a/common/comic_db.h b/common/comic_db.h index 7f4463e7..f3c5cde6 100644 --- a/common/comic_db.h +++ b/common/comic_db.h @@ -72,7 +72,7 @@ public: QVariant characters;//string QVariant notes;//string - QVariant comicVineURL;//string + QVariant comicVineID;//string QImage cover; diff --git a/common/yacreader_global.h b/common/yacreader_global.h index 49132fb2..1aafdb46 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -8,7 +8,7 @@ #endif -#define VERSION "7.0.2" +#define VERSION "7.1.0" #define PATH "PATH" #define MAG_GLASS_SIZE "MAG_GLASS_SIZE"