diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index a7b6f8e4..91bd18c8 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -33,7 +33,10 @@ HEADERS += comic_flow.h \ ./db/treeitem.h \ ./db/treemodel.h \ ./db/tablemodel.h \ - ./db/tableitem.h + ./db/tableitem.h \ + ./db/comic.h \ + ./db/folder.h \ + ./db/library_item.h SOURCES += comic_flow.cpp \ create_library_dialog.cpp \ library_creator.cpp \ @@ -54,7 +57,10 @@ SOURCES += comic_flow.cpp \ ./db/treeitem.cpp \ ./db/treemodel.cpp \ ./db/tablemodel.cpp \ - ./db/tableitem.cpp + ./db/tableitem.cpp \ + ./db/comic.cpp \ + ./db/folder.cpp \ + ./db/library_item.cpp include(./server/server.pri) diff --git a/YACReaderLibrary/db/comic.cpp b/YACReaderLibrary/db/comic.cpp new file mode 100644 index 00000000..1841f1ee --- /dev/null +++ b/YACReaderLibrary/db/comic.cpp @@ -0,0 +1,101 @@ +#include "comic.h" + +#include +#include +#include + +Comic::Comic() +{ + +} + +Comic::Comic(qulonglong cparentId, qulonglong ccomicInfoId, QString cname, QString cpath, QString chash) + :comicInfoId(ccomicInfoId),hash(chash) +{ + parentId = cparentId; + name = cname; + path = cpath; +} + +qulonglong Comic::insert(QSqlDatabase & db) +{ + //TODO comprobar si ya hay comic info con ese hash + QSqlQuery comicInfoInsert(db); + comicInfoInsert.prepare("INSERT INTO comic_info (hash) " + "VALUES (:hash)"); + comicInfoInsert.bindValue(":hash", hash); + comicInfoInsert.exec(); + qulonglong comicInfoId =comicInfoInsert.lastInsertId().toLongLong(); + + QSqlQuery query(db); + query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) " + "VALUES (:parentId,:comicInfoId,:name, :path)"); + query.bindValue(":parentId", parentId); + query.bindValue(":comicInfoId", comicInfoId); + query.bindValue(":name", name); + query.bindValue(":path", path); + query.exec(); + return query.lastInsertId().toLongLong(); +} + +QList Comic::getComicsFromParent(qulonglong parentId, QSqlDatabase & db) +{ + QList list; + + QSqlQuery selectQuery(db); //TODO check + selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); + selectQuery.bindValue(":parentId", parentId); + selectQuery.exec(); + + Comic * currentItem; + while (selectQuery.next()) + { + QList data; + QSqlRecord record = selectQuery.record(); + for(int i=0;iid = record.value(0).toLongLong(); + currentItem->parentId = record.value(1).toLongLong(); + currentItem->name = record.value(2).toString(); + currentItem->hash = record.value(3).toString(); + int lessThan = 0; + if(list.isEmpty()) + list.append(currentItem); + else + { + Comic * last = static_cast(list.back()); + QString nameLast = last->name; + QString nameCurrent = currentItem->name; + QList::iterator i; + i = list.end(); + i--; + while ((0 > (lessThan = nameCurrent.localeAwareCompare(nameLast))) && i != list.begin()) //se usa la misma ordenación que en QDir + { + i--; + nameLast = (*i)->name; + } + if(lessThan>0) //si se ha encontrado un elemento menor que current, se inserta justo después + list.insert(++i,currentItem); + else + list.insert(i,currentItem); + + } + } + + return list; +} + +void Comic::removeFromDB(QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM comic WHERE id = :id"); + query.bindValue(":id", id); + query.exec(); +} + +bool Comic::isDir() +{ + return false; +} \ No newline at end of file diff --git a/YACReaderLibrary/db/comic.h b/YACReaderLibrary/db/comic.h new file mode 100644 index 00000000..338f05e3 --- /dev/null +++ b/YACReaderLibrary/db/comic.h @@ -0,0 +1,24 @@ +#ifndef __COMIC_H +#define __COMIC_H + +#include "library_item.h" +#include +#include + +class Comic : public LibraryItem +{ +public: + qulonglong comicInfoId; + QString hash; + + Comic(); + Comic(qulonglong cparentId, qulonglong ccomicInfoId, QString cname, QString cpath, QString chash); + //Comic(QString fn, QString fp):name(fn),path(fp),knownParent(false), knownId(false){}; + qulonglong insert(QSqlDatabase & db); + static QList getComicsFromParent(qulonglong parentId, QSqlDatabase & db); + bool isDir(); + void removeFromDB(QSqlDatabase & db); +}; + + +#endif \ No newline at end of file diff --git a/YACReaderLibrary/db/folder.cpp b/YACReaderLibrary/db/folder.cpp new file mode 100644 index 00000000..f411e6c5 --- /dev/null +++ b/YACReaderLibrary/db/folder.cpp @@ -0,0 +1,71 @@ + +#include "folder.h" +#include +#include +#include + +qulonglong Folder::insert(QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("INSERT INTO folder (parentId, name, path) " + "VALUES (:parentId, :name, :path)"); + query.bindValue(":parentId", parentId); + query.bindValue(":name", name); + query.bindValue(":path", path); + query.exec(); + return query.lastInsertId().toLongLong(); +} + +QList Folder::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db) +{ + QList list; + + QSqlQuery selectQuery(db); //TODO check + selectQuery.prepare("SELECT * FROM folder WHERE parentId = :parentId"); + selectQuery.bindValue(":parentId", parentId); + selectQuery.exec(); + + Folder * currentItem; + while (selectQuery.next()) + { + QList data; + QSqlRecord record = selectQuery.record(); + for(int i=0;i(list.back()); + QString nameLast = last->name; //TODO usar info name si está disponible, sino el nombre del fichero..... + QString nameCurrent = currentItem->name; + QList::iterator i; + i = list.end(); + i--; + while ((0 > (lessThan = nameCurrent.localeAwareCompare(nameLast))) && i != list.begin()) + { + i--; + nameLast = (*i)->name; + } + if(lessThan>0) //si se ha encontrado un elemento menor que current, se inserta justo después + list.insert(++i,currentItem); + else + list.insert(i,currentItem); + + } + } + + return list; +} + +void Folder::removeFromDB(QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM folder WHERE id = :id"); + query.bindValue(":id", id); + query.exec(); +} + diff --git a/YACReaderLibrary/db/folder.h b/YACReaderLibrary/db/folder.h new file mode 100644 index 00000000..dba5c44c --- /dev/null +++ b/YACReaderLibrary/db/folder.h @@ -0,0 +1,26 @@ +#ifndef __FOLDER_H +#define __FOLDER_H + +#include "library_item.h" + +#include +#include + +class Folder : public LibraryItem +{ +public: + bool knownParent; + bool knownId; + + Folder():knownParent(false), knownId(false){}; + Folder(qulonglong sid, qulonglong pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;}; + Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;}; + void setId(qulonglong sid){id = sid;knownId = true;}; + void setFather(qulonglong pid){parentId = pid;knownParent = true;}; + static QList getFoldersFromParent(qulonglong parentId, QSqlDatabase & db); + qulonglong insert(QSqlDatabase & db); + bool isDir(){return true;}; + void removeFromDB(QSqlDatabase & db); +}; + +#endif \ No newline at end of file diff --git a/YACReaderLibrary/db/library_item.cpp b/YACReaderLibrary/db/library_item.cpp new file mode 100644 index 00000000..e69de29b diff --git a/YACReaderLibrary/db/library_item.h b/YACReaderLibrary/db/library_item.h new file mode 100644 index 00000000..52c3d654 --- /dev/null +++ b/YACReaderLibrary/db/library_item.h @@ -0,0 +1,17 @@ +#ifndef __LIBRARY_ITEM_H +#define __LIBRARY_ITEM_H + +#include + +class LibraryItem +{ +public: + virtual bool isDir() = 0; + virtual void removeFromDB(QSqlDatabase & db) = 0; + QString name; + QString path; + qulonglong parentId; + qulonglong id; +}; + +#endif \ No newline at end of file diff --git a/YACReaderLibrary/db/tableitem.cpp b/YACReaderLibrary/db/tableitem.cpp new file mode 100644 index 00000000..0557980a --- /dev/null +++ b/YACReaderLibrary/db/tableitem.cpp @@ -0,0 +1,42 @@ + +#include + +#include "tableitem.h" + +//! [0] +TableItem::TableItem(const QList &data) +{ + itemData = data; +} +//! [0] + +//! [1] +TableItem::~TableItem() +{ + +} +//! [1] + + +//! [5] +int TableItem::columnCount() const +{ + return itemData.count(); +} +//! [5] + +//! [6] +QVariant TableItem::data(int column) const +{ + return itemData.value(column); +} +//! [6] + + +//! [8] +int TableItem::row() const +{ + + return 0; +} +//! [8] diff --git a/YACReaderLibrary/db/tableitem.h b/YACReaderLibrary/db/tableitem.h new file mode 100644 index 00000000..ebad058a --- /dev/null +++ b/YACReaderLibrary/db/tableitem.h @@ -0,0 +1,24 @@ +#ifndef TABLEITEM_H +#define TABLEITEM_H + +#include +#include + +//! [0] +class TableItem +{ +public: + TableItem(const QList &data); + ~TableItem(); + int columnCount() const; + QVariant data(int column) const; + int row() const; + unsigned long long int id; //TODO sustituir por una clase adecuada +private: + QList itemData; + + +}; +//! [0] + +#endif \ No newline at end of file diff --git a/YACReaderLibrary/db/tablemodel.cpp b/YACReaderLibrary/db/tablemodel.cpp new file mode 100644 index 00000000..fee9ca3b --- /dev/null +++ b/YACReaderLibrary/db/tablemodel.cpp @@ -0,0 +1,211 @@ + +#include +#include + +#include "tableitem.h" +#include "tablemodel.h" +#include "data_base_management.h" +#include "qnaturalsorting.h" + +TableModel::TableModel(QObject *parent) + : QAbstractItemModel(parent) +{ + connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset())); + connect(this,SIGNAL(reset()),this,SIGNAL(modelReset())); +} + +//! [0] +TableModel::TableModel( QSqlQuery &sqlquery, QObject *parent) + : QAbstractItemModel(parent) +{ + setupModelData(sqlquery); +} +//! [0] + +//! [1] +TableModel::~TableModel() +{ + qDeleteAll(_data); +} +//! [1] + +//! [2] +int TableModel::columnCount(const QModelIndex &parent) const +{ + if(_data.isEmpty()) + return 0; + return _data.first()->columnCount(); +} +//! [2] + +//! [3] +QVariant TableModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DecorationRole) + { + return QVariant(); + } + + if (role != Qt::DisplayRole) + return QVariant(); + + TableItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} +//! [3] + +//! [4] +Qt::ItemFlags TableModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} +//! [4] + +//! [5] +QVariant TableModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section)//TODO obtener esto de la query + { + case 0: + return QVariant(QString("Id")); + case 1: + return QVariant(QString("ParentId")); + case 2: + return QVariant(QString("File Name")); + case 3: + return QVariant(QString("Path")); + } + } + + if(orientation == Qt::Vertical && role == Qt::DecorationRole) + return QVariant(QIcon(":/images/icon.png")); + + return QVariant(); +} +//! [5] + +//! [6] +QModelIndex TableModel::index(int row, int column, const QModelIndex &parent) + const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column, _data.at(row)); +} +//! [6] + +//! [7] +QModelIndex TableModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} +//! [7] + +//! [8] +int TableModel::rowCount(const QModelIndex &parent) const +{ + TreeItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + return _data.count(); + + return 0; +} +//! [8] + +QStringList TableModel::getPaths(const QString & _source) +{ + QStringList paths; + QString source = _source + "/.yacreaderlibrary/covers/"; + QList::ConstIterator itr; + for(itr = _data.constBegin();itr != _data.constEnd();itr++) + { + QString path = (*itr)->data(4).toString(); + paths << source+ path +".jpg"; + } + + return paths; +} + +void TableModel::setupModelData(unsigned long long int folderId,QSqlDatabase & db) +{ + //QFile f(QCoreApplication::applicationDirPath()+"/performance.txt"); + //f.open(QIODevice::Append); + emit(beforeReset()); + //QElapsedTimer timer; + //timer.start(); + qDeleteAll(_data); + _data.clear(); + + //QTextStream txtS(&f); + //txtS << "TABLEMODEL: Tiempo de borrado: " << timer.elapsed() << "ms\r\n"; + db.open(); + //crear la consulta + //timer.restart(); + QSqlQuery selectQuery(db); //TODO check + selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + //txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n"; + //timer.restart(); + setupModelData(selectQuery); + //txtS << "TABLEMODEL: Tiempo de creación del modelo: " << timer.elapsed() << "ms\r\n"; + db.close(); + emit(reset()); + //f.close(); +} + +QString TableModel::getComicPath(QModelIndex & mi) +{ + if(mi.isValid()) + return _data.at(mi.row())->data(3).toString(); + return ""; +} +void TableModel::setupModelData(QSqlQuery &sqlquery) +{ + TableItem * currentItem; + while (sqlquery.next()) + { + QList data; + QSqlRecord record = sqlquery.record(); + for(int i=0;idata(2).toString(); //TODO usar info name si está disponible, sino el nombre del fichero..... + QString nameCurrent = currentItem->data(2).toString(); + QList::iterator i; + i = _data.end(); + i--; + while ((lessThan = naturalSortLessThanCI(nameCurrent,nameLast)) && i != _data.begin()) + { + i--; + nameLast = (*i)->data(2).toString(); + } + if(!lessThan) //si se ha encontrado un elemento menor que current, se inserta justo después + _data.insert(++i,currentItem); + else + _data.insert(i,currentItem); + + } + } +} \ No newline at end of file diff --git a/YACReaderLibrary/db/tablemodel.h b/YACReaderLibrary/db/tablemodel.h new file mode 100644 index 00000000..9a0b8e30 --- /dev/null +++ b/YACReaderLibrary/db/tablemodel.h @@ -0,0 +1,52 @@ +#ifndef TABLEMODEL_H +#define TABLEMODEL_H + +#include +#include +#include +#include +#include + +class TableItem; + +//! [0] +class TableModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + TableModel(QObject *parent = 0); + TableModel( QSqlQuery &sqlquery, QObject *parent = 0); + ~TableModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + void setupModelData(unsigned long long int parentFolder,QSqlDatabase & db); + + //Métodos de conveniencia + QStringList getPaths(const QString & _source); + QString getComicPath(QModelIndex & mi); + //getComicInfo(QModelIndex & mi); --> para la edición + //getComicsInfo(QList 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 list); -->inserta la información común para los comics seleccionados +private: + void setupModelData( QSqlQuery &sqlquery); + + QList _data; + +signals: + void beforeReset(); + void reset(); +}; +//! [0] + +#endif diff --git a/YACReaderLibrary/db/treeitem.h b/YACReaderLibrary/db/treeitem.h index 63678932..14ed0489 100644 --- a/YACReaderLibrary/db/treeitem.h +++ b/YACReaderLibrary/db/treeitem.h @@ -61,9 +61,11 @@ public: TreeItem *parent(); TreeItem *parentItem; unsigned long long int id; + QList comicNames; private: QList childItems; QList itemData; + }; diff --git a/YACReaderLibrary/db/treemodel.cpp b/YACReaderLibrary/db/treemodel.cpp index 73303f92..46642dfa 100644 --- a/YACReaderLibrary/db/treemodel.cpp +++ b/YACReaderLibrary/db/treemodel.cpp @@ -221,6 +221,15 @@ void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent) data << sqlquery.value(2).toString(); data << sqlquery.value(3).toString(); TreeItem * item = new TreeItem(data); + + /*QSqlQuery selectQuery(_database); //TODO check + selectQuery.prepare("select fileName from comic where parentId = :parentId"); + selectQuery.bindValue(":parentId", sqlquery.value(0).toLongLong()); + selectQuery.exec(); + while (selectQuery.next()) { + item->comicNames.append(sqlquery.value(0).toString()); + }*/ + item->id = sqlquery.value(0).toLongLong(); items.value(sqlquery.value(1).toLongLong())->appendChild(item); //se añade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index b3f25463..e384bb8f 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -29,5 +29,8 @@ ../images/setUnread.png ../images/setAllUnread.png ../images/showMarks.png + ../images/importCover.png + ../images/editComic.png + ../images/selectAll.png diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index 3681fd3e..fbff32d7 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -15,151 +15,6 @@ QMutex mutex; */ - -qint64 Folder::insert(QSqlDatabase & db) -{ - QSqlQuery query(db); - query.prepare("INSERT INTO folder (parentId, name, path) " - "VALUES (:parentId, :name, :path)"); - query.bindValue(":parentId", parentId); - query.bindValue(":name", name); - query.bindValue(":path", path); - query.exec(); - return query.lastInsertId().toLongLong(); -} - -QList Folder::getFoldersFromParent(qint64 parentId, QSqlDatabase & db) -{ - QList list; - - QSqlQuery selectQuery(db); //TODO check - selectQuery.prepare("SELECT * FROM folder WHERE parentId = :parentId"); - selectQuery.bindValue(":parentId", parentId); - selectQuery.exec(); - - Folder * currentItem; - while (selectQuery.next()) - { - QList data; - QSqlRecord record = selectQuery.record(); - for(int i=0;i(list.back()); - QString nameLast = last->name; //TODO usar info name si está disponible, sino el nombre del fichero..... - QString nameCurrent = currentItem->name; - QList::iterator i; - i = list.end(); - i--; - while ((0 > (lessThan = nameCurrent.localeAwareCompare(nameLast))) && i != list.begin()) - { - i--; - nameLast = (*i)->name; - } - if(lessThan>0) //si se ha encontrado un elemento menor que current, se inserta justo después - list.insert(++i,currentItem); - else - list.insert(i,currentItem); - - } - } - - return list; -} - -void Folder::removeFromDB(QSqlDatabase & db) -{ - QSqlQuery query(db); - query.prepare("DELETE FROM folder WHERE id = :id"); - query.bindValue(":id", id); - query.exec(); -} - - - -qint64 Comic::insert(QSqlDatabase & db) -{ - //TODO comprobar si ya hay comic info con ese hash - QSqlQuery comicInfoInsert(db); - comicInfoInsert.prepare("INSERT INTO comic_info (hash) " - "VALUES (:hash)"); - comicInfoInsert.bindValue(":hash", hash); - comicInfoInsert.exec(); - qint64 comicInfoId =comicInfoInsert.lastInsertId().toLongLong(); - - QSqlQuery query(db); - query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) " - "VALUES (:parentId,:comicInfoId,:name, :path)"); - query.bindValue(":parentId", parentId); - query.bindValue(":comicInfoId", comicInfoId); - query.bindValue(":name", name); - query.bindValue(":path", path); - query.exec(); - return query.lastInsertId().toLongLong(); -} - -QList Comic::getComicsFromParent(qint64 parentId, QSqlDatabase & db) -{ - QList list; - - QSqlQuery selectQuery(db); //TODO check - selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); - selectQuery.bindValue(":parentId", parentId); - selectQuery.exec(); - - Comic * currentItem; - while (selectQuery.next()) - { - QList data; - QSqlRecord record = selectQuery.record(); - for(int i=0;iid = record.value(0).toLongLong(); - currentItem->parentId = record.value(1).toLongLong(); - currentItem->name = record.value(2).toString(); - currentItem->hash = record.value(3).toString(); - int lessThan = 0; - if(list.isEmpty()) - list.append(currentItem); - else - { - Comic * last = static_cast(list.back()); - QString nameLast = last->name; - QString nameCurrent = currentItem->name; - QList::iterator i; - i = list.end(); - i--; - while ((0 > (lessThan = nameCurrent.localeAwareCompare(nameLast))) && i != list.begin()) //se usa la misma ordenación que en QDir - { - i--; - nameLast = (*i)->name; - } - if(lessThan>0) //si se ha encontrado un elemento menor que current, se inserta justo después - list.insert(++i,currentItem); - else - list.insert(i,currentItem); - - } - } - - return list; -} - -void Comic::removeFromDB(QSqlDatabase & db) -{ - QSqlQuery query(db); - query.prepare("DELETE FROM comic WHERE id = :id"); - query.bindValue(":id", id); - query.exec(); -} //-------------------------------------------------------------------------------- LibraryCreator::LibraryCreator() { @@ -249,7 +104,7 @@ void LibraryCreator::stop() } //retorna el id del ultimo de los folders -qint64 LibraryCreator::insertFolders() +qulonglong LibraryCreator::insertFolders() { QList::iterator i; int currentId = 0; @@ -269,7 +124,7 @@ qint64 LibraryCreator::insertFolders() return 0; } -/*qint64 LibraryCreator::insertFolder(qint64 parentId,const Folder & folder) +/*qulonglong LibraryCreator::insertFolder(qulonglong parentId,const Folder & folder) { QSqlQuery query(_database); query.prepare("INSERT INTO folder (parentId, name, path) " @@ -281,7 +136,7 @@ qint64 LibraryCreator::insertFolders() return query.lastInsertId().toLongLong(); }*/ -/*qint64 LibraryCreator::insertComic(const Comic & comic) +/*qulonglong LibraryCreator::insertComic(const Comic & comic) { //TODO comprobar si ya hay comic info con ese hash QSqlQuery comicInfoInsert(_database); @@ -289,7 +144,7 @@ qint64 LibraryCreator::insertFolders() "VALUES (:hash)"); comicInfoInsert.bindValue(":hash", comic.hash); comicInfoInsert.exec(); - qint64 comicInfoId =comicInfoInsert.lastInsertId().toLongLong(); + qulonglong comicInfoId =comicInfoInsert.lastInsertId().toLongLong(); QSqlQuery query(_database); query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) " diff --git a/YACReaderLibrary/library_creator.h b/YACReaderLibrary/library_creator.h index 992c1315..0bdeb425 100644 --- a/YACReaderLibrary/library_creator.h +++ b/YACReaderLibrary/library_creator.h @@ -14,51 +14,8 @@ #include #include - -class LibraryItem -{ -public: - virtual bool isDir() = 0; - virtual void removeFromDB(QSqlDatabase & db) = 0; - QString name; - QString path; - qint64 parentId; - qint64 id; -}; - -class Folder : public LibraryItem -{ -public: - bool knownParent; - bool knownId; - - Folder():knownParent(false), knownId(false){}; - Folder(qint64 sid, qint64 pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;}; - Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;}; - void setId(qint64 sid){id = sid;knownId = true;}; - void setFather(qint64 pid){parentId = pid;knownParent = true;}; - static QList getFoldersFromParent(qint64 parentId, QSqlDatabase & db); - qint64 insert(QSqlDatabase & db); - bool isDir(){return true;}; - void removeFromDB(QSqlDatabase & db); -}; - -class Comic : public LibraryItem -{ -public: - qint64 comicInfoId; - QString hash; - - Comic(){}; - Comic(qint64 cparentId, qint64 ccomicInfoId, QString cname, QString cpath, QString chash) - :comicInfoId(ccomicInfoId),hash(chash){parentId = cparentId;name = cname; path = cpath;}; - //Comic(QString fn, QString fp):name(fn),path(fp),knownParent(false), knownId(false){}; - qint64 insert(QSqlDatabase & db); - static QList getComicsFromParent(qint64 parentId, QSqlDatabase & db); - bool isDir(){return false;}; - void removeFromDB(QSqlDatabase & db); -}; - +#include "folder.h" +#include "comic.h" class LibraryCreator : public QThread @@ -83,10 +40,10 @@ public: void update(QDir currentDirectory); void run(); bool createTables(); - qint64 insertFolders();//devuelve el id del último folder añadido (último en la ruta) + qulonglong insertFolders();//devuelve el id del último folder añadido (último en la ruta) void insertComic(const QString & relativePath,const QFileInfo & fileInfo); - //qint64 insertFolder(qint64 parentId,const Folder & folder); - //qint64 insertComic(const Comic & comic); + //qulonglong insertFolder(qulonglong parentId,const Folder & folder); + //qulonglong insertComic(const Comic & comic); bool stopRunning; signals: void finished(); diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index faa7444d..703c8a93 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -44,13 +44,11 @@ void LibraryWindow::setupUI() void LibraryWindow::doLayout() { - QSplitter * sVertical = new QSplitter(Qt::Vertical); - QSplitter * sHorizontal = new QSplitter(Qt::Horizontal); + QSplitter * sVertical = new QSplitter(Qt::Vertical); //spliter derecha + QSplitter * sHorizontal = new QSplitter(Qt::Horizontal); //spliter principal //TODO: flowType is a global variable - optionsDialog = new OptionsDialog(this); - optionsDialog->restoreOptions(); + //CONFIG COMIC_FLOW-------------------------------------------------------- comicFlow = new ComicFlow(0,flowType); - comicFlow->setFocusPolicy(Qt::StrongFocus); comicFlow->setShowMarks(true); QMatrix m; @@ -67,17 +65,46 @@ void LibraryWindow::doLayout() slideSizeF = QSize(width,height); comicFlow->setSlideSize(slideSizeW); setFocusProxy(comicFlow); + //------------------------------------------------------------------------- + //CONFIG TREE/TABLE VIEWS-------------------------------------------------- comicView = new QTableView; foldersView = new QTreeView; + //------------------------------------------------------------------------- - - sVertical->addWidget(comicFlow); - sVertical->addWidget(comicView); + //CONFIG FLOW/COMICS------------------------------------------------------- /*sVertical->setStretchFactor(0,1); sVertical->setStretchFactor(1,0); */ + //views + foldersView->setAnimated(true); + foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); + foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); + foldersView->header()->hide(); + foldersView->setUniformRowHeights(true); + comicView->setAlternatingRowColors(true); + //comicView->setStyleSheet("alternate-background-color: #e7e7d7;background-color: white;"); + //comicView->setItemDelegate(new YACReaderComicViewDelegate()); + comicView->setContextMenuPolicy(Qt::ActionsContextMenu); + comicView->setShowGrid(false); + comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + comicView->horizontalHeader()->setStretchLastSection(true); + comicView->horizontalHeader()->setClickable(false); + //comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); + comicView->verticalHeader()->setDefaultSectionSize(24); + comicView->verticalHeader()->setClickable(false); //TODO comportamiento anómalo + comicView->setCornerButtonEnabled(false); + comicView->setStyleSheet("QTableView {selection-background-color: #d7d7c7; selection-color: #000000;}"); +// comicView->verticalHeader()->setStyleSheet("QHeaderView::section" +//"{" +// "background-color: white /* steelblue */" +//"}"); + comicView->setSelectionBehavior(QAbstractItemView::SelectRows); + comicView->setSelectionMode(QAbstractItemView::ExtendedSelection); + //------------------------------------------------------------------------- + + //CONFIG NAVEGACIÓN/BÚSQUEDA----------------------------------------------- left = new QWidget; QVBoxLayout * l = new QVBoxLayout; selectedLibrary = new QComboBox; @@ -104,37 +131,23 @@ void LibraryWindow::doLayout() l->addLayout(searchLayout); l->setSpacing(1); left->setLayout(l); + //------------------------------------------------------------------------- + //FINAL LAYOUT------------------------------------------------------------- + sVertical->addWidget(comicFlow); + QWidget *comics = new QWidget; + QVBoxLayout * comicsLayout = new QVBoxLayout; + comicsLayout->setContentsMargins(2,2,0,0); + comicsLayout->addWidget(editInfoToolBar = new QToolBar(comics)); + comicsLayout->addWidget(comicView); + comics->setLayout(comicsLayout); + sVertical->addWidget(comics); sHorizontal->addWidget(left); sHorizontal->addWidget(sVertical); sHorizontal->setStretchFactor(0,0); sHorizontal->setStretchFactor(1,1); setCentralWidget(sHorizontal); - - //views - foldersView->setAnimated(true); - foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); - foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); - foldersView->header()->hide(); - foldersView->setUniformRowHeights(true); - - comicView->setAlternatingRowColors(true); - //comicView->setStyleSheet("alternate-background-color: #e7e7d7;background-color: white;"); - //comicView->setItemDelegate(new YACReaderComicViewDelegate()); - comicView->setContextMenuPolicy(Qt::ActionsContextMenu); - comicView->setShowGrid(false); - comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); - comicView->horizontalHeader()->setStretchLastSection(true); - //comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); - comicView->verticalHeader()->setDefaultSectionSize(24); -// comicView->verticalHeader()->setStyleSheet("QHeaderView::section" -//"{" -// "background-color: white /* steelblue */" -//"}"); - comicView->setSelectionBehavior(QAbstractItemView::SelectRows); - comicView->setSelectionMode(QAbstractItemView::ExtendedSelection); - - + //FINAL LAYOUT------------------------------------------------------------- fullScreenToolTip = new QLabel(this); fullScreenToolTip->setText(tr(" press 'F' to close fullscreen mode ")); @@ -156,6 +169,8 @@ void LibraryWindow::doDialogs() exportLibraryDialog = new ExportLibraryDialog(this); importLibraryDialog = new ImportLibraryDialog(this); addLibraryDialog = new AddLibraryDialog(this); + optionsDialog = new OptionsDialog(this); + optionsDialog->restoreOptions(); had = new HelpAboutDialog(this); //TODO load data. QString sufix = QLocale::system().name(); if(QFile(":/files/about_"+sufix+".html").exists()) @@ -303,6 +318,24 @@ void LibraryWindow::createActions() openContainingFolderComicAction = new QAction(this); openContainingFolderComicAction->setText(tr("Open containing folder...")); openContainingFolderComicAction->setIcon(QIcon(":/images/open.png")); + + //Edit comics actions------------------------------------------------------ + selectAllComicsAction = new QAction(this); + selectAllComicsAction->setText(tr("Select all comics")); + selectAllComicsAction->setIcon(QIcon(":/images/selectAll.png")); + + editSelectedComicsAction = new QAction(this); + editSelectedComicsAction->setText(tr("Edit")); + editSelectedComicsAction->setIcon(QIcon(":/images/editComic.png")); + + asignOrderActions = new QAction(this); + asignOrderActions->setText(tr("Asign current order to comics")); + asignOrderActions->setIcon(QIcon(":/images/fit.png")); + + forceConverExtractedAction = new QAction(this); + forceConverExtractedAction->setText(tr("Update cover")); + forceConverExtractedAction->setIcon(QIcon(":/images/importCover.png")); + //------------------------------------------------------------------------- } //TODO unificar con disableActions @@ -407,6 +440,13 @@ void LibraryWindow::createToolBars() comicFlow->addAction(toggleFullScreenAction); comicFlow->addAction(openComicAction); + + editInfoToolBar->addAction(openComicAction); + editInfoToolBar->addSeparator(); + editInfoToolBar->addAction(editSelectedComicsAction); + editInfoToolBar->addAction(selectAllComicsAction); + editInfoToolBar->addSeparator(); + editInfoToolBar->addAction(forceConverExtractedAction); } void LibraryWindow::createMenus() @@ -495,6 +535,9 @@ void LibraryWindow::createConnections() //connect(dm,SIGNAL(directoryLoaded(QString)),foldersView,SLOT(expandAll())); //connect(dm,SIGNAL(directoryLoaded(QString)),this,SLOT(updateFoldersView(QString))); + //Comicts edition + connect(selectAllComicsAction,SIGNAL(triggered()),comicView,SLOT(selectAll())); + } void LibraryWindow::loadLibrary(const QString & name) diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 455e5cdd..b99dd9cc 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -96,10 +96,16 @@ private: QAction * setAllAsNonReadAction; QAction * showHideMarksAction; + QAction * selectAllComicsAction; + QAction * editSelectedComicsAction; + QAction * asignOrderActions; + QAction * forceConverExtractedAction; + QToolBar * libraryToolBar; QToolBar * treeActions; QToolBar * comicsToolBar; + QToolBar * editInfoToolBar; OptionsDialog * optionsDialog; diff --git a/YACReaderLibrary/properties_dialog.cpp b/YACReaderLibrary/properties_dialog.cpp index 8853f496..3ad230e6 100644 --- a/YACReaderLibrary/properties_dialog.cpp +++ b/YACReaderLibrary/properties_dialog.cpp @@ -2,16 +2,16 @@ #include #include #include - +#include PropertiesDialog::PropertiesDialog(QWidget * parent) :QDialog(parent) { - QVBoxLayout * l = new QVBoxLayout(); - - sa = new QScrollArea(this); - _cover = new QLabel(sa); + QHBoxLayout * l = new QHBoxLayout(); + + sa = new QScrollArea(); + _cover = new QLabel(); _cover->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); _cover->setScaledContents(true); _cover->setAlignment(Qt::AlignTop|Qt::AlignHCenter); @@ -24,18 +24,42 @@ PropertiesDialog::PropertiesDialog(QWidget * parent) sa->setFrameStyle(QFrame::NoFrame); sa->setAlignment(Qt::AlignCenter); - l->addWidget(sa); + QVBoxLayout * coverLayout = new QVBoxLayout(); + coverLayout->addWidget(sa); + //coverLayout->addStretch(); + + l->addLayout(coverLayout); QVBoxLayout * info = new QVBoxLayout(); info->addWidget(_name = new QLabel("name")); info->addWidget(_pages = new QLabel("pages")); info->addWidget(_size = new QLabel("size")); - info->setSizeConstraint(QLayout::SetMaximumSize); + info->addStretch(); + //coverLayout->setSizeConstraint(QLayout::SetMaximumSize); l->addLayout(info); + l->addStretch(); + //l->setSizeConstraint(QLayout::SetNoConstraint); this->setLayout(l); this->setWindowTitle(tr("Comic properties")); + + int heightDesktopResolution = QApplication::desktop()->screenGeometry().height(); + int widthDesktopResolution = QApplication::desktop()->screenGeometry().width(); + int sHeight,sWidth; + sHeight = static_cast(heightDesktopResolution*0.5); + sWidth = static_cast(sHeight*1.4); + this->resize(sWidth,sHeight); } +void PropertiesDialog::setComics(QList comics) +{ + +} + +void PropertiesDialog::updateComics(QList comics) +{ + +} +//Deprecated void PropertiesDialog::setCover(const QPixmap & cover) { _cover->setPixmap(cover); @@ -43,20 +67,20 @@ void PropertiesDialog::setCover(const QPixmap & cover) int heightDesktopResolution = QApplication::desktop()->screenGeometry().height(); int widthDesktopResolution = QApplication::desktop()->screenGeometry().width(); int sHeight,sWidth; - sHeight = static_cast(heightDesktopResolution*0.84); + sHeight = static_cast(heightDesktopResolution*0.5); if(aspectRatio<1) { - sWidth = static_cast(sHeight*0.70); - this->resize(sWidth,sHeight); + sWidth = static_cast(sHeight*1.4); + //this->resize(sWidth,sHeight); this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2)); - _cover->resize(static_cast((height()-90)*aspectRatio), - (height()-90)); + _cover->resize(static_cast((sa->height())*aspectRatio), + (sa->height())); } else { - sWidth = static_cast(sHeight*1.10); - this->resize(sWidth,sHeight); + sWidth = static_cast(sHeight/1.16); + //this->resize(sWidth,sHeight); this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2)); _cover->resize((width()-25), static_cast((width()-25)/aspectRatio)); diff --git a/YACReaderLibrary/properties_dialog.h b/YACReaderLibrary/properties_dialog.h index 2454680a..4eea80f3 100644 --- a/YACReaderLibrary/properties_dialog.h +++ b/YACReaderLibrary/properties_dialog.h @@ -7,6 +7,8 @@ #include #include +#include "comic.h" + class PropertiesDialog : public QDialog { Q_OBJECT @@ -20,6 +22,10 @@ public: PropertiesDialog(QWidget * parent = 0); public slots: + void setComics(QList comics); + void updateComics(QList comics); + + //Deprecated void setCover(const QPixmap & cover); void setFilename(const QString & name); void setNumpages(int pages); diff --git a/images/editComic.png b/images/editComic.png new file mode 100644 index 00000000..1b9803dd Binary files /dev/null and b/images/editComic.png differ diff --git a/images/importCover.png b/images/importCover.png new file mode 100644 index 00000000..ae814ec8 Binary files /dev/null and b/images/importCover.png differ diff --git a/images/selectAll.png b/images/selectAll.png new file mode 100644 index 00000000..8d4ab94f Binary files /dev/null and b/images/selectAll.png differ