on 4635884 help sign in
84 lines 3.0 kB history raw
1/*
2 * Copyright (C) 2014-2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#ifndef SYSTEMIMAGE_H
18#define SYSTEMIMAGE_H
20#include <QObject>
21#include <QLoggingCategory>
23Q_DECLARE_LOGGING_CATEGORY(SYSTEMIMAGEPLUGIN)
25class SystemImage : public QObject
27 Q_OBJECT
28 Q_DISABLE_COPY(SystemImage)
30 Q_PROPERTY(bool updateAvailable READ updateAvailable NOTIFY updateAvailableStatus)
31 Q_PROPERTY(bool updateDownloading READ updateDownloading NOTIFY updateAvailableStatus)
32 Q_PROPERTY(QString availableVersion READ availableVersion NOTIFY updateAvailableStatus)
33 Q_PROPERTY(QString updateSize READ updateSize NOTIFY updateAvailableStatus)
34 Q_PROPERTY(bool updateApplying READ updateApplying NOTIFY updateApplyingChanged)
35 Q_PROPERTY(bool updateDownloaded READ updateDownloaded NOTIFY updateDownloadedChanged)
37public:
38 explicit SystemImage(QObject *parent = nullptr);
39 ~SystemImage() = default;
41 bool updateAvailable() const { return m_updateAvailable; }
42 bool updateDownloading() const { return m_downloading; }
43 QString availableVersion() const { return m_availableVersion; }
44 QString updateSize() const { return m_updateSize; }
45 bool updateApplying() const { return m_updateApplying; }
46 bool updateDownloaded() const { return m_downloaded; }
48public Q_SLOTS:
49 Q_INVOKABLE void checkForUpdate();
50 Q_INVOKABLE void applyUpdate();
51 Q_INVOKABLE void factoryReset();
53private Q_SLOTS:
54 void onUpdateAvailableStatus(bool is_available, bool updateDownloading, const QString &available_version,
55 int update_size, const QString &last_update_date, const QString &error_reason);
56 void onUpdateDownloaded();
57 void onUpdateFailed(int consecutive_failure_count, const QString & last_reason);
58 void onUpdateApplied(bool applied);
59 void onRebooting(bool status);
61Q_SIGNALS:
62 void updateAvailableStatus();
63 void updateDownloadedChanged();
64 void updateApplyingChanged();
66private Q_SLOTS:
67 void setUpdateApplying(bool status);
69private:
70 void resetUpdateStatus();
71 QString formatSize(quint64 size) const;
73private:
74 bool m_updateAvailable = false;
75 bool m_updateApplying = false;
76 bool m_downloading = false;
77 bool m_downloaded = false;
78 QString m_availableVersion;
79 QString m_updateSize;
80 QString m_lastUpdateDate;
81 QString m_errorReason;
82};
84#endif // SYSTEMIMAGE_H