FlightGear next
LauncherPackageDelegate.cxx
Go to the documentation of this file.
1
2// Copyright (C) 2020 James Turner <james@flightgear.org>
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License as
6// published by the Free Software Foundation; either version 2 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18#include "config.h"
19
21
22#include <QDebug>
23#include <QJSEngine>
24
25#include <simgear/package/Root.hxx>
26
27#include <Main/globals.hxx>
29
31
32LauncherPackageDelegate::LauncherPackageDelegate(QObject* parent) : QObject(parent)
33{
34 globals->packageRoot()->addDelegate(this);
35 const auto http = globals->get_subsystem<FGHTTPClient>();
36 _defaultCatalogId = http->getDefaultCatalogId();
37}
38
40{
41 globals->packageRoot()->removeDelegate(this);
42}
43
44void LauncherPackageDelegate::catalogRefreshed(simgear::pkg::CatalogRef aCatalog, simgear::pkg::Delegate::StatusCode aReason)
45{
47
48 if (aCatalog) {
49 // if catalog download / write to disk failed, show a notification
50 if ((aReason == Delegate::FAIL_EXTRACT) ||
51 (aReason == Delegate::FAIL_DOWNLOAD) ||
52 (aReason == Delegate::FAIL_FILESYSTEM) ||
53 (aReason == Delegate::FAIL_VALIDATION)) {
54 QJSValue args = nc->jsEngine()->newObject();
55 args.setProperty("catalogUri", QString::fromStdString(aCatalog->url()));
56 nc->postNotification("catalog-refresh-failed",
57 QUrl{"qrc:///qml/CatalogRefreshFailedNotification.qml"},
58 args);
59 }
60 }
61
62 if ((aReason != Delegate::STATUS_REFRESHED) || !aCatalog) {
63 return;
64 }
65
66 if (aCatalog->migratedFrom() != simgear::pkg::CatalogRef{}) {
67 QJSValue args = nc->jsEngine()->newObject();
68
69 args.setProperty("newCatalogName", QString::fromStdString(aCatalog->name()));
70
71 if (aCatalog->id() == _defaultCatalogId) {
72 nc->postNotification("did-migrate-official-catalog-to-" + QString::fromStdString(_defaultCatalogId),
73 QUrl{"qrc:///qml/DidMigrateOfficialCatalogNotification.qml"},
74 args);
75 } else {
76 nc->postNotification("did-migrate-catalog-to-" + QString::fromStdString(aCatalog->id()),
77 QUrl{"qrc:///qml/DidMigrateOtherCatalogNotification.qml"},
78 args);
79 }
80 }
81}
82
83void LauncherPackageDelegate::finishInstall(simgear::pkg::InstallRef ref, simgear::pkg::Delegate::StatusCode status)
84{
85 Q_UNUSED(ref)
86 Q_UNUSED(status)
87}
std::string getDefaultCatalogId() const
static LauncherNotificationsController * instance()
LauncherPackageDelegate(QObject *parent=nullptr)
void catalogRefreshed(simgear::pkg::CatalogRef aCatalog, StatusCode aReason) override
void finishInstall(simgear::pkg::InstallRef ref, StatusCode status) override
static int status
FGGlobals * globals
Definition globals.cxx:142