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);
emit(addLibrary(QDir::cleanPath(path->text()),nameEdit->text()));
close();
}
void AddLibraryDialog::nameSetted(const QString & text)

View File

@ -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,30 +75,28 @@ void CreateLibraryDialog::setupUI()
setWindowTitle(tr("Create new library"));
}
void CreateLibraryDialog::show(const QMap<QString,QString> & 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);
if(!libraries.contains(nameEdit->text()))
{
emit(createLibrary(QDir::cleanPath(path->text()),QDir::cleanPath(path->text())+"/.yacreaderlibrary",nameEdit->text()));
close();
}
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"));
emit(libraryExists(nameEdit->text()));
}
void CreateLibraryDialog::showCurrentFile(QString file)
{
currentFileLabel->setText(tr("Importing : \n") + file);
currentFileLabel->update();
//this->adjustSize();
//is->update();
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::nameSetted(const QString & text)
@ -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;

View File

@ -18,24 +18,25 @@
QLabel * textLabel;
QLabel * message;
QProgressBar *progressBar;
QLabel * currentFileLabel;
QLineEdit * path;
QLineEdit * nameEdit;
QPushButton * find;
QPushButton * accept;
QPushButton * cancel;
QMap<QString,QString> 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 pathSetted(const QString & text);
void show(const QMap<QString,QString> & libraries);
signals:
void createLibrary(QString source, QString target, QString name);
void cancelCreate();
void libraryExists(const QString & name);
};
class UpdateLibraryDialog : public QDialog

View File

@ -86,13 +86,25 @@ void ImportLibraryDialog::setupUI()
setModal(true);
setWindowTitle(tr("Extract a catalog"));
}
void ImportLibraryDialog::show(const QMap<QString,QString> & libs)
{
libraries = libs;
QDialog::show();
}
void ImportLibraryDialog::add()
{
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()
{

View File

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

View File

@ -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,6 +1110,9 @@ void LibraryWindow::showAddLibrary()
void LibraryWindow::openLibrary(QString path, QString name)
{
if(!libraries.contains(name))
{
//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"))
@ -1117,10 +1120,16 @@ void LibraryWindow::openLibrary(QString path, QString name)
_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
{
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();
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);
}

View File

@ -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

View File

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