]> git.mxchange.org Git - flightgear.git/commitdiff
Restructure paths handling in the launcher
authorJames Turner <zakalawe@mac.com>
Fri, 8 Apr 2016 09:26:19 +0000 (10:26 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 8 Apr 2016 09:26:34 +0000 (10:26 +0100)
- move the dialog into a new ‘add-ons’ tab

- separate out ‘restore settings’ from selecting a new fg-data

- actually relaunch the app

src/GUI/Launcher.ui
src/GUI/PathsDialog.cxx
src/GUI/PathsDialog.hxx
src/GUI/PathsDialog.ui
src/GUI/QtLauncher.cxx
src/GUI/QtLauncher_private.hxx
src/GUI/SetupRootDialog.ui

index 3ba4e55a51aff83367a95af0e38bff9b481fde95..a49f3cb8c4f37100848ca936632ddac5fd41fcc3 100644 (file)
        <property name="bottomMargin">
         <number>8</number>
        </property>
+       <item row="8" column="0">
+        <widget class="QPushButton" name="restoreDefaultsButton">
+         <property name="text">
+          <string>Restore Defaults...</string>
+         </property>
+         <property name="autoDefault">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
        <item row="0" column="0">
         <layout class="QHBoxLayout" name="horizontalLayout_4">
          <item>
          </item>
         </layout>
        </item>
-       <item row="8" column="0" colspan="2">
+       <item row="7" column="0" colspan="2">
         <widget class="QGroupBox" name="groupBox_2">
          <property name="title">
           <string>Additional options</string>
          </layout>
         </widget>
        </item>
-       <item row="7" column="0">
+       <item row="6" column="0">
         <spacer name="verticalSpacer">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
         </spacer>
        </item>
-       <item row="6" column="0">
-        <widget class="QPushButton" name="pathsButton">
-         <property name="text">
-          <string>Configure add-on aircraft and scenery…</string>
-         </property>
-         <property name="startupOnly" stdset="0">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-       <item row="6" column="1">
-        <widget class="QPushButton" name="changeRootButton">
-         <property name="text">
-          <string>Change data files location…</string>
-         </property>
-        </widget>
-       </item>
       </layout>
      </widget>
     </widget>
        <property name="autoDefault">
         <bool>false</bool>
        </property>
+       <property name="default">
+        <bool>false</bool>
+       </property>
        <property name="flat">
         <bool>false</bool>
        </property>
index 1809c711426a301ac32ad42f1db6baa622399908..9ded69d401b2353a75c962b225fcc64a4ca27a5b 100644 (file)
@@ -4,18 +4,21 @@
 #include <QSettings>
 #include <QFileDialog>
 #include <QMessageBox>
+#include <QDebug>
+#include <QProcess>
 
 #include "CatalogListModel.hxx"
 #include "AddCatalogDialog.hxx"
 #include "AircraftModel.hxx"
+#include "QtLauncher_private.hxx"
 
 #include <Main/options.hxx>
 #include <Main/globals.hxx>
 #include <Network/HTTPClient.hxx>
 
-PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
-    QDialog(parent),
-    m_ui(new Ui::PathsDialog),
+AddOnsPage::AddOnsPage(QWidget *parent, simgear::pkg::RootRef root) :
+    QWidget(parent),
+    m_ui(new Ui::AddOnsPage),
     m_packageRoot(root)
 {
     m_ui->setupUi(this);
@@ -33,27 +36,30 @@ PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
     m_ui->aircraftPathsList->setDropIndicatorShown(true);
 
     connect(m_ui->addCatalog, &QToolButton::clicked,
-            this, &PathsDialog::onAddCatalog);
+            this, &AddOnsPage::onAddCatalog);
     connect(m_ui->addDefaultCatalogButton, &QPushButton::clicked,
-            this, &PathsDialog::onAddDefaultCatalog);
+            this, &AddOnsPage::onAddDefaultCatalog);
     connect(m_ui->removeCatalog, &QToolButton::clicked,
-            this, &PathsDialog::onRemoveCatalog);
+            this, &AddOnsPage::onRemoveCatalog);
             
     connect(m_ui->addSceneryPath, &QToolButton::clicked,
-            this, &PathsDialog::onAddSceneryPath);
+            this, &AddOnsPage::onAddSceneryPath);
     connect(m_ui->removeSceneryPath, &QToolButton::clicked,
-            this, &PathsDialog::onRemoveSceneryPath);
+            this, &AddOnsPage::onRemoveSceneryPath);
 
     connect(m_ui->addAircraftPath, &QToolButton::clicked,
-            this, &PathsDialog::onAddAircraftPath);
+            this, &AddOnsPage::onAddAircraftPath);
     connect(m_ui->removeAircraftPath, &QToolButton::clicked,
-            this, &PathsDialog::onRemoveAircraftPath);
+            this, &AddOnsPage::onRemoveAircraftPath);
 
     connect(m_ui->changeDownloadDir, &QPushButton::clicked,
-            this, &PathsDialog::onChangeDownloadDir);
+            this, &AddOnsPage::onChangeDownloadDir);
 
     connect(m_ui->clearDownloadDir, &QPushButton::clicked,
-            this, &PathsDialog::onClearDownloadDir);
+            this, &AddOnsPage::onClearDownloadDir);
+
+    connect(m_ui->changeDataDir, &QPushButton::clicked,
+            this, &AddOnsPage::onChangeDataDir);
 
     QSettings settings;
             
@@ -71,42 +77,17 @@ PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
     updateUi();
 }
 
-PathsDialog::~PathsDialog()
+AddOnsPage::~AddOnsPage()
 {
     delete m_ui;
 }
 
-void PathsDialog::accept()
-{
-    QSettings settings;
-    QStringList paths;
-    for (int i=0; i<m_ui->sceneryPathsList->count(); ++i) {
-        paths.append(m_ui->sceneryPathsList->item(i)->text());
-    }
-
-    settings.setValue("scenery-paths", paths);
-    paths.clear();
-
-    for (int i=0; i<m_ui->aircraftPathsList->count(); ++i) {
-        paths.append(m_ui->aircraftPathsList->item(i)->text());
-    }
-
-    settings.setValue("aircraft-paths", paths);
-
-    if (m_downloadDir.isEmpty()) {
-        settings.remove("download-dir");
-    } else {
-        settings.setValue("download-dir", m_downloadDir);
-    }
-    
-    QDialog::accept();
-}
-
-void PathsDialog::onAddSceneryPath()
+void AddOnsPage::onAddSceneryPath()
 {
     QString path = QFileDialog::getExistingDirectory(this, tr("Choose scenery folder"));
     if (!path.isEmpty()) {
         m_ui->sceneryPathsList->addItem(path);
+        saveSceneryPaths();
     }
 
     // work around a Qt OS-X bug - this dialog is ending ordered
@@ -115,14 +96,15 @@ void PathsDialog::onAddSceneryPath()
     window()->raise();
 }
 
-void PathsDialog::onRemoveSceneryPath()
+void AddOnsPage::onRemoveSceneryPath()
 {
     if (m_ui->sceneryPathsList->currentItem()) {
         delete m_ui->sceneryPathsList->currentItem();
+        saveSceneryPaths();
     }
 }
 
-void PathsDialog::onAddAircraftPath()
+void AddOnsPage::onAddAircraftPath()
 {
     QString path = QFileDialog::getExistingDirectory(this, tr("Choose aircraft folder"));
     if (!path.isEmpty()) {
@@ -156,6 +138,8 @@ void PathsDialog::onAddAircraftPath()
                 m_ui->aircraftPathsList->addItem(path);
             }
         }
+
+        saveAircraftPaths();
     }
     // work around a Qt OS-X bug - this dialog is ending ordered
     // behind the main settings dialog (consequence of modal-dialog
@@ -163,14 +147,40 @@ void PathsDialog::onAddAircraftPath()
     window()->raise();
 }
 
-void PathsDialog::onRemoveAircraftPath()
+void AddOnsPage::onRemoveAircraftPath()
 {
     if (m_ui->aircraftPathsList->currentItem()) {
         delete m_ui->aircraftPathsList->currentItem();
+        saveAircraftPaths();
     }
 }
 
-void PathsDialog::onAddCatalog()
+void AddOnsPage::saveAircraftPaths()
+{
+    QSettings settings;
+    QStringList paths;
+
+    for (int i=0; i<m_ui->aircraftPathsList->count(); ++i) {
+        paths.append(m_ui->aircraftPathsList->item(i)->text());
+    }
+
+    settings.setValue("aircraft-paths", paths);
+}
+
+void AddOnsPage::saveSceneryPaths()
+{
+    QSettings settings;
+    QStringList paths;
+    for (int i=0; i<m_ui->sceneryPathsList->count(); ++i) {
+        paths.append(m_ui->sceneryPathsList->item(i)->text());
+    }
+
+    settings.setValue("scenery-paths", paths);
+
+    emit sceneryPathsChanged();
+}
+
+void AddOnsPage::onAddCatalog()
 {
     QScopedPointer<AddCatalogDialog> dlg(new AddCatalogDialog(this, m_packageRoot));
     dlg->exec();
@@ -179,7 +189,7 @@ void PathsDialog::onAddCatalog()
     }
 }
 
-void PathsDialog::onAddDefaultCatalog()
+void AddOnsPage::onAddDefaultCatalog()
 {
     // check it's not a duplicate somehow
     FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
@@ -196,7 +206,7 @@ void PathsDialog::onAddDefaultCatalog()
      }
 }
 
-void PathsDialog::onRemoveCatalog()
+void AddOnsPage::onRemoveCatalog()
 {
     QModelIndex mi = m_ui->catalogsList->currentIndex();
     FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
@@ -228,25 +238,74 @@ void PathsDialog::onRemoveCatalog()
     updateUi();
 }
 
-void PathsDialog::onChangeDownloadDir()
+void AddOnsPage::onChangeDownloadDir()
 {
     QString path = QFileDialog::getExistingDirectory(this,
                                                      tr("Choose downloads folder"),
                                                      m_downloadDir);
-    if (!path.isEmpty()) {
-        m_downloadDir = path;
-        updateUi();
+    if (path.isEmpty()) {
+        return; // user cancelled
     }
+
+    m_downloadDir = path;
+    setDownloadDir();
 }
 
-void PathsDialog::onClearDownloadDir()
+void AddOnsPage::onClearDownloadDir()
 {
     // does this need an 'are you sure'?
     m_downloadDir.clear();
+
+    setDownloadDir();
+}
+
+void AddOnsPage::setDownloadDir()
+{
+    QSettings settings;
+    if (m_downloadDir.isEmpty()) {
+        settings.remove("download-dir");
+    } else {
+        settings.setValue("download-dir", m_downloadDir);
+    }
+
+    if (m_downloadDir.isEmpty()) {
+        flightgear::Options::sharedInstance()->clearOption("download-dir");
+    } else {
+        flightgear::Options::sharedInstance()->setOption("download-dir", m_downloadDir.toStdString());
+    }
+
+    emit downloadDirChanged();
     updateUi();
 }
 
-void PathsDialog::updateUi()
+void AddOnsPage::onChangeDataDir()
+{
+    QMessageBox mbox(this);
+    mbox.setText(tr("Change the data files used by FlightGear?"));
+    mbox.setInformativeText(tr("FlightGear requires additional files to operate. "
+                               "(Also called the base package, or fg-data) "
+                               "You can restart FlightGear and choose a "
+                               "different data files location, or restore the default setting."));
+    QPushButton* quitButton = mbox.addButton(tr("Restart FlightGear now"), QMessageBox::YesRole);
+    mbox.addButton(QMessageBox::Cancel);
+    mbox.setDefaultButton(QMessageBox::Cancel);
+    mbox.setIconPixmap(QPixmap(":/app-icon-large"));
+
+    mbox.exec();
+    if (mbox.clickedButton() != quitButton) {
+        return;
+    }
+
+    {
+        QSettings settings;
+        // set the option to the magic marker value
+        settings.setValue("fg-root", "!ask");
+    } // scope the ensure settings are written nicely
+
+    QtLauncher::restartTheApp(QStringList());
+}
+
+void AddOnsPage::updateUi()
 {
     QString s = m_downloadDir;
     if (s.isEmpty()) {
@@ -260,6 +319,18 @@ void PathsDialog::updateUi()
     QString m = tr("Download location: %1").arg(s);
     m_ui->downloadLocation->setText(m);
 
+    QString dataLoc;
+    QSettings settings;
+    QString root = settings.value("fg-root").toString();
+    if (root.isNull()) {
+        dataLoc = tr("built-in");
+    } else {
+        dataLoc = root;
+    }
+
+    m_ui->dataLocation->setText(tr("Data location: %1").arg(dataLoc));
+
+
     FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
     m_ui->addDefaultCatalogButton->setEnabled(!http->isDefaultCatalogInstalled());
 }
index acafe3d06589726dd9d568462dd5dbc3ea67b861..b6303421ec6a2b37a121ee95e3d0a49ab3dad41c 100644 (file)
@@ -7,21 +7,22 @@
 
 
 namespace Ui {
-class PathsDialog;
+class AddOnsPage;
 }
 
 class CatalogListModel;
 
-class PathsDialog : public QDialog
+class AddOnsPage : public QWidget
 {
     Q_OBJECT
 
 public:
-    explicit PathsDialog(QWidget *parent, simgear::pkg::RootRef root);
-    ~PathsDialog();
+    explicit AddOnsPage(QWidget *parent, simgear::pkg::RootRef root);
+    ~AddOnsPage();
 
-protected:
-    virtual void accept();
+signals:
+    void downloadDirChanged();
+    void sceneryPathsChanged();
     
 private slots:
     void onAddSceneryPath();
@@ -36,10 +37,16 @@ private slots:
 
     void onChangeDownloadDir();
     void onClearDownloadDir();
+
+    void onChangeDataDir();
 private:
     void updateUi();
+    void setDownloadDir();
+
+    void saveAircraftPaths();
+    void saveSceneryPaths();
 
-    Ui::PathsDialog* m_ui;
+    Ui::AddOnsPage* m_ui;
     CatalogListModel* m_catalogsModel;
     simgear::pkg::RootRef m_packageRoot;
     QString m_downloadDir;
index 6b02983d684de89d6ba59c5c1b0f18903c35ec55..723025976b99992b59e20aeb9b39f98e5213205e 100644 (file)
@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
- <class>PathsDialog</class>
- <widget class="QDialog" name="PathsDialog">
+ <class>AddOnsPage</class>
+ <widget class="QWidget" name="AddOnsPage">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>600</width>
-    <height>600</height>
+    <width>608</width>
+    <height>617</height>
    </rect>
   </property>
   <property name="windowTitle">
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QLabel" name="downloadLocation">
+    <widget class="QLabel" name="dataLocation">
      <property name="text">
       <string>TextLabel</string>
      </property>
     </widget>
    </item>
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
+    <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1,0">
      <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
        <property name="sizeHint" stdset="0">
         <size>
-         <width>40</width>
+         <width>16</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="changeDownloadDir">
+      <widget class="QLabel" name="label_4">
        <property name="text">
-        <string>Change...</string>
+        <string>FlightGear needs certain files (sometimes called 'fg-data') to function - these are included as part of stable releases.</string>
+       </property>
+       <property name="wordWrap">
+        <bool>true</bool>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="clearDownloadDir">
+      <widget class="QPushButton" name="changeDataDir">
        <property name="text">
-        <string>Use default location</string>
+        <string>Change...</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
    <item>
-    <widget class="QLabel" name="label_2">
+    <widget class="QLabel" name="downloadLocation">
      <property name="text">
-      <string>Aircraft hangars and automatic scenery downloads may cause this location to contain large numbers of files. Changing this location will cause files to be downloaded again.</string>
-     </property>
-     <property name="wordWrap">
-      <bool>true</bool>
+      <string>TextLabel</string>
      </property>
     </widget>
    </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0">
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>16</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Aircraft hangars and automatic scenery downloads may cause this location to contain large numbers of files. Changing this location will cause files to be downloaded again.</string>
+       </property>
+       <property name="wordWrap">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="changeDownloadDir">
+       <property name="text">
+        <string>Change...</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="clearDownloadDir">
+       <property name="text">
+        <string>Use default</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
      </layout>
     </widget>
    </item>
-   <item>
-    <widget class="QDialogButtonBox" name="buttonBox">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="standardButtons">
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
  <resources/>
- <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>PathsDialog</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>248</x>
-     <y>254</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>157</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>rejected()</signal>
-   <receiver>PathsDialog</receiver>
-   <slot>reject()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>316</x>
-     <y>260</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>286</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
 </ui>
index 0d32aa9f024d2c7375a8df7f3e70cf05f1288e28..ae2a95c0a2bcf9c134d7f92d38f89750490d1006 100644 (file)
@@ -360,14 +360,8 @@ void initApp(int& argc, char** argv)
         Qt::KeyboardModifiers mods = app->queryKeyboardModifiers();
         if (mods & (Qt::AltModifier | Qt::ShiftModifier)) {
             qWarning() << "Alt/shift pressed during launch";
-
-            // wipe out our settings
             QSettings settings;
-            settings.clear();
-
             settings.setValue("fg-root", "!ask");
-
-            Options::sharedInstance()->addOption("restore-defaults", "");
         }
     }
 }
@@ -504,8 +498,6 @@ QtLauncher::QtLauncher() :
     connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun()));
     connect(m_ui->quitButton, SIGNAL(clicked()), this, SLOT(onQuit()));
 
-    connect(m_ui->changeRootButton, SIGNAL(clicked()), this, SLOT(onChangeRoot()));
-
     connect(m_ui->aircraftHistory, &QPushButton::clicked,
           this, &QtLauncher::onPopupAircraftHistory);
 
@@ -574,9 +566,17 @@ QtLauncher::QtLauncher() :
             this, &QtLauncher::onAircraftInstallFailed);
     connect(m_aircraftModel, &AircraftItemModel::scanCompleted,
             this, &QtLauncher::updateSelectedAircraft);
-    connect(m_ui->pathsButton, &QPushButton::clicked,
-            this, &QtLauncher::onEditPaths);
+    connect(m_ui->restoreDefaultsButton, &QPushButton::clicked,
+            this, &QtLauncher::onRestoreDefaults);
+
 
+    AddOnsPage* addOnsPage = new AddOnsPage(NULL, globals->packageRoot());
+    connect(addOnsPage, &AddOnsPage::downloadDirChanged,
+            this, &QtLauncher::onDownloadDirChanged);
+    connect(addOnsPage, &AddOnsPage::sceneryPathsChanged,
+            this, &QtLauncher::setSceneryPaths);
+
+    m_ui->tabWidget->addTab(addOnsPage, tr("Add-ons"));
     // after any kind of reset, try to restore selection and scroll
     // to match the m_selectedAircraft. This needs to be delayed
     // fractionally otherwise the scrollTo seems to be ignored,
@@ -842,6 +842,11 @@ void QtLauncher::onRun()
         }
     }
 
+    if (settings.contains("restore-defaults-on-run")) {
+        settings.remove("restore-defaults-on-run");
+        opt->addOption("restore-defaults", "");
+    }
+
     saveSettings();
 
     qApp->exit(0);
@@ -905,12 +910,9 @@ void QtLauncher::onToggleTerrasync(bool enabled)
         if (!info.exists()) {
             QMessageBox msg;
             msg.setWindowTitle(tr("Create download folder?"));
-            msg.setText(tr("The download folder '%1' does not exist, create it now? "
-                           "Click 'change location' to choose another folder "
-                           "to store downloaded files").arg(downloadDir));
+            msg.setText(tr("The download folder '%1' does not exist, create it now?").arg(downloadDir));
             msg.addButton(QMessageBox::Yes);
             msg.addButton(QMessageBox::Cancel);
-            msg.addButton(tr("Change location"), QMessageBox::ActionRole);
             int result = msg.exec();
 
             if (result == QMessageBox::Cancel) {
@@ -918,11 +920,6 @@ void QtLauncher::onToggleTerrasync(bool enabled)
                 return;
             }
 
-            if (result == QMessageBox::ActionRole) {
-                onEditPaths();
-                return;
-            }
-
             QDir d(downloadDir);
             d.mkpath(downloadDir);
         }
@@ -989,6 +986,30 @@ void QtLauncher::onCancelDownload(const QModelIndex& index)
     i->cancelDownload();
 }
 
+void QtLauncher::onRestoreDefaults()
+{
+    QMessageBox mbox(this);
+    mbox.setText(tr("Restore all settings to defaults?"));
+    mbox.setInformativeText(tr("Restoring settings to their defaults may affect available add-ons such as scenery or aircraft."));
+    QPushButton* quitButton = mbox.addButton(tr("Restore and restart now"), QMessageBox::YesRole);
+    mbox.addButton(QMessageBox::Cancel);
+    mbox.setDefaultButton(QMessageBox::Cancel);
+    mbox.setIconPixmap(QPixmap(":/app-icon-large"));
+
+    mbox.exec();
+    if (mbox.clickedButton() != quitButton) {
+        return;
+    }
+
+    {
+        QSettings settings;
+        settings.clear();
+        settings.setValue("restore-defaults-on-run", true);
+    }
+
+    restartTheApp(QStringList());
+}
+
 void QtLauncher::maybeUpdateSelectedAircraft(QModelIndex index)
 {
     QUrl u = index.data(AircraftURIRole).toUrl();
@@ -1136,103 +1157,58 @@ void QtLauncher::onSubsytemIdleTimeout()
     globals->get_subsystem_mgr()->update(0.0);
 }
 
-void QtLauncher::onEditPaths()
+void QtLauncher::onDownloadDirChanged()
 {
-    QSettings settings;
-    QString previousDownloadDir = settings.value("download-dir").toString();
+    // replace existing package root
+    globals->get_subsystem<FGHTTPClient>()->shutdown();
+    globals->setPackageRoot(simgear::pkg::RootRef());
 
-    PathsDialog dlg(this, globals->packageRoot());
-    dlg.exec();
-    if (dlg.result() == QDialog::Accepted) {
-        QString dd = settings.value("download-dir").toString();
-        bool downloadDirChanged = (previousDownloadDir != dd);
-        if (downloadDirChanged) {
-            qDebug() << "download dir changed, resetting package root";
-
-            if (dd.isEmpty()) {
-                flightgear::Options::sharedInstance()->clearOption("download-dir");
-            } else {
-                flightgear::Options::sharedInstance()->setOption("download-dir", dd.toStdString());
-            }
-
-            // replace existing package root
-            globals->get_subsystem<FGHTTPClient>()->shutdown();
-            globals->setPackageRoot(simgear::pkg::RootRef());
-
-            // create new root with updated download-dir value
-            fgInitPackageRoot();
+    // create new root with updated download-dir value
+    fgInitPackageRoot();
 
-            globals->get_subsystem<FGHTTPClient>()->init();
-        }
+    globals->get_subsystem<FGHTTPClient>()->init();
 
-        // re-scan the aircraft list
-        m_aircraftModel->setPackageRoot(globals->packageRoot());
-        m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
-        m_aircraftModel->scanDirs();
+    // re-scan the aircraft list
+    QSettings settings;
+    m_aircraftModel->setPackageRoot(globals->packageRoot());
+    m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
+    m_aircraftModel->scanDirs();
 
-        // re-set scenery dirs
-        setSceneryPaths();
-    }
+    // re-set scenery dirs
+    setSceneryPaths();
 }
 
-void QtLauncher::onChangeRoot()
+simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
 {
-    QMessageBox mbox(this);
-    mbox.setText(tr("Change the data files location used by FlightGear?"));
-    mbox.setInformativeText(tr("FlightGear cannot work without its data files. "
-                               "(Also called the base package) "
-                               "To change which files are used, quit FlightGear and open it again, "
-                               "while holding down the 'shift' key, and you will be able to choose a "
-                               "different data files location, or restore the default setting."));
-    QPushButton* quitButton = mbox.addButton(tr("Quit FlightGear now"), QMessageBox::YesRole);
-    mbox.addButton(QMessageBox::Cancel);
-    mbox.setDefaultButton(QMessageBox::Cancel);
-    mbox.setIconPixmap(QPixmap(":/app-icon-large"));
-
-    mbox.exec();
-    if (mbox.clickedButton() != quitButton) {
-        return;
+    if (uri.scheme() != "package") {
+        qWarning() << "invalid URL scheme:" << uri;
+        return simgear::pkg::PackageRef();
     }
 
-    // following code doesn't work reliably, so we take the simpler
-    // option of asking the user to re-launch us while holding down
-    // the hot-key (shift)
-#if 0
-    {
-        QSettings settings;
-        // set the option to the magic marker value
-        settings.setValue("fg-root", "!ask");
-    } // scope the ensure settings are written nicel
+    QString ident = uri.path();
+    return globals->packageRoot()->getPackageById(ident.toStdString());
+}
 
+void QtLauncher::restartTheApp(QStringList fgArgs)
+{
     // Spawn a new instance of myApplication:
     QProcess proc;
-#if defined(Q_OS_MAC)
     QStringList args;
 
+#if defined(Q_OS_MAC)
     QDir dir(qApp->applicationDirPath()); // returns the 'MacOS' dir
     dir.cdUp(); // up to 'contents' dir
     dir.cdUp(); // up to .app dir
-    args << dir.absolutePath();
+    // see 'man open' for details, but '-n' ensures we launch a new instance,
+    // and we want to pass remaining arguments to us, not open.
+    args << "-n" << dir.absolutePath() << "--args" << "--launcher" << fgArgs;
+    qDebug() << "args" << args;
     proc.startDetached("open", args);
 #else
-    proc.startDetached(qApp->applicationFilePath());
+    args << "--launcher" << fgArgs;
+    proc.startDetached(qApp->applicationFilePath(), args);
 #endif
-#endif
-
-    qDebug() << "doing app exit";
     qApp->exit(-1);
 }
 
-simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
-{
-    if (uri.scheme() != "package") {
-        qWarning() << "invalid URL scheme:" << uri;
-        return simgear::pkg::PackageRef();
-    }
-
-    QString ident = uri.path();
-    return globals->packageRoot()->getPackageById(ident.toStdString());
-}
-
-
 #include "QtLauncher.moc"
index c2a06b6395136a4cadcd05ef18ba8bb71ce2a7be..58dc053fe7519a7713ab3d83d385dcf2185e4adf 100644 (file)
@@ -53,6 +53,7 @@ public:
 
     void setSceneryPaths();
 
+    static void restartTheApp(QStringList fgArgs);
 protected:
     virtual void closeEvent(QCloseEvent *event);
 
@@ -85,9 +86,6 @@ private slots:
 
     void onSubsytemIdleTimeout();
 
-    void onEditPaths();
-    void onChangeRoot();
-
     void onAircraftInstalledCompleted(QModelIndex index);
     void onAircraftInstallFailed(QModelIndex index, QString errorMessage);
 
@@ -95,6 +93,9 @@ private slots:
 
     void maybeRestoreAircraftSelection();
 
+    void onRestoreDefaults();
+
+    void onDownloadDirChanged();
 private:
 
     /**
index 9e8465a560ef5611d44e33da6ca9a7b587455d11..71a31a91628824e475684a16f99fde5123145c54 100644 (file)
    <item row="6" column="1">
     <widget class="QLabel" name="label_2">
      <property name="text">
-      <string>To download a compressed archive of the files, click the 'Download' button. Once the download is complete, extract the files to a suitabe location and choose the folder using the button above.</string>
+      <string>To download a compressed archive of the files, click the 'Download' button. Once the download is complete, extract the files to a suitable location and choose the folder using the button above.</string>
      </property>
      <property name="wordWrap">
       <bool>true</bool>