unique libraries name forced

This commit is contained in:
Luis Ángel San Martín 2013-06-27 21:47:05 +02:00
parent 181be7be4c
commit 252198bb61
8 changed files with 89 additions and 73 deletions

View File

@ -71,7 +71,6 @@ void AddLibraryDialog::add()
{ {
//accept->setEnabled(false); //accept->setEnabled(false);
emit(addLibrary(QDir::cleanPath(path->text()),nameEdit->text())); emit(addLibrary(QDir::cleanPath(path->text()),nameEdit->text()));
close();
} }
void AddLibraryDialog::nameSetted(const QString & text) void AddLibraryDialog::nameSetted(const QString & text)

View File

@ -49,21 +49,6 @@ void CreateLibraryDialog::setupUI()
content->addWidget(find,1,2); content->addWidget(find,1,2);
content->setColumnMinimumWidth(2,0); //TODO 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; 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."))); 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); message->setWordWrap(true);
@ -75,9 +60,6 @@ void CreateLibraryDialog::setupUI()
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(content); mainLayout->addLayout(content);
mainLayout->addLayout(middleLayout);
mainLayout->addStretch();
mainLayout->addWidget(progressBar);
mainLayout->addLayout(bottomLayout); mainLayout->addLayout(bottomLayout);
QHBoxLayout * imgMainLayout = new QHBoxLayout; QHBoxLayout * imgMainLayout = new QHBoxLayout;
@ -93,32 +75,30 @@ void CreateLibraryDialog::setupUI()
setWindowTitle(tr("Create new library")); setWindowTitle(tr("Create new library"));
} }
void CreateLibraryDialog::show(const QMap<QString,QString> & libs)
{
libraries = libs;
QDialog::show();
}
void CreateLibraryDialog::create() void CreateLibraryDialog::create()
{ {
QFileInfo f(path->text()); QFileInfo f(path->text());
if(f.exists() && f.isDir() && f.isWritable()) if(f.exists() && f.isDir() && f.isWritable())
{ {
progressBar->show(); if(!libraries.contains(nameEdit->text()))
message->show(); {
currentFileLabel->setText("Importing : \n\n\n\n\n"); emit(createLibrary(QDir::cleanPath(path->text()),QDir::cleanPath(path->text())+"/.yacreaderlibrary",nameEdit->text()));
this->adjustSize(); close();
accept->setEnabled(false); }
emit(createLibrary(QDir::cleanPath(path->text()),QDir::cleanPath(path->text())+"/.yacreaderlibrary",nameEdit->text())); else
close(); emit(libraryExists(nameEdit->text()));
} }
else 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")); 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) void CreateLibraryDialog::nameSetted(const QString & text)
{ {
if(!text.isEmpty()) if(!text.isEmpty())
@ -163,11 +143,8 @@ void CreateLibraryDialog::findPath()
void CreateLibraryDialog::close() void CreateLibraryDialog::close()
{ {
progressBar->hide();
path->clear(); path->clear();
nameEdit->clear(); nameEdit->clear();
currentFileLabel->setText("");
this->adjustSize();
accept->setEnabled(false); accept->setEnabled(false);
QDialog::close(); QDialog::close();
} }
@ -176,7 +153,7 @@ void CreateLibraryDialog::setDataAndStart(QString name, QString path)
{ {
this->path->setText(path); this->path->setText(path);
this->nameEdit->setText(name); this->nameEdit->setText(name);
show(); QDialog::show();
create(); create();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -199,12 +176,6 @@ UpdateLibraryDialog::UpdateLibraryDialog(QWidget * parent)
mainLayout->addStretch(); mainLayout->addStretch();
progressBar = new QProgressBar(this);
progressBar->setMinimum(0);
progressBar->setMaximum(0);
progressBar->setTextVisible(false);
mainLayout->addWidget(progressBar);
mainLayout->addLayout(bottom); mainLayout->addLayout(bottom);
QHBoxLayout * imgMainLayout = new QHBoxLayout; QHBoxLayout * imgMainLayout = new QHBoxLayout;

View File

@ -18,24 +18,25 @@
QLabel * textLabel; QLabel * textLabel;
QLabel * message; QLabel * message;
QProgressBar *progressBar; QProgressBar *progressBar;
QLabel * currentFileLabel;
QLineEdit * path; QLineEdit * path;
QLineEdit * nameEdit; QLineEdit * nameEdit;
QPushButton * find; QPushButton * find;
QPushButton * accept; QPushButton * accept;
QPushButton * cancel; QPushButton * cancel;
QMap<QString,QString> libraries;
void setupUI(); void setupUI();
public slots: public slots:
void create(); void create();
void findPath(); void findPath();
void showCurrentFile(QString file);
void close(); void close();
void setDataAndStart(QString name, QString paht); void setDataAndStart(QString name, QString paht);
void nameSetted(const QString & text); void nameSetted(const QString & text);
void pathSetted(const QString & text); void pathSetted(const QString & text);
void show(const QMap<QString,QString> & libraries);
signals: signals:
void createLibrary(QString source, QString target, QString name); void createLibrary(QString source, QString target, QString name);
void cancelCreate(); void cancelCreate();
void libraryExists(const QString & name);
}; };
class UpdateLibraryDialog : public QDialog class UpdateLibraryDialog : public QDialog

View File

@ -86,12 +86,24 @@ void ImportLibraryDialog::setupUI()
setModal(true); setModal(true);
setWindowTitle(tr("Extract a catalog")); setWindowTitle(tr("Extract a catalog"));
} }
void ImportLibraryDialog::show(const QMap<QString,QString> & libs)
{
libraries = libs;
QDialog::show();
}
void ImportLibraryDialog::add() void ImportLibraryDialog::add()
{ {
accept->setEnabled(false); if(!libraries.contains(nameEdit->text()))
progressBar->show(); {
emit(unpackCLC(QDir::cleanPath(path->text()),QDir::cleanPath(destPath->text()),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() void ImportLibraryDialog::findPath()

View File

@ -29,15 +29,18 @@
void setupUI(); void setupUI();
int progressCount; int progressCount;
void closeEvent ( QCloseEvent * e ); void closeEvent ( QCloseEvent * e );
QMap<QString,QString> libraries;
public slots: public slots:
void add(); void add();
void findPath(); void findPath();
void findDestination(); void findDestination();
void close(); void close();
void nameEntered(); void nameEntered();
void show(const QMap<QString,QString> & libs);
signals: signals:
void unpackCLC(QString clc,QString targetFolder, QString name); void unpackCLC(QString clc,QString targetFolder, QString name);
void libraryExists(const QString & name);
}; };
#endif #endif

View File

@ -260,7 +260,6 @@ void LibraryWindow::doLayout()
void LibraryWindow::doDialogs() void LibraryWindow::doDialogs()
{ {
createLibraryDialog = new CreateLibraryDialog(this); createLibraryDialog = new CreateLibraryDialog(this);
updateLibraryDialog = new UpdateLibraryDialog(this);
renameLibraryDialog = new RenameLibraryDialog(this); renameLibraryDialog = new RenameLibraryDialog(this);
propertiesDialog = new PropertiesDialog(this); propertiesDialog = new PropertiesDialog(this);
exportLibraryDialog = new ExportLibraryDialog(this); exportLibraryDialog = new ExportLibraryDialog(this);
@ -646,10 +645,11 @@ void LibraryWindow::createConnections()
//libraryCreator connections //libraryCreator connections
connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString))); 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(importComicsInfoDialog,SIGNAL(finished(int)),this,SLOT(reloadCurrentLibrary()));
connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString))); //connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString)));
connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString))); //connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString)));
connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget())); connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget()));
connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary())); connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary()));
connect(libraryCreator,SIGNAL(created()),this,SLOT(openLastCreated())); 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(unpackCLC(QString,QString,QString)),this,SLOT(importLibrary(QString,QString,QString)));
connect(importLibraryDialog,SIGNAL(rejected()),packageManager,SLOT(cancel())); connect(importLibraryDialog,SIGNAL(rejected()),packageManager,SLOT(cancel()));
connect(importLibraryDialog,SIGNAL(rejected()),this,SLOT(deleteCurrentLibrary())); 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()),importLibraryDialog,SLOT(hide()));
connect(packageManager,SIGNAL(imported()),this,SLOT(openLastCreated())); connect(packageManager,SIGNAL(imported()),this,SLOT(openLastCreated()));
//create and update dialogs //create and update dialogs
connect(createLibraryDialog,SIGNAL(cancelCreate()),this,SLOT(cancelCreating())); connect(createLibraryDialog,SIGNAL(cancelCreate()),this,SLOT(cancelCreating()));
connect(updateLibraryDialog,SIGNAL(cancelUpdate()),this,SLOT(stopLibraryCreator()));
//open existing library from dialog. //open existing library from dialog.
connect(addLibraryDialog,SIGNAL(addLibrary(QString,QString)),this,SLOT(openLibrary(QString,QString))); connect(addLibraryDialog,SIGNAL(addLibrary(QString,QString)),this,SLOT(openLibrary(QString,QString)));
@ -695,7 +695,7 @@ void LibraryWindow::createConnections()
//actions //actions
connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary())); connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary()));
connect(exportLibraryAction,SIGNAL(triggered()),exportLibraryDialog,SLOT(show())); 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(openLibraryAction,SIGNAL(triggered()),this,SLOT(showAddLibrary()));
connect(showPropertiesAction,SIGNAL(triggered()),this,SLOT(showProperties())); connect(showPropertiesAction,SIGNAL(triggered()),this,SLOT(showProperties()));
@ -1067,7 +1067,7 @@ void LibraryWindow::setComicsUnreaded()
void LibraryWindow::createLibrary() void LibraryWindow::createLibrary()
{ {
createLibraryDialog->show(); createLibraryDialog->show(libraries);
} }
void LibraryWindow::create(QString source, QString dest, QString name) void LibraryWindow::create(QString source, QString dest, QString name)
@ -1110,16 +1110,25 @@ void LibraryWindow::showAddLibrary()
void LibraryWindow::openLibrary(QString path, QString name) void LibraryWindow::openLibrary(QString path, QString name)
{ {
path.remove("/.yacreaderlibrary"); if(!libraries.contains(name))
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
if(d.exists(path + "/.yacreaderlibrary"))
{ {
_lastAdded = name; //TODO: fix bug, /a/b/c/.yacreaderlibrary/d/e
_sourceLastAdded = path; path.remove("/.yacreaderlibrary");
openLastCreated(); 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 else
QMessageBox::warning(this,tr("Library not found"),tr("The selected folder doesn't contain any library.")); {
libraryAlreadyExists(name);
}
} }
void LibraryWindow::loadLibraries() void LibraryWindow::loadLibraries()
@ -1175,7 +1184,6 @@ void LibraryWindow::saveLibraries()
void LibraryWindow::updateLibrary() void LibraryWindow::updateLibrary()
{ {
//updateLibraryDialog->show();
importWidget->setUpdateLook(); importWidget->setUpdateLook();
showImportingWidget(); showImportingWidget();
@ -1245,12 +1253,25 @@ void LibraryWindow::renameLibrary()
void LibraryWindow::rename(QString newName) void LibraryWindow::rename(QString newName)
{ {
QString currentLibrary = selectedLibrary->currentText(); QString currentLibrary = selectedLibrary->currentText();
QString path = libraries.value(currentLibrary); if(newName != currentLibrary)
libraries.remove(currentLibrary); {
//selectedLibrary->removeItem(selectedLibrary->currentIndex()); if(!libraries.contains(newName))
libraries.insert(newName,path); {
selectedLibrary->renameCurrentLibrary(newName); QString path = libraries.value(currentLibrary);
saveLibraries(); 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)); //selectedLibrary->setCurrentIndex(selectedLibrary->findText(newName));
} }
@ -1662,3 +1683,13 @@ void LibraryWindow::updateHistory(const QModelIndex &mi)
forwardAction->setEnabled(false); 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);
}

View File

@ -15,7 +15,6 @@ class QThread;
class QStackedWidget; class QStackedWidget;
class YACReaderSearchLineEdit; class YACReaderSearchLineEdit;
class CreateLibraryDialog; class CreateLibraryDialog;
class UpdateLibraryDialog;
class ExportLibraryDialog; class ExportLibraryDialog;
class ImportLibraryDialog; class ImportLibraryDialog;
class ExportComicsInfoDialog; class ExportComicsInfoDialog;
@ -57,7 +56,6 @@ private:
YACReaderSideBar * sideBar; YACReaderSideBar * sideBar;
QSplitter * sVertical; QSplitter * sVertical;
CreateLibraryDialog * createLibraryDialog; CreateLibraryDialog * createLibraryDialog;
UpdateLibraryDialog * updateLibraryDialog;
ExportLibraryDialog * exportLibraryDialog; ExportLibraryDialog * exportLibraryDialog;
ImportLibraryDialog * importLibraryDialog; ImportLibraryDialog * importLibraryDialog;
ExportComicsInfoDialog * exportComicsInfoDialog; ExportComicsInfoDialog * exportComicsInfoDialog;
@ -256,6 +254,8 @@ public:
void backward(); void backward();
void forward(); void forward();
void updateHistory(const QModelIndex & mi); void updateHistory(const QModelIndex & mi);
void libraryAlreadyExists(const QString & name);
void importLibraryPackage();
}; };
#endif #endif

View File

@ -58,7 +58,6 @@ void RenameLibraryDialog::rename()
{ {
//accept->setEnabled(false); //accept->setEnabled(false);
emit(renameLibrary(newNameEdit->text())); emit(renameLibrary(newNameEdit->text()));
close();
} }
void RenameLibraryDialog::nameSetted(const QString & text) void RenameLibraryDialog::nameSetted(const QString & text)