1
0
Fork 0

Launcher: update all aircraft UI.

Replaces more complex previous attempt, which was also not hooked
up properly, ooops.
This commit is contained in:
James Turner 2017-04-14 18:31:23 +01:00
parent c19fc6bc06
commit 95a6d31e18
5 changed files with 38 additions and 99 deletions

View file

@ -78,7 +78,6 @@ if (HAVE_QT)
LocationWidget.ui LocationWidget.ui
NoOfficialHangar.ui NoOfficialHangar.ui
InstallSceneryDialog.ui InstallSceneryDialog.ui
UpdateAllAircraft.ui
) )
qt5_add_resources(qrc_sources resources.qrc) qt5_add_resources(qrc_sources resources.qrc)

View file

@ -443,7 +443,7 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="aircraftPage"> <widget class="QWidget" name="aircraftPage">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0,0"> <layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0,0,0">
<property name="spacing"> <property name="spacing">
<number>4</number> <number>4</number>
</property> </property>
@ -533,6 +533,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QLabel" name="updateAircraftLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;%1 aircraft have updates available, &lt;a href=&quot;action:update&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;click here to update&lt;/span&gt;&lt;/a&gt; (Or &lt;a href=&quot;action:hide&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;hide this&lt;/span&gt;&lt;/a&gt;)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QListView" name="aircraftList"> <widget class="QListView" name="aircraftList">
<property name="verticalScrollMode"> <property name="verticalScrollMode">
@ -570,8 +577,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>643</width> <width>90</width>
<height>644</height> <height>20</height>
</rect> </rect>
</property> </property>
</widget> </widget>
@ -603,8 +610,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>643</width> <width>173</width>
<height>644</height> <height>23</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">

View file

@ -69,26 +69,6 @@ private:
Ui::NoOfficialHangarMessage* m_ui; Ui::NoOfficialHangarMessage* m_ui;
}; };
class UpdateAllAircraftMessage : public QWidget
{
Q_OBJECT
public:
UpdateAllAircraftMessage() :
m_ui(new Ui::UpdateAllAircraftMessage)
{
m_ui->setupUi(this);
// proxy this signal upwards
connect(m_ui->label, &QLabel::linkActivated, this, &UpdateAllAircraftMessage::linkActivated);
connect(m_ui->updateAllButton, &QPushButton::clicked, this, &UpdateAllAircraftMessage::updateAll);
}
Q_SIGNALS:
void linkActivated(QUrl link);
void updateAll();
private:
Ui::UpdateAllAircraftMessage* m_ui;
};
#include "LauncherMainWindow.moc" #include "LauncherMainWindow.moc"
QQmlPrivate::AutoParentResult launcher_autoParent(QObject* thing, QObject* parent) QQmlPrivate::AutoParentResult launcher_autoParent(QObject* thing, QObject* parent)
@ -195,6 +175,8 @@ LauncherMainWindow::LauncherMainWindow() :
m_ui->locationHistory->setIcon(historyIcon); m_ui->locationHistory->setIcon(historyIcon);
m_aircraftModel = new AircraftItemModel(this); m_aircraftModel = new AircraftItemModel(this);
connect(m_aircraftModel, &AircraftItemModel::packagesNeedUpdating,
this, &LauncherMainWindow::onPackagesNeedUpdate);
m_aircraftProxy->setSourceModel(m_aircraftModel); m_aircraftProxy->setSourceModel(m_aircraftModel);
m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
@ -241,6 +223,9 @@ LauncherMainWindow::LauncherMainWindow() :
connect(m_aircraftProxy, &AircraftProxyModel::modelReset, connect(m_aircraftProxy, &AircraftProxyModel::modelReset,
this, &LauncherMainWindow::delayedAircraftModelReset); this, &LauncherMainWindow::delayedAircraftModelReset);
connect(m_ui->updateAircraftLabel, &QLabel::linkActivated,
this, &LauncherMainWindow::onUpdateAircraftLink);
QSettings settings; QSettings settings;
m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList()); m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
m_aircraftModel->setPackageRoot(globals->packageRoot()); m_aircraftModel->setPackageRoot(globals->packageRoot());
@ -254,6 +239,7 @@ LauncherMainWindow::LauncherMainWindow() :
m_ui->stack->addWidget(m_viewCommandLinePage); m_ui->stack->addWidget(m_viewCommandLinePage);
checkOfficialCatalogMessage(); checkOfficialCatalogMessage();
checkUpdateAircraft();
restoreSettings(); restoreSettings();
updateSettingsSummary(); updateSettingsSummary();
} }
@ -833,14 +819,6 @@ void LauncherMainWindow::updateSelectedAircraft()
} }
} }
void LauncherMainWindow::onUpdateAllAircraft()
{
const PackageList& toBeUpdated = globals->packageRoot()->packagesNeedingUpdate();
std::for_each(toBeUpdated.begin(), toBeUpdated.end(), [](PackageRef pkg) {
globals->packageRoot()->scheduleToUpdate(pkg->install());
});
}
void LauncherMainWindow::onPackagesNeedUpdate(bool yes) void LauncherMainWindow::onPackagesNeedUpdate(bool yes)
{ {
Q_UNUSED(yes); Q_UNUSED(yes);
@ -1034,22 +1012,28 @@ void LauncherMainWindow::onOfficialCatalogMessageLink(QUrl link)
void LauncherMainWindow::checkUpdateAircraft() void LauncherMainWindow::checkUpdateAircraft()
{ {
if (shouldShowOfficialCatalogMessage()) { const size_t numToUpdate = globals->packageRoot()->packagesNeedingUpdate().size();
return; // don't interfere const bool showUpdateMessage = (numToUpdate > 0);
}
const bool showUpdateMessage = !globals->packageRoot()->packagesNeedingUpdate().empty(); static QString originalText = m_ui->updateAircraftLabel->text();
m_aircraftModel->setMessageWidgetVisible(showUpdateMessage); const QString t = originalText.arg(numToUpdate);
if (showUpdateMessage) { m_ui->updateAircraftLabel->setText(t);
UpdateAllAircraftMessage* messageWidget = new UpdateAllAircraftMessage; m_ui->updateAircraftLabel->setVisible(showUpdateMessage);
// connect(messageWidget, &UpdateAllAircraftMessage::linkActivated,
// this, &LauncherMainWindow::onMessageLink);
connect(messageWidget, &UpdateAllAircraftMessage::updateAll, this, &LauncherMainWindow::onUpdateAllAircraft);
QModelIndex index = m_aircraftProxy->mapFromSource(m_aircraftModel->messageWidgetIndex());
m_ui->aircraftList->setIndexWidget(index, messageWidget);
}
} }
void LauncherMainWindow::onUpdateAircraftLink(QUrl link)
{
QString s = link.toString();
if (s == "action:hide") {
m_ui->updateAircraftLabel->hide();
} else if (s == "action:update") {
m_ui->updateAircraftLabel->hide();
const PackageList& toBeUpdated = globals->packageRoot()->packagesNeedingUpdate();
std::for_each(toBeUpdated.begin(), toBeUpdated.end(), [](PackageRef pkg) {
globals->packageRoot()->scheduleToUpdate(pkg->install());
});
}
}
simgear::pkg::PackageRef LauncherMainWindow::packageForAircraftURI(QUrl uri) const simgear::pkg::PackageRef LauncherMainWindow::packageForAircraftURI(QUrl uri) const
{ {

View file

@ -98,8 +98,6 @@ private slots:
Q_INVOKABLE void onDownloadDirChanged(); Q_INVOKABLE void onDownloadDirChanged();
void onUpdateAllAircraft();
void onPackagesNeedUpdate(bool yes); void onPackagesNeedUpdate(bool yes);
void onClickToolboxButton(); void onClickToolboxButton();
@ -110,6 +108,7 @@ private slots:
void onChangeDataDir(); void onChangeDataDir();
void onSettingsSearchChanged(); void onSettingsSearchChanged();
void onUpdateAircraftLink(QUrl link);
private: private:
/** /**

View file

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpdateAllAircraftMessage</class>
<widget class="QWidget" name="UpdateAllAircraftMessage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>607</width>
<height>44</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/app-icon-large</normaloff>:/app-icon-large</iconset>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;%1 aircraft have updates available. (&lt;a href=&quot;action:hide&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Click&lt;/span&gt;&lt;/a&gt; to hide this)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateAllButton">
<property name="text">
<string>Update all</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>