diff options
| author | Aleix Pol <aleixpol@kde.org> | 2015-09-17 16:00:18 (GMT) |
|---|---|---|
| committer | Aleix Pol <aleixpol@kde.org> | 2015-09-17 16:00:18 (GMT) |
| commit | 681f93b9d9eb52c1b7b046285a7c94c69cef0563 (patch) | |
| tree | 6da1404ed134d6fe721641d6c22ae05c21284f49 | |
| parent | 2212ffa829755250df4d06ca0df5ea0f34c00ec9 (diff) | |
Refactor Updates pages to match the VDG design
| -rw-r--r-- | discover/qml/Main.qml | 2 | ||||
| -rw-r--r-- | discover/qml/PresentUpdatesPage.qml | 27 | ||||
| -rw-r--r-- | discover/qml/UpdateProgressPage.qml | 48 | ||||
| -rw-r--r-- | discover/qml/UpdatesPage.qml | 105 | ||||
| -rw-r--r-- | discover/resources.qrc | 1 | ||||
| -rw-r--r-- | libmuon/resources/ResourcesUpdatesModel.cpp | 20 | ||||
| -rw-r--r-- | libmuon/resources/ResourcesUpdatesModel.h | 10 |
7 files changed, 153 insertions, 60 deletions
diff --git a/discover/qml/Main.qml b/discover/qml/Main.qml index 9ca5e44..bac4734 100644 --- a/discover/qml/Main.qml +++ b/discover/qml/Main.qml @@ -37,7 +37,7 @@ Rectangle //toplevels property Component topBrowsingComp: Qt.createComponent("qrc:/qml/BrowsingPage.qml") property Component topInstalledComp: Qt.createComponent("qrc:/qml/InstalledPage.qml") - property Component topUpdateComp: Qt.createComponent("qrc:/qml/PresentUpdatesPage.qml") + property Component topUpdateComp: Qt.createComponent("qrc:/qml/UpdatesPage.qml") property Component topSourcesComp: Qt.createComponent("qrc:/qml/SourcesPage.qml") property Component currentTopLevel: defaultStartup ? topBrowsingComp : loadingComponent property bool defaultStartup: true diff --git a/discover/qml/PresentUpdatesPage.qml b/discover/qml/PresentUpdatesPage.qml index bffb0a5..536755c 100644 --- a/discover/qml/PresentUpdatesPage.qml +++ b/discover/qml/PresentUpdatesPage.qml @@ -7,24 +7,7 @@ import org.kde.kquickcontrolsaddons 2.0 ScrollView { id: page - readonly property real proposedMargin: (width-app.actualWidth)/2 - readonly property Component tools: RowLayout { - Button { - text: i18n("Update") - enabled: updateModel.hasUpdates - onClicked: { - var updates = page.Stack.view.push(updatesPage) - updates.start() - } - } - } - property var icon: "system-updates" - property string title: i18n("Updates (%1)", updateModel.updatesCount) - - Component { - id: updatesPage - UpdateProgressPage {} - } + property real proposedMargin: 0 ColumnLayout { @@ -32,12 +15,8 @@ ScrollView width: app.actualWidth Repeater { id: rep - model: UpdateModel { - id: updateModel - backend: ResourcesUpdatesModel { - id: updates - } - } + model: updateModel + delegate: ColumnLayout { id: col property var currentRow: index diff --git a/discover/qml/UpdateProgressPage.qml b/discover/qml/UpdateProgressPage.qml index e037d4e..34b1f7b 100644 --- a/discover/qml/UpdateProgressPage.qml +++ b/discover/qml/UpdateProgressPage.qml @@ -1,46 +1,38 @@ import QtQuick 2.1 import QtQuick.Controls 1.1 -import org.kde.muon 1.0 +import QtQuick.Layouts 1.1 -Item +ColumnLayout { id: page readonly property real proposedMargin: (width-app.actualWidth)/2 readonly property string title: i18n("Updating...") readonly property string icon: "system-software-update" - + function start() { - updatesModel.prepare() - updatesModel.updateAll() - } - ResourcesUpdatesModel { - id: updatesModel - onProgressingChanged: if(!isProgressing) page.Stack.view.pop() + resourcesUpdatesModel.prepare() + resourcesUpdatesModel.updateAll() } + onVisibleChanged: window.navigationEnabled=!visible Binding { target: progressBox property: "enabled" - value: !page.visible + value: !visible } ProgressBar { id: progress - anchors { - right: parent.right - left: parent.left - top: parent.top - rightMargin: proposedMargin - leftMargin: proposedMargin - } - value: updatesModel.progress + width: app.actualWidth + + value: resourcesUpdatesModel.progress minimumValue: 0 maximumValue: 100 - indeterminate: updatesModel.progress==-1 + indeterminate: resourcesUpdatesModel.progress==-1 Label { anchors.centerIn: parent - text: updatesModel.remainingTime + text: resourcesUpdatesModel.remainingTime horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter visible: text!="" @@ -48,21 +40,15 @@ Item } ScrollView { - anchors { - top: progress.bottom - right: parent.right - left: parent.left - bottom: parent.bottom - rightMargin: proposedMargin - leftMargin: proposedMargin - topMargin: 10 - bottomMargin: 10 - } + Layout.fillWidth: true + Layout.fillHeight: true + ListView { id: messageFlickable + width: app.actualWidth property bool userScrolled: false clip: true - model: updatesModel + model: resourcesUpdatesModel delegate: Label { text: display height: paintedHeight diff --git a/discover/qml/UpdatesPage.qml b/discover/qml/UpdatesPage.qml new file mode 100644 index 0000000..d8c7e7f --- /dev/null +++ b/discover/qml/UpdatesPage.qml @@ -0,0 +1,105 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 1.2 +import org.kde.muon 1.0 +import org.kde.kquickcontrolsaddons 2.0 +import org.kde.kcoreaddons 1.0 + +ConditionalLoader +{ + id: page + + readonly property var icon: "system-updates" + readonly property string title: i18n("System Update") + readonly property real proposedMargin: (width-app.actualWidth)/2 + readonly property Component tools: RowLayout { + Button { + Component { + id: updatesPage + UpdateProgressPage {} + } + + text: i18n("Update") + enabled: updateModel.hasUpdates + onClicked: { + var updates = page.Stack.view.push(updatesPage) + updates.start() + } + } + } + + ResourcesUpdatesModel { + id: resourcesUpdatesModel + + onFinished: page.Stack.view.pop() + } + + UpdateModel { + id: updateModel + backend: resourcesUpdatesModel + } + + condition: updateModel.hasUpdates + componentTrue: PresentUpdatesPage { + proposedMargin: page.proposedMargin + } + + componentFalse: Item { + ColumnLayout { + width: app.actualWidth + anchors.centerIn: parent + QIconItem { + anchors.horizontalCenter: parent.horizontalCenter + + id: icon + width: 128 + height: 128 + } + Label { + id: title + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + Label { + id: description + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + } + + readonly property var secSinceUpdate: resourcesUpdatesModel.secsToLastUpdate + + state: ( secSinceUpdate < 0 ? "unknown" + : secSinceUpdate < 1000 * 60 * 60 * 24 ? "uptodate" + : secSinceUpdate < 1000 * 60 * 60 * 24 * 7 ? "medium" + : "low" + ) + + states: [ + State { + name: "uptodate" + PropertyChanges { target: icon; icon: "security-high" } + PropertyChanges { target: title; text: i18nc("@info", "The software on this computer is up to date.") } + PropertyChanges { target: description; text: i18nc("@info", "Last checked %1 ago.", Format.formatDecimalDuration(secSinceUpdate*1000, 0)) } + }, + State { + name: "medium" + PropertyChanges { target: icon; icon: "security-medium" } + PropertyChanges { target: title; text: i18nc("@info", "No updates are available.") } + PropertyChanges { target: description; text: i18nc("@info", "Last checked %1 ago.", Format.formatDecimalDuration(secSinceUpdate*1000, 0)) } + }, + State { + name: "low" + PropertyChanges { target: icon; icon: "security-low" } + PropertyChanges { target: title; text: i18nc("@info", "The last check for updates was over a week ago.") } + PropertyChanges { target: description; text: i18nc("@info", "Last checked %1 ago.", Format.formatDecimalDuration(secSinceUpdate*1000, 0)) } + }, + State { + name: "unknown" + PropertyChanges { target: icon; icon: "security-low" } + PropertyChanges { target: title; text: i18nc("@info", "It is unknown when the last check for updates was.") } + PropertyChanges { target: description; text: i18nc("@info", "Please click <em>Check for Updates</em> to check.") } + } + ] + } +} diff --git a/discover/resources.qrc b/discover/resources.qrc index a2fc606..52549b1 100644 --- a/discover/resources.qrc +++ b/discover/resources.qrc @@ -17,6 +17,7 @@ <file>qml/Breadcrumbs.qml</file> <file>qml/InstallApplicationButton.qml</file> <file>qml/Rating.qml</file> + <file>qml/UpdatesPage.qml</file> <file>qml/UpdateProgressPage.qml</file> <file>qml/ReviewDialog.qml</file> <file>qml/ProgressView.qml</file> diff --git a/libmuon/resources/ResourcesUpdatesModel.cpp b/libmuon/resources/ResourcesUpdatesModel.cpp index 2962b42..b0f8233 100644 --- a/libmuon/resources/ResourcesUpdatesModel.cpp +++ b/libmuon/resources/ResourcesUpdatesModel.cpp @@ -85,7 +85,6 @@ void ResourcesUpdatesModel::slotProgressingChanged(bool progressing) const bool newProgressing = isProgressing(); if (newProgressing != m_lastIsProgressing) { m_lastIsProgressing = newProgressing; - emit progressingChanged(); if (!m_lastIsProgressing) { if (!m_kded) m_kded = new QDBusInterface("org.kde.kded", "/kded", @@ -103,6 +102,11 @@ void ResourcesUpdatesModel::slotProgressingChanged(bool progressing) QDBusConnection::sessionBus().send(message); } } + emit progressingChanged(newProgressing); + + if (!newProgressing) { + Q_EMIT finished(); + } } } @@ -123,6 +127,11 @@ void ResourcesUpdatesModel::message(const QString& msg) appendRow(new QStandardItem(msg)); } +int ResourcesUpdatesModel::count() const +{ + return rowCount(); +} + void ResourcesUpdatesModel::prepare() { foreach(AbstractBackendUpdater* upd, m_updaters) { @@ -135,7 +144,7 @@ void ResourcesUpdatesModel::updateAll() Q_ASSERT(m_resources); if(m_updaters.isEmpty()) - emit progressingChanged(); + emit progressingChanged(false); else { Q_FOREACH (AbstractBackendUpdater* upd, m_updaters) { if (upd->hasUpdates()) @@ -153,7 +162,7 @@ QString ResourcesUpdatesModel::remainingTime() const } // Ignore ETA if it's larger than 2 days. - if(maxEta==0 && maxEta < 2 * 24 * 60 * 60) + if(maxEta==0 || maxEta > 2 * 24 * 60 * 60) return QString(); else return i18nc("@item:intext Remaining time", "%1 remaining", KFormat().formatDuration(maxEta)); @@ -258,3 +267,8 @@ void ResourcesUpdatesModel::cancel() qWarning() << "tried to cancel " << upd->metaObject()->className() << "which is not cancelable"; } } + +qint64 ResourcesUpdatesModel::secsToLastUpdate() const +{ + return lastUpdate().secsTo(QDateTime::currentDateTime()); +} diff --git a/libmuon/resources/ResourcesUpdatesModel.h b/libmuon/resources/ResourcesUpdatesModel.h index b7600ca..1033478 100644 --- a/libmuon/resources/ResourcesUpdatesModel.h +++ b/libmuon/resources/ResourcesUpdatesModel.h @@ -22,6 +22,7 @@ #define RESOURCESUPDATESMODEL_H #include <QStandardItemModel> +#include <QDateTime> #include "libMuonCommon_export.h" class AbstractResourcesBackend; @@ -39,6 +40,9 @@ class MUONCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel Q_PROPERTY(quint64 downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged) Q_PROPERTY(bool isCancelable READ isCancelable NOTIFY cancelableChanged) Q_PROPERTY(bool isProgressing READ isProgressing NOTIFY progressingChanged) + Q_PROPERTY(QDateTime lastUpdate READ lastUpdate NOTIFY progressingChanged) + Q_PROPERTY(qint64 secsToLastUpdate READ secsToLastUpdate NOTIFY progressingChanged) + Q_PROPERTY(int count READ count NOTIFY caca) public: explicit ResourcesUpdatesModel(QObject* parent = nullptr); @@ -57,14 +61,18 @@ class MUONCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel void addResources(const QList<AbstractResource*>& resources); void removeResources(const QList<AbstractResource*>& resources); + qint64 secsToLastUpdate() const; + int count() const; + signals: void downloadSpeedChanged(); void progressChanged(); void etaChanged(); void cancelableChanged(); - void progressingChanged(); + void progressingChanged(bool progressing); void statusMessageChanged(const QString& message); void statusDetailChanged(const QString& msg); + void finished(); public slots: void cancel(); |
