--- /dev/null
+// AddCatalogDialog.cxx - part of GUI launcher using Qt5
+//
+// Written by James Turner, started March 2015.
+//
+// Copyright (C) 2015 James Turner <zakalawe@mac.com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#include "AddCatalogDialog.hxx"
+#include "ui_AddCatalogDialog.h"
+
+#include <QPushButton>
+#include <QDebug>
+
+#include <Include/version.h>
+
+using namespace simgear::pkg;
+
+AddCatalogDialog::AddCatalogDialog(QWidget *parent, RootRef root) :
+ QDialog(parent),
+ m_state(STATE_START),
+ ui(new Ui::AddCatalogDialog),
+ m_packageRoot(root)
+{
+ ui->setupUi(this);
+
+ connect(ui->urlEdit, &QLineEdit::textEdited,
+ this, &AddCatalogDialog::onUrlTextChanged);
+
+ updateUi();
+}
+
+AddCatalogDialog::~AddCatalogDialog()
+{
+ delete ui;
+}
+
+CatalogRef AddCatalogDialog::addedCatalog()
+{
+ return m_result;
+}
+
+void AddCatalogDialog::onUrlTextChanged()
+{
+ m_catalogUrl = QUrl::fromUserInput(ui->urlEdit->text());
+ updateUi();
+}
+
+void AddCatalogDialog::updateUi()
+{
+ QPushButton* b = ui->buttonBox->button(QDialogButtonBox::Ok);
+
+ switch (m_state) {
+ case STATE_START:
+ b->setText(tr("Next"));
+ b->setEnabled(m_catalogUrl.isValid() && !m_catalogUrl.isRelative());
+ break;
+
+ case STATE_DOWNLOADING:
+ b->setEnabled(false);
+ break;
+
+ case STATE_DOWNLOAD_FAILED:
+ b->setEnabled(false);
+ break;
+
+ case STATE_FINISHED:
+ b->setEnabled(true);
+ b->setText(tr("Okay"));
+ break;
+ }
+
+ if (m_state == STATE_FINISHED) {
+ QString catDesc = QString::fromStdString(m_result->description());
+ QString s = tr("Successfully retrieved aircraft information from '%1'. "
+ "%2 aircraft are included in this hangar.").arg(catDesc).arg(m_result->packages().size());
+ ui->resultsSummaryLabel->setText(s);
+ } else if (m_state == STATE_DOWNLOAD_FAILED) {
+ Delegate::FailureCode code = m_result->status();
+ qWarning() << Q_FUNC_INFO << "failed with code" << code;
+ QString s;
+ switch (code) {
+ case Delegate::FAIL_DOWNLOAD:
+ s = tr("Failed to download aircraft descriptions from '%1'. "
+ "Check the address (URL) and your network connection.").arg(m_catalogUrl.toString());
+ break;
+
+ case Delegate::FAIL_VERSION:
+ s = tr("The provided hangar is for a different version of FLightGear. "
+ "(This is version %1)").arg(QString::fromUtf8(FLIGHTGEAR_VERSION));
+ break;
+
+ default:
+ s = tr("Unknown error occured trying to set up the hangar.");
+ }
+
+ ui->resultsSummaryLabel->setText(s);
+ }
+}
+
+void AddCatalogDialog::startDownload()
+{
+ Q_ASSERT(m_catalogUrl.isValid());
+
+ m_result = Catalog::createFromUrl(m_packageRoot, m_catalogUrl.toString().toStdString());
+ m_result->addStatusCallback(this, &AddCatalogDialog::onCatalogStatusChanged);
+ m_state = STATE_DOWNLOADING;
+ updateUi();
+ ui->stack->setCurrentIndex(STATE_DOWNLOADING);
+}
+
+void AddCatalogDialog::accept()
+{
+ switch (m_state) {
+ case STATE_START:
+ startDownload();
+ break;
+
+ case STATE_DOWNLOADING:
+ case STATE_DOWNLOAD_FAILED:
+ // can't happen, button is disabled
+ break;
+
+ case STATE_FINISHED:
+ QDialog::accept();
+ break;
+ }
+}
+
+void AddCatalogDialog::reject()
+{
+ if (m_result && !m_result->id().empty()) {
+ // user may have successfully download the catalog, but choosen
+ // not to add it. so remove it here
+ m_packageRoot->removeCatalogById(m_result->id());
+ }
+
+ QDialog::reject();
+}
+
+void AddCatalogDialog::onCatalogStatusChanged(Catalog* cat)
+{
+ Delegate::FailureCode s = cat->status();
+ qDebug() << Q_FUNC_INFO << "cat status:" << s;
+ switch (s) {
+ case Delegate::CATALOG_REFRESHED:
+ m_state = STATE_FINISHED;
+ break;
+
+ case Delegate::FAIL_IN_PROGRESS:
+ // don't jump to STATE_FINISHED
+ return;
+
+ // all the actual failure codes
+ default:
+ m_state = STATE_DOWNLOAD_FAILED;
+ break;
+ }
+
+ ui->stack->setCurrentIndex(STATE_FINISHED);
+ updateUi();
+}
+
--- /dev/null
+// AddCatalogDialog.hxx - part of GUI launcher using Qt5
+//
+// Written by James Turner, started March 2015.
+//
+// Copyright (C) 2015 James Turner <zakalawe@mac.com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#ifndef FG_GUI_ADDCATALOGDIALOG_HXX
+#define FG_GUI_ADDCATALOGDIALOG_HXX
+
+#include <QDialog>
+#include <QUrl>
+
+#include <simgear/package/Root.hxx>
+#include <simgear/package/Catalog.hxx>
+
+namespace Ui {
+class AddCatalogDialog;
+}
+
+class AddCatalogDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit AddCatalogDialog(QWidget *parent,
+ simgear::pkg::RootRef root);
+ ~AddCatalogDialog();
+
+ simgear::pkg::CatalogRef addedCatalog();
+
+private slots:
+ virtual void reject();
+ virtual void accept();
+
+ void onUrlTextChanged();
+private:
+ void startDownload();
+ void updateUi();
+
+ // callback from the catalog
+ void onCatalogStatusChanged(simgear::pkg::Catalog* cat);
+
+ enum State {
+ STATE_START = 0, // awaiting user input on first screen
+ STATE_DOWNLOADING = 1, // in-progress, showing progress page
+ STATE_FINISHED = 2, // catalog added ok, showing summary page
+ STATE_DOWNLOAD_FAILED // download checks failed for some reason
+
+ };
+
+ State m_state;
+
+ Ui::AddCatalogDialog *ui;
+ simgear::pkg::RootRef m_packageRoot;
+ QUrl m_catalogUrl;
+ simgear::pkg::CatalogRef m_result;
+};
+
+#endif // FG_GUI_ADDCATALOGDIALOG_HXX
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AddCatalogDialog</class>
+ <widget class="QDialog" name="AddCatalogDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>500</width>
+ <height>200</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Add aircraft hangar</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QStackedWidget" name="stack">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="page">
+ <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,1">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Enter the URL of an aircraft hangar:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="urlEdit">
+ <property name="placeholderText">
+ <string>http://www.somesite.com/flightgear-aircraft.xml</string>
+ </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>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="page_2">
+ <layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,1">
+ <item>
+ <widget class="QLabel" name="downloadDescription">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Please waiting, downloading and checking the hangar information.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximum">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>-1</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="page_3">
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <widget class="QLabel" name="resultsSummaryLabel">
+ <property name="text">
+ <string>Lorem Ipsum</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </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>AddCatalogDialog</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>AddCatalogDialog</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>
+</ui>
if (HAVE_QT)
- qt5_wrap_ui(uic_sources Launcher.ui EditRatingsFilterDialog.ui SetupRootDialog.ui)
+ qt5_wrap_ui(uic_sources Launcher.ui
+ EditRatingsFilterDialog.ui
+ SetupRootDialog.ui
+ AddCatalogDialog.ui)
qt5_add_resources(qrc_sources resources.qrc)
include_directories(${PROJECT_BINARY_DIR}/src/GUI)
AircraftModel.cxx
CatalogListModel.cxx
CatalogListModel.hxx
+ AddCatalogDialog.cxx
+ AddCatalogDialog.hxx
${uic_sources}
${qrc_sources})
#include <simgear/structure/exception.hxx>
#include <simgear/misc/sg_path.hxx>
+#include <simgear/package/Package.hxx>
+
// FlightGear
#include <Main/globals.hxx>
{
}
+void CatalogListModel::refresh()
+{
+ beginResetModel();
+ endResetModel();
+}
+
int CatalogListModel::rowCount(const QModelIndex& parent) const
{
return m_packageRoot->catalogs().size();
return QUrl(QString::fromStdString(cat->url()));
} else if (role == CatalogIdRole) {
return QString::fromStdString(cat->id());
+ } else if (role == CatalogPackageCountRole) {
+ return static_cast<quint32>(cat->packages().size());
+ } else if (role == CatalogInstallCountRole) {
+ return static_cast<quint32>(cat->installedPackages().size());
}
return QVariant();
const int CatalogUrlRole = Qt::UserRole + 1;
const int CatalogIdRole = Qt::UserRole + 2;
+const int CatalogPackageCountRole = Qt::UserRole + 3;
+const int CatalogInstallCountRole = Qt::UserRole + 4;
class CatalogListModel : public QAbstractListModel
{
~CatalogListModel();
+ void refresh();
+
virtual int rowCount(const QModelIndex& parent) const;
virtual QVariant data(const QModelIndex& index, int role) const;
#include "AircraftItemDelegate.hxx"
#include "AircraftModel.hxx"
#include "CatalogListModel.hxx"
+#include "AddCatalogDialog.hxx"
#include <Main/globals.hxx>
#include <Navaids/NavDataCache.hxx>
m_catalogsModel = new CatalogListModel(this, r);
m_ui->catalogsList->setModel(m_catalogsModel);
+ connect(m_ui->addCatalog, &QToolButton::clicked,
+ this, &QtLauncher::onAddCatalog);
+ connect(m_ui->removeCatalog, &QToolButton::clicked,
+ this, &QtLauncher::onRemoveCatalog);
+
QSettings settings;
m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
m_aircraftModel->scanDirs();
void QtLauncher::onAddCatalog()
{
-
+ AddCatalogDialog* dlg = new AddCatalogDialog(this, globals->packageRoot());
+ dlg->exec();
+ if (dlg->result() == QDialog::Accepted) {
+ m_catalogsModel->refresh();
+ }
}
void QtLauncher::onRemoveCatalog()