diff --git a/YACReaderLibrary/add_library_dialog.cpp b/YACReaderLibrary/add_library_dialog.cpp index e13599bd..53ef8f60 100644 --- a/YACReaderLibrary/add_library_dialog.cpp +++ b/YACReaderLibrary/add_library_dialog.cpp @@ -71,7 +71,6 @@ void AddLibraryDialog::add() { //accept->setEnabled(false); emit(addLibrary(QDir::cleanPath(path->text()),nameEdit->text())); - close(); } void AddLibraryDialog::nameSetted(const QString & text) diff --git a/YACReaderLibrary/create_library_dialog.cpp b/YACReaderLibrary/create_library_dialog.cpp index a2d1cfb4..a6d21598 100644 --- a/YACReaderLibrary/create_library_dialog.cpp +++ b/YACReaderLibrary/create_library_dialog.cpp @@ -49,21 +49,6 @@ void CreateLibraryDialog::setupUI() content->addWidget(find,1,2); content->setColumnMinimumWidth(2,0); //TODO - QHBoxLayout *middleLayout = new QHBoxLayout; - - progressBar = new QProgressBar(this); - progressBar->setMinimum(0); - progressBar->setMaximum(0); - progressBar->setTextVisible(false); - progressBar->hide(); - - currentFileLabel = new QLabel(""); - currentFileLabel->setWordWrap(true); - middleLayout->addWidget(currentFileLabel); - middleLayout->addStretch(); - middleLayout->setSizeConstraint(QLayout::SetMaximumSize); - - QHBoxLayout *bottomLayout = new QHBoxLayout; bottomLayout->addWidget(message = new QLabel(tr("Create a library could take several minutes. You can stop the process and update the library later for completing the task."))); message->setWordWrap(true); @@ -75,9 +60,6 @@ void CreateLibraryDialog::setupUI() QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(content); - mainLayout->addLayout(middleLayout); - mainLayout->addStretch(); - mainLayout->addWidget(progressBar); mainLayout->addLayout(bottomLayout); QHBoxLayout * imgMainLayout = new QHBoxLayout; @@ -93,32 +75,30 @@ void CreateLibraryDialog::setupUI() setWindowTitle(tr("Create new library")); } +void CreateLibraryDialog::show(const QMap & libs) +{ + libraries = libs; + QDialog::show(); +} + void CreateLibraryDialog::create() { QFileInfo f(path->text()); if(f.exists() && f.isDir() && f.isWritable()) { - progressBar->show(); - message->show(); - currentFileLabel->setText("Importing : \n\n\n\n\n"); - this->adjustSize(); - accept->setEnabled(false); - emit(createLibrary(QDir::cleanPath(path->text()),QDir::cleanPath(path->text())+"/.yacreaderlibrary",nameEdit->text())); - close(); + if(!libraries.contains(nameEdit->text())) + { + emit(createLibrary(QDir::cleanPath(path->text()),QDir::cleanPath(path->text())+"/.yacreaderlibrary",nameEdit->text())); + close(); + } + else + emit(libraryExists(nameEdit->text())); } else QMessageBox::critical(NULL,tr("Path not found"),tr("The selected path does not exist or is not a valid path. Be sure that you have write access to this folder")); } -void CreateLibraryDialog::showCurrentFile(QString file) -{ - currentFileLabel->setText(tr("Importing : \n") + file); - currentFileLabel->update(); - //this->adjustSize(); - //is->update(); -} - void CreateLibraryDialog::nameSetted(const QString & text) { if(!text.isEmpty()) @@ -163,11 +143,8 @@ void CreateLibraryDialog::findPath() void CreateLibraryDialog::close() { - progressBar->hide(); path->clear(); nameEdit->clear(); - currentFileLabel->setText(""); - this->adjustSize(); accept->setEnabled(false); QDialog::close(); } @@ -176,7 +153,7 @@ void CreateLibraryDialog::setDataAndStart(QString name, QString path) { this->path->setText(path); this->nameEdit->setText(name); - show(); + QDialog::show(); create(); } //----------------------------------------------------------------------------- @@ -199,12 +176,6 @@ UpdateLibraryDialog::UpdateLibraryDialog(QWidget * parent) mainLayout->addStretch(); - progressBar = new QProgressBar(this); - progressBar->setMinimum(0); - progressBar->setMaximum(0); - progressBar->setTextVisible(false); - - mainLayout->addWidget(progressBar); mainLayout->addLayout(bottom); QHBoxLayout * imgMainLayout = new QHBoxLayout; diff --git a/YACReaderLibrary/create_library_dialog.h b/YACReaderLibrary/create_library_dialog.h index e24e3e11..e162cf1a 100644 --- a/YACReaderLibrary/create_library_dialog.h +++ b/YACReaderLibrary/create_library_dialog.h @@ -18,24 +18,25 @@ QLabel * textLabel; QLabel * message; QProgressBar *progressBar; - QLabel * currentFileLabel; QLineEdit * path; QLineEdit * nameEdit; QPushButton * find; QPushButton * accept; QPushButton * cancel; + QMap libraries; void setupUI(); public slots: void create(); void findPath(); - void showCurrentFile(QString file); void close(); void setDataAndStart(QString name, QString paht); - void nameSetted(const QString & text); + void nameSetted(const QString & text); void pathSetted(const QString & text); + void show(const QMap & libraries); signals: void createLibrary(QString source, QString target, QString name); void cancelCreate(); + void libraryExists(const QString & name); }; class UpdateLibraryDialog : public QDialog diff --git a/YACReaderLibrary/import_library_dialog.cpp b/YACReaderLibrary/import_library_dialog.cpp index ad38fd1e..0892bc17 100644 --- a/YACReaderLibrary/import_library_dialog.cpp +++ b/YACReaderLibrary/import_library_dialog.cpp @@ -86,12 +86,24 @@ void ImportLibraryDialog::setupUI() setModal(true); setWindowTitle(tr("Extract a catalog")); } +void ImportLibraryDialog::show(const QMap & libs) +{ + libraries = libs; + QDialog::show(); +} void ImportLibraryDialog::add() { - accept->setEnabled(false); - progressBar->show(); - emit(unpackCLC(QDir::cleanPath(path->text()),QDir::cleanPath(destPath->text()),nameEdit->text())); + if(!libraries.contains(nameEdit->text())) + { + accept->setEnabled(false); + progressBar->show(); + emit(unpackCLC(QDir::cleanPath(path->text()),QDir::cleanPath(destPath->text()),nameEdit->text())); + } + else + { + emit(libraryExists(nameEdit->text())); + } } void ImportLibraryDialog::findPath() diff --git a/YACReaderLibrary/import_library_dialog.h b/YACReaderLibrary/import_library_dialog.h index 7c4f9305..b41b646c 100644 --- a/YACReaderLibrary/import_library_dialog.h +++ b/YACReaderLibrary/import_library_dialog.h @@ -29,15 +29,18 @@ void setupUI(); int progressCount; void closeEvent ( QCloseEvent * e ); + QMap libraries; public slots: void add(); void findPath(); void findDestination(); void close(); void nameEntered(); + void show(const QMap & libs); signals: void unpackCLC(QString clc,QString targetFolder, QString name); + void libraryExists(const QString & name); }; #endif diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index d5742464..ca062f39 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -260,7 +260,6 @@ void LibraryWindow::doLayout() void LibraryWindow::doDialogs() { createLibraryDialog = new CreateLibraryDialog(this); - updateLibraryDialog = new UpdateLibraryDialog(this); renameLibraryDialog = new RenameLibraryDialog(this); propertiesDialog = new PropertiesDialog(this); exportLibraryDialog = new ExportLibraryDialog(this); @@ -646,10 +645,11 @@ void LibraryWindow::createConnections() //libraryCreator connections connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString))); + connect(createLibraryDialog,SIGNAL(libraryExists(QString)),this,SLOT(libraryAlreadyExists(QString))); connect(importComicsInfoDialog,SIGNAL(finished(int)),this,SLOT(reloadCurrentLibrary())); - connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString))); - connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString))); + //connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString))); + //connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString))); connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget())); connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary())); connect(libraryCreator,SIGNAL(created()),this,SLOT(openLastCreated())); @@ -668,13 +668,13 @@ void LibraryWindow::createConnections() connect(importLibraryDialog,SIGNAL(unpackCLC(QString,QString,QString)),this,SLOT(importLibrary(QString,QString,QString))); connect(importLibraryDialog,SIGNAL(rejected()),packageManager,SLOT(cancel())); connect(importLibraryDialog,SIGNAL(rejected()),this,SLOT(deleteCurrentLibrary())); + connect(importLibraryDialog,SIGNAL(libraryExists(QString)),this,SLOT(libraryAlreadyExists(QString))); connect(packageManager,SIGNAL(imported()),importLibraryDialog,SLOT(hide())); connect(packageManager,SIGNAL(imported()),this,SLOT(openLastCreated())); //create and update dialogs connect(createLibraryDialog,SIGNAL(cancelCreate()),this,SLOT(cancelCreating())); - connect(updateLibraryDialog,SIGNAL(cancelUpdate()),this,SLOT(stopLibraryCreator())); //open existing library from dialog. connect(addLibraryDialog,SIGNAL(addLibrary(QString,QString)),this,SLOT(openLibrary(QString,QString))); @@ -695,7 +695,7 @@ void LibraryWindow::createConnections() //actions connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary())); connect(exportLibraryAction,SIGNAL(triggered()),exportLibraryDialog,SLOT(show())); - connect(importLibraryAction,SIGNAL(triggered()),importLibraryDialog,SLOT(show())); + connect(importLibraryAction,SIGNAL(triggered()),this,SLOT(importLibraryPackage())); connect(openLibraryAction,SIGNAL(triggered()),this,SLOT(showAddLibrary())); connect(showPropertiesAction,SIGNAL(triggered()),this,SLOT(showProperties())); @@ -1067,7 +1067,7 @@ void LibraryWindow::setComicsUnreaded() void LibraryWindow::createLibrary() { - createLibraryDialog->show(); + createLibraryDialog->show(libraries); } void LibraryWindow::create(QString source, QString dest, QString name) @@ -1110,16 +1110,25 @@ void LibraryWindow::showAddLibrary() void LibraryWindow::openLibrary(QString path, QString name) { - path.remove("/.yacreaderlibrary"); - QDir d; //TODO change this by static methods (utils class?? with delTree for example) - if(d.exists(path + "/.yacreaderlibrary")) + if(!libraries.contains(name)) { - _lastAdded = name; - _sourceLastAdded = path; - openLastCreated(); + //TODO: fix bug, /a/b/c/.yacreaderlibrary/d/e + path.remove("/.yacreaderlibrary"); + QDir d; //TODO change this by static methods (utils class?? with delTree for example) + if(d.exists(path + "/.yacreaderlibrary")) + { + _lastAdded = name; + _sourceLastAdded = path; + openLastCreated(); + addLibraryDialog->close(); + } + else + QMessageBox::warning(this,tr("Library not found"),tr("The selected folder doesn't contain any library.")); } else - QMessageBox::warning(this,tr("Library not found"),tr("The selected folder doesn't contain any library.")); + { + libraryAlreadyExists(name); + } } void LibraryWindow::loadLibraries() @@ -1175,7 +1184,6 @@ void LibraryWindow::saveLibraries() void LibraryWindow::updateLibrary() { - //updateLibraryDialog->show(); importWidget->setUpdateLook(); showImportingWidget(); @@ -1245,12 +1253,25 @@ void LibraryWindow::renameLibrary() void LibraryWindow::rename(QString newName) { QString currentLibrary = selectedLibrary->currentText(); - QString path = libraries.value(currentLibrary); - libraries.remove(currentLibrary); - //selectedLibrary->removeItem(selectedLibrary->currentIndex()); - libraries.insert(newName,path); - selectedLibrary->renameCurrentLibrary(newName); - saveLibraries(); + if(newName != currentLibrary) + { + if(!libraries.contains(newName)) + { + QString path = libraries.value(currentLibrary); + libraries.remove(currentLibrary); + //selectedLibrary->removeItem(selectedLibrary->currentIndex()); + libraries.insert(newName,path); + selectedLibrary->renameCurrentLibrary(newName); + saveLibraries(); + renameLibraryDialog->close(); + } + else + { + libraryAlreadyExists(newName); + } + } + else + renameLibraryDialog->close(); //selectedLibrary->setCurrentIndex(selectedLibrary->findText(newName)); } @@ -1662,3 +1683,13 @@ void LibraryWindow::updateHistory(const QModelIndex &mi) forwardAction->setEnabled(false); } + +void LibraryWindow::libraryAlreadyExists(const QString & name) +{ + QMessageBox::information(this,tr("Library name already exists"),tr("There is another library with the name '%1'.").arg(name)); +} + +void LibraryWindow::importLibraryPackage() +{ + importLibraryDialog->show(libraries); +} \ No newline at end of file diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 3a634d80..7b27c410 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -15,7 +15,6 @@ class QThread; class QStackedWidget; class YACReaderSearchLineEdit; class CreateLibraryDialog; -class UpdateLibraryDialog; class ExportLibraryDialog; class ImportLibraryDialog; class ExportComicsInfoDialog; @@ -57,7 +56,6 @@ private: YACReaderSideBar * sideBar; QSplitter * sVertical; CreateLibraryDialog * createLibraryDialog; - UpdateLibraryDialog * updateLibraryDialog; ExportLibraryDialog * exportLibraryDialog; ImportLibraryDialog * importLibraryDialog; ExportComicsInfoDialog * exportComicsInfoDialog; @@ -256,6 +254,8 @@ public: void backward(); void forward(); void updateHistory(const QModelIndex & mi); + void libraryAlreadyExists(const QString & name); + void importLibraryPackage(); }; #endif diff --git a/YACReaderLibrary/rename_library_dialog.cpp b/YACReaderLibrary/rename_library_dialog.cpp index 071d7ac5..22202865 100644 --- a/YACReaderLibrary/rename_library_dialog.cpp +++ b/YACReaderLibrary/rename_library_dialog.cpp @@ -58,7 +58,6 @@ void RenameLibraryDialog::rename() { //accept->setEnabled(false); emit(renameLibrary(newNameEdit->text())); - close(); } void RenameLibraryDialog::nameSetted(const QString & text)