Warning, /system/apper/plasmoid/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2012 Luís Gabriel Lima <lampih@gmail.com>
0003 * Copyright 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
0004 *
0005 * This program is free software; you can redistribute it and/or
0006 * modify it under the terms of the GNU General Public License as
0007 * published by the Free Software Foundation; either version 2 of
0008 * the License, or (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0017 */
0018
0019 import QtQuick 1.1
0020 import org.kde.plasma.core 0.1 as PlasmaCore
0021 import org.kde.plasma.components 0.1 as PlasmaComponents
0022 import org.kde.apper 0.1 as Apper
0023
0024 FocusScope {
0025 id: root
0026
0027 state: ""
0028
0029 property int minimumHeight: 320
0030 property int minimumWidth: 370
0031 property int maximumHeight: 0
0032 property int maximumWidth: 0
0033 property int preferredHeight: 0
0034 property int preferredWidth: 0
0035 property int implicitHeight: 0
0036 property int implicitWidth: 0
0037
0038 property bool checkedForUpdates: false
0039 property string tooltipText: i18n("Software Updates")
0040 property string tooltipIcon: "kpackagekit-updates"
0041
0042 property Component compactRepresentation: CompactRepresentation {
0043 text: tooltipText
0044 icon: tooltipIcon
0045 }
0046
0047 anchors.fill: parent
0048 clip: true
0049
0050 PlasmaCore.Theme {
0051 id: theme
0052 }
0053
0054 Component.onCompleted: {
0055 getUpdatesTransaction.package.connect(updatesModel.addSelectedPackage);
0056 getUpdatesTransaction.errorCode.connect(errorCode);
0057 getUpdatesTransaction.finished.connect(getUpdatesFinished);
0058
0059 Daemon.updatesChanged.connect(updatesChanged);
0060
0061 // This allows the plasmoid to shrink when the layout changes
0062 plasmoid.status = "PassiveStatus"
0063 plasmoid.aspectRatioMode = IgnoreAspectRatio
0064 plasmoid.popupEvent.connect(popupEventSlot)
0065 plasmoid.setAction('checkForNewUpdates', i18n("Check for new updates"), 'view-refresh')
0066 dbusInterface.registerService()
0067 dbusInterface.reviewUpdates.connect(reviewUpdates)
0068 dbusInterface.reviewUpdates.connect(plasmoid.showPopup)
0069 }
0070
0071 function popupEventSlot(popped) {
0072 if (popped) {
0073 root.forceActiveFocus()
0074 getUpdates()
0075 }
0076 }
0077
0078 function action_checkForNewUpdates() {
0079 transactionView.refreshCache();
0080 var error = transactionView.transaction.internalError;
0081 if (error) {
0082 statusView.title = PkStrings.daemonError(error);
0083 statusView.subTitle = transactionView.transaction.internalErrorMessage;
0084 statusView.iconName = "dialog-error";
0085 root.state = "MESSAGE";
0086 } else {
0087 root.state = "TRANSACTION";
0088 }
0089 }
0090
0091 function reviewUpdates() {
0092 if (root.state !== "TRANSACTION") {
0093 // If we are not checking for updates show
0094 // the package selection
0095 if (checkedForUpdates && root.state !== "BUSY") {
0096 root.state = "SELECTION";
0097 } else {
0098 getUpdates();
0099 }
0100 }
0101 }
0102
0103 function installUpdates() {
0104 transactionView.update(updatesModel.selectedPackagesToInstall());
0105 root.state = "TRANSACTION";
0106 }
0107
0108 function getUpdates() {
0109 if (!checkedForUpdates) {
0110 state = "BUSY"
0111 getUpdatesTransaction.cancel()
0112 updatesModel.clear()
0113 getUpdatesTransaction.getUpdates()
0114 checkedForUpdates = true
0115 }
0116 }
0117
0118 function errorCode() {
0119 statusView.title = i18n("Failed to get updates");
0120 statusView.subTitle = PkStrings.daemonError(error);
0121 statusView.iconName = "dialog-error";
0122 state = "MESSAGE";
0123 plasmoid.status = "PassiveStatus"
0124 }
0125
0126 function getUpdatesFinished() {
0127 updatesModel.finished();
0128 updatesModel.clearSelectedNotPresent();
0129 updatesView.sortModel.sortNow();
0130 updateIcon();
0131 decideState(false);
0132 }
0133
0134 function decideState(force) {
0135 if (force || state !== "TRANSACTION") {
0136 if (updatesModel.rowCount() === 0) {
0137 var lastTime = DaemonHelper.getTimeSinceLastRefresh();
0138 statusView.title = PkStrings.lastCacheRefreshTitle(lastTime);
0139 statusView.subTitle = PkStrings.lastCacheRefreshSubTitle(lastTime);
0140 statusView.iconName = PkIcons.lastCacheRefreshIconName(lastTime);
0141 state = "MESSAGE";
0142 plasmoid.status = "PassiveStatus"
0143 } else {
0144 plasmoid.status = "ActiveStatus"
0145 root.state = "SELECTION";
0146 }
0147 }
0148 }
0149
0150 function updatesChanged() {
0151 checkedForUpdates = false;
0152 getUpdates();
0153 }
0154
0155 function updateIcon() {
0156 if (updatesModel.rowCount()) {
0157 if (updatesModel.countInfo(Apper.Transaction.InfoSecurity)) {
0158 tooltipIcon = "kpackagekit-security"
0159 } else if (updatesModel.countInfo(Apper.Transaction.InfoImportant)) {
0160 tooltipIcon = "kpackagekit-important"
0161 } else {
0162 tooltipIcon = "kpackagekit-updates"
0163 }
0164 tooltipText = i18np("You have one update",
0165 "You have %1 updates",
0166 updatesModel.rowCount())
0167 } else {
0168 tooltipIcon = "kpackagekit-updates"
0169 tooltipText = i18n("Your system is up to date")
0170 }
0171 }
0172
0173 Apper.PackageModel {
0174 id: updatesModel
0175 checkable: true
0176 }
0177
0178 Apper.DBusUpdaterInterface {
0179 id: dbusInterface
0180 }
0181
0182 Timer {
0183 // Grab updates in five minutes
0184 interval: 360000
0185 running: true
0186 repeat: false
0187 onTriggered: getUpdates()
0188 }
0189
0190 Apper.PkTransaction {
0191 id: getUpdatesTransaction
0192 }
0193
0194 StatusView {
0195 id: busyView
0196 opacity: 0
0197 anchors.fill: parent
0198 anchors.margins: 4
0199 state: "BUSY"
0200 title: PkStrings.action(getUpdatesTransaction.role, getUpdatesTransaction.transactionFlags)
0201 subTitle: PkStrings.status(getUpdatesTransaction.status)
0202 }
0203
0204 Column {
0205 id: statusColumn
0206 opacity: 0
0207 spacing: 4
0208 anchors.fill: parent
0209 anchors.margins: 4
0210 StatusView {
0211 id: statusView
0212 height: parent.height - refreshBT.height - parent.anchors.margins - parent.spacing
0213 width: parent.width
0214 }
0215 PlasmaComponents.Button {
0216 id: refreshBT
0217 anchors.right: parent.right
0218 text: i18n("Check for new updates")
0219 iconSource: "system-software-update"
0220 onClicked: action_checkForNewUpdates()
0221 }
0222 }
0223
0224 Updates {
0225 id: updatesView
0226 opacity: 0
0227 anchors.fill: parent
0228 anchors.margins: 4
0229 onUpdateClicked: installUpdates()
0230 }
0231
0232 Transaction {
0233 id: transactionView
0234 opacity: 0
0235 anchors.fill: parent
0236 anchors.margins: 4
0237 onFinished: {
0238 if (success) {
0239 if (root.state !== "BUSY") {
0240 checkedForUpdates = false;
0241 getUpdates();
0242 }
0243 } else {
0244 decideState(true);
0245 }
0246 }
0247 }
0248
0249 states: [
0250 State {
0251 name: "SELECTION"
0252 PropertyChanges { target: updatesView; opacity: 1 }
0253 PropertyChanges { target: updatesView; focus: true }
0254 },
0255 State {
0256 name: "TRANSACTION"
0257 PropertyChanges { target: transactionView; opacity: 1 }
0258 PropertyChanges { target: transactionView; focus: true }
0259 },
0260 State {
0261 name: "BUSY"
0262 PropertyChanges { target: busyView; opacity: 1 }
0263 },
0264 State {
0265 name: "MESSAGE"
0266 PropertyChanges { target: statusColumn; opacity: 1 }
0267 PropertyChanges { target: refreshBT; focus: true }
0268 }
0269 ]
0270
0271 transitions: Transition {
0272 NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
0273 }
0274 }