1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
* Copyright (C) 2014-2016 Canonical Ltd
*
* This file is part of Ubuntu Clock App
*
* Ubuntu Clock App is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Ubuntu Clock App 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, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import WorldClock 1.0
import U1db 1.0 as U1db
import Alarm 1.0
import Ubuntu.Components 1.3
import "components"
import QtQuick.Window 2.2
Window {
id: rootWindow
// Property to store the state of an application (active or suspended)
property bool applicationState: Qt.application.active
/*
The width and height defined below are the same dimension used by the
designers in the clock visual spec.
*/
minimumWidth: units.gu(40)
minimumHeight: units.gu(70)
maximumWidth: units.gu(50)
onApplicationStateChanged: {
localTimeSource.update()
/*
Reload the alarm model when the clock app gains focus to refresh
the alarm page UI in the case of alarm notifications.
*/
if(applicationState && !mainPage.isColdStart && (mainStack.currentPage.isMainPage
|| mainStack.currentPage.isAlarmPage)) {
console.log("[LOG]: Alarm Database unloaded")
alarmModelLoader.source = ""
alarmModelLoader.source = Qt.resolvedUrl("alarm/AlarmModelComponent.qml")
}
}
MainView {
id: clockApp
// objectName for functional testing purposes (autopilot-qt5)
objectName: "clockMainView"
// applicationName for click packages (used as an unique app identifier)
applicationName: "com.ubuntu.clock"
backgroundColor: "#FFFFFF"
anchors.fill: parent
anchorToKeyboard: true
// Database to store the user preferences locally
U1db.Database {
id: clockDB
path: "user-preferences"
}
// Document to store clock mode chosen by user
U1db.Document {
id: clockModeDocument
create: true
database: clockDB
docId: "clockModeDocument"
defaults: { "digitalMode": false }
}
U1db.Document {
id: userLocationDocument
create: true
database: clockDB
docId: "userLocationDocument"
defaults: { "lat": "NaN", "long": "Nan", "location": "Null" }
}
DateTime {
id: localTimeSource
updateInterval: 1000
}
AlarmSound {
id: alarmSoundHelper
// Create CustomSounds directory if it does not exist on app startup
Component.onCompleted: createCustomAlarmSoundDirectory()
}
PageStack {
id: mainStack
Component.onCompleted: push(mainPage)
MainPage {
id: mainPage
readonly property bool isMainPage: true
Loader {
id: alarmModelLoader
asynchronous: false
}
alarmModel: alarmModelLoader.item
/*
FIXME: When the upstream QT bug at
https://bugreports.qt-project.org/browse/QTBUG-40275 is fixed
it will be possible to receive a datetime object directly for notLocalizedDateTimeString variable.
*/
notLocalizedDateTimeString: localTimeSource.notLocalizedCurrentDateTimeString
localizedTimeString: localTimeSource.localizedCurrentTimeString
localizedDateString: localTimeSource.localizedCurrentDateString
}
}
}
}
|