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);
143 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
151 objectName: "sectionMenu"
152 property QtObject menuData: null
153 property var menuIndex: undefined
155 text: menuData && menuData.label || ""
163 Menus.ProgressValueMenu {
164 objectName: "progressMenu"
165 property QtObject menuData: null
166 property int menuIndex: -1
168 text: menuData && menuData.label || ""
169 iconSource: menuData && menuData.icon || ""
170 value : menuData && menuData.actionState || 0.0
171 enabled: menuData && menuData.sensitive || false
179 objectName: "standardMenu"
180 property QtObject menuData: null
181 property int menuIndex: -1
183 text: menuData && menuData.label || ""
184 iconSource: menuData && menuData.icon || ""
185 enabled: menuData && menuData.sensitive || false
188 menuModel.activate(menuIndex);
189 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
197 Menus.CheckableMenu {
198 objectName: "checkableMenu"
199 property QtObject menuData: null
200 property int menuIndex: -1
202 text: menuData && menuData.label || ""
203 enabled: menuData && menuData.sensitive || false
204 checked: menuData && menuData.isToggled || false
207 menuModel.activate(menuIndex);
208 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
218 objectName: "switchMenu"
219 property QtObject menuData: null
220 property int menuIndex: -1
222 text: menuData && menuData.label || ""
223 iconSource: menuData && menuData.icon || ""
224 enabled: menuData && menuData.sensitive || false
225 checked: menuData && menuData.isToggled || false
228 menuModel.activate(menuIndex);
229 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
238 objectName: "alarmMenu"
239 property QtObject menuData: null
240 property var menuModel: menuFactory.menuModel
241 property int menuIndex: -1
242 property var extendedData: menuData && menuData.ext || undefined
243 // TODO - bug #1260728
244 property var timeFormatter: Utils.GDateTimeFormatter {
245 time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
246 format: getExtendedProperty(extendedData, "xCanonicalTimeFormat", "")
249 text: menuData && menuData.label || ""
250 iconSource: menuData && menuData.icon || "image://theme/alarm-clock"
251 time: timeFormatter.timeString
252 enabled: menuData && menuData.sensitive || false
254 onMenuModelChanged: {
257 onMenuIndexChanged: {
261 menuModel.activate(menuIndex);
264 function loadAttributes() {
265 if (!menuModel || menuIndex == -1) return;
266 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
267 'x-canonical-time-format': 'string'});
276 objectName: "appointmentMenu"
277 property QtObject menuData: null
278 property var menuModel: menuFactory.menuModel
279 property int menuIndex: -1
280 property var extendedData: menuData && menuData.ext || undefined
281 // TODO - bug #1260728
282 property var timeFormatter: Utils.GDateTimeFormatter {
283 time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
284 format: getExtendedProperty(extendedData, "xCanonicalTimeFormat", "")
287 text: menuData && menuData.label || ""
288 iconSource: menuData && menuData.icon || "image://theme/calendar"
289 time: timeFormatter.timeString
290 eventColor: getExtendedProperty(extendedData, "xCanonicalColor", Qt.rgba(0.0, 0.0, 0.0, 0.0))
291 enabled: menuData && menuData.sensitive || false
293 onMenuModelChanged: {
296 onMenuIndexChanged: {
300 menuModel.activate(menuIndex);
303 function loadAttributes() {
304 if (!menuModel || menuIndex == -1) return;
305 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-color': 'string',
306 'x-canonical-time': 'int64',
307 'x-canonical-time-format': 'string'});
316 objectName: "wifiSection"
317 property QtObject menuData: null
318 property var menuModel: menuFactory.menuModel
319 property int menuIndex: -1
320 property var extendedData: menuData && menuData.ext || undefined
322 text: menuData && menuData.label || ""
323 busy: getExtendedProperty(extendedData, "xCanonicalBusyAction", false)
325 onMenuModelChanged: {
328 onMenuIndexChanged: {
332 function loadAttributes() {
333 if (!menuModel || menuIndex == -1) return;
334 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-busy-action': 'bool'})
342 Menus.AccessPointMenu {
343 objectName: "accessPoint"
344 property QtObject menuData: null
345 property var menuModel: menuFactory.menuModel
346 property int menuIndex: -1
347 property var extendedData: menuData && menuData.ext || undefined
349 property var strengthAction: UnityMenuAction {
352 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
355 text: menuData && menuData.label || ""
356 enabled: menuData && menuData.sensitive || false
357 checked: menuData && menuData.isToggled || false
358 secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
359 adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
360 signalStrength: strengthAction.valid ? strengthAction.state : 0
362 onMenuModelChanged: {
365 onMenuIndexChanged: {
369 menuModel.activate(menuIndex);
370 shell.hideIndicatorMenu(UbuntuAnimation.BriskDuration);
373 function loadAttributes() {
374 if (!menuModel || menuIndex == -1) return;
375 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
376 'x-canonical-wifi-ap-is-secure': 'bool',
377 'x-canonical-wifi-ap-strength-action': 'string'});
385 MessageMenuItemFactory {
386 objectName: "messageItem"
387 menuModel: menuFactory.menuModel
394 Menus.GroupedMessageMenu {
395 objectName: "groupedMessage"
396 property QtObject menuData: null
397 property var menuModel: menuFactory.menuModel
398 property int menuIndex: -1
399 property var extendedData: menuData && menuData.ext || undefined
401 text: menuData && menuData.label || ""
402 iconSource: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_app.svg")
403 count: menuData && menuData.actionState.length > 0 ? menuData.actionState[0] : "0"
404 enabled: menuData && menuData.sensitive || false
407 onMenuModelChanged: {
410 onMenuIndexChanged: {
414 menuModel.activate(menuIndex, true);
415 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
418 menuModel.activate(menuIndex, false);
421 function loadAttributes() {
422 if (!menuModel || menuIndex == -1) return;
423 menuModel.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
431 Menus.MediaPlayerMenu {
432 objectName: "mediaPayerMenu"
433 property QtObject menuData: null
434 property var menuModel: menuFactory.menuModel
435 property int menuIndex: -1
436 property var actionState: menuData && menuData.actionState || undefined
438 playerIcon: menuData && menuData.icon || ""
439 playerName: menuData && menuData.label || ""
441 albumArt: getExtendedProperty(actionState, "art-url", "")
442 song: getExtendedProperty(actionState, "title", "unknown")
443 artist: getExtendedProperty(actionState, "artist", "unknown")
444 album: getExtendedProperty(actionState, "album", "unknown")
445 running: getExtendedProperty(actionState, "running", false)
446 state: getExtendedProperty(actionState, "state", "")
447 enabled: menuData && menuData.sensitive || false
450 model.activate(modelIndex);
456 id: playbackItemMenu;
458 Menus.PlaybackItemMenu {
459 objectName: "playbackItemMenu"
460 property QtObject menuData: null
461 property var menuModel: menuFactory.menuModel
462 property int menuIndex: -1
463 property var extendedData: menuData && menuData.ext || undefined
465 property var playAction: UnityMenuAction {
468 name: getExtendedProperty(extendedData, "xCanonicalPlayAction", "")
470 property var nextAction: UnityMenuAction {
473 name: getExtendedProperty(extendedData, "xCanonicalNextAction", "")
475 property var previousAction: UnityMenuAction {
478 name: getExtendedProperty(extendedData, "xCanonicalPreviousAction", "")
481 playing: playAction.state === "Playing"
482 canPlay: playAction.valid
483 canGoNext: nextAction.valid
484 canGoPrevious: previousAction.valid
485 enabled: menuData && menuData.sensitive || false
488 playAction.activate();
491 nextAction.activate();
494 previousAction.activate();
496 onMenuModelChanged: {
499 onMenuIndexChanged: {
503 function loadAttributes() {
504 if (!menuModel || menuIndex == -1) return;
505 menuModel.loadExtendedAttributes(modelIndex, {'x-canonical-play-action': 'string',
506 'x-canonical-next-action': 'string',
507 'x-canonical-previous-action': 'string'});
516 objectName: "transferMenu"
518 property QtObject menuData: null
519 property var menuModel: menuFactory.menuModel
520 property int menuIndex: -1
521 property var extendedData: menuData && menuData.ext || undefined
522 property var uid: getExtendedProperty(extendedData, "xCanonicalUid", undefined)
524 text: menuData && menuData.label || ""
525 iconSource: menuData && menuData.icon || ""
527 enabled: menuData && menuData.sensitive || false
534 busName: rootModel.busName
535 objectPath: rootModel.actions["indicator"]
537 property var activateAction: action("activate-transfer")
538 property var cancelAction: action("cancel-transfer")
539 property var transferStateAction: uid !== undefined ? action("transfer-state."+uid) : null
541 Component.onCompleted: actionGroup.start()
544 property var transferState: {
545 if (actionGroup.transferStateAction === null) return undefined;
546 return actionGroup.transferStateAction.valid ? actionGroup.transferStateAction.state : undefined
549 property var runningState : transferState !== undefined ? transferState["state"] : undefined
550 property var secondsLeft : transferState !== undefined ? transferState["seconds-left"] : undefined
552 active: runningState !== undefined && runningState !== Menus.TransferState.Finished
553 progress: transferState !== undefined ? transferState["percent"] : 0.0
555 // TODO - Should be in the SDK
556 property var timeRemaining: {
557 if (secondsLeft === undefined) return undefined;
560 var hours = Math.floor(secondsLeft / (60 * 60));
561 var minutes = Math.floor(secondsLeft / 60) % 60;
562 var seconds = secondsLeft % 60;
564 remaining += hours + (hours == 1 ? " hour" : " hours");
567 if (remaining != "") remaining += ", ";
568 remaining += minutes + (minutes == 1 ? " minute" : " minutes");
570 // don't include seconds if hours > 0
571 if (hours == 0 && minutes < 5 && seconds > 0) {
572 if (remaining != "") remaining += ", ";
573 remaining += seconds + (seconds == 1 ? " second" : " seconds");
576 remaining = "0 seconds";
577 return remaining + " remaining";
581 switch (runningState) {
582 case Menus.TransferState.Queued:
583 return i18n.tr("In queue…");
584 case Menus.TransferState.Hashing:
585 case Menus.TransferState.Processing:
586 case Menus.TransferState.Running:
587 return timeRemaining === undefined ? i18n.tr("Downloading") : timeRemaining;
588 case Menus.TransferState.Paused:
589 return i18n.tr("Paused, tap to resume");
590 case Menus.TransferState.Canceled:
591 return i18n.tr("Canceled");
592 case Menus.TransferState.Finished:
593 return i18n.tr("Finished");
594 case Menus.TransferState.Error:
595 return i18n.tr("Failed, tap to retry");
600 onMenuModelChanged: {
603 onMenuIndexChanged: {
607 actionGroup.activateAction.activate(uid);
610 actionGroup.cancelAction.activate(uid);
613 function loadAttributes() {
614 if (!menuModel || menuIndex == -1) return;
615 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-uid': 'string'});
621 id: buttonSectionMenu;
624 objectName: "buttonSectionMenu"
625 property QtObject menuData: null
626 property var menuModel: menuFactory.menuModel
627 property int menuIndex: -1
628 property var extendedData: menuData && menuData.ext || undefined
630 iconSource: menuData && menuData.icon || ""
631 enabled: menuData && menuData.sensitive || false
632 text: menuData && menuData.label || ""
635 onMenuModelChanged: {
638 onMenuIndexChanged: {
641 function loadAttributes() {
642 if (!menuModel || menuIndex == -1) return;
643 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
647 text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
650 menuModel.activate(menuIndex);
656 function load(modelData) {
657 if (modelData.type !== undefined) {
658 var component = _map[modelData.type];
659 if (component !== undefined) {
663 if (modelData.isCheck || modelData.isRadio) {
664 return checkableMenu;
666 if (modelData.isSeparator) {
667 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