diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 4b273a5f..a7b6f8e4 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -31,7 +31,9 @@ HEADERS += comic_flow.h \ bundle_creator.h \ ./db/data_base_management.h \ ./db/treeitem.h \ - ./db/treemodel.h + ./db/treemodel.h \ + ./db/tablemodel.h \ + ./db/tableitem.h SOURCES += comic_flow.cpp \ create_library_dialog.cpp \ library_creator.cpp \ @@ -50,7 +52,9 @@ SOURCES += comic_flow.cpp \ bundle_creator.cpp \ ./db/data_base_management.cpp \ ./db/treeitem.cpp \ - ./db/treemodel.cpp + ./db/treemodel.cpp \ + ./db/tablemodel.cpp \ + ./db/tableitem.cpp include(./server/server.pri) diff --git a/YACReaderLibrary/comic_flow.cpp b/YACReaderLibrary/comic_flow.cpp index 533ef45b..2dbf6562 100644 --- a/YACReaderLibrary/comic_flow.cpp +++ b/YACReaderLibrary/comic_flow.cpp @@ -5,10 +5,6 @@ #include #include - - - - ComicFlow::ComicFlow(QWidget* parent,FlowType flowType) :YACReaderFlow(parent,flowType) { @@ -27,62 +23,6 @@ ComicFlow::~ComicFlow() delete updateTimer; } -QString ComicFlow::getImagePath() const -{ - return "";//imagePath; -} - -QStringList ComicFlow::getImageFiles() const -{ - return imageFiles; -} - -// get list of all files in a directory (will be filtered later) -// this is usually very fast so no need to put it in a separate thread -static QStringList findFiles(const QString& path = QString()) -{ - //list files; - QStringList files; - - QDir dir = QDir::current(); - if(!path.isEmpty()) - dir = QDir(path); - - dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); - dir.setNameFilters(QStringList() << "*.jpg"); - //dir.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); - QFileInfoList list = dir.entryInfoList(); - - qSort(list.begin(),list.end(),naturalSortLessThanCIFileInfo); - - for (int i = 0; i < list.size(); ++i) - { - QFileInfo fileInfo = list.at(i); - files.append(dir.absoluteFilePath(fileInfo.fileName())); - } - - //std::sort(files.begin(), files.end(), naturalSortLessThanCI); - - return files; -} - -// take only files which are readable (as images) -// also seems to be fast as it does a quick check only -static QStringList filterImages(const QStringList& files) -{ - QStringList imageFiles; - - QImageReader reader; - foreach(QString fname, files) - { - reader.setFileName(fname); - if(reader.canRead()) - imageFiles += fname; - } - - return imageFiles; -} - void ComicFlow::setImagePaths(const QStringList& paths) { clear(); @@ -135,7 +75,6 @@ void ComicFlow::updateImageData() imagesSetted[idx] = true; numImagesLoaded++; } - } // try to load only few images on the left and right side diff --git a/YACReaderLibrary/comic_flow.h b/YACReaderLibrary/comic_flow.h index fe0910f4..e4448de2 100644 --- a/YACReaderLibrary/comic_flow.h +++ b/YACReaderLibrary/comic_flow.h @@ -16,12 +16,9 @@ class ComicFlow : public YACReaderFlow { Q_OBJECT public: - ComicFlow(QWidget* parent = 0,FlowType flowType = CoverFlowLike); + ComicFlow(QWidget* parent = 0,FlowType flowType = CoverFlowLike); virtual ~ComicFlow(); - //void render(); - QString getImagePath() const; //TOTO quitar no se usa - QStringList getImageFiles() const; void setImagePaths(const QStringList& paths); //bool eventFilter(QObject *target, QEvent *event); void keyPressEvent(QKeyEvent* event); diff --git a/YACReaderLibrary/db/treemodel.cpp b/YACReaderLibrary/db/treemodel.cpp index c5d0bd14..050c5412 100644 --- a/YACReaderLibrary/db/treemodel.cpp +++ b/YACReaderLibrary/db/treemodel.cpp @@ -55,6 +55,8 @@ TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent) { + connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset())); + connect(this,SIGNAL(reset()),this,SIGNAL(modelReset())); } //! [0] @@ -182,6 +184,7 @@ int TreeModel::rowCount(const QModelIndex &parent) const void TreeModel::setupModelData(QString path) { + emit(beforeReset()); if(rootItem == 0) delete rootItem; //TODO comprobar que se libera bien la memoria @@ -197,6 +200,7 @@ void TreeModel::setupModelData(QString path) QSqlQuery selectQuery("select * from folder order by parentId,name",_database); setupModelData(selectQuery,rootItem); + emit(reset()); } void TreeModel::setupModelData(QSqlQuery &sqlquery, TreeItem *parent) diff --git a/YACReaderLibrary/db/treemodel.h b/YACReaderLibrary/db/treemodel.h index 61e8a646..456700bf 100644 --- a/YACReaderLibrary/db/treemodel.h +++ b/YACReaderLibrary/db/treemodel.h @@ -76,6 +76,9 @@ private: TreeItem *rootItem; //el árbol QSqlDatabase _database; +signals: + void beforeReset(); + void reset(); }; //! [0] diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index fb386a1b..eca19e09 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -68,7 +68,7 @@ void LibraryWindow::doLayout() comicFlow->setSlideSize(slideSizeW); setFocusProxy(comicFlow); - comicView = new QListView; + comicView = new QTableView; foldersView = new QTreeView; @@ -115,10 +115,21 @@ void LibraryWindow::doLayout() foldersView->setAnimated(true); foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); foldersView->setContextMenuPolicy(Qt::ActionsContextMenu); + foldersView->header()->hide(); comicView->setAlternatingRowColors(true); + comicView->setStyleSheet("alternate-background-color: #e7e7d7;background-color: white;"); //comicView->setItemDelegate(new YACReaderComicViewDelegate()); comicView->setContextMenuPolicy(Qt::ActionsContextMenu); + //comicView->verticalHeader()->hide(); + comicView->setShowGrid(false); + comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + comicView->horizontalHeader()->setStretchLastSection(true); + comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); + comicView->setSelectionBehavior(QAbstractItemView::SelectRows); + comicView->setSelectionMode(QAbstractItemView::ExtendedSelection); + + fullScreenToolTip = new QLabel(this); fullScreenToolTip->setText(tr(" press 'F' to close fullscreen mode ")); @@ -157,7 +168,7 @@ void LibraryWindow::doModels() { //dirmodels dm = new TreeModel(); - dmCV = new QSqlQueryModel(); + dmCV = new TableModel(); /*proxyFilter = new YACReaderTreeSearch(); @@ -289,14 +300,54 @@ void LibraryWindow::createActions() openContainingFolderComicAction->setIcon(QIcon(":/images/open.png")); } +//TODO unificar con disableActions +void LibraryWindow::disableAllActions() +{ + updateLibraryAction->setEnabled(false); + renameLibraryAction->setEnabled(false); + deleteLibraryAction->setEnabled(false); + removeLibraryAction->setEnabled(false); + foldersFilter->setEnabled(false); + clearFoldersFilter->setEnabled(false); + setAsReadAction->setEnabled(false); + setAsNonReadAction->setEnabled(false); + setAllAsReadAction->setEnabled(false); + setAllAsNonReadAction->setEnabled(false); +} + +//librería de sólo lectura void LibraryWindow::disableActions() { + updateLibraryAction->setEnabled(false); + openComicAction->setEnabled(false); + showPropertiesAction->setEnabled(false); + openContainingFolderAction->setEnabled(false); + openContainingFolderComicAction->setEnabled(false); + setAsReadAction->setEnabled(false); + setAsNonReadAction->setEnabled(false); + setAllAsReadAction->setEnabled(false); + setAllAsNonReadAction->setEnabled(false); } +//librería abierta void LibraryWindow::enableActions() { + updateLibraryAction->setEnabled(true); + openComicAction->setEnabled(true); + showPropertiesAction->setEnabled(true); + openContainingFolderAction->setEnabled(true); + openContainingFolderComicAction->setEnabled(true); + setAsReadAction->setEnabled(true); + setAsNonReadAction->setEnabled(true); + setAllAsReadAction->setEnabled(true); + setAllAsNonReadAction->setEnabled(true); } void LibraryWindow::enableLibraryActions() { + renameLibraryAction->setEnabled(true); + deleteLibraryAction->setEnabled(true); + removeLibraryAction->setEnabled(true); + foldersFilter->setEnabled(true); + clearFoldersFilter->setEnabled(true); } void LibraryWindow::createToolBars() @@ -449,31 +500,12 @@ void LibraryWindow::loadLibrary(const QString & name) QDir d; //TODO change this by static methods (utils class?? with delTree for example) if(d.exists(path)) { - TreeModel * oldTM = dm; - dm = new TreeModel(); dm->setupModelData(path); foldersView->setModel(dm); - foldersView->header()->hideSection(1); - foldersView->header()->hideSection(2); - foldersView->header()->hideSection(3); - foldersView->header()->adjustSize(); - foldersView->header()->hide(); - loadCovers(QModelIndex()); - /*proxyFilter = new YACReaderTreeSearch(); - proxyFilter->setSourceModel(dm); - proxyFilter->setFilterRole(Qt::DisplayRole);*/ - - //connect(dm,SIGNAL(directoryLoaded(QString)),this,SLOT(updateFoldersView(QString))); - includeComicsCheckBox->setCheckState(Qt::Unchecked); - - //foldersView->expandAll(); - - /*if(oldTM!=0) - delete oldTM;*/ //TODO corregir error al liberar memoria } else { @@ -483,51 +515,22 @@ void LibraryWindow::loadLibrary(const QString & name) } d.setCurrent(libraries.value(name)); d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); - if(d.count()<=1) + if(d.count()<=1) //librería de sólo lectura { //QMessageBox::critical(NULL,QString::number(d.count()),QString::number(d.count())); - updateLibraryAction->setEnabled(false); - openComicAction->setEnabled(false); - showPropertiesAction->setEnabled(false); - openContainingFolderAction->setEnabled(false); - openContainingFolderComicAction->setEnabled(false); - setAsReadAction->setEnabled(false); - setAsNonReadAction->setEnabled(false); - setAllAsReadAction->setEnabled(false); - setAllAsNonReadAction->setEnabled(false); + disableActions(); importedCovers = true; } - else + else //librería normal abierta { - updateLibraryAction->setEnabled(true); - openComicAction->setEnabled(true); - showPropertiesAction->setEnabled(true); - openContainingFolderAction->setEnabled(true); - openContainingFolderComicAction->setEnabled(true); - setAsReadAction->setEnabled(true); - setAsNonReadAction->setEnabled(true); - setAllAsReadAction->setEnabled(true); - setAllAsNonReadAction->setEnabled(true); + enableActions(); importedCovers = false; } - renameLibraryAction->setEnabled(true); - deleteLibraryAction->setEnabled(true); - removeLibraryAction->setEnabled(true); - foldersFilter->setEnabled(true); - clearFoldersFilter->setEnabled(true); + enableLibraryActions(); } else { - updateLibraryAction->setEnabled(false); - renameLibraryAction->setEnabled(false); - deleteLibraryAction->setEnabled(false); - removeLibraryAction->setEnabled(false); - foldersFilter->setEnabled(false); - clearFoldersFilter->setEnabled(false); - setAsReadAction->setEnabled(false); - setAsNonReadAction->setEnabled(false); - setAllAsReadAction->setEnabled(false); - setAllAsNonReadAction->setEnabled(false); + disableAllActions(); } } @@ -544,28 +547,18 @@ void LibraryWindow::loadCovers(const QModelIndex & mi) TreeItem *item = static_cast(mi.internalPointer()); folderId = item->id; } - QSqlQuery selectQuery(dm->getDatabase()); //TODO check - selectQuery.prepare("select fileName from comic where comic.parentId = :parentId"); - selectQuery.bindValue(":parentId", folderId); - selectQuery.exec(); - dmCV->setQuery(selectQuery); + dmCV->setupModelData(folderId,dm->getDatabase()); comicView->setModel(dmCV); + //TODO automatizar (valorar si se deja al modelo) + comicView->horizontalHeader()->hideSection(0); + comicView->horizontalHeader()->hideSection(1); + comicView->horizontalHeader()->hideSection(3); //TODO - QSqlQuery selectQueryPaths(dm->getDatabase()); //TODO check - selectQueryPaths.prepare("select ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); - selectQueryPaths.bindValue(":parentId", folderId); - selectQueryPaths.exec(); - QStringList paths; - QString currentLibrary = selectedLibrary->currentText(); - QString path = libraries.value(currentLibrary); - path = path + "/.yacreaderlibrary/covers/"; - while (selectQueryPaths.next()) { - paths << path+selectQueryPaths.value(0).toString()+".jpg"; - } + QStringList paths = dmCV->getPaths(currentPath()); comicFlow->setImagePaths(paths); comicFlow->setFocus(Qt::OtherFocusReason); - paths = comicFlow->getImageFiles(); + if(paths.size()>0 && !importedCovers) { openComicAction->setEnabled(true); @@ -584,8 +577,8 @@ void LibraryWindow::loadCovers(const QModelIndex & mi) setAllAsReadAction->setEnabled(false); setAllAsNonReadAction->setEnabled(false); } - /*if(paths.size()>0) - comicView->setCurrentIndex(dmCV->index(paths[0]));*/ + if(paths.size()>0) + comicView->setCurrentIndex(dmCV->index(0,0)); } void LibraryWindow::centerComicFlow(const QModelIndex & mi) @@ -608,26 +601,24 @@ void LibraryWindow::centerComicFlow(const QModelIndex & mi) void LibraryWindow::updateComicView(int i) { - /*if((paths.size()>0)&&skip==0) - comicView->setCurrentIndex(dmCV->index(paths[i]));*/ + if(skip==0) + { + QModelIndex mi = dmCV->index(i,2); + comicView->setCurrentIndex(mi); + comicView->scrollTo(mi,QAbstractItemView::EnsureVisible); + } skip?(--skip):0; } void LibraryWindow::openComic() { - //int index = comicFlow->centerIndex(); if(!importedCovers) { - QModelIndex mi = comicView->currentIndex(); - QString path;// = QDir::cleanPath(dmCV->filePath(mi)); - - path.remove("/.yacreaderlibrary"); - path.remove(path.size()-4,4); + QString path = currentPath() + dmCV->getComicPath(comicView->currentIndex()); + QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+"/YACReader",QStringList() << path); //Comic is readed setCurrentComicReaded(); - - } } @@ -1004,6 +995,7 @@ void LibraryWindow::reloadOptions() comicFlow->setFlowType(flowType); } +//TODO esto sobra void LibraryWindow::updateFoldersView(QString path) { //QModelIndex mi = dm->index(path); @@ -1036,5 +1028,7 @@ void LibraryWindow::searchInFiles(int state) } } - - +QString LibraryWindow::currentPath() +{ + return libraries.value(selectedLibrary->currentText()); +} \ No newline at end of file diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 087edd6a..455e5cdd 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -2,7 +2,7 @@ #define __LIBRARYWINDOW_H #include -#include +#include #include #include #include @@ -11,8 +11,6 @@ #include #include #include -#include -#include #include "create_library_dialog.h" #include "add_library_dialog.h" @@ -26,6 +24,7 @@ #include "import_library_dialog.h" #include "package_manager.h" #include "treemodel.h" +#include "tablemodel.h" class LibraryWindow : public QMainWindow { @@ -56,12 +55,12 @@ private: QPushButton * clearFoldersFilter; QCheckBox * includeComicsCheckBox; //------------- - QListView * comicView; + QTableView * comicView; QTreeView * foldersView; QComboBox * selectedLibrary; TreeModel * dm; - QSqlQueryModel * dmCV; - QStringList paths; + TableModel * dmCV; + //QStringList paths; QMap libraries; QLabel * fullScreenToolTip; YACReaderIconProvider fip; @@ -121,10 +120,12 @@ private: void doDialogs(); void doModels(); + void disableAllActions(); void disableActions(); void enableActions(); void enableLibraryActions(); + QString currentPath(); public: LibraryWindow(); public slots: