changeset 13668:421afeae929b

Added a settings wizard that appears at first startup of Octave GUI.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sat, 10 Sep 2011 18:33:58 +0200
parents 9b74f97919e1
children 803ac0c6a2c0
files gui/octave-gui.pro gui/src/OctaveGUI.cpp gui/src/ResourceManager.cpp gui/src/ResourceManager.h gui/src/SettingsDialog.ui gui/src/WelcomeWizard.cpp gui/src/WelcomeWizard.h gui/src/WelcomeWizard.ui
diffstat 8 files changed, 475 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/gui/octave-gui.pro	Sat Sep 10 15:36:02 2011 +0200
+++ b/gui/octave-gui.pro	Sat Sep 10 18:33:58 2011 +0200
@@ -80,7 +80,8 @@
     src/terminal/KPty.cpp \
     src/terminal/KPtyDevice.cpp \
     src/TerminalView.cpp \
-    src/TerminalHighlighter.cpp
+    src/TerminalHighlighter.cpp \
+    src/WelcomeWizard.cpp
 
 HEADERS += \
         src/lexer/lexeroctavegui.h \
@@ -106,7 +107,9 @@
     src/terminal/KPtyDevice.h \
     src/terminal/KPty.h \
     src/TerminalView.h \
-    src/TerminalHighlighter.h
+    src/TerminalHighlighter.h \
+    src/WelcomeWizard.h
 
 FORMS += \
-    src/SettingsDialog.ui
+    src/SettingsDialog.ui \
+    src/WelcomeWizard.ui
--- a/gui/src/OctaveGUI.cpp	Sat Sep 10 15:36:02 2011 +0200
+++ b/gui/src/OctaveGUI.cpp	Sat Sep 10 18:33:58 2011 +0200
@@ -20,6 +20,7 @@
 #include <QTranslator>
 #include <QSettings>
 #include "CommandLineParser.h"
+#include "WelcomeWizard.h"
 #include "ResourceManager.h"
 #include "MainWindow.h"
 
@@ -27,23 +28,68 @@
 main (int argc, char *argv[])
 {
   QApplication application (argc, argv);
-  CommandLineParser commandLineParser;
-  commandLineParser.registerOption ("--config", "-c", "Tells OctaveGUI to use that configuration file.", true);
-  commandLineParser.parse (argc, argv);
-
-  QSettings *settings = ResourceManager::instance ()->settings ();
-  QString language = settings->value ("language").toString ();
+  while (true)
+    {
+      if (ResourceManager::instance ()->isFirstRun ())
+        {
+          WelcomeWizard welcomeWizard;
+          int returnCode = welcomeWizard.exec ();
 
-  QString translatorFile = ResourceManager::instance ()->findTranslatorFile (language);
-  QTranslator translator;
-  translator.load (translatorFile);
-  application.installTranslator (&translator);
+          QSettings *settings = ResourceManager::instance ()->settings ();
+          settings->setValue ("connectOnStartup", true);
+          settings->setValue ("showMessageOfTheDay", true);
+          settings->setValue ("showTopic", true);
+          settings->setValue ("autoIdentification", false);
+          settings->setValue ("nickServPassword", "");
+          settings->setValue ("useCustomFileEditor", false);
+          settings->setValue ("customFileEditor", "emacs");
+          settings->setValue ("editor/showLineNumbers", true);
+          settings->setValue ("editor/highlightActualLine", true);
+          settings->setValue ("editor/codeCompletion", true);
+          settings->setValue ("editor/fontName", "Monospace");
+          settings->setValue ("editor/fontSize", 10);
+          settings->setValue ("showFilenames", true);
+          settings->setValue ("showFileSize", false);
+          settings->setValue ("showFileType", false);
+          settings->setValue ("showLastModified", false);
+          settings->setValue ("showHiddenFiles", false);
+          settings->setValue ("useAlternatingRowColors", true);
+          settings->setValue ("useProxyServer", false);
+          settings->setValue ("proxyType", "Sock5Proxy");
+          settings->setValue ("proxyHostName", "none");
+          settings->setValue ("proxyPort", 8080);
+          settings->setValue ("proxyUserName", "");
+          settings->setValue ("proxyPassword", "");
+          settings->sync ();
+          ResourceManager::instance ()->reloadSettings ();
 
-  ResourceManager::instance ()->updateNetworkSettings ();
-  ResourceManager::instance ()->loadIcons ();
+          application.quit ();
+          // We are in an infinite loop, so everything else than a return
+          // will cause the application to restart from the very beginning.
+          if (returnCode == QDialog::Rejected)
+            return 0;
+        }
+      else
+        {
+          CommandLineParser commandLineParser;
+          commandLineParser.registerOption ("--config", "-c", "Tells OctaveGUI to use that configuration file.", true);
+          commandLineParser.parse (argc, argv);
+
+          QSettings *settings = ResourceManager::instance ()->settings ();
+          QString language = settings->value ("language").toString ();
 
-  MainWindow w;
-  w.show ();
-  w.activateWindow();
-  return application.exec ();
+          QString translatorFile = ResourceManager::instance ()->findTranslatorFile (language);
+          QTranslator translator;
+          translator.load (translatorFile);
+          application.installTranslator (&translator);
+
+          ResourceManager::instance ()->updateNetworkSettings ();
+          ResourceManager::instance ()->loadIcons ();
+
+          MainWindow w;
+          w.show ();
+          w.activateWindow();
+          return application.exec ();
+        }
+    }
 }
--- a/gui/src/ResourceManager.cpp	Sat Sep 10 15:36:02 2011 +0200
+++ b/gui/src/ResourceManager.cpp	Sat Sep 10 18:33:58 2011 +0200
@@ -25,9 +25,7 @@
 ResourceManager::ResourceManager ()
 {
   m_settings = 0;
-  QDesktopServices desktopServices;
-  m_homePath = desktopServices.storageLocation (QDesktopServices::HomeLocation);
-  setSettings(m_homePath + "/.octave-gui");
+  reloadSettings ();
 }
 
 ResourceManager::~ResourceManager ()
@@ -48,13 +46,25 @@
 }
 
 void
+ResourceManager::reloadSettings ()
+{
+  QDesktopServices desktopServices;
+  m_homePath = desktopServices.storageLocation (QDesktopServices::HomeLocation);
+  setSettings(m_homePath + "/.octave-gui");
+}
+
+void
 ResourceManager::setSettings (QString file)
 {
   delete m_settings;
+
+  m_firstRun = false;
   if (!QFile::exists (file))
-    {
-      QFile::copy("../default-settings/.octave-gui", file);
-    }
+    m_firstRun = true;
+
+  // If the settings file does not exist, QSettings automatically creates it.
+  // Therefore we have to check if it exists before instantiating the settings object.
+  // That way we can detect if the user ran this application before.
   m_settings = new QSettings (file, QSettings::IniFormat);
 }
 
@@ -75,6 +85,12 @@
   return QIcon ();
 }
 
+bool
+ResourceManager::isFirstRun ()
+{
+  return m_firstRun;
+}
+
 void
 ResourceManager::updateNetworkSettings ()
 {
--- a/gui/src/ResourceManager.h	Sat Sep 10 15:36:02 2011 +0200
+++ b/gui/src/ResourceManager.h	Sat Sep 10 18:33:58 2011 +0200
@@ -46,11 +46,13 @@
 
   QSettings *settings ();
   QString homePath ();
+  void reloadSettings ();
   void setSettings (QString file);
   QString findTranslatorFile (QString language);
   void updateNetworkSettings ();
   void loadIcons ();
   QIcon icon (Icon icon);
+  bool isFirstRun ();
 
   const char *octaveKeywords ();
 private:
@@ -60,6 +62,7 @@
   QString m_homePath;
   QMap <Icon, QIcon> m_icons;
   static ResourceManager m_singleton;
+  bool m_firstRun;
 };
 
 #endif // RESOURCEMANAGER_H
--- a/gui/src/SettingsDialog.ui	Sat Sep 10 15:36:02 2011 +0200
+++ b/gui/src/SettingsDialog.ui	Sat Sep 10 18:33:58 2011 +0200
@@ -32,7 +32,7 @@
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>1</number>
+      <number>0</number>
      </property>
      <widget class="QWidget" name="chatTab">
       <attribute name="title">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/src/WelcomeWizard.cpp	Sat Sep 10 18:33:58 2011 +0200
@@ -0,0 +1,36 @@
+#include "WelcomeWizard.h"
+#include "ui_WelcomeWizard.h"
+
+WelcomeWizard::WelcomeWizard (QWidget *parent) :
+  QDialog (parent),
+  ui (new Ui::WelcomeWizard)
+{
+  ui->setupUi (this);
+  connect (ui->nextButton1, SIGNAL (clicked ()), this, SLOT (next ()));
+  connect (ui->nextButton2, SIGNAL (clicked ()), this, SLOT (next ()));
+  connect (ui->nextButton3, SIGNAL (clicked ()), this, SLOT (next ()));
+  connect (ui->nextButton4, SIGNAL (clicked ()), this, SLOT (next ()));
+
+  connect (ui->previousButton2, SIGNAL (clicked ()), this, SLOT (previous ()));
+  connect (ui->previousButton3, SIGNAL (clicked ()), this, SLOT (previous ()));
+  connect (ui->previousButton4, SIGNAL (clicked ()), this, SLOT (previous ()));
+  connect (ui->previousButton5, SIGNAL (clicked ()), this, SLOT (previous ()));
+}
+
+WelcomeWizard::~WelcomeWizard()
+{
+  delete ui;
+}
+
+void
+WelcomeWizard::next ()
+{
+  ui->stackedWidget->setCurrentIndex (ui->stackedWidget->currentIndex () + 1);
+}
+
+void
+WelcomeWizard::previous ()
+{
+  ui->stackedWidget->setCurrentIndex (ui->stackedWidget->currentIndex () - 1);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/src/WelcomeWizard.h	Sat Sep 10 18:33:58 2011 +0200
@@ -0,0 +1,26 @@
+#ifndef WELCOMEWIZARD_H
+#define WELCOMEWIZARD_H
+
+#include <QDialog>
+
+namespace Ui {
+class WelcomeWizard;
+}
+
+class WelcomeWizard : public QDialog
+{
+  Q_OBJECT
+
+public:
+  explicit WelcomeWizard(QWidget *parent = 0);
+  ~WelcomeWizard();
+
+public slots:
+  void next ();
+  void previous ();
+
+private:
+  Ui::WelcomeWizard *ui;
+};
+
+#endif // WELCOMEWIZARD_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/src/WelcomeWizard.ui	Sat Sep 10 18:33:58 2011 +0200
@@ -0,0 +1,319 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WelcomeWizard</class>
+ <widget class="QDialog" name="WelcomeWizard">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>647</width>
+    <height>400</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>647</width>
+    <height>400</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>647</width>
+    <height>400</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Welcome to GNU Octave</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <widget class="QStackedWidget" name="stackedWidget">
+     <property name="currentIndex">
+      <number>0</number>
+     </property>
+     <widget class="QWidget" name="page">
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <widget class="QLabel" name="label">
+         <property name="text">
+          <string>It appears that you have launched Octave GUI for the first time on this computer, since no configuration file could be found at '~/.octave-gui'. This wizard will guide you through the essential settings you should make before you can start using Octave GUI. If you want to transfer your settings you have previously made just close this dialog and copy over the settings file to your home folder. The presence of that file will automatically be detected and will skip this wizard. IMPORTANT: This wizard is not fully functional yet. Just click your way to the end and it will create a standard settings file.</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignJustify|Qt::AlignVCenter</set>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>218</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
+         <item>
+          <spacer name="horizontalSpacer">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <widget class="QPushButton" name="nextButton1">
+           <property name="text">
+            <string>Next</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="page_2">
+      <layout class="QVBoxLayout" name="verticalLayout_4">
+       <item>
+        <layout class="QVBoxLayout" name="verticalLayout_3">
+         <item>
+          <spacer name="verticalSpacer_2">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>40</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <layout class="QHBoxLayout" name="horizontalLayout">
+           <item>
+            <widget class="QPushButton" name="previousButton2">
+             <property name="text">
+              <string>Previous</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <spacer name="horizontalSpacer_2">
+             <property name="orientation">
+              <enum>Qt::Horizontal</enum>
+             </property>
+             <property name="sizeHint" stdset="0">
+              <size>
+               <width>40</width>
+               <height>20</height>
+              </size>
+             </property>
+            </spacer>
+           </item>
+           <item>
+            <widget class="QPushButton" name="nextButton2">
+             <property name="text">
+              <string>Next</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="page_3">
+      <layout class="QHBoxLayout" name="horizontalLayout_4">
+       <item>
+        <layout class="QVBoxLayout" name="verticalLayout_5">
+         <item>
+          <spacer name="verticalSpacer_3">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>40</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <layout class="QHBoxLayout" name="horizontalLayout_3">
+           <item>
+            <widget class="QPushButton" name="previousButton3">
+             <property name="text">
+              <string>Previous</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <spacer name="horizontalSpacer_3">
+             <property name="orientation">
+              <enum>Qt::Horizontal</enum>
+             </property>
+             <property name="sizeHint" stdset="0">
+              <size>
+               <width>40</width>
+               <height>20</height>
+              </size>
+             </property>
+            </spacer>
+           </item>
+           <item>
+            <widget class="QPushButton" name="nextButton3">
+             <property name="text">
+              <string>Next</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="page_4">
+      <layout class="QHBoxLayout" name="horizontalLayout_6">
+       <item>
+        <layout class="QVBoxLayout" name="verticalLayout_6">
+         <item>
+          <spacer name="verticalSpacer_4">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>40</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <layout class="QHBoxLayout" name="horizontalLayout_5">
+           <item>
+            <widget class="QPushButton" name="previousButton4">
+             <property name="text">
+              <string>Previous</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <spacer name="horizontalSpacer_4">
+             <property name="orientation">
+              <enum>Qt::Horizontal</enum>
+             </property>
+             <property name="sizeHint" stdset="0">
+              <size>
+               <width>40</width>
+               <height>20</height>
+              </size>
+             </property>
+            </spacer>
+           </item>
+           <item>
+            <widget class="QPushButton" name="nextButton4">
+             <property name="text">
+              <string>Next</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="page_5">
+      <layout class="QHBoxLayout" name="horizontalLayout_8">
+       <item>
+        <layout class="QVBoxLayout" name="verticalLayout_7">
+         <item>
+          <spacer name="verticalSpacer_5">
+           <property name="orientation">
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>40</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <layout class="QHBoxLayout" name="horizontalLayout_7">
+           <item>
+            <widget class="QPushButton" name="previousButton5">
+             <property name="text">
+              <string>Previous</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <spacer name="horizontalSpacer_5">
+             <property name="orientation">
+              <enum>Qt::Horizontal</enum>
+             </property>
+             <property name="sizeHint" stdset="0">
+              <size>
+               <width>40</width>
+               <height>20</height>
+              </size>
+             </property>
+            </spacer>
+           </item>
+           <item>
+            <widget class="QPushButton" name="finishButton">
+             <property name="text">
+              <string>Finish</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>finishButton</sender>
+   <signal>clicked()</signal>
+   <receiver>WelcomeWizard</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>577</x>
+     <y>372</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>323</x>
+     <y>199</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>