2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Nick Dedekind <nick.dedekind@canonical.com>
21import Ubuntu.Settings.Menus 0.1 as Menus
22import Ubuntu.Settings.Components 0.1 as SettingsComponents
24import Utils 0.1 as Utils
25import Ubuntu.Components.ListItems 0.1 as ListItems
26import Ubuntu.Components 0.1
31 property var rootModel: null
32 property var menuModel: null
35 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
36 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
38 "com.canonical.indicator.button" : buttonMenu,
39 "com.canonical.indicator.div" : separatorMenu,
40 "com.canonical.indicator.section" : sectionMenu,
41 "com.canonical.indicator.progress" : progressMenu,
42 "com.canonical.indicator.slider" : sliderMenu,
43 "com.canonical.indicator.switch" : switchMenu,
44 "com.canonical.indicator.alarm" : alarmMenu,
45 "com.canonical.indicator.appointment" : appointmentMenu,
46 "com.canonical.indicator.transfer" : transferMenu,
47 "com.canonical.indicator.button-section" : buttonSectionMenu,
49 "com.canonical.indicator.messages.messageitem" : messageItem,
50 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
52 "com.canonical.unity.slider" : sliderMenu,
53 "com.canonical.unity.switch" : switchMenu,
55 "com.canonical.unity.media-player" : mediaPayerMenu,
56 "com.canonical.unity.playback-item" : playbackItemMenu,
58 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
59 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
62 function getExtendedProperty(object, propertyName, defaultValue) {
63 if (object && object.hasOwnProperty(propertyName)) {
64 return object[propertyName];
73 objectName: "separatorMenu"
81 objectName: "sliderMenu"
82 property QtObject menuData: null
83 property var menuModel: menuFactory.menuModel
84 property int menuIndex: -1
85 property var extendedData: menuData && menuData.ext || undefined
86 property var serverValue: getExtendedProperty(menuData, "actionState", undefined)
88 text: menuData && menuData.label || ""
89 iconSource: menuData && menuData.icon || ""
90 minIcon: getExtendedProperty(extendedData, "minIcon", "")
91 maxIcon: getExtendedProperty(extendedData, "maxIcon", "")
93 minimumValue: getExtendedProperty(extendedData, "minValue", 0.0)
95 var maximum = getExtendedProperty(extendedData, "maxValue", 1.0);
96 if (maximum <= minimumValue) {
97 return minimumValue + 1;
101 enabled: menuData && menuData.sensitive || false
103 onMenuModelChanged: {
106 onMenuIndexChanged: {
109 onServerValueChanged: {
110 // value can be changed by slider, so a binding won't work.
111 if (serverValue !== undefined) {
116 menuModel.changeState(menuIndex, value);
119 function loadAttributes() {
120 if (!menuModel || menuIndex == -1) return;
121 menuModel.loadExtendedAttributes(menuIndex, {'min-value': 'double',
122 'max-value': 'double',
124 'max-icon': 'icon'});
133 objectName: "buttonMenu"
134 property QtObject menuData: null
135 property var menuModel: menuFactory.menuModel
136 property int menuIndex: -1
138 buttonText: menuData && menuData.label || ""
139 enabled: menuData && menuData.sensitive || false
142 menuModel.activate(menuIndex);
150 objectName: "sectionMenu"
151 property QtObject menuData: null
152 property var menuIndex: undefined
154 text: menuData && menuData.label || ""
162 Menus.ProgressValueMenu {
163 objectName: "progressMenu"
164 property QtObject menuData: null
165 property int menuIndex: -1
167 text: menuData && menuData.label || ""
168 iconSource: menuData && menuData.icon || ""
169 value : menuData && menuData.actionState || 0.0
170 enabled: menuData && menuData.sensitive || false
178 objectName: "standardMenu"
179 property QtObject menuData: null
180 property int menuIndex: -1
182 text: menuData && menuData.label || ""
183 iconSource: menuData && menuData.icon || ""
184 enabled: menuData && menuData.sensitive || false
187 menuModel.activate(menuIndex);
195 Menus.CheckableMenu {
196 objectName: "checkableMenu"
197 property QtObject menuData: null
198 property int menuIndex: -1
200 text: menuData && menuData.label || ""
201 enabled: menuData && menuData.sensitive || false
202 checked: menuData && menuData.isToggled || false
205 menuModel.activate(menuIndex);
215 objectName: "switchMenu"
216 property QtObject menuData: null
217 property int menuIndex: -1
219 text: menuData && menuData.label || ""
220 iconSource: menuData && menuData.icon || ""
221 enabled: menuData && menuData.sensitive || false
222 checked: menuData && menuData.isToggled || false
225 menuModel.activate(menuIndex);
234 objectName: "alarmMenu"
235 property QtObject menuData: null
236 property var menuModel: menuFactory.menuModel
237 property int menuIndex: -1
238 property var extendedData: menuData && menuData.ext || undefined
239 // TODO - bug #1260728
240 property var timeFormatter: Utils.GDateTimeFormatter {
241 time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
242 format: getExtendedProperty(extendedData, "xCanonicalTimeFormat", "")
245 text: menuData && menuData.label || ""
246 iconSource: menuData && menuData.icon || "image://theme/alarm-clock"
247 time: timeFormatter.timeString
248 enabled: menuData && menuData.sensitive || false
250 onMenuModelChanged: {
253 onMenuIndexChanged: {
257 menuModel.activate(menuIndex);
260 function loadAttributes() {
261 if (!menuModel || menuIndex == -1) return;
262 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
263 'x-canonical-time-format': 'string'});
272 objectName: "appointmentMenu"
273 property QtObject menuData: null
274 property var menuModel: menuFactory.menuModel
275 property int menuIndex: -1
276 property var extendedData: menuData && menuData.ext || undefined
277 // TODO - bug #1260728
278 property var timeFormatter: Utils.GDateTimeFormatter {
279 time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
280 format: getExtendedProperty(extendedData, "xCanonicalTimeFormat", "")
283 text: menuData && menuData.label || ""
284 iconSource: menuData && menuData.icon || "image://theme/calendar"
285 time: timeFormatter.timeString
286 eventColor: getExtendedProperty(extendedData, "xCanonicalColor", Qt.rgba(0.0, 0.0, 0.0, 0.0))
287 enabled: menuData && menuData.sensitive || false
289 onMenuModelChanged: {
292 onMenuIndexChanged: {
296 menuModel.activate(menuIndex);
299 function loadAttributes() {
300 if (!menuModel || menuIndex == -1) return;
301 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-color': 'string',
302 'x-canonical-time': 'int64',
303 'x-canonical-time-format': 'string'});
312 objectName: "wifiSection"
313 property QtObject menuData: null
314 property var menuModel: menuFactory.menuModel
315 property int menuIndex: -1
316 property var extendedData: menuData && menuData.ext || undefined
318 text: menuData && menuData.label || ""
319 busy: getExtendedProperty(extendedData, "xCanonicalBusyAction", false)
321 onMenuModelChanged: {
324 onMenuIndexChanged: {
328 function loadAttributes() {
329 if (!menuModel || menuIndex == -1) return;
330 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-busy-action': 'bool'})
338 Menus.AccessPointMenu {
339 objectName: "accessPoint"
340 property QtObject menuData: null
341 property var menuModel: menuFactory.menuModel
342 property int menuIndex: -1
343 property var extendedData: menuData && menuData.ext || undefined
345 property var strengthAction: UnityMenuAction {
348 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
351 text: menuData && menuData.label || ""
352 enabled: menuData && menuData.sensitive || false
353 checked: menuData && menuData.isToggled || false
354 secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
355 adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
356 signalStrength: strengthAction.valid ? strengthAction.state : 0
358 onMenuModelChanged: {
361 onMenuIndexChanged: {
365 menuModel.activate(menuIndex);
368 function loadAttributes() {
369 if (!menuModel || menuIndex == -1) return;
370 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
371 'x-canonical-wifi-ap-is-secure': 'bool',
372 'x-canonical-wifi-ap-strength-action': 'string'});
380 MessageMenuItemFactory {
381 objectName: "messageItem"
382 menuModel: menuFactory.menuModel
389 Menus.GroupedMessageMenu {
390 objectName: "groupedMessage"
391 property QtObject menuData: null
392 property var menuModel: menuFactory.menuModel
393 property int menuIndex: -1
394 property var extendedData: menuData && menuData.ext || undefined
396 text: menuData && menuData.label || ""
397 iconSource: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_app.svg")
398 count: menuData && menuData.actionState.length > 0 ? menuData.actionState[0] : "0"
399 enabled: menuData && menuData.sensitive || false
402 onMenuModelChanged: {
405 onMenuIndexChanged: {
409 menuModel.activate(menuIndex, true);
412 menuModel.activate(menuIndex, false);
415 function loadAttributes() {
416 if (!menuModel || menuIndex == -1) return;
417 menuModel.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
425 Menus.MediaPlayerMenu {
426 objectName: "mediaPayerMenu"
427 property QtObject menuData: null
428 property var menuModel: menuFactory.menuModel
429 property int menuIndex: -1
430 property var actionState: menuData && menuData.actionState || undefined
432 playerIcon: menuData && menuData.icon || ""
433 playerName: menuData && menuData.label || ""
435 albumArt: getExtendedProperty(actionState, "art-url", "")
436 song: getExtendedProperty(actionState, "title", "unknown")
437 artist: getExtendedProperty(actionState, "artist", "unknown")
438 album: getExtendedProperty(actionState, "album", "unknown")
439 running: getExtendedProperty(actionState, "running", false)
440 state: getExtendedProperty(actionState, "state", "")
441 enabled: menuData && menuData.sensitive || false
444 model.activate(modelIndex);
450 id: playbackItemMenu;
452 Menus.PlaybackItemMenu {
453 objectName: "playbackItemMenu"
454 property QtObject menuData: null
455 property var menuModel: menuFactory.menuModel
456 property int menuIndex: -1
457 property var extendedData: menuData && menuData.ext || undefined
459 property var playAction: UnityMenuAction {
462 name: getExtendedProperty(extendedData, "xCanonicalPlayAction", "")
464 property var nextAction: UnityMenuAction {
467 name: getExtendedProperty(extendedData, "xCanonicalNextAction", "")
469 property var previousAction: UnityMenuAction {
472 name: getExtendedProperty(extendedData, "xCanonicalPreviousAction", "")
475 playing: playAction.state === "Playing"
476 canPlay: playAction.valid
477 canGoNext: nextAction.valid
478 canGoPrevious: previousAction.valid
479 enabled: menuData && menuData.sensitive || false
482 playAction.activate();
485 nextAction.activate();
488 previousAction.activate();
490 onMenuModelChanged: {
493 onMenuIndexChanged: {
497 function loadAttributes() {
498 if (!menuModel || menuIndex == -1) return;
499 menuModel.loadExtendedAttributes(modelIndex, {'x-canonical-play-action': 'string',
500 'x-canonical-next-action': 'string',
501 'x-canonical-previous-action': 'string'});
510 objectName: "transferMenu"
512 property QtObject menuData: null
513 property var menuModel: menuFactory.menuModel
514 property int menuIndex: -1
515 property var extendedData: menuData && menuData.ext || undefined
516 property var uid: getExtendedProperty(extendedData, "xCanonicalUid", undefined)
518 text: menuData && menuData.label || ""
519 iconSource: menuData && menuData.icon || ""
521 enabled: menuData && menuData.sensitive || false
528 busName: rootModel.busName
529 objectPath: rootModel.actions["indicator"]
531 property var activateAction: action("activate-transfer")
532 property var cancelAction: action("cancel-transfer")
533 property var transferStateAction: uid !== undefined ? action("transfer-state."+uid) : null
535 Component.onCompleted: actionGroup.start()
538 property var transferState: {
539 if (actionGroup.transferStateAction === null) return undefined;
540 return actionGroup.transferStateAction.valid ? actionGroup.transferStateAction.state : undefined
543 property var runningState : transferState !== undefined ? transferState["state"] : undefined
544 property var secondsLeft : transferState !== undefined ? transferState["seconds-left"] : undefined
546 active: runningState !== undefined && runningState !== Menus.TransferState.Finished
547 progress: transferState !== undefined ? transferState["percent"] : 0.0
549 // TODO - Should be in the SDK
550 property var timeRemaining: {
551 if (secondsLeft === undefined) return undefined;
554 var hours = Math.floor(secondsLeft / (60 * 60));
555 var minutes = Math.floor(secondsLeft / 60) % 60;
556 var seconds = secondsLeft % 60;
558 remaining += hours + (hours == 1 ? " hour" : " hours");
561 if (remaining != "") remaining += ", ";
562 remaining += minutes + (minutes == 1 ? " minute" : " minutes");
564 // don't include seconds if hours > 0
565 if (hours == 0 && minutes < 5 && seconds > 0) {
566 if (remaining != "") remaining += ", ";
567 remaining += seconds + (seconds == 1 ? " second" : " seconds");
570 remaining = "0 seconds";
571 return remaining + " remaining";
575 switch (runningState) {
576 case Menus.TransferState.Queued:
577 return i18n.tr("In queue…");
578 case Menus.TransferState.Hashing:
579 case Menus.TransferState.Processing:
580 case Menus.TransferState.Running:
581 return timeRemaining === undefined ? i18n.tr("Downloading") : timeRemaining;
582 case Menus.TransferState.Paused:
583 return i18n.tr("Paused, tap to resume");
584 case Menus.TransferState.Canceled:
585 return i18n.tr("Canceled");
586 case Menus.TransferState.Finished:
587 return i18n.tr("Finished");
588 case Menus.TransferState.Error:
589 return i18n.tr("Failed, tap to retry");
594 onMenuModelChanged: {
597 onMenuIndexChanged: {
601 actionGroup.activateAction.activate(uid);
604 actionGroup.cancelAction.activate(uid);
607 function loadAttributes() {
608 if (!menuModel || menuIndex == -1) return;
609 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-uid': 'string'});
615 id: buttonSectionMenu;
618 objectName: "buttonSectionMenu"
619 property QtObject menuData: null
620 property var menuModel: menuFactory.menuModel
621 property int menuIndex: -1
622 property var extendedData: menuData && menuData.ext || undefined
624 iconSource: menuData && menuData.icon || ""
625 enabled: menuData && menuData.sensitive || false
626 text: menuData && menuData.label || ""
629 onMenuModelChanged: {
632 onMenuIndexChanged: {
635 function loadAttributes() {
636 if (!menuModel || menuIndex == -1) return;
637 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
641 text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
644 menuModel.activate(menuIndex);
650 function load(modelData) {
651 if (modelData.type !== undefined) {
652 var component = _map[modelData.type];
653 if (component !== undefined) {
657 if (modelData.isCheck || modelData.isRadio) {
658 return checkableMenu;
660 if (modelData.isSeparator) {
661 return separatorMenu;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list