a?adida "prueba unitaria" en debug para check new version

a?adida la table db_info que almacena la versi?n con la que fue creada

a?adido el soporte para pasar informaci?n de los c?mics seleccionados al di?logo
de edici?n

a?adido processLibrary a LibraryCreator
This commit is contained in:
Luis Ángel San Martín 2012-06-17 22:18:37 +02:00
parent 31c062dbfe
commit c2fb7003c0
9 changed files with 131 additions and 46 deletions

View File

@ -71,5 +71,14 @@ bool DataBaseManagement::createTables(QSqlDatabase & database)
queryComic.prepare("CREATE TABLE comic (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, comicInfoId INTEGER NOT NULL, fileName TEXT NOT NULL, path TEXT, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE, FOREIGN KEY(comicInfoId) REFERENCES comic_info(id))"); queryComic.prepare("CREATE TABLE comic (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, comicInfoId INTEGER NOT NULL, fileName TEXT NOT NULL, path TEXT, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE, FOREIGN KEY(comicInfoId) REFERENCES comic_info(id))");
success = success && queryComic.exec(); success = success && queryComic.exec();
//DB INFO
QSqlQuery queryDBInfo(database);
queryDBInfo.prepare("CREATE TABLE db_info (version TEXT NOT NULL)");
success = success && queryDBInfo.exec();
QSqlQuery query("INSERT INTO db_info (version) "
"VALUES ('5.0.0')",database);
return success; return success;
} }

View File

@ -211,7 +211,7 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
} }
} }
Comic TableModel::getComic(QModelIndex & mi) Comic TableModel::getComic(const QModelIndex & mi)
{ {
Comic c; Comic c;
_database.open(); _database.open();
@ -220,6 +220,16 @@ Comic TableModel::getComic(QModelIndex & mi)
return c; return c;
} }
Comic TableModel::_getComic(const QModelIndex & mi)
{
Comic c;
c.load(_data.at(mi.row())->data(0).toLongLong(),_database);
return c;
}
QVector<bool> TableModel::getReadList() QVector<bool> TableModel::getReadList()
{ {
int numComics = _data.count(); int numComics = _data.count();
@ -252,4 +262,20 @@ QVector<bool> TableModel::setAllComicsRead(bool read)
_database.close(); _database.close();
return readList; return readList;
}
QList<Comic> TableModel::getComics(QList<QModelIndex> list)
{
QList<Comic> comics;
_database.open();
_database.transaction();
QList<QModelIndex>::const_iterator itr;
for(itr = list.constBegin(); itr!= list.constEnd();itr++)
{
comics.append(_getComic(*itr));
}
_database.commit();
_database.close();
return comics;
} }

View File

@ -35,16 +35,16 @@ public:
//Métodos de conveniencia //Métodos de conveniencia
QStringList getPaths(const QString & _source); QStringList getPaths(const QString & _source);
QString getComicPath(QModelIndex & mi); QString getComicPath(QModelIndex & mi);
Comic getComic(QModelIndex & mi); //--> para la edición Comic getComic(const QModelIndex & mi); //--> para la edición
QVector<bool> getReadList(); QVector<bool> getReadList();
QVector<bool> setAllComicsRead(bool read); QVector<bool> setAllComicsRead(bool read);
//getComicsInfo(QList<QModelIndex> list); --> recupera la información común a los comics seleccionados QList<Comic> getComics(QList<QModelIndex> list); //--> recupera la información común a los comics seleccionados
//setcomicInfo(QModelIndex & mi); --> inserta en la base datos //setcomicInfo(QModelIndex & mi); --> inserta en la base datos
//setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez. //setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez.
//setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados //setComicInfoForSelectedComis(QList<QModelIndex> list); -->inserta la información común para los comics seleccionados
private: private:
void setupModelData( QSqlQuery &sqlquery); void setupModelData( QSqlQuery &sqlquery);
Comic _getComic(const QModelIndex & mi);
QList<TableItem *> _data; QList<TableItem *> _data;
QSqlDatabase _database; QSqlDatabase _database;

View File

@ -24,19 +24,22 @@ LibraryCreator::LibraryCreator()
void LibraryCreator::createLibrary(const QString &source, const QString &target) void LibraryCreator::createLibrary(const QString &source, const QString &target)
{ {
_source = source; processLibrary(source,target);
_target = target;
if(!QDir(target+"/library.ydb").exists())
_mode = CREATOR;
else
_mode = UPDATER;
} }
void LibraryCreator::updateLibrary(const QString &source, const QString &target) void LibraryCreator::updateLibrary(const QString &source, const QString &target)
{
processLibrary(source,target);
}
void LibraryCreator::processLibrary(const QString & source, const QString & target)
{ {
_source = source; _source = source;
_target = target; _target = target;
_mode = UPDATER; if(!(QFile(target+"/library.ydb").exists())) //TODO, no sirve sólo con realizar el update, hay que validar la base de datos y determinar si existe "/covers"
_mode = CREATOR;
else
_mode = UPDATER;
} }

View File

@ -27,6 +27,7 @@
void updateLibrary(const QString & source, const QString & target); void updateLibrary(const QString & source, const QString & target);
void stop(); void stop();
private: private:
void processLibrary(const QString & source, const QString & target);
enum Mode {CREATOR,UPDATER}; enum Mode {CREATOR,UPDATER};
//atributos "globales" durante el proceso de creación y actualización //atributos "globales" durante el proceso de creación y actualización
enum Mode _mode; enum Mode _mode;

View File

@ -361,6 +361,9 @@ void LibraryWindow::disableAllActions()
setAsNonReadAction->setEnabled(false); setAsNonReadAction->setEnabled(false);
setAllAsReadAction->setEnabled(false); setAllAsReadAction->setEnabled(false);
setAllAsNonReadAction->setEnabled(false); setAllAsNonReadAction->setEnabled(false);
selectAllComicsAction->setEnabled(false);
editSelectedComicsAction->setEnabled(false);
asignOrderActions->setEnabled(false);
} }
//librería de sólo lectura //librería de sólo lectura
@ -375,6 +378,9 @@ void LibraryWindow::disableActions()
setAsNonReadAction->setEnabled(false); setAsNonReadAction->setEnabled(false);
setAllAsReadAction->setEnabled(false); setAllAsReadAction->setEnabled(false);
setAllAsNonReadAction->setEnabled(false); setAllAsNonReadAction->setEnabled(false);
selectAllComicsAction->setEnabled(false);
editSelectedComicsAction->setEnabled(false);
asignOrderActions->setEnabled(false);
} }
//librería abierta //librería abierta
void LibraryWindow::enableActions() void LibraryWindow::enableActions()
@ -456,7 +462,7 @@ void LibraryWindow::createToolBars()
editInfoToolBar->addAction(editSelectedComicsAction); editInfoToolBar->addAction(editSelectedComicsAction);
editInfoToolBar->addAction(selectAllComicsAction); editInfoToolBar->addAction(selectAllComicsAction);
editInfoToolBar->addSeparator(); editInfoToolBar->addSeparator();
editInfoToolBar->addAction(forceConverExtractedAction); //editInfoToolBar->addAction(forceConverExtractedAction);
editInfoToolBar->addWidget(new QToolBarStretch()); editInfoToolBar->addWidget(new QToolBarStretch());
editInfoToolBar->addAction(hideComicViewAction); editInfoToolBar->addAction(hideComicViewAction);
} }
@ -549,6 +555,7 @@ void LibraryWindow::createConnections()
//connect(dm,SIGNAL(directoryLoaded(QString)),this,SLOT(updateFoldersView(QString))); //connect(dm,SIGNAL(directoryLoaded(QString)),this,SLOT(updateFoldersView(QString)));
//Comicts edition //Comicts edition
connect(selectAllComicsAction,SIGNAL(triggered()),comicView,SLOT(selectAll())); connect(selectAllComicsAction,SIGNAL(triggered()),comicView,SLOT(selectAll()));
connect(editSelectedComicsAction,SIGNAL(triggered()),this,SLOT(showProperties()));
connect(hideComicViewAction, SIGNAL(toggled(bool)),this, SLOT(hideComicFlow(bool))); connect(hideComicViewAction, SIGNAL(toggled(bool)),this, SLOT(hideComicFlow(bool)));
@ -653,6 +660,9 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
setAsNonReadAction->setEnabled(true); setAsNonReadAction->setEnabled(true);
setAllAsReadAction->setEnabled(true); setAllAsReadAction->setEnabled(true);
setAllAsNonReadAction->setEnabled(true); setAllAsNonReadAction->setEnabled(true);
selectAllComicsAction->setEnabled(true);
editSelectedComicsAction->setEnabled(true);
asignOrderActions->setEnabled(true);
} }
else else
{ {
@ -662,6 +672,9 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
setAsNonReadAction->setEnabled(false); setAsNonReadAction->setEnabled(false);
setAllAsReadAction->setEnabled(false); setAllAsReadAction->setEnabled(false);
setAllAsNonReadAction->setEnabled(false); setAllAsNonReadAction->setEnabled(false);
selectAllComicsAction->setEnabled(false);
editSelectedComicsAction->setEnabled(false);
asignOrderActions->setEnabled(false);
} }
if(paths.size()>0) if(paths.size()>0)
comicView->setCurrentIndex(dmCV->index(0,0)); comicView->setCurrentIndex(dmCV->index(0,0));
@ -995,17 +1008,22 @@ void LibraryWindow::setFoldersFilter(QString filter)
void LibraryWindow::showProperties() void LibraryWindow::showProperties()
{ {
QModelIndex mi = comicView->currentIndex(); QModelIndexList indexList = comicView->selectionModel()->selectedRows();
QString path = QDir::cleanPath(currentPath()+dmCV->getComicPath(mi));
ThumbnailCreator tc(path,""); QList<Comic> comics = dmCV->getComics(indexList);
tc.create();
propertiesDialog->setCover(tc.getCover()); //QModelIndex mi = comicView->currentIndex();
//QString path = QDir::cleanPath(currentPath()+dmCV->getComicPath(mi));
//ThumbnailCreator tc(path,"");
//tc.create();
propertiesDialog->setComics(comics);
/*propertiesDialog->setCover(tc.getCover());
propertiesDialog->setFilename(path.split("/").last()); propertiesDialog->setFilename(path.split("/").last());
propertiesDialog->setNumpages(tc.getNumPages()); propertiesDialog->setNumpages(tc.getNumPages());
QFile file(path); QFile file(path);
propertiesDialog->setSize(file.size()/(1024.0*1024)); propertiesDialog->setSize(file.size()/(1024.0*1024));
file.close(); file.close();*/
propertiesDialog->show(); propertiesDialog->show();
} }

View File

@ -231,7 +231,14 @@ void PropertiesDialog::createButtonBox()
void PropertiesDialog::setComics(QList<Comic> comics) void PropertiesDialog::setComics(QList<Comic> comics)
{ {
if(comics.length() > 1)
{
}
else
{
Comic comic = comics.at(0);
title->setText(comic.name);
}
} }

View File

@ -4,7 +4,8 @@
#include <QtGlobal> #include <QtGlobal>
#include <QStringList> #include <QStringList>
#define VERSION "0.4.5" #define VERSION "5.0"
#define PREVIOUS_VERSION "0.4.5"
HttpVersionChecker::HttpVersionChecker() HttpVersionChecker::HttpVersionChecker()
:QWidget() :QWidget()
@ -42,9 +43,18 @@ void HttpVersionChecker::read(const QHttpResponseHeader &){
void HttpVersionChecker::httpRequestFinished(int requestId, bool error) void HttpVersionChecker::httpRequestFinished(int requestId, bool error)
{ {
#ifdef QT_DEBUG
QString response("YACReader-5.0.0 win32.exe");
#else
QString response(content);
#endif
checkNewVersion(response);
}
QString response(content); //TODO escribir prueba unitaria
#ifdef Q_WS_WIN bool HttpVersionChecker::checkNewVersion(QString sourceContent)
{
#ifdef Q_WS_WIN
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32.*"); QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32.*");
#endif #endif
@ -60,34 +70,44 @@ void HttpVersionChecker::httpRequestFinished(int requestId, bool error)
bool newVersion = false; bool newVersion = false;
bool sameVersion = true; bool sameVersion = true;
//bool currentVersionIsNewer = false; //bool currentVersionIsNewer = false;
#ifdef QT_DEBUG
QString version(PREVIOUS_VERSION);
#else
QString version(VERSION); QString version(VERSION);
QStringList sl = version.split("."); #endif
if((index = rx.indexIn(response))!=-1) QStringList sl = version.split(".");
{ if((index = rx.indexIn(sourceContent))!=-1)
int length = qMin(sl.size(),(rx.cap(4)!="")?4:3); {
for(int i=0;i<length;i++) int length = qMin(sl.size(),(rx.cap(4)!="")?4:3);
{ for(int i=0;i<length;i++)
{
if(rx.cap(i+1).toInt()<sl.at(i).toInt()) if(rx.cap(i+1).toInt()<sl.at(i).toInt())
{ {
return; return false;
} }
if(rx.cap(i+1).toInt()>sl.at(i).toInt()){ if(rx.cap(i+1).toInt()>sl.at(i).toInt()){
newVersion=true; newVersion=true;
break; break;
} }
else else
sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt(); sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt();
} }
if(!newVersion && sameVersion) if(!newVersion && sameVersion)
{ {
if((sl.size()==3)&&(rx.cap(4)!="")) if((sl.size()==3)&&(rx.cap(4)!=""))
newVersion = true; newVersion = true;
} }
} }
if(newVersion == true) if(newVersion == true)
emit newVersionDetected(); {
} emit newVersionDetected();
return true;
}
else
{
return false;
}
}

View File

@ -22,6 +22,7 @@
int httpGetId; int httpGetId;
QByteArray content; QByteArray content;
bool found; bool found;
bool checkNewVersion(QString sourceContent);
signals: signals:
void newVersionDetected(); void newVersionDetected();
}; };