~ubuntu-branches/debian/jessie/apper/jessie

« back to all changes in this revision

Viewing changes to plasmoid/package/contents/ui/main.qml

  • Committer: Package Import Robot
  • Author(s): Matthias Klumpp
  • Date: 2013-07-30 12:34:46 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130730123446-cgzujaj03pc61drn
Tags: 0.8.1-1
* New upstream release: 0.8.1
* Depend on software-properties-kde instead of suggesting it (Closes: #696583)
* Add patch to make AppStream loading more failsafe

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright 2012  Luís Gabriel Lima <lampih@gmail.com>
 
3
 * Copyright 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
3
4
 *
4
5
 * This program is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU General Public License as
18
19
import QtQuick 1.1
19
20
import org.kde.plasma.core 0.1 as PlasmaCore
20
21
import org.kde.plasma.components 0.1 as PlasmaComponents
21
 
import org.packagekit 0.1 as PackageKit
 
22
import org.kde.apper 0.1 as Apper
22
23
 
23
24
FocusScope {
24
25
    id: root
25
26
 
26
 
    state: "BUSY"
 
27
    state: ""
27
28
 
28
29
    property int minimumHeight: 320
29
30
    property int minimumWidth: 370
35
36
    property int implicitWidth: 0
36
37
 
37
38
    property bool checkedForUpdates: false
 
39
    property string tooltipText: i18n("Software Updates")
 
40
    property string tooltipIcon: "kpackagekit-updates"
 
41
 
 
42
    property Component compactRepresentation: CompactRepresentation {
 
43
        text: tooltipText
 
44
        icon: tooltipIcon
 
45
    }
38
46
 
39
47
    anchors.fill: parent
40
48
    clip: true
45
53
 
46
54
    Component.onCompleted: {
47
55
        getUpdatesTransaction.package.connect(updatesModel.addSelectedPackage);
 
56
        getUpdatesTransaction.errorCode.connect(errorCode);
48
57
        getUpdatesTransaction.finished.connect(getUpdatesFinished);
49
58
 
50
59
        Daemon.updatesChanged.connect(updatesChanged);
51
 
        UpdaterPlasmoid.getUpdates.connect(getUpdates);
52
 
        UpdaterPlasmoid.checkForNewUpdates.connect(checkForNewUpdates);
53
 
        UpdaterPlasmoid.reviewUpdates.connect(reviewUpdates);
54
 
    }
55
 
 
56
 
    function checkForNewUpdates() {
 
60
 
 
61
        // This allows the plasmoid to shrink when the layout changes
 
62
        plasmoid.status = "PassiveStatus"
 
63
        plasmoid.aspectRatioMode = IgnoreAspectRatio
 
64
        plasmoid.popupEvent.connect(popupEventSlot)
 
65
        plasmoid.setAction('checkForNewUpdates', i18n("Check for new updates"), 'view-refresh')
 
66
        dbusInterface.registerService()
 
67
        dbusInterface.reviewUpdates.connect(reviewUpdates)
 
68
        dbusInterface.reviewUpdates.connect(plasmoid.showPopup)
 
69
    }
 
70
 
 
71
    function popupEventSlot(popped) {
 
72
        if (popped) {
 
73
            root.forceActiveFocus()
 
74
            getUpdates()
 
75
        }
 
76
    }
 
77
 
 
78
    function action_checkForNewUpdates() {
57
79
        transactionView.refreshCache();
58
 
        root.state = "TRANSACTION";
 
80
        var error = transactionView.transaction.internalError;
 
81
        if (error) {
 
82
            statusView.title = PkStrings.daemonError(error);
 
83
            statusView.subTitle = transactionView.transaction.internalErrorMessage;
 
84
            statusView.iconName = "dialog-error";
 
85
            root.state = "MESSAGE";
 
86
        } else {
 
87
            root.state = "TRANSACTION";
 
88
        }
59
89
    }
60
90
 
61
91
    function reviewUpdates() {
82
112
            getUpdatesTransaction.reset();
83
113
            updatesModel.clear();
84
114
            getUpdatesTransaction.getUpdates();
85
 
            checkedForUpdates = true;
 
115
            var error = getUpdatesTransaction.internalError;
 
116
            if (error) {
 
117
                statusView.title = PkStrings.daemonError(error);
 
118
                statusView.subTitle = getUpdatesTransaction.internalErrorMessage;
 
119
                statusView.iconName = "dialog-error";
 
120
                state = "MESSAGE";
 
121
            } else {
 
122
                checkedForUpdates = true;
 
123
            }
86
124
        }
87
125
    }
88
126
 
 
127
    function errorCode() {
 
128
        statusView.title = i18n("Failed to get updates");
 
129
        statusView.subTitle = PkStrings.daemonError(error);
 
130
        statusView.iconName = "dialog-error";
 
131
        state = "MESSAGE";
 
132
        plasmoid.status = "PassiveStatus"
 
133
    }
 
134
 
89
135
    function getUpdatesFinished() {
90
136
        updatesModel.finished();
91
137
        updatesView.sortModel.sortNow();
92
138
        updatesModel.clearSelectedNotPresent();
93
 
        UpdaterPlasmoid.updateIcon();
 
139
        updateIcon();
94
140
        decideState(false);
95
141
    }
96
142
 
97
143
    function decideState(force) {
98
144
        if (force || state !== "TRANSACTION") {
99
145
            if (updatesModel.rowCount() === 0) {
100
 
                var lastTime = UpdaterPlasmoid.getTimeSinceLastRefresh();
 
146
                var lastTime = DaemonHelper.getTimeSinceLastRefresh();
101
147
                statusView.title = PkStrings.lastCacheRefreshTitle(lastTime);
102
148
                statusView.subTitle = PkStrings.lastCacheRefreshSubTitle(lastTime);
103
149
                statusView.iconName = PkIcons.lastCacheRefreshIconName(lastTime);
104
 
                state = "UPTODATE";
105
 
                UpdaterPlasmoid.setActive(false);
 
150
                state = "MESSAGE";
 
151
                plasmoid.status = "PassiveStatus"
106
152
            } else {
107
 
                UpdaterPlasmoid.setActive(true);
 
153
                plasmoid.status = "ActiveStatus"
108
154
                root.state = "SELECTION";
109
155
            }
110
156
        }
115
161
        getUpdates();
116
162
    }
117
163
 
118
 
    PackageKit.Transaction {
 
164
    function updateIcon() {
 
165
        if (updatesModel.rowCount()) {
 
166
            if (updatesModel.countInfo(Apper.Transaction.InfoSecurity)) {
 
167
                tooltipIcon = "kpackagekit-security"
 
168
            } else if (updatesModel.countInfo(Apper.Transaction.InfoImportant)) {
 
169
                tooltipIcon = "kpackagekit-important"
 
170
            } else {
 
171
                tooltipIcon = "kpackagekit-updates"
 
172
            }
 
173
            tooltipText = i18np("You have one update",
 
174
                                "You have %1 updates",
 
175
                                updatesModel.rowCount())
 
176
        } else {
 
177
            tooltipIcon = "kpackagekit-updates"
 
178
            tooltipText = i18n("Your system is up to date")
 
179
        }
 
180
    }
 
181
 
 
182
    Apper.PackageModel {
 
183
        id: updatesModel
 
184
        checkable: true
 
185
    }
 
186
 
 
187
    Apper.DBusUpdaterInterface {
 
188
        id: dbusInterface
 
189
    }
 
190
 
 
191
    Timer {
 
192
        // Grab updates in five minutes
 
193
        interval: 360000
 
194
        running: true
 
195
        repeat: false
 
196
        onTriggered: getUpdates()
 
197
    }
 
198
 
 
199
    Apper.Transaction {
119
200
        id: getUpdatesTransaction
120
201
        onChanged: {
121
 
            busyView.title = PkStrings.action(role);
 
202
            busyView.title = PkStrings.action(role, transactionFlags);
122
203
            busyView.subTitle = PkStrings.status(status);
123
204
        }
124
205
    }
127
208
        id: busyView
128
209
        opacity: 0
129
210
        anchors.fill: parent
 
211
        anchors.margins: 4
130
212
        state: "BUSY"
131
213
    }
132
214
 
138
220
        anchors.margins: 4
139
221
        StatusView {
140
222
            id: statusView
141
 
            height: parent.height - refreshBT.height - parent.anchors.margins
 
223
            height: parent.height - refreshBT.height - parent.anchors.margins - parent.spacing
142
224
            width: parent.width
143
225
        }
144
226
        PlasmaComponents.Button {
146
228
            anchors.right: parent.right
147
229
            text:  i18n("Check for new updates")
148
230
            iconSource: "system-software-update"
149
 
            onClicked: checkForNewUpdates()
 
231
            onClicked: action_checkForNewUpdates()
150
232
        }
151
233
    }
152
234
 
154
236
        id: updatesView
155
237
        opacity: 0
156
238
        anchors.fill: parent
 
239
        anchors.margins: 4
157
240
        onUpdateClicked: installUpdates()
158
241
    }
159
242
 
161
244
        id: transactionView
162
245
        opacity: 0
163
246
        anchors.fill: parent
 
247
        anchors.margins: 4
164
248
        onFinished: {
165
249
            if (success) {
166
250
                if (root.state !== "BUSY") {
189
273
            PropertyChanges { target: busyView; opacity: 1 }
190
274
        },
191
275
        State {
192
 
            name: "UPTODATE"
 
276
            name: "MESSAGE"
193
277
            PropertyChanges { target: statusColumn; opacity: 1 }
194
278
            PropertyChanges { target: refreshBT; focus: true }
195
279
        }