diff --git a/src/plasma/contents/ui/main.qml b/src/plasma/contents/ui/main.qml index 387ae63..d667a5c 100644 --- a/src/plasma/contents/ui/main.qml +++ b/src/plasma/contents/ui/main.qml @@ -1,98 +1,103 @@ /*************************************************************************** * Copyright (C) 2014 by Aleix Pol Gonzalez * * Copyright (C) 2015 by Lukáš Tinkl * * Copyright (C) 2015 by Jan Grulich * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.2 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.PackageKit 1.0 Item { Plasmoid.fullRepresentation: Full {} Plasmoid.toolTipSubText: PkUpdates.message Plasmoid.icon: PkUpdates.iconName Plasmoid.switchWidth: units.gridUnit * 10; Plasmoid.switchHeight: units.gridUnit * 10; property bool checkDaily: plasmoid.configuration.daily property bool checkWeekly: plasmoid.configuration.weekly property bool checkMonthly: plasmoid.configuration.monthly property bool checkOnMobile: plasmoid.configuration.check_on_mobile property bool checkOnBattery: plasmoid.configuration.check_on_battery readonly property int secsInDay: 60 * 60 * 24; readonly property int secsInWeek: secsInDay * 7; readonly property int secsInMonth: secsInDay * 30; readonly property bool networkAllowed: PkUpdates.isNetworkMobile ? checkOnMobile : PkUpdates.isNetworkOnline readonly property bool batteryAllowed: PkUpdates.isOnBattery ? checkOnBattery : true Timer { id: timer repeat: true triggeredOnStart: true interval: 1000 * 60 * 60; // 1 hour onTriggered: { if (needsForcedUpdate() && networkAllowed && batteryAllowed) { PkUpdates.checkUpdates(); } } } Binding { target: plasmoid property: "status" value: PkUpdates.isActive || !PkUpdates.isSystemUpToDate ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus; } Plasmoid.compactRepresentation: PlasmaCore.IconItem { source: PkUpdates.iconName anchors.fill: parent MouseArea { anchors.fill: parent onClicked: plasmoid.expanded = !plasmoid.expanded } } function needsForcedUpdate() { var secs = (Date.now() - PkUpdates.lastRefreshTimestamp())/1000; // compare with the saved timestamp if (secs < 0) { // never checked before return true; } else if (checkDaily) { return secs >= secsInDay; } else if (checkWeekly) { return secs >= secsInWeek; } else if (checkMonthly) { return secs >= secsInMonth; } return false; } Connections { target: PkUpdates onNetworkStateChanged: timer.restart() onIsOnBatteryChanged: timer.restart() } - Component.onCompleted: timer.start() + Component.onCompleted: { + if(!needsForcedUpdate() && batteryAllowed) { + PkUpdates.checkUpdates(false); + } + timer.start() + } }