diff options
| author | 2015-02-22 14:06:29 -0500 | |
|---|---|---|
| committer | 2015-02-22 14:06:29 -0500 | |
| commit | 306d6d3ca9c9ad774d19135681a7f9805f77035f (patch) | |
| tree | a3e36ac2cc769162c30a1bcc33e126f7a4f4ccea /SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp | |
| parent | 016003905ca0e8e459e3dc33e786beda8ec92f45 (diff) | |
Imported Upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp index c9a7f28..a2a9c36 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp @@ -446,17 +446,55 @@ bool DbDialog::testDatabase() bool DbDialog::validate() { + // Name + if (!ui->generateCheckBox->isChecked()) + { + if (ui->nameEdit->text().isEmpty()) + { + setValidState(ui->nameEdit, false, tr("Enter an unique database name.")); + return false; + } + } + + Db* registeredDb = DBLIST->getByName(ui->nameEdit->text()); + if (registeredDb && (mode == Mode::ADD || registeredDb != db)) + { + qDebug() << ui->generateCheckBox->isChecked(); + setValidState(ui->nameEdit, false, tr("This name is already in use. Please enter unique name.")); + return false; + } + setValidState(ui->nameEdit, true); + + // File if (ui->fileEdit->text().isEmpty()) + { + setValidState(ui->fileEdit, false, tr("Enter a database file path.")); return false; + } - if (ui->nameEdit->text().isEmpty()) + registeredDb = DBLIST->getByPath(ui->fileEdit->text()); + if (registeredDb && (mode == Mode::ADD || registeredDb != db)) + { + setValidState(ui->fileEdit, false, tr("This database is already on the list under name: %1").arg(registeredDb->getName())); return false; + } + setValidState(ui->fileEdit, true); + // Type if (ui->typeCombo->count() == 0) + { + // No need to set validation message here. SQLite3 plugin is built in, + // so if this happens, something is really, really wrong. + qCritical() << "No db plugins loaded in db dialog!"; return false; + } if (ui->typeCombo->currentIndex() < 0) + { + setValidState(ui->typeCombo, false, tr("Select a database type.")); return false; + } + setValidState(ui->typeCombo, true); return true; } @@ -480,11 +518,9 @@ void DbDialog::typeChanged(int index) void DbDialog::valueForNameGenerationChanged() { + updateState(); if (!ui->generateCheckBox->isChecked()) - { - updateState(); return; - } DbPlugin* plugin = nullptr; if (dbPlugins.count() > 0) |
