Unity 8
InactivityTimer.qml
1 /*
2  * Copyright (C) 2015 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 
20 Item {
21  readonly property alias running: internalTimer.running
22  property alias interval: internalTimer.interval
23  property var page
24  property int lastInputTimestamp
25 
26  function start() {
27  internalTimer.start();
28  }
29 
30  ////
31 
32  onLastInputTimestampChanged: {
33  if (internalTimer.running) {
34  internalTimer.restart();
35  }
36  }
37 
38  Connections {
39  target: page
40  onIsReadyChanged: {
41  if (page.isReady && internalTimer.running) {
42  internalTimer.restart();
43  }
44  }
45  }
46 
47  Timer {
48  id: internalTimer
49 
50  interval: 3000
51 
52  onTriggered: {
53  if (page.isReady) {
54  if (!page.shown) {
55  page.show();
56  }
57  } else if (!page.skipped) {
58  restart();
59  }
60  }
61  }
62 }