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))");
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;
}

View File

@ -211,7 +211,7 @@ void TableModel::setupModelData(QSqlQuery &sqlquery)
}
}
Comic TableModel::getComic(QModelIndex & mi)
Comic TableModel::getComic(const QModelIndex & mi)
{
Comic c;
_database.open();
@ -220,6 +220,16 @@ Comic TableModel::getComic(QModelIndex & mi)
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()
{
int numComics = _data.count();
@ -252,4 +262,20 @@ QVector<bool> TableModel::setAllComicsRead(bool read)
_database.close();
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
QStringList getPaths(const QString & _source);
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> 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
//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
private:
void setupModelData( QSqlQuery &sqlquery);
Comic _getComic(const QModelIndex & mi);
QList<TableItem *> _data;
QSqlDatabase _database;

View File

@ -24,19 +24,22 @@ LibraryCreator::LibraryCreator()
void LibraryCreator::createLibrary(const QString &source, const QString &target)
{
_source = source;
_target = target;
if(!QDir(target+"/library.ydb").exists())
_mode = CREATOR;
else
_mode = UPDATER;
processLibrary(source,target);
}
void LibraryCreator::updateLibrary(const QString &source, const QString &target)
{
processLibrary(source,target);
}
void LibraryCreator::processLibrary(const QString & source, const QString & target)
{
_source = source;
_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 stop();
private:
void processLibrary(const QString & source, const QString & target);
enum Mode {CREATOR,UPDATER};
//atributos "globales" durante el proceso de creación y actualización
enum Mode _mode;

View File

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

View File

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

View File

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