on xenial help sign in
Add plugin to read changelog from file
commit12f1ccaa98fda4c36f87fb47b0de44b28c39ac85 authorMarius Gripsgard <marius@ubports.com> dateWed 15 Aug 2018, 22:33 (8 years ago) parentf4fdb19
5 files changed+115−1
plugins/Wizard/CMakeLists.txt+1 plugins/Wizard/Changelog.cpp+58 plugins/Wizard/Changelog.h+52 plugins/Wizard/plugin.cpp+2 qml/Wizard/Pages/11-changelog.qml+2−1
plugins/Wizard/CMakeLists.txt+1
@@ -10,6 +10,7 @@ add_library(Wizard-qml MODULE
1010 timezonemodel.cpp
1111 Status.cpp
1212 keyboardLayoutsModel.cpp
13+ Changelog.cpp
1314)
1415
1516qt5_use_modules(Wizard-qml DBus Qml)
plugins/Wizard/Changelog.cppnew file+58
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright (C) 2018 The UBports project
3+ * Written by: Marius Gripsgard <marius@ubports.com>
4+ *
5+ * This program is free software: you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 3, as published
7+ * by the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License along
15+ * with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#include "Changelog.h"
19+
20+#include <QDir>
21+#include <QFile>
22+#include <QTextStream>
23+
24+Changelog::Changelog()
25+ : QObject()
26+{
27+ readChangelog();
28+ if(QFile::exists(changelogPath()))
29+ m_fsWatcher.addPath(changelogPath());
30+ connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged, this, &Changelog::watcherFileChanged);
31+}
32+
33+QString Changelog::changelogPath()
34+{
35+ return "/usr/share/ubports/changelogs/current";
36+}
37+
38+QString Changelog::text() const
39+{
40+ return m_text;
41+}
42+
43+void Changelog::readChangelog()
44+{
45+ if(!QFile::exists(changelogPath()))
46+ return;
47+ QFile f(changelogPath());
48+ if (!f.open(QFile::ReadOnly | QFile::Text)) return;
49+ QTextStream in(&f);
50+ m_text = in.readAll();
51+}
52+
53+void Changelog::watcherFileChanged()
54+{
55+ readChangelog();
56+ Q_EMIT textChanged();
57+ m_fsWatcher.removePath(changelogPath());
58+}
plugins/Wizard/Changelog.hnew file+52
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright (C) 2018 The UBports project
3+ * Written by: Marius Gripsgard <marius@ubports.com>
4+ *
5+ * This program is free software: you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 3, as published
7+ * by the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License along
15+ * with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#ifndef WIZARD_CHANGELOG_H
19+#define WIZARD_CHANGELOG_H
20+
21+#include <QFileSystemWatcher>
22+#include <QObject>
23+#include <QString>
24+
25+class Changelog : public QObject
26+{
27+ Q_OBJECT
28+ Q_PROPERTY(QString text READ text NOTIFY textChanged)
29+
30+public:
31+ Changelog();
32+ ~Changelog() = default;
33+
34+ QString text() const;
35+
36+Q_SIGNALS:
37+ void textChanged();
38+
39+private Q_SLOTS:
40+ void watcherFileChanged();
41+
42+private:
43+ Q_DISABLE_COPY(Changelog)
44+
45+ static QString changelogPath();
46+ void readChangelog();
47+
48+ QFileSystemWatcher m_fsWatcher;
49+ QString m_text;
50+};
51+
52+#endif
plugins/Wizard/plugin.cpp+2
@@ -20,6 +20,7 @@
2020#include "timezonemodel.h"
2121#include "LocalePlugin.h"
2222#include "Status.h"
23+#include "Changelog.h"
2324#include "keyboardLayoutsModel.h"
2425
2526#include <QtQml/qqml.h>
@@ -33,4 +34,5 @@ void WizardPlugin::registerTypes(const char *uri)
3334 qmlRegisterType<TimeZoneLocationModel>(uri, 0, 1, "TimeZoneModel");
3435 qmlRegisterType<KeyboardLayoutsModel>(uri, 0, 1, "KeyboardLayoutsModel");
3536 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
37+ qmlRegisterType<Changelog>(uri, 0, 1, "Changelog");
3638}
qml/Wizard/Pages/11-changelog.qml+2−1
@@ -20,6 +20,7 @@
2020import QtQuick 2.4
2121import Ubuntu.Components 1.3
2222import AccountsService 0.1
23+import Wizard 0.1
2324import ".." as LocalComponents
2425
2526LocalComponents.Page {
@@ -42,7 +43,7 @@ LocalComponents.Page {
4243 }
4344
4445 Label {
45− text: "This is where cool stuff would go"
46+ text: Changelog.text
4647 }
4748 }
4849