From 28d8bd2940464708418210489d031d70d38b0adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 11 Oct 2014 17:01:15 +0200 Subject: [PATCH] Added drop support for copying/moving comics in the current folder --- YACReader/main_window_viewer.cpp | 2 +- YACReaderLibrary/YACReaderLibrary.pro | 6 +- YACReaderLibrary/comic_files_manager.cpp | 50 +++++++++++++ YACReaderLibrary/comic_files_manager.h | 32 +++++++++ YACReaderLibrary/comics_view.cpp | 53 ++++++++++++++ YACReaderLibrary/comics_view.h | 17 +++-- YACReaderLibrary/db/treemodel.cpp | 2 + YACReaderLibrary/db_helper.cpp | 32 ++++++++- YACReaderLibrary/db_helper.h | 1 + YACReaderLibrary/library_creator.cpp | 91 +++++++++++++++++------ YACReaderLibrary/library_creator.h | 22 +++--- YACReaderLibrary/library_window.cpp | 92 +++++++++++++++++++++++- YACReaderLibrary/library_window.h | 8 +++ common/comic.cpp | 21 ++++-- common/comic.h | 15 ++-- 15 files changed, 393 insertions(+), 51 deletions(-) create mode 100644 YACReaderLibrary/comic_files_manager.cpp create mode 100644 YACReaderLibrary/comic_files_manager.h diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index d8bd1db5..43ae0987 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -1281,7 +1281,7 @@ void MainWindowViewer::dropEvent(QDropEvent *event) if (info.isFile()) { QStringList imageSuffixs = Comic::getSupportedImageLiteralFormats(); - if(imageSuffixs.contains("."+info.suffix())) //image dropped + if(imageSuffixs.contains(info.suffix())) //image dropped openFolderFromPath(info.absoluteDir().absolutePath(),info.fileName()); else openComicFromPath(fName); // if is file, setText diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 1808cf7f..013e4ec9 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -119,7 +119,8 @@ HEADERS += comic_flow.h \ comics_view.h \ classic_comics_view.h \ empty_folder_widget.h \ - no_search_results_widget.h + no_search_results_widget.h \ + comic_files_manager.h SOURCES += comic_flow.cpp \ @@ -167,7 +168,8 @@ SOURCES += comic_flow.cpp \ comics_view.cpp \ classic_comics_view.cpp \ empty_folder_widget.cpp \ - no_search_results_widget.cpp + no_search_results_widget.cpp \ + comic_files_manager.cpp diff --git a/YACReaderLibrary/comic_files_manager.cpp b/YACReaderLibrary/comic_files_manager.cpp new file mode 100644 index 00000000..f187aab6 --- /dev/null +++ b/YACReaderLibrary/comic_files_manager.cpp @@ -0,0 +1,50 @@ +#include "comic_files_manager.h" +#include +#include +#include + +ComicFilesManager::ComicFilesManager(QObject *parent) : + QObject(parent), canceled(false) +{ +} + +void ComicFilesManager::copyComicsTo(const QList &sourceComics, const QString &folderDest) +{ + comics = sourceComics; + folder = folderDest; + move = false; +} + +void ComicFilesManager::moveComicsTo(const QList &sourceComics, const QString &folderDest) +{ + comics = sourceComics; + folder = folderDest; + move = true; +} + +void ComicFilesManager::process() +{ + int i=0; + bool successProcesingFiles = false; + foreach (QString source, comics) { + QFileInfo info(source); + if(QFile::copy(source, QDir::cleanPath(folder+'/'+info.fileName()))) + { + successProcesingFiles = true; + if(move) + QFile::remove(source); + } + + i++; + emit progress(i); + } + + if(successProcesingFiles) + emit success(); + emit finished(); +} + +void ComicFilesManager::cancel() +{ + +} diff --git a/YACReaderLibrary/comic_files_manager.h b/YACReaderLibrary/comic_files_manager.h new file mode 100644 index 00000000..7058e17e --- /dev/null +++ b/YACReaderLibrary/comic_files_manager.h @@ -0,0 +1,32 @@ +#ifndef COMIC_FILES_MANAGER_H +#define COMIC_FILES_MANAGER_H + +#include + +//this class is intended to work in background, just use moveToThread and process to start working +class ComicFilesManager : public QObject +{ + Q_OBJECT +public: + explicit ComicFilesManager(QObject *parent = 0); + void copyComicsTo(const QList & sourceComics, const QString & folderDest); + void moveComicsTo(const QList & comics, const QString & folderDest); + +signals: + void currentComic(QString); + void progress(int); + void finished(); + void success(); //at least one comics has been copied or moved +public slots: + void process(); + void cancel(); + +protected: + bool move; + bool canceled; + QList comics; + QString folder; + +}; + +#endif // COMIC_FILES_MANAGER_H diff --git a/YACReaderLibrary/comics_view.cpp b/YACReaderLibrary/comics_view.cpp index 5a1dac7b..4f1a77f7 100644 --- a/YACReaderLibrary/comics_view.cpp +++ b/YACReaderLibrary/comics_view.cpp @@ -1,11 +1,64 @@ #include "comics_view.h" +#include "comic.h" + +#include "QsLog.h" ComicsView::ComicsView(QWidget *parent) : QWidget(parent),model(NULL) { + setAcceptDrops(true); } void ComicsView::setModel(TableModel *m) { model = m; } + +void ComicsView::dragEnterEvent(QDragEnterEvent *event) +{ + QList urlList; + + if (event->mimeData()->hasUrls()) + { + urlList = event->mimeData()->urls(); + foreach (QUrl url, urlList) + { + if(Comic::fileIsComic(url)) + { + event->acceptProposedAction(); + return; + } + } + } +} + +void ComicsView::dropEvent(QDropEvent *event) +{ + bool accepted = false; +QLOG_DEBUG() << "drop" << event->dropAction(); + if(event->dropAction() == Qt::CopyAction) + { + QLOG_DEBUG() << "copy"; + emit copyComicsToCurrentFolder(filterInvalidComicFiles(event->mimeData()->urls())); + + } + else if(event->dropAction() & Qt::MoveAction) + { + QLOG_DEBUG() << "move"; + emit moveComicsToCurrentFolder(filterInvalidComicFiles(event->mimeData()->urls())); + } + + if(accepted) + event->acceptProposedAction(); +} + +QList ComicsView::filterInvalidComicFiles(const QList &list) +{ + QList validComicFiles; + foreach (QUrl url, list) { + if(Comic::fileIsComic(url)) + validComicFiles << url.toLocalFile(); + } + + return validComicFiles; +} diff --git a/YACReaderLibrary/comics_view.h b/YACReaderLibrary/comics_view.h index d4739f02..d2c6754a 100644 --- a/YACReaderLibrary/comics_view.h +++ b/YACReaderLibrary/comics_view.h @@ -1,13 +1,9 @@ #ifndef COMICS_VIEW_H #define COMICS_VIEW_H -#include +#include #include "tablemodel.h" -#include -#include -#include -#include class YACReaderTableView; class QSplitter; @@ -37,12 +33,23 @@ public: signals: void selected(unsigned int); void comicRated(int,QModelIndex); + + //Drops + void copyComicsToCurrentFolder(QList); + void moveComicsToCurrentFolder(QList); + public slots: virtual void setShowMarks(bool show) = 0; virtual void selectAll() = 0; protected: TableModel * model; + //Drop to import + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + +private: + QList filterInvalidComicFiles(const QList & list); }; #endif // COMICS_VIEW_H diff --git a/YACReaderLibrary/db/treemodel.cpp b/YACReaderLibrary/db/treemodel.cpp index f04b7bef..219eaa0e 100644 --- a/YACReaderLibrary/db/treemodel.cpp +++ b/YACReaderLibrary/db/treemodel.cpp @@ -449,6 +449,8 @@ QString TreeModel::getDatabase() QString TreeModel::getFolderPath(const QModelIndex &folder) { + if(!folder.isValid()) //root folder + return "/"; return static_cast(folder.internalPointer())->data(TreeModel::Path).toString(); } diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 17678360..64124760 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -564,12 +564,42 @@ Folder DBHelper::loadFolder(qulonglong id, QSqlDatabase & db) folder.parentId = record.value("parentId").toULongLong(); folder.name = record.value("name").toString(); folder.path = record.value("path").toString(); + folder.knownId = true; //new 7.1 folder.setFinished(record.value("finished").toBool()); folder.setCompleted(record.value("completed").toBool()); } - return folder; + return folder; +} + +Folder DBHelper::loadFolder(const QString &folderName, qulonglong parentId, QSqlDatabase &db) +{ + Folder folder; + + QLOG_DEBUG() << "Looking for folder with name = " << folderName << " and parent " << parentId; + + QSqlQuery query(db); + query.prepare("SELECT * FROM folder WHERE parentId = :parentId AND name = :folderName"); + query.bindValue(":parentId",parentId); + query.bindValue(":folderName", folderName); + query.exec(); + + folder.parentId = parentId; + if(query.next()) + { + QSqlRecord record = query.record(); + folder.id = record.value("id").toULongLong(); + folder.name = record.value("name").toString(); + folder.path = record.value("path").toString(); + folder.knownId = true; + //new 7.1 + folder.setFinished(record.value("finished").toBool()); + folder.setCompleted(record.value("completed").toBool()); + QLOG_DEBUG() << "FOUND!!"; + } + + return folder; } ComicDB DBHelper::loadComic(qulonglong id, QSqlDatabase & db) diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index c06251d9..4b310469 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -49,6 +49,7 @@ public: static QList getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true); //load static Folder loadFolder(qulonglong id, QSqlDatabase & db); + static Folder loadFolder(const QString & folderName, qulonglong parentId, QSqlDatabase & db); static ComicDB loadComic(qulonglong id, QSqlDatabase & db); static ComicDB loadComic(QString cname, QString cpath, QString chash, QSqlDatabase & database); static ComicInfo loadComicInfo(QString hash, QSqlDatabase & db); diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index 23f8ed63..22b7ea2c 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -36,7 +36,7 @@ using namespace std; //-------------------------------------------------------------------------------- LibraryCreator::LibraryCreator() - :creation(false) + :creation(false), partialUpdate(false) { _nameFilter << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt"; } @@ -44,12 +44,45 @@ LibraryCreator::LibraryCreator() void LibraryCreator::createLibrary(const QString &source, const QString &target) { creation = true; - processLibrary(source,target); + processLibrary(source, target); } void LibraryCreator::updateLibrary(const QString &source, const QString &target) { - processLibrary(source,target); + partialUpdate = false; + processLibrary(source, target); +} + +void LibraryCreator::updateFolder(const QString &source, const QString &target, const QString &sourceFolder) +{ + partialUpdate = true; + + _currentPathFolders.clear(); + _currentPathFolders.append(Folder(1,1,"root","/")); + + QString relativeFolderPath = sourceFolder; + relativeFolderPath = relativeFolderPath.remove(QDir::cleanPath(source)); + + if(relativeFolderPath.startsWith("/")) + relativeFolderPath = relativeFolderPath.remove(0,1);//remove firts '/' + + QStringList folders = relativeFolderPath.split('/'); + + QSqlDatabase db = DataBaseManagement::loadDatabase(target); + + foreach (QString folderName, folders) { + qulonglong parentId = _currentPathFolders.last().id; + _currentPathFolders.append(DBHelper::loadFolder(folderName, parentId, db)); + QLOG_DEBUG() << "Folder appended : " << _currentPathFolders.last().id << " " << _currentPathFolders.last().name << " with parent" << _currentPathFolders.last().parentId; + } + + QSqlDatabase::removeDatabase(_database.connectionName()); + + QLOG_DEBUG() << "Relative path : " << relativeFolderPath; + + _sourceFolder = sourceFolder; + + processLibrary(source, target); } void LibraryCreator::processLibrary(const QString & source, const QString & target) @@ -108,7 +141,7 @@ void LibraryCreator::run() /*QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);*/ _database.transaction(); - //se crea la librería + //se crea la librería create(QDir(_source)); _database.commit(); _database.close(); @@ -118,9 +151,14 @@ void LibraryCreator::run() } else { - QLOG_INFO() << "Starting to update library ( " << _source << "," << _target << ")"; - _currentPathFolders.clear(); - _currentPathFolders.append(Folder(1,1,"root","/")); + QLOG_INFO() << "Starting to update folder" << _sourceFolder << "in library ( " << _source << "," << _target << ")"; + if(!partialUpdate) + { + _currentPathFolders.clear(); + _currentPathFolders.append(Folder(1,1,"root","/")); + QLOG_DEBUG() << "update whole library"; + } + _database = DataBaseManagement::loadDatabase(_target); //_database.setDatabaseName(_target+"/library.ydb"); if(!_database.open()) @@ -133,19 +171,28 @@ void LibraryCreator::run() } QSqlQuery pragma("PRAGMA foreign_keys = ON",_database); _database.transaction(); - update(QDir(_source)); + if(partialUpdate) + update(QDir(_sourceFolder)); + else + update(QDir(_source)); _database.commit(); _database.close(); QSqlDatabase::removeDatabase(_target); - //si estabamos en modo creación, se está añadiendo una librería que ya existía y se ha actualizado antes de añadirse. - if(!creation) - emit(updated()); - else - emit(created()); + //si estabamos en modo creación, se está añadiendo una librería que ya existía y se ha actualizado antes de añadirse. + if(!partialUpdate) + { + if(!creation) + emit(updated()); + else + emit(created()); + } QLOG_INFO() << "Update library END"; } - msleep(100);//TODO try to solve the problem with the udpate dialog (ya no se usa más...) - emit(finished()); + //msleep(100);//TODO try to solve the problem with the udpate dialog (ya no se usa más...) + if(partialUpdate) + emit updatedCurrentFolder(); + else + emit finished(); creation = false; } @@ -201,10 +248,10 @@ void LibraryCreator::create(QDir dir) #endif if(fileInfo.isDir()) { - //se añade al path actual el folder, aún no se sabe si habrá que añadirlo a la base de datos + //se añade al path actual el folder, aún no se sabe si habrá que añadirlo a la base de datos _currentPathFolders.append(Folder(fileInfo.fileName(),relativePath)); create(QDir(fileInfo.absoluteFilePath())); - //una vez importada la información del folder, se retira del path actual ya que no volverá a ser visitado + //una vez importada la información del folder, se retira del path actual ya que no volverá a ser visitado _currentPathFolders.pop_back(); } else @@ -221,7 +268,7 @@ bool LibraryCreator::checkCover(const QString & hash) void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo & fileInfo) { - //Se calcula el hash del cómic + //Se calcula el hash del cómic QCryptographicHash crypto(QCryptographicHash::Sha1); QFile file(fileInfo.absoluteFilePath()); @@ -244,7 +291,7 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo & if (numPages > 0 || exists) { - //en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos + //en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos insertFolders(); comic.info.numPages = numPages; comic.parentId = _currentPathFolders.last().id; @@ -337,7 +384,7 @@ void LibraryCreator::update(QDir dirS) #else QString path = QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source); #endif - _currentPathFolders.append(Folder(fileInfoS.fileName(),path)); //folder actual no está en la BD + _currentPathFolders.append(Folder(fileInfoS.fileName(),path)); //folder actual no está en la BD create(QDir(fileInfoS.absoluteFilePath())); _currentPathFolders.pop_back(); } @@ -476,7 +523,7 @@ void LibraryCreator::update(QDir dirS) { if(fileInfoS.isFile() && !fileInfoD->isDir()) { - //TODO comprobar fechas + tamaño + //TODO comprobar fechas + tamaño //if(fileInfoS.lastModified()>fileInfoD.lastModified()) //{ // dirD.mkpath(_target+(QDir::cleanPath(fileInfoS.absolutePath()).remove(_source))); @@ -585,7 +632,7 @@ void ThumbnailCreator::create() } if(!archive.isValid()) QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource; - //se filtran para obtener sólo los formatos soportados + //se filtran para obtener sólo los formatos soportados QList order = archive.getFileNames(); QList fileNames = FileComic::filter(order); _numPages = fileNames.size(); diff --git a/YACReaderLibrary/library_creator.h b/YACReaderLibrary/library_creator.h index 26479fd2..f051b5d1 100644 --- a/YACReaderLibrary/library_creator.h +++ b/YACReaderLibrary/library_creator.h @@ -22,32 +22,37 @@ { Q_OBJECT public: - LibraryCreator(); - void createLibrary(const QString & source, const QString & target); - void updateLibrary(const QString & source, const QString & target); - void stop(); + LibraryCreator(); + void createLibrary(const QString & source, const QString & target); + void updateLibrary(const QString & source, const QString & target); + void updateFolder(const QString & source, const QString & target, const QString & folder); + 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 + //atributos "globales" durante el proceso de creación y actualización enum Mode _mode; QString _source; QString _target; + QString _sourceFolder; //used for partial updates QStringList _nameFilter; QSqlDatabase _database; - QList _currentPathFolders; //lista de folders en el orden en el que están siendo explorados, el último es el folder actual + QList _currentPathFolders; //lista de folders en el orden en el que están siendo explorados, el último es el folder actual //recursive method void create(QDir currentDirectory); void update(QDir currentDirectory); void run(); - qulonglong 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) bool checkCover(const QString & hash); void insertComic(const QString & relativePath,const QFileInfo & fileInfo); //qulonglong insertFolder(qulonglong parentId,const Folder & folder); //qulonglong insertComic(const Comic & comic); bool stopRunning; - //LibraryCreator está en modo creación si creation == true; + //LibraryCreator está en modo creación si creation == true; bool creation; + bool partialUpdate; + signals: void finished(); void coverExtracted(QString); @@ -57,6 +62,7 @@ void created(); void failedCreatingDB(QString); void failedOpeningDB(QString); + void updatedCurrentFolder(); }; class ThumbnailCreator : public QObject diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index e8e6b702..116c639d 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -71,6 +71,8 @@ #include "no_search_results_widget.h" +#include "comic_files_manager.h" + #include "QsLog.h" #ifdef Q_OS_WIN @@ -389,6 +391,8 @@ void LibraryWindow::disconnectComicsViewConnections(ComicsView * widget) disconnect(widget,SIGNAL(selected(unsigned int)),this,SLOT(openComic())); disconnect(widget,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openComic())); disconnect(selectAllComicsAction,SIGNAL(triggered()),widget,SLOT(selectAll())); + disconnect(comicsView, SIGNAL(copyComicsToCurrentFolder(QList)), this, SLOT(copyAndImportComicsToCurrentFolder(QList))); + disconnect(comicsView, SIGNAL(moveComicsToCurrentFolder(QList)), this, SLOT(moveAndImportComicsToCurrentFolder(QList))); } void LibraryWindow::doComicsViewConnections() @@ -398,6 +402,9 @@ void LibraryWindow::doComicsViewConnections() connect(comicsView,SIGNAL(selected(unsigned int)),this,SLOT(openComic())); connect(comicsView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openComic())); connect(selectAllComicsAction,SIGNAL(triggered()),comicsView,SLOT(selectAll())); + //Drops + connect(comicsView, SIGNAL(copyComicsToCurrentFolder(QList)), this, SLOT(copyAndImportComicsToCurrentFolder(QList))); + connect(comicsView, SIGNAL(moveComicsToCurrentFolder(QList)), this, SLOT(moveAndImportComicsToCurrentFolder(QList))); } void LibraryWindow::createActions() @@ -925,6 +932,8 @@ void LibraryWindow::createConnections() connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget())); connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary())); connect(libraryCreator,SIGNAL(created()),this,SLOT(openLastCreated())); + connect(libraryCreator,SIGNAL(updatedCurrentFolder()), this, SLOT(showRootWidget())); + connect(libraryCreator,SIGNAL(updatedCurrentFolder()), this, SLOT(reloadCovers())); connect(libraryCreator,SIGNAL(comicAdded(QString,QString)),importWidget,SLOT(newComic(QString,QString))); //libraryCreator errors connect(libraryCreator,SIGNAL(failedCreatingDB(QString)),this,SLOT(manageCreatingError(QString))); @@ -1244,6 +1253,73 @@ void LibraryWindow::loadCoversFromCurrentModel() } } +void LibraryWindow::copyAndImportComicsToCurrentFolder(const QList &comics) +{ + QString destFolderPath = currentFolderPath(); + + QProgressDialog * progressDialog = newProgressDialog(tr("Copying comics..."),comics.size()); + + ComicFilesManager * comicFilesManager = new ComicFilesManager(); + comicFilesManager->copyComicsTo(comics,destFolderPath); + + processComicFiles(comicFilesManager, progressDialog); +} + +void LibraryWindow::moveAndImportComicsToCurrentFolder(const QList &comics) +{ + QString destFolderPath = currentFolderPath(); + + QProgressDialog * progressDialog = newProgressDialog(tr("Moving comics..."),comics.size()); + + ComicFilesManager * comicFilesManager = new ComicFilesManager(); + comicFilesManager->moveComicsTo(comics,destFolderPath); + + processComicFiles(comicFilesManager, progressDialog); +} + +void LibraryWindow::processComicFiles(ComicFilesManager * comicFilesManager, QProgressDialog * progressDialog) +{ + connect(comicFilesManager,SIGNAL(progress(int)), progressDialog, SLOT(setValue(int))); + + QThread * thread = NULL; + + thread = new QThread(); + + comicFilesManager->moveToThread(thread); + + connect(thread, SIGNAL(started()), comicFilesManager, SLOT(process())); + connect(comicFilesManager, SIGNAL(success()), this, SLOT(updateCurrentFolder())); + connect(comicFilesManager, SIGNAL(finished()), thread, SLOT(quit())); + connect(comicFilesManager, SIGNAL(finished()), comicFilesManager, SLOT(deleteLater())); + connect(comicFilesManager, SIGNAL(finished()), progressDialog, SLOT(close())); + connect(comicFilesManager, SIGNAL(finished()), progressDialog, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + if(thread != NULL) + thread->start(); +} + +void LibraryWindow::updateCurrentFolder() +{ + importWidget->setUpdateLook(); + showImportingWidget(); + + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.getPath(currentLibrary); + _lastAdded = currentLibrary; + libraryCreator->updateFolder(QDir::cleanPath(path),QDir::cleanPath(path+"/.yacreaderlibrary"),currentFolderPath()); + libraryCreator->start(); +} + +QProgressDialog *LibraryWindow::newProgressDialog(const QString &label, int maxValue) +{ + QProgressDialog * progressDialog = new QProgressDialog(label,"Cancel",0,maxValue,this); + progressDialog->setWindowModality(Qt::WindowModal); + progressDialog->setMinimumWidth(350); + progressDialog->show(); + return progressDialog; +} + void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child) { QModelIndex dest = foldersModel->index(child,0,mi); @@ -1885,7 +1961,21 @@ void LibraryWindow::reloadOptions() QString LibraryWindow::currentPath() { - return libraries.getPath(selectedLibrary->currentText()); + return libraries.getPath(selectedLibrary->currentText()); +} + +QString LibraryWindow::currentFolderPath() +{ + QString path; + + if(foldersView->selectionModel()->selectedRows().length()>0) + path = foldersModel->getFolderPath(foldersView->currentIndex()); + else + path = foldersModel->getFolderPath(QModelIndex()); + + QLOG_DEBUG() << "current folder path : " << QDir::cleanPath(currentPath()+path); + + return QDir::cleanPath(currentPath()+path); } //TODO ComicsView: some actions in the comics toolbar can be relative to a certain view diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 87fd65c4..db644e8d 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -56,6 +56,8 @@ class ComicsViewTransition; class EmptyFolderWidget; class NoSearchResultsWidget; class EditShortcutsDialog; +class ComicFilesManager; +class QProgressDialog; #include "comic_db.h" @@ -227,6 +229,7 @@ private: //void enableLibraryActions(); QString currentPath(); + QString currentFolderPath(); //settings QSettings * settings; @@ -319,6 +322,11 @@ public slots: void toggleComicsView(); void checkSearchNumResults(int numResults); void loadCoversFromCurrentModel(); + void copyAndImportComicsToCurrentFolder(const QList & comics); + void moveAndImportComicsToCurrentFolder(const QList &comics); + void processComicFiles(ComicFilesManager * comicFilesManager, QProgressDialog * progressDialog); + void updateCurrentFolder(); //imports new comics from the current folder + QProgressDialog * newProgressDialog(const QString & label, int maxValue); }; #endif diff --git a/common/comic.cpp b/common/comic.cpp index 6c5b4821..96775a61 100644 --- a/common/comic.cpp +++ b/common/comic.cpp @@ -13,8 +13,11 @@ #include "compressed_archive.h" #include "comic_db.h" -QStringList Comic::extensions = QStringList() << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp"; -QStringList Comic::literalExtensions = QStringList() << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp"; +QStringList Comic::imageExtensions = QStringList() << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp"; +QStringList Comic::literalImageExtensions = QStringList() << "jpg" << "jpeg" << "png" << "gif" << "tiff" << "tif" << "bmp"; + +QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt"; +QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "7z" << "cb7" << "arj" << "cbt"; //----------------------------------------------------------------------------- Comic::Comic() @@ -177,7 +180,13 @@ bool Comic::pageIsLoaded(int page) { if(page < 0 || page >= _pages.size()) return false; - return _loadedPages[page]; + return _loadedPages[page]; +} + +bool Comic::fileIsComic(QUrl &path) +{ + QFileInfo info(path.toLocalFile()); + return literalComicExtensions.contains(info.suffix()); } //////////////////////////////////////////////////////////////////////////////// @@ -302,7 +311,7 @@ void FileComic::crcError(int index) emit crcErrorFound(tr("CRC error on page (%1): some of the pages will not be displayed correctly").arg(index+1)); } -//TODO: comprobar que si se produce uno de estos errores, la carga del cómic es irrecuperable +//TODO: comprobar que si se produce uno de estos errores, la carga del c�mic es irrecuperable void FileComic::unknownError(int index) { Q_UNUSED(index) @@ -425,7 +434,7 @@ void FileComic::process() return; } - //se filtran para obtener sólo los formatos soportados + //se filtran para obtener s�lo los formatos soportados _order = archive.getFileNames(); _fileNames = filter(_order); @@ -472,7 +481,7 @@ void FileComic::process() emit imageLoaded(sortedIndex,_pages[sortedIndex]); }*/ - emit imagesLoaded(); + emit imagesLoaded(); //moveToThread(QApplication::instance()->thread()); } diff --git a/common/comic.h b/common/comic.h index d034c470..63180ae1 100644 --- a/common/comic.h +++ b/common/comic.h @@ -49,8 +49,11 @@ class ComicDB; bool _isPDF; - static QStringList extensions; - static QStringList literalExtensions; + static QStringList imageExtensions; + static QStringList literalImageExtensions; + static QStringList comicExtensions; + static QStringList literalComicExtensions; + public: Bookmarks * bm; @@ -74,12 +77,14 @@ class ComicDB; //QPixmap * currentPage(); bool loaded(); //QPixmap * operator[](unsigned int index); - QVector * getRawData(){return &_pages;}; + QVector * getRawData(){return &_pages;} QByteArray getRawPage(int page); bool pageIsLoaded(int page); - inline static QStringList getSupportedImageFormats() { return extensions;}; - inline static QStringList getSupportedImageLiteralFormats() { return literalExtensions;}; + inline static QStringList getSupportedImageFormats() { return imageExtensions;} + inline static QStringList getSupportedImageLiteralFormats() { return literalImageExtensions;} + + static bool fileIsComic(QUrl & path); public slots: void loadFinished();