Warning, /system/plasma-pk-updates/src/plasma/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /*************************************************************************** 0002 * Copyright (C) 2014 by Aleix Pol Gonzalez <aleixpol@blue-systems.com> * 0003 * Copyright (C) 2015 by Lukáš Tinkl <lukas@kde.org> * 0004 * Copyright (C) 2015 by Jan Grulich <jgrulich@redhat.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0020 ***************************************************************************/ 0021 0022 import QtQuick 2.2 0023 import org.kde.plasma.plasmoid 2.0 0024 import org.kde.plasma.core 2.0 as PlasmaCore 0025 import org.kde.plasma.PackageKit 1.0 0026 0027 Item 0028 { 0029 Plasmoid.fullRepresentation: Full {} 0030 Plasmoid.toolTipSubText: PkUpdates.message 0031 Plasmoid.icon: PkUpdates.iconName 0032 0033 Plasmoid.switchWidth: units.gridUnit * 10; 0034 Plasmoid.switchHeight: units.gridUnit * 10; 0035 0036 property bool checkDaily: plasmoid.configuration.daily 0037 property bool checkWeekly: plasmoid.configuration.weekly 0038 property bool checkMonthly: plasmoid.configuration.monthly 0039 0040 property bool checkOnMobile: plasmoid.configuration.check_on_mobile 0041 property bool checkOnBattery: plasmoid.configuration.check_on_battery 0042 0043 property double lastCheckAttempt: PkUpdates.lastRefreshTimestamp() 0044 readonly property int secsAutoCheckLimit: 10 * 60 0045 0046 readonly property int secsInDay: 60 * 60 * 24; 0047 readonly property int secsInWeek: secsInDay * 7; 0048 readonly property int secsInMonth: secsInDay * 30; 0049 0050 readonly property bool networkAllowed: PkUpdates.isNetworkMobile ? checkOnMobile : PkUpdates.isNetworkOnline 0051 readonly property bool batteryAllowed: PkUpdates.isOnBattery ? checkOnBattery : true 0052 0053 Timer { 0054 id: timer 0055 repeat: true 0056 triggeredOnStart: true 0057 interval: 1000 * 60 * 60; // 1 hour 0058 onTriggered: { 0059 if (needsForcedUpdate() && networkAllowed && batteryAllowed) { 0060 lastCheckAttempt = Date.now(); 0061 PkUpdates.checkUpdates(false /* manual */); 0062 } 0063 } 0064 } 0065 0066 Binding { 0067 target: plasmoid 0068 property: "status" 0069 value: PkUpdates.isActive || !PkUpdates.isSystemUpToDate ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus; 0070 } 0071 0072 Plasmoid.compactRepresentation: PlasmaCore.IconItem { 0073 source: PkUpdates.iconName 0074 anchors.fill: parent 0075 MouseArea { 0076 anchors.fill: parent 0077 onClicked: plasmoid.expanded = !plasmoid.expanded 0078 } 0079 } 0080 0081 function needsForcedUpdate() { 0082 if ((Date.now() - lastCheckAttempt)/1000 < secsAutoCheckLimit) { 0083 return false; 0084 } 0085 0086 var secs = (Date.now() - PkUpdates.lastRefreshTimestamp())/1000; // compare with the saved timestamp 0087 if (secs < 0) { // never checked before 0088 return true; 0089 } else if (checkDaily) { 0090 return secs >= secsInDay; 0091 } else if (checkWeekly) { 0092 return secs >= secsInWeek; 0093 } else if (checkMonthly) { 0094 return secs >= secsInMonth; 0095 } 0096 return false; 0097 } 0098 0099 Connections { 0100 target: PkUpdates 0101 onNetworkStateChanged: timer.restart() 0102 onIsOnBatteryChanged: timer.restart() 0103 } 0104 0105 Component.onCompleted: { 0106 timer.start() 0107 } 0108 }