From 75c9406abf2d090208a06bb6fa7871a141c1fa02 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 9 Sep 2016 22:52:17 +0200 Subject: gui/main-window: be more robust when our current config disappears from disk --- gui/main-window.cpp | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'gui') diff --git a/gui/main-window.cpp b/gui/main-window.cpp index 4daf7560..89316f9e 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -349,34 +349,59 @@ void MainWindow::refresh_config_list(bool warn) return; } + bool file_ok = false; + QString current = group::ini_filename(); + QIcon icon(":/images/settings16.png"); { - inhibit_qt_signals l(*ui.iconcomboProfile); + { + inhibit_qt_signals l(*ui.iconcomboProfile); - ui.iconcomboProfile->clear(); - ui.iconcomboProfile->addItems(ini_list); + ui.iconcomboProfile->clear(); + ui.iconcomboProfile->addItems(ini_list); - QIcon icon(":/images/settings16.png"); + { + const int sz = ini_list.size(); - { - const int sz = ini_list.size(); + for (int i = 0; i < sz; i++) + ui.iconcomboProfile->setItemIcon(i, icon); + } - for (int i = 0; i < sz; i++) - ui.iconcomboProfile->setItemIcon(i, icon); + ui.iconcomboProfile->setCurrentText(current); } - { - const QString pathname = group::ini_pathname(); + const QString pathname = group::ini_pathname(); - if (!QFile(pathname).exists()) + if (!QFile(pathname).exists()) + { { QFile file(pathname); (void) file.open(QFile::ReadWrite); } - } - ui.iconcomboProfile->setCurrentText(current); + const QStringList ini_list = group::ini_list(); + + if (ini_list.contains(current)) + { + { + inhibit_qt_signals q(ui.iconcomboProfile); + + ui.iconcomboProfile->clear(); + ui.iconcomboProfile->addItems(ini_list); + for (int i = 0; i < ini_list.size(); i++) + ui.iconcomboProfile->setItemIcon(i, icon); + ui.iconcomboProfile->setCurrentText(current); + } + + options::detail::bundler::refresh_all_bundles(true); + } + } + else + { + file_ok = true; + ui.iconcomboProfile->setCurrentText(current); + } } set_title(); -- cgit v1.2.3