diff libgui/src/resource-manager.cc @ 17930:ffdbb82a0c78

allow welcome wizard dialog to be canceled * resource-manager.h, resource-manager.cc (class resource_manager): Cache settings directory and file, but not first_run. (resource_manager::get_gui_translation_dir, resource_manager::do_update_network_settings): Only access settings if it is valid. (resource_manager::do_reload_settings): Don't set first_run. (resource_manager::do_get_home_path): Delete. * welcome-wizard.cc (welcome_wizard::welcome_wizard): Provide cancel button. * octave-gui.cc (octave_start_gui): Don't loop over welcome wizard. Run welcome wizard once if settings file is missing and exit Octave if welcome wizard returns a rejected status. Otherwise, load resources and start Octave.
author John W. Eaton <jwe@octave.org>
date Thu, 14 Nov 2013 16:52:21 -0500
parents 86c6ae5f969e
children cd97a7ef7355
line wrap: on
line diff
--- a/libgui/src/resource-manager.cc	Thu Nov 14 19:17:01 2013 +0100
+++ b/libgui/src/resource-manager.cc	Thu Nov 14 16:52:21 2013 -0500
@@ -57,9 +57,17 @@
 }
 
 resource_manager::resource_manager (void)
-  : settings (0), home_path (), first_run (false)
+  : settings_directory (), settings_file (), settings (0),
+    default_settings (0)
 {
-  do_reload_settings ();
+  QDesktopServices desktopServices;
+
+  QString home_path
+    = desktopServices.storageLocation (QDesktopServices::HomeLocation);
+
+  settings_directory = home_path + "/.config/octave/";
+
+  settings_file = settings_directory + "/qt-settings";
 
   default_settings = new QSettings (default_qt_settings_file (),
                                     QSettings::IniFormat);
@@ -71,7 +79,6 @@
   delete default_settings;
 }
 
-
 QString
 resource_manager::get_gui_translation_dir (void)
 {
@@ -91,26 +98,36 @@
 
   QString qt_trans_dir
     = QLibraryInfo::location (QLibraryInfo::TranslationsPath);
+
   QSettings *settings = resource_manager::get_settings ();
-  // FIXME: what should happen if settings is 0?
 
-  // get the locale from the settings
-  QString language = settings->value ("language","SYSTEM").toString ();
-  if (language == "SYSTEM")
-    language = QLocale::system ().name ();    // get system wide locale
+  if (settings)
+    {
+      // get the locale from the settings
+      QString language = settings->value ("language","SYSTEM").toString ();
+
+      if (language == "SYSTEM")
+        language = QLocale::system ().name ();    // get system wide locale
+
+      // load the translator file for qt strings
+      loaded = qt_tr->load ("qt_" + language, qt_trans_dir);
 
-  // load the translator file for qt strings
-  loaded = qt_tr->load ("qt_" + language, qt_trans_dir);
-  if (!loaded) // try lower case
-    qt_tr->load ("qt_" + language.toLower (), qt_trans_dir);
+      if (!loaded) // try lower case
+        qt_tr->load ("qt_" + language.toLower (), qt_trans_dir);
+
+      // load the translator file for qscintilla settings
+      loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir);
 
-  // load the translator file for qscintilla settings
-  loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir);
-  if (!loaded) // try lower case
-    qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir);
+      if (!loaded) // try lower case
+        qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir);
 
-  // load the translator file for gui strings
-  gui_tr->load (language, get_gui_translation_dir ());
+      // load the translator file for gui strings
+      gui_tr->load (language, get_gui_translation_dir ());
+    }
+  else
+    {
+      // FIXME: Is this an error?  If so, what should we do?
+    }
 }
 
 bool
@@ -149,42 +166,25 @@
 }
 
 QString
-resource_manager::do_get_home_path (void) const
+resource_manager::do_get_settings_directory (void)
 {
-  return home_path;
-}
-
-QString
-resource_manager::do_get_settings_path (void)
-{
-  QDesktopServices desktopServices;
-  home_path = desktopServices.storageLocation (QDesktopServices::HomeLocation);
-  QString settings_path = home_path + "/.config/octave/";
-  return settings_path;
+  return settings_directory;
 }
 
 QString
 resource_manager::do_get_settings_file (void)
 {
-  return do_get_settings_path ()  + "qt-settings";
+  return settings_file;
 }
 
 void
 resource_manager::do_reload_settings (void)
 {
-  QDesktopServices desktopServices;
-  home_path = desktopServices.storageLocation (QDesktopServices::HomeLocation);
-  QString settings_path = do_get_settings_path ();
-  QString settings_file = do_get_settings_file ();
-
-  if (!QFile::exists (settings_file))
+  if (! QFile::exists (settings_file))
     {
-      QDir ("/").mkpath (settings_path);
+      QDir ("/").mkpath (settings_directory);
       QFile::copy (default_qt_settings_file (), settings_file);
-      first_run = true;
     }
-  else
-    first_run = false;
 
   do_set_settings (settings_file);
 }
@@ -199,33 +199,40 @@
 bool
 resource_manager::do_is_first_run (void) const
 {
-  return first_run;
+  return ! QFile::exists (settings_file);
 }
 
 void
 resource_manager::do_update_network_settings (void)
 {
-  QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
-
-  if (settings->value ("useProxyServer",false).toBool ())
+  if (settings)
     {
-      QString proxyTypeString = settings->value ("proxyType").toString ();
+      QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
+
+      if (settings->value ("useProxyServer",false).toBool ())
+        {
+          QString proxyTypeString = settings->value ("proxyType").toString ();
 
-      if (proxyTypeString == "Socks5Proxy")
-        proxyType = QNetworkProxy::Socks5Proxy;
-      else if (proxyTypeString == "HttpProxy")
-        proxyType = QNetworkProxy::HttpProxy;
+          if (proxyTypeString == "Socks5Proxy")
+            proxyType = QNetworkProxy::Socks5Proxy;
+          else if (proxyTypeString == "HttpProxy")
+            proxyType = QNetworkProxy::HttpProxy;
+        }
+
+      QNetworkProxy proxy;
+
+      proxy.setType (proxyType);
+      proxy.setHostName (settings->value ("proxyHostName").toString ());
+      proxy.setPort (settings->value ("proxyPort",80).toInt ());
+      proxy.setUser (settings->value ("proxyUserName").toString ());
+      proxy.setPassword (settings->value ("proxyPassword").toString ());
+
+      QNetworkProxy::setApplicationProxy (proxy);
     }
-
-  QNetworkProxy proxy;
-
-  proxy.setType (proxyType);
-  proxy.setHostName (settings->value ("proxyHostName").toString ());
-  proxy.setPort (settings->value ("proxyPort",80).toInt ());
-  proxy.setUser (settings->value ("proxyUserName").toString ());
-  proxy.setPassword (settings->value ("proxyPassword").toString ());
-
-  QNetworkProxy::setApplicationProxy (proxy);
+  else
+    {
+      // FIXME: Is this an error?  If so, what should we do?
+    }
 }
 
 QStringList