summaryrefslogtreecommitdiff
path: root/rockwork/MainMenuPage.qml
blob: 32c7b96b228c5ee429820d519a663e6166a09a87 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import QtQuick 2.4
import QtQuick.Layouts 1.1
import Ubuntu.Components 1.3

Page {
    id: root
    title: pebble.name

    property var pebble: null

    head {
        actions: [
            Action {
                iconName: "info"
                text: i18n.tr("About")
                onTriggered: {
                    pageStack.push(Qt.resolvedUrl("InfoPage.qml"))
                }
            },
            Action {
                iconName: "ubuntu-sdk-symbolic"
                text: i18n.tr("Developer tools")
                onTriggered: {
                    pageStack.push(Qt.resolvedUrl("DeveloperToolsPage.qml"), {pebble: root.pebble})
                }
            }
        ]
    }

    //Creating the menu list this way to allow the text field to be translatable (http://askubuntu.com/a/476331)
    ListModel {
        id: mainMenuModel
        dynamicRoles: true
    }

    Component.onCompleted: {
        populateMainMenu();
    }

    Connections {
        target: root.pebble
        onFirmwareUpgradeAvailableChanged: {
            populateMainMenu();
        }
    }

    function populateMainMenu() {
        mainMenuModel.clear();

        mainMenuModel.append({
            icon: "stock_notification",
            text: i18n.tr("Manage notifications"),
            page: "NotificationsPage.qml",
            color: "blue"
        });

        mainMenuModel.append({
            icon: "stock_application",
            text: i18n.tr("Manage Apps"),
            page: "InstalledAppsPage.qml",
            showWatchApps: true,
            color: UbuntuColors.green
        });

        mainMenuModel.append({
            icon: "clock-app-symbolic",
            text: i18n.tr("Manage Watchfaces"),
            page: "InstalledAppsPage.qml",
            showWatchFaces: true,
            color: "black"
        });

        mainMenuModel.append({
            icon: "settings",
            text: i18n.tr("Settings"),
            page: "SettingsPage.qml",
            showWatchFaces: true,
            color: "gold"
        });

        if (root.pebble.firmwareUpgradeAvailable) {
            mainMenuModel.append({
                icon: "preferences-system-updates-symbolic",
                text: i18n.tr("Firmware upgrade"),
                page: "FirmwareUpgradePage.qml",
                color: "red"
            });
        }

    }

    PebbleModels {
        id: modelModel
    }

    GridLayout {
        anchors.fill: parent
        columns: parent.width > parent.height ? 2 : 1

        Item {
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.maximumHeight: units.gu(30)

            RowLayout {
                anchors.fill: parent
                anchors.margins: units.gu(1)
                spacing: units.gu(1)

                Item {
                    Layout.alignment: Qt.AlignHCenter
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    Layout.minimumWidth: watchImage.width
                    Image {
                        id: watchImage
                        width: implicitWidth * height / implicitHeight
                        height: parent.height
                        anchors.horizontalCenter: parent.horizontalCenter

                        source:  modelModel.get(root.pebble.model).image
                        fillMode: Image.PreserveAspectFit

                        Item {
                            id: watchFace
                            height: parent.height * (modelModel.get(root.pebble.model - 1).shape === "rectangle" ? .5 : .515)
                            width: height * (modelModel.get(root.pebble.model - 1).shape === "rectangle" ? .85 : 1)
                            anchors.centerIn: parent
                            anchors.horizontalCenterOffset: units.dp(1)
                            anchors.verticalCenterOffset: units.dp(modelModel.get(root.pebble.model - 1).shape === "rectangle" ? 0 : 1)

                            Image {
                                id: image
                                anchors.fill: parent
                                source: "file://" + root.pebble.screenshots.latestScreenshot
                                visible: false
                            }

                            Component.onCompleted: {
                                if (!root.pebble.screenshots.latestScreenshot) {
                                    root.pebble.requestScreenshot();
                                }
                            }

                            Rectangle {
                                id: textItem
                                anchors.fill: parent
                                layer.enabled: true
                                radius: modelModel.get(root.pebble.model - 1).shape === "rectangle" ? units.gu(.5) : height / 2
                                // This item should be used as the 'mask'
                                layer.samplerName: "maskSource"
                                layer.effect: ShaderEffect {
                                    property var colorSource: image;
                                    fragmentShader: "
                                        uniform lowp sampler2D colorSource;
                                        uniform lowp sampler2D maskSource;
                                        uniform lowp float qt_Opacity;
                                        varying highp vec2 qt_TexCoord0;
                                        void main() {
                                            gl_FragColor =
                                                texture2D(colorSource, qt_TexCoord0)
                                                * texture2D(maskSource, qt_TexCoord0).a
                                                * qt_Opacity;
                                        }
                                    "
                                }
                            }
                        }
                    }
                }
                ColumnLayout {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    spacing: units.gu(2)
                    Rectangle {
                        height: units.gu(10)
                        width: height
                        radius: height / 2
                        color: root.pebble.connected ? UbuntuColors.green : UbuntuColors.red

                        Icon {
                            anchors.fill: parent
                            anchors.margins: units.gu(2)
                            color: "white"
                            name: root.pebble.connected ? "tick" : "dialog-error-symbolic"
                        }
                    }

                    Label {
                        text: root.pebble.connected ? i18n.tr("Connected") : i18n.tr("Disconnected")
                        Layout.fillWidth: true
                    }
                }
            }
        }


        Column {
            Layout.fillWidth: true
            Layout.preferredHeight: childrenRect.height
            spacing: menuRepeater.count > 0 ? 0 : units.gu(2)
            Label {
                text: i18n.tr("Your Pebble smartwatch is disconnected. Please make sure it is powered on, within range and it is paired properly in the Bluetooth System Settings.")
                width: parent.width - units.gu(4)
                anchors.horizontalCenter: parent.horizontalCenter
                wrapMode: Text.WordWrap
                visible: !root.pebble.connected
                fontSize: "large"
                horizontalAlignment: Text.AlignHCenter
            }

            Button {
                text: i18n.tr("Open System Settings")
                visible: !root.pebble.connected
                onClicked: Qt.openUrlExternally("settings://system/bluetooth")
                color: UbuntuColors.orange
                anchors.horizontalCenter: parent.horizontalCenter
            }

            Label {
                text: i18n.tr("Your Pebble smartwatch is in factory mode and needs to be initialized.")
                width: parent.width - units.gu(4)
                anchors.horizontalCenter: parent.horizontalCenter
                wrapMode: Text.WordWrap
                visible: root.pebble.connected && root.pebble.recovery && !root.pebble.upgradingFirmware
                fontSize: "large"
                horizontalAlignment: Text.AlignHCenter
            }
            Button {
                text: i18n.tr("Initialize Pebble")
                onClicked: root.pebble.performFirmwareUpgrade();
                visible: root.pebble.connected && root.pebble.recovery && !root.pebble.upgradingFirmware
                color: UbuntuColors.orange
                anchors.horizontalCenter: parent.horizontalCenter
            }

            Rectangle {
                id: upgradeIcon
                height: units.gu(10)
                width: height
                radius: width / 2
                color: UbuntuColors.orange
                anchors.horizontalCenter: parent.horizontalCenter
                Icon {
                    anchors.fill: parent
                    anchors.margins: units.gu(1)
                    name: "preferences-system-updates-symbolic"
                    color: "white"
                }

                RotationAnimation on rotation {
                    duration: 2000
                    loops: Animation.Infinite
                    from: 0
                    to: 360
                    running: upgradeIcon.visible
                }
                visible: root.pebble.connected && root.pebble.upgradingFirmware
            }

            Label {
                text: i18n.tr("Upgrading...")
                fontSize: "large"
                anchors.horizontalCenter: parent.horizontalCenter
                visible: root.pebble.connected && root.pebble.upgradingFirmware
            }

            Repeater {
                id: menuRepeater
                model: root.pebble.connected && !root.pebble.recovery && !root.pebble.upgradingFirmware ? mainMenuModel : null
                delegate: ListItem {

                    RowLayout {
                        anchors.fill: parent
                        anchors.margins: units.gu(1)

                        UbuntuShape {
                            Layout.fillHeight: true
                            Layout.preferredWidth: height
                            backgroundColor: model.color
                            Icon {
                                anchors.fill: parent
                                anchors.margins: units.gu(.5)
                                name: model.icon
                                color: "white"
                            }
                        }


                        Label {
                            text: model.text
                            Layout.fillWidth: true
                        }
                    }

                    onClicked: {
                        var options = {};
                        options["pebble"] = root.pebble
                        var modelItem = mainMenuModel.get(index)
                        options["showWatchApps"] = modelItem.showWatchApps
                        options["showWatchFaces"] = modelItem.showWatchFaces
                        pageStack.push(Qt.resolvedUrl(model.page), options)
                    }
                }
            }
        }
    }

    Connections {
        target: pebble
        onOpenURL: {
            if (url) {
                pageStack.push(Qt.resolvedUrl("AppSettingsPage.qml"), {uuid: uuid, url: url, pebble: pebble})
            }
        }
    }
}