]> git.mxchange.org Git - flightgear.git/commitdiff
Change handling of default hangar / catalog.
authorJames Turner <zakalawe@mac.com>
Mon, 23 Nov 2015 22:58:00 +0000 (22:58 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 23 Nov 2015 22:58:00 +0000 (22:58 +0000)
- no longer re-add it on startup, add an explicit button in the UI

(will add a more obvious item to the aircraft list in a follow-up
commit)

src/GUI/AddCatalogDialog.cxx
src/GUI/AddCatalogDialog.hxx
src/GUI/PathsDialog.cxx
src/GUI/PathsDialog.hxx
src/GUI/PathsDialog.ui
src/Network/HTTPClient.cxx
src/Network/HTTPClient.hxx

index abca2c51df6845798ccf7f762439edd0349f995f..27ba210b990c3596f369c951271b4ad2c4f8ec2b 100644 (file)
@@ -52,6 +52,12 @@ CatalogRef AddCatalogDialog::addedCatalog()
     return m_result;
 }
 
+void AddCatalogDialog::setUrlAndDownload(QUrl url)
+{
+    m_catalogUrl = url;
+    startDownload();
+}
+
 void AddCatalogDialog::onUrlTextChanged()
 {
     m_catalogUrl = QUrl::fromUserInput(ui->urlEdit->text());
index d67393dfabff6d1ec24b6b6621e4bf71307bbb4f..88a748892127b53ea199d380f3adaa3ac7739666 100644 (file)
@@ -42,6 +42,7 @@ public:
 
     simgear::pkg::CatalogRef addedCatalog();
 
+    void setUrlAndDownload(QUrl url);
 private slots:
     virtual void reject();
     virtual void accept();
index 3abc281a88093fd10f3cfdbd0af79803558c8068..9282de1e07c275670af0c35d31cda34ae351f26e 100644 (file)
@@ -9,6 +9,8 @@
 #include "AddCatalogDialog.hxx"
 
 #include <Main/options.hxx>
+#include <Main/globals.hxx>
+#include <Network/HTTPClient.hxx>
 
 PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
     QDialog(parent),
@@ -22,6 +24,8 @@ PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
 
     connect(m_ui->addCatalog, &QToolButton::clicked,
             this, &PathsDialog::onAddCatalog);
+    connect(m_ui->addDefaultCatalogButton, &QPushButton::clicked,
+            this, &PathsDialog::onAddDefaultCatalog);
     connect(m_ui->removeCatalog, &QToolButton::clicked,
             this, &PathsDialog::onRemoveCatalog);
             
@@ -120,26 +124,60 @@ void PathsDialog::onRemoveAircraftPath()
 
 void PathsDialog::onAddCatalog()
 {
-    AddCatalogDialog* dlg = new AddCatalogDialog(this, m_packageRoot);
+    QScopedPointer<AddCatalogDialog> dlg(new AddCatalogDialog(this, m_packageRoot));
     dlg->exec();
     if (dlg->result() == QDialog::Accepted) {
         m_catalogsModel->refresh();
     }
 }
 
+void PathsDialog::onAddDefaultCatalog()
+{
+    // check it's not a duplicate somehow
+    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    if (http->isDefaultCatalogInstalled())
+        return;
+
+     QScopedPointer<AddCatalogDialog> dlg(new AddCatalogDialog(this, m_packageRoot));
+     QUrl url(QString::fromStdString(http->getDefaultCatalogUrl()));
+     dlg->setUrlAndDownload(url);
+     dlg->exec();
+     if (dlg->result() == QDialog::Accepted) {
+         m_catalogsModel->refresh();
+         updateUi();
+     }
+}
+
 void PathsDialog::onRemoveCatalog()
 {
     QModelIndex mi = m_ui->catalogsList->currentIndex();
+    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+
     if (mi.isValid()) {
+        QString s = QStringLiteral("Remove aircraft hangar '%1'? All installed aircraft from this "
+                                   "hangar will be removed.");
+        QString pkgId = mi.data(CatalogIdRole).toString();
+
+        if (pkgId.toStdString() == http->getDefaultCatalogId()) {
+            s = QStringLiteral("Remove default aircraft hangar? "
+                               "This hangar contains all the default aircraft included with FlightGear. "
+                               "If you change your mind in the future, click the 'restore' button.");
+        } else {
+            s = s.arg(mi.data(Qt::DisplayRole).toString());
+        }
+
         QMessageBox mb;
-        mb.setText(QStringLiteral("Remove aircraft hangar '%1'?").arg(mi.data(Qt::DisplayRole).toString()));
+        mb.setText(s);
         mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
         mb.setDefaultButton(QMessageBox::No);
         mb.exec();
         
-        QString pkgId = mi.data(CatalogIdRole).toString();
-        m_packageRoot->removeCatalogById(pkgId.toStdString());
+        if (mb.result() == QMessageBox::Yes) {
+            m_packageRoot->removeCatalogById(pkgId.toStdString());
+        }
     }
+
+    updateUi();
 }
 
 void PathsDialog::onChangeDownloadDir()
@@ -173,4 +211,7 @@ void PathsDialog::updateUi()
 
     QString m = tr("Download location: %1").arg(s);
     m_ui->downloadLocation->setText(m);
+
+    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    m_ui->addDefaultCatalogButton->setEnabled(!http->isDefaultCatalogInstalled());
 }
index bbd15341edc106136f63d599fe625d86f512ed4e..acafe3d06589726dd9d568462dd5dbc3ea67b861 100644 (file)
@@ -32,7 +32,8 @@ private slots:
 
     void onAddCatalog();
     void onRemoveCatalog();
-    
+    void onAddDefaultCatalog();
+
     void onChangeDownloadDir();
     void onClearDownloadDir();
 private:
index 50e5f2dc83cf9748ca93c4f28f940a5c0009356b..393c10ee643d83510f1170a8f3c9b2df32cf15f4 100644 (file)
       <property name="spacing">
        <number>0</number>
       </property>
-      <item row="1" column="0">
-       <spacer name="horizontalSpacer_5">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>567</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item row="1" column="2">
+      <item row="1" column="3">
        <widget class="QToolButton" name="removeCatalog">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
         </property>
        </widget>
       </item>
-      <item row="1" column="1">
+      <item row="1" column="2">
        <widget class="QToolButton" name="addCatalog">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
         </property>
        </widget>
       </item>
-      <item row="0" column="0" colspan="3">
+      <item row="1" column="1">
+       <spacer name="horizontalSpacer_5">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>567</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="0">
+       <widget class="QPushButton" name="addDefaultCatalogButton">
+        <property name="text">
+         <string>Restore default aircraft hangar</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0" colspan="4">
        <widget class="QListView" name="catalogsList"/>
       </item>
      </layout>
index 19c963797c8b2a56227e31ed7a0c061d4369f5d7..57b6626dd3b6932547512fa9a072867667d5e0db 100644 (file)
@@ -147,18 +147,6 @@ void FGHTTPClient::init()
     
     _packageDelegate.reset(new FGDelegate);
     packageRoot->addDelegate(_packageDelegate.get());
-
-    const char * defaultCatalogId = fgGetString("/sim/package-system/default-catalog/id", "org.flightgear.official" );
-    const char * defaultCatalogUrl = fgGetString("/sim/package-system/default-catalog/url",
-            "http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");
-    // setup default catalog if not present
-    pkg::Catalog* defaultCatalog = packageRoot->getCatalogById( defaultCatalogId );
-    if (!defaultCatalog) {
-      // always show this message
-      SG_LOG(SG_GENERAL, SG_ALERT, "default catalog not found, installing '"
-        << defaultCatalogId << "' from '" << defaultCatalogUrl << "'.");
-      pkg::Catalog::createFromUrl(packageRoot,defaultCatalogUrl);
-    }
     
     // start a refresh now
     packageRoot->refresh();
@@ -167,6 +155,47 @@ void FGHTTPClient::init()
     _inited = true;
 }
 
+namespace {
+
+std::string _getDefaultCatalogId()
+{
+    return fgGetString("/sim/package-system/default-catalog/id", "org.flightgear.official" );
+}
+
+pkg::CatalogRef getDefaultCatalog()
+{
+    if (!globals->packageRoot())
+        return pkg::CatalogRef();
+
+    return globals->packageRoot()->getCatalogById(_getDefaultCatalogId());
+}
+
+} // of anonymous namespace
+
+bool FGHTTPClient::isDefaultCatalogInstalled() const
+{
+    return getDefaultCatalog().valid();
+}
+
+void FGHTTPClient::addDefaultCatalog()
+{
+    pkg::CatalogRef defaultCatalog = getDefaultCatalog();
+    if (!defaultCatalog.valid()) {
+      pkg::Catalog::createFromUrl(globals->packageRoot(), getDefaultCatalogUrl());
+    }
+}
+
+std::string FGHTTPClient::getDefaultCatalogId() const
+{
+    return _getDefaultCatalogId();
+}
+
+std::string FGHTTPClient::getDefaultCatalogUrl() const
+{
+    return fgGetString("/sim/package-system/default-catalog/url",
+                       "http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");;
+}
+
 static naRef f_package_existingInstall( pkg::Package& pkg,
                                         const nasal::CallContext& ctx )
 {
index a203501f0caa1bba9a1dbd4490dcaaa80c161ee4..3a92ee1ef1a29a23d9cc6ad226257fdd47ab8066 100644 (file)
@@ -41,6 +41,11 @@ public:
     virtual void shutdown();
     virtual void update(double);
 
+    bool isDefaultCatalogInstalled() const;
+    void addDefaultCatalog();
+
+    std::string getDefaultCatalogId() const;
+    std::string getDefaultCatalogUrl() const;
 private:
     class FGDelegate;