Fix opening a database on startup.

Commit e32fce8581
(main.cpp: mainwin must exist for read_cmdline() in GUI mode)
created the Mainwindow before parsing the commandline,
but the MainWindow constructor opened a default database if set.

With this change, the MinWindow constructor does not open a default
database. Now the default database is explicitly opened after parsing
the command line, if no other database is already open.

Rename init_database() to setup_open_database()
It is re-entrant.
This commit is contained in:
Christian Hohnstaedt 2021-04-28 16:49:18 +02:00
parent 71fb8edc7e
commit 5d4b52ac87
3 changed files with 7 additions and 8 deletions

View File

@ -368,6 +368,10 @@ int main(int argc, char *argv[])
read_cmdline(argc, argv);
mainwin->importMulti(cmdline_items, 1);
cmdline_items = NULL;
if (!Database.isOpen())
mainwin->init_database(QString());
else
mainwin->setup_open_database();
mainwin->show();
gui->exec();
} else {

View File

@ -133,11 +133,6 @@ MainWindow::MainWindow() : QMainWindow()
check_oom(dhgenBar);
dhgenBar->setMinimum(0);
dhgenBar->setMaximum(0);
enum open_result result = Database.isOpen() ? init_database() :
init_database(QString());
if (result == pw_exit)
throw pw_exit;
}
void MainWindow::dropEvent(QDropEvent *event)
@ -557,7 +552,7 @@ enum open_result MainWindow::init_database(const QString &name,
close_database();
try {
Database.open(name, pass);
return init_database();
return setup_open_database();
} catch (errorEx &err) {
XCA_ERROR(err);
return open_abort;
@ -567,7 +562,7 @@ enum open_result MainWindow::init_database(const QString &name,
return pw_ok;
}
enum open_result MainWindow::init_database()
enum open_result MainWindow::setup_open_database()
{
if (!Database.isOpen())
return open_abort;

View File

@ -109,7 +109,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow
public slots:
enum open_result init_database(const QString &dbName,
const Passwd &pass = Passwd());
enum open_result init_database();
enum open_result setup_open_database();
void new_database();
void load_database();
void close_database();