From 6d9008d3ff9c5a53e284216a480028ef6aa804f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 5 May 2013 15:30:56 +0200 Subject: [PATCH] Corregida la validaci?n a los di?logos de crear y a?adir --- YACReaderLibrary/add_library_dialog.cpp | 36 +++++++++++++- YACReaderLibrary/add_library_dialog.h | 2 + YACReaderLibrary/create_library_dialog.cpp | 55 ++++++++++++++++++---- YACReaderLibrary/create_library_dialog.h | 2 + 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/YACReaderLibrary/add_library_dialog.cpp b/YACReaderLibrary/add_library_dialog.cpp index e94b4691..e13599bd 100644 --- a/YACReaderLibrary/add_library_dialog.cpp +++ b/YACReaderLibrary/add_library_dialog.cpp @@ -17,10 +17,12 @@ void AddLibraryDialog::setupUI() textLabel = new QLabel(tr("Comics folder : ")); path = new QLineEdit; textLabel->setBuddy(path); + connect(path,SIGNAL(textChanged(QString)),this,SLOT(pathSetted(QString))); nameLabel = new QLabel(tr("Library Name : ")); nameEdit = new QLineEdit; nameLabel->setBuddy(nameEdit); + connect(nameEdit,SIGNAL(textChanged(QString)),this,SLOT(nameSetted(QString))); accept = new QPushButton(tr("Add")); accept->setDisabled(true); @@ -72,14 +74,46 @@ void AddLibraryDialog::add() close(); } +void AddLibraryDialog::nameSetted(const QString & text) +{ + if(!text.isEmpty()) + { + if(!path->text().isEmpty()) + { + QFileInfo fi(path->text()); + if(fi.isDir()) + accept->setEnabled(true); + else + accept->setEnabled(false); + } + } + else + accept->setEnabled(false); +} + +void AddLibraryDialog::pathSetted(const QString & text) +{ + QFileInfo fi(text); + if(fi.isDir()) + { + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + void AddLibraryDialog::findPath() { QString s = QFileDialog::getExistingDirectory(0,"Comics directory","."); if(!s.isEmpty()) { path->setText(s); - accept->setEnabled(true); + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); } + else + accept->setEnabled(false); } void AddLibraryDialog::close() diff --git a/YACReaderLibrary/add_library_dialog.h b/YACReaderLibrary/add_library_dialog.h index f6274270..4cbdd42b 100644 --- a/YACReaderLibrary/add_library_dialog.h +++ b/YACReaderLibrary/add_library_dialog.h @@ -25,6 +25,8 @@ void add(); void findPath(); void close(); + void nameSetted(const QString & text); + void pathSetted(const QString & text); signals: void addLibrary(QString target, QString name); }; diff --git a/YACReaderLibrary/create_library_dialog.cpp b/YACReaderLibrary/create_library_dialog.cpp index 240ebeab..596258b8 100644 --- a/YACReaderLibrary/create_library_dialog.cpp +++ b/YACReaderLibrary/create_library_dialog.cpp @@ -17,10 +17,12 @@ void CreateLibraryDialog::setupUI() textLabel = new QLabel(tr("Comics folder : ")); path = new QLineEdit; textLabel->setBuddy(path); + connect(path,SIGNAL(textChanged(QString)),this,SLOT(pathSetted(QString))); nameLabel = new QLabel(tr("Library Name : ")); nameEdit = new QLineEdit; nameLabel->setBuddy(nameEdit); + connect(nameEdit,SIGNAL(textChanged(QString)),this,SLOT(nameSetted(QString))); accept = new QPushButton(tr("Create")); accept->setDisabled(true); @@ -108,16 +110,6 @@ void CreateLibraryDialog::create() 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::findPath() -{ - QString s = QFileDialog::getExistingDirectory(0,"Comics directory","."); - if(!s.isEmpty()) - { - path->setText(s); - accept->setEnabled(true); - } -} - void CreateLibraryDialog::showCurrentFile(QString file) { currentFileLabel->setText(tr("Importing : \n") + file); @@ -125,6 +117,49 @@ void CreateLibraryDialog::showCurrentFile(QString file) //this->adjustSize(); //is->update(); } + +void CreateLibraryDialog::nameSetted(const QString & text) +{ + if(!text.isEmpty()) + { + if(!path->text().isEmpty()) + { + QFileInfo fi(path->text()); + if(fi.isDir()) + accept->setEnabled(true); + else + accept->setEnabled(false); + } + } + else + accept->setEnabled(false); +} + +void CreateLibraryDialog::pathSetted(const QString & text) +{ + QFileInfo fi(text); + if(fi.isDir()) + { + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + +void CreateLibraryDialog::findPath() +{ + QString s = QFileDialog::getExistingDirectory(0,"Comics directory","."); + if(!s.isEmpty()) + { + path->setText(s); + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + void CreateLibraryDialog::close() { progressBar->hide(); diff --git a/YACReaderLibrary/create_library_dialog.h b/YACReaderLibrary/create_library_dialog.h index a671fcce..e24e3e11 100644 --- a/YACReaderLibrary/create_library_dialog.h +++ b/YACReaderLibrary/create_library_dialog.h @@ -31,6 +31,8 @@ void showCurrentFile(QString file); void close(); void setDataAndStart(QString name, QString paht); + void nameSetted(const QString & text); + void pathSetted(const QString & text); signals: void createLibrary(QString source, QString target, QString name); void cancelCreate();