Unity 8
 All Classes Functions
MenuItemFactory.qml
1 /*
2  * Copyright 2013 Canonical Ltd.
3  *
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.
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 Lesser General Public License for more details.
12  *
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/>.
15  *
16  * Authors:
17  * Nick Dedekind <nick.dedekind@canonical.com>
18  */
19 
20 import QtQuick 2.0
21 import Ubuntu.Settings.Menus 0.1 as Menus
22 import QMenuModel 0.1
23 import Utils 0.1 as Utils
24 import Ubuntu.Components.ListItems 0.1 as ListItems
25 import Ubuntu.Components 1.1
26 
27 Item {
28  id: menuFactory
29 
30  property var rootModel: null
31  property var menuModel: null
32 
33  property var _map: {
34  "default": {
35  "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
36  "unity.widgets.systemsettings.tablet.switch" : switchMenu,
37 
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,
48  "com.canonical.indicator.link" : linkMenu,
49 
50  "com.canonical.indicator.messages.messageitem" : messageItem,
51  "com.canonical.indicator.messages.sourceitem" : groupedMessage,
52 
53  "com.canonical.unity.slider" : sliderMenu,
54  "com.canonical.unity.switch" : switchMenu,
55 
56  "com.canonical.unity.media-player" : mediaPayerMenu,
57  "com.canonical.unity.playback-item" : playbackItemMenu,
58 
59  "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
60  "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
61  "com.canonical.indicator.network.modeminfoitem" : modeminfoitem,
62  },
63  "indicator-messages" : {
64  "com.canonical.indicator.button" : messagesButtonMenu
65  }
66  }
67 
68  function getExtendedProperty(object, propertyName, defaultValue) {
69  if (object && object.hasOwnProperty(propertyName)) {
70  return object[propertyName];
71  }
72  return defaultValue;
73  }
74 
75  Component {
76  id: separatorMenu;
77 
78  Menus.SeparatorMenu {
79  objectName: "separatorMenu"
80  }
81  }
82 
83  Component {
84  id: sliderMenu;
85 
86  Menus.SliderMenu {
87  objectName: "sliderMenu"
88  property QtObject menuData: null
89  property var menuModel: menuFactory.menuModel
90  property int menuIndex: -1
91  property var extendedData: menuData && menuData.ext || undefined
92  property var serverValue: getExtendedProperty(menuData, "actionState", undefined)
93 
94  text: menuData && menuData.label || ""
95  iconSource: menuData && menuData.icon || ""
96  minIcon: getExtendedProperty(extendedData, "minIcon", "")
97  maxIcon: getExtendedProperty(extendedData, "maxIcon", "")
98 
99  minimumValue: getExtendedProperty(extendedData, "minValue", 0.0)
100  maximumValue: {
101  var maximum = getExtendedProperty(extendedData, "maxValue", 1.0);
102  if (maximum <= minimumValue) {
103  return minimumValue + 1;
104  }
105  return maximum;
106  }
107  enabled: menuData && menuData.sensitive || false
108  highlightWhenPressed: false
109 
110  onMenuModelChanged: {
111  loadAttributes();
112  }
113  onMenuIndexChanged: {
114  loadAttributes();
115  }
116  onServerValueChanged: {
117  // value can be changed by slider, so a binding won't work.
118  if (serverValue !== undefined) {
119  value = serverValue;
120  }
121  }
122  onUpdated: {
123  menuModel.changeState(menuIndex, value);
124  }
125 
126  function loadAttributes() {
127  if (!menuModel || menuIndex == -1) return;
128  menuModel.loadExtendedAttributes(menuIndex, {'min-value': 'double',
129  'max-value': 'double',
130  'min-icon': 'icon',
131  'max-icon': 'icon'});
132  }
133  }
134  }
135 
136  Component {
137  id: buttonMenu;
138 
139  Menus.ButtonMenu {
140  objectName: "buttonMenu"
141  property QtObject menuData: null
142  property var menuModel: menuFactory.menuModel
143  property int menuIndex: -1
144 
145  buttonText: menuData && menuData.label || ""
146  enabled: menuData && menuData.sensitive || false
147  highlightWhenPressed: false
148 
149  onTriggered: {
150  menuModel.activate(menuIndex);
151  }
152  }
153  }
154 
155  Component {
156  id: messagesButtonMenu;
157 
158  Item {
159  objectName: "messagesButtonMenu"
160  property QtObject menuData: null
161  property var menuModel: menuFactory.menuModel
162  property int menuIndex: -1
163 
164  implicitHeight: units.gu(5)
165  enabled: menuData && menuData.sensitive || false
166 
167  Label {
168  id: buttonMenuLabel
169  text: menuData && menuData.label || ""
170  anchors.centerIn: parent
171  font.bold: true
172  }
173 
174  MouseArea {
175  anchors {
176  fill: buttonMenuLabel
177  margins: units.gu(-1)
178  }
179  onClicked: menuModel.activate(menuIndex);
180  }
181  }
182  }
183 
184  Component {
185  id: sectionMenu;
186 
187  Menus.SectionMenu {
188  objectName: "sectionMenu"
189  property QtObject menuData: null
190  property var menuIndex: undefined
191 
192  text: menuData && menuData.label || ""
193  busy: false
194  }
195  }
196 
197  Component {
198  id: progressMenu;
199 
200  Menus.ProgressValueMenu {
201  objectName: "progressMenu"
202  property QtObject menuData: null
203  property int menuIndex: -1
204 
205  text: menuData && menuData.label || ""
206  iconSource: menuData && menuData.icon || ""
207  value : menuData && menuData.actionState || 0.0
208  enabled: menuData && menuData.sensitive || false
209  highlightWhenPressed: false
210  }
211  }
212 
213  Component {
214  id: standardMenu;
215 
216  Menus.StandardMenu {
217  objectName: "standardMenu"
218  property QtObject menuData: null
219  property int menuIndex: -1
220 
221  text: menuData && menuData.label || ""
222  iconSource: menuData && menuData.icon || ""
223  enabled: menuData && menuData.sensitive || false
224  highlightWhenPressed: false
225 
226  onTriggered: {
227  menuModel.activate(menuIndex);
228  }
229 
230  // FIXME : At the moment, the indicators aren't using
231  // com.canonical.indicators.link for settings menu. Need to fudge it.
232  property bool settingsMenu: menuData && menuData.action.indexOf("settings") > -1 || false
233  backColor: settingsMenu ? Qt.rgba(1,1,1,0.07) : "transparent"
234  component: settingsMenu ? buttonForSettings : undefined
235  Component {
236  id: buttonForSettings
237  Icon {
238  name: "settings"
239  height: units.gu(3)
240  width: height
241  color: Theme.palette.selected.backgroundText
242  }
243  }
244  }
245  }
246 
247  Component {
248  id: linkMenu;
249 
250  Menus.StandardMenu {
251  objectName: "linkMenu"
252  property QtObject menuData: null
253  property int menuIndex: -1
254 
255  text: menuData && menuData.label || ""
256  iconSource: menuData && menuData.icon || ""
257  enabled: menuData && menuData.sensitive || false
258  highlightWhenPressed: false
259 
260  onTriggered: {
261  menuModel.activate(menuIndex);
262  }
263 
264  backColor: Qt.rgba(1,1,1,0.07)
265 
266  component: menuData.icon ? icon : undefined
267  Component {
268  id: icon
269  Icon {
270  source: menuData.icon
271  height: units.gu(3)
272  width: height
273  color: Theme.palette.selected.backgroundText
274  }
275  }
276  }
277  }
278 
279  Component {
280  id: checkableMenu;
281 
282  Menus.CheckableMenu {
283  objectName: "checkableMenu"
284  property QtObject menuData: null
285  property int menuIndex: -1
286 
287  text: menuData && menuData.label || ""
288  enabled: menuData && menuData.sensitive || false
289  checked: menuData && menuData.isToggled || false
290  highlightWhenPressed: false
291 
292  onTriggered: {
293  menuModel.activate(menuIndex);
294  }
295  }
296  }
297 
298  Component {
299  id: switchMenu;
300 
301  Menus.SwitchMenu {
302  objectName: "switchMenu"
303  property QtObject menuData: null
304  property int menuIndex: -1
305 
306  text: menuData && menuData.label || ""
307  iconSource: menuData && menuData.icon || ""
308  enabled: menuData && menuData.sensitive || false
309  checked: menuData && menuData.isToggled || false
310  highlightWhenPressed: false
311 
312  onTriggered: {
313  menuModel.activate(menuIndex);
314  }
315  }
316  }
317 
318  Component {
319  id: alarmMenu;
320 
321  Menus.EventMenu {
322  objectName: "alarmMenu"
323  property QtObject menuData: null
324  property var menuModel: menuFactory.menuModel
325  property int menuIndex: -1
326  property var extendedData: menuData && menuData.ext || undefined
327  // TODO - bug #1260728
328  property var timeFormatter: Utils.GDateTimeFormatter {
329  time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
330  format: getExtendedProperty(extendedData, "xCanonicalTimeFormat", "")
331  }
332 
333  text: menuData && menuData.label || ""
334  iconSource: menuData && menuData.icon || "image://theme/alarm-clock"
335  time: timeFormatter.timeString
336  enabled: menuData && menuData.sensitive || false
337  highlightWhenPressed: false
338 
339  onMenuModelChanged: {
340  loadAttributes();
341  }
342  onMenuIndexChanged: {
343  loadAttributes();
344  }
345  onTriggered: {
346  menuModel.activate(menuIndex);
347  }
348 
349  function loadAttributes() {
350  if (!menuModel || menuIndex == -1) return;
351  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
352  'x-canonical-time-format': 'string'});
353  }
354  }
355  }
356 
357  Component {
358  id: appointmentMenu;
359 
360  Menus.EventMenu {
361  objectName: "appointmentMenu"
362  property QtObject menuData: null
363  property var menuModel: menuFactory.menuModel
364  property int menuIndex: -1
365  property var extendedData: menuData && menuData.ext || undefined
366  // TODO - bug #1260728
367  property var timeFormatter: Utils.GDateTimeFormatter {
368  time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
369  format: getExtendedProperty(extendedData, "xCanonicalTimeFormat", "")
370  }
371 
372  text: menuData && menuData.label || ""
373  iconSource: menuData && menuData.icon || "image://theme/calendar"
374  time: timeFormatter.timeString
375  eventColor: getExtendedProperty(extendedData, "xCanonicalColor", Qt.rgba(0.0, 0.0, 0.0, 0.0))
376  enabled: menuData && menuData.sensitive || false
377  highlightWhenPressed: false
378 
379  onMenuModelChanged: {
380  loadAttributes();
381  }
382  onMenuIndexChanged: {
383  loadAttributes();
384  }
385  onTriggered: {
386  menuModel.activate(menuIndex);
387  }
388 
389  function loadAttributes() {
390  if (!menuModel || menuIndex == -1) return;
391  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-color': 'string',
392  'x-canonical-time': 'int64',
393  'x-canonical-time-format': 'string'});
394  }
395  }
396  }
397 
398  Component {
399  id: wifiSection;
400 
401  Menus.SectionMenu {
402  objectName: "wifiSection"
403  property QtObject menuData: null
404  property var menuModel: menuFactory.menuModel
405  property int menuIndex: -1
406  property var extendedData: menuData && menuData.ext || undefined
407 
408  text: menuData && menuData.label || ""
409  busy: getExtendedProperty(extendedData, "xCanonicalBusyAction", false)
410 
411  onMenuModelChanged: {
412  loadAttributes();
413  }
414  onMenuIndexChanged: {
415  loadAttributes();
416  }
417 
418  function loadAttributes() {
419  if (!menuModel || menuIndex == -1) return;
420  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-busy-action': 'bool'})
421  }
422  }
423  }
424 
425  Component {
426  id: accessPoint;
427 
428  Menus.AccessPointMenu {
429  objectName: "accessPoint"
430  property QtObject menuData: null
431  property var menuModel: menuFactory.menuModel
432  property int menuIndex: -1
433  property var extendedData: menuData && menuData.ext || undefined
434 
435  property var strengthAction: UnityMenuAction {
436  model: menuModel
437  index: menuIndex
438  name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
439  }
440 
441  text: menuData && menuData.label || ""
442  enabled: menuData && menuData.sensitive || false
443  active: menuData && menuData.isToggled || false
444  secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
445  adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
446  signalStrength: strengthAction.valid ? strengthAction.state : 0
447  highlightWhenPressed: false
448 
449  onMenuModelChanged: {
450  loadAttributes();
451  }
452  onMenuIndexChanged: {
453  loadAttributes();
454  }
455  onTriggered: {
456  menuModel.activate(menuIndex);
457  }
458 
459  function loadAttributes() {
460  if (!menuModel || menuIndex == -1) return;
461  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
462  'x-canonical-wifi-ap-is-secure': 'bool',
463  'x-canonical-wifi-ap-strength-action': 'string'});
464  }
465  }
466  }
467 
468  Component {
469  id: modeminfoitem;
470  ModemInfoItem {
471  objectName: "modemInfoItem"
472  property QtObject menuData: null
473  property var menuModel: menuFactory.menuModel
474  property int menuIndex: -1
475  property var extendedData: menuData && menuData.ext || undefined
476  highlightWhenPressed: false
477 
478  property var statusLabelAction: UnityMenuAction {
479  model: menuModel
480  index: menuIndex
481  name: getExtendedProperty(extendedData, "xCanonicalModemStatusLabelAction", "")
482  }
483  statusText: statusLabelAction.valid ? statusLabelAction.state : ""
484 
485  property var statusIconAction: UnityMenuAction {
486  model: menuModel
487  index: menuIndex
488  name: getExtendedProperty(extendedData, "xCanonicalModemStatusIconAction", "")
489  }
490  statusIcon: statusIconAction.valid ? statusIconAction.state : ""
491 
492  property var connectivityIconAction: UnityMenuAction {
493  model: menuModel
494  index: menuIndex
495  name: getExtendedProperty(extendedData, "xCanonicalModemConnectivityIconAction", "")
496  }
497  connectivityIcon: connectivityIconAction.valid ? connectivityIconAction.state : ""
498 
499  property var simIdentifierLabelAction: UnityMenuAction {
500  model: menuModel
501  index: menuIndex
502  name: getExtendedProperty(extendedData, "xCanonicalModemSimIdentifierLabelAction", "")
503  }
504  simIdentifierText: simIdentifierLabelAction.valid ? simIdentifierLabelAction.state : ""
505 
506  property var roamingAction: UnityMenuAction {
507  model: menuModel
508  index: menuIndex
509  name: getExtendedProperty(extendedData, "xCanonicalModemRoamingAction", "")
510  }
511  roaming: roamingAction.valid ? roamingAction.state : false
512 
513  property var unlockAction: UnityMenuAction {
514  model: menuModel
515  index: menuIndex
516  name: getExtendedProperty(extendedData, "xCanonicalModemLockedAction", "")
517  }
518  onUnlock: {
519  unlockAction.activate();
520  }
521  locked: unlockAction.valid ? unlockAction.state : false
522 
523  onMenuModelChanged: {
524  loadAttributes();
525  }
526  onMenuIndexChanged: {
527  loadAttributes();
528  }
529 
530  function loadAttributes() {
531  if (!menuModel || menuIndex == -1) return;
532  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-modem-status-label-action': 'string',
533  'x-canonical-modem-status-icon-action': 'string',
534  'x-canonical-modem-connectivity-icon-action': 'string',
535  'x-canonical-modem-sim-identifier-label-action': 'string',
536  'x-canonical-modem-roaming-action': 'string',
537  'x-canonical-modem-locked-action': 'string'});
538  }
539  }
540  }
541 
542  Component {
543  id: messageItem
544 
545  MessageMenuItemFactory {
546  objectName: "messageItem"
547  menuModel: menuFactory.menuModel
548  }
549  }
550 
551  Component {
552  id: groupedMessage
553 
554  Menus.GroupedMessageMenu {
555  objectName: "groupedMessage"
556  property QtObject menuData: null
557  property var menuModel: menuFactory.menuModel
558  property int menuIndex: -1
559  property var extendedData: menuData && menuData.ext || undefined
560 
561  text: menuData && menuData.label || ""
562  iconSource: getExtendedProperty(extendedData, "icon", "image://theme/message")
563  count: menuData && menuData.actionState.length > 0 ? menuData.actionState[0] : "0"
564  enabled: menuData && menuData.sensitive || false
565  highlightWhenPressed: false
566  removable: true
567 
568  onMenuModelChanged: {
569  loadAttributes();
570  }
571  onMenuIndexChanged: {
572  loadAttributes();
573  }
574  onClicked: {
575  menuModel.activate(menuIndex, true);
576  }
577  onDismissed: {
578  menuModel.activate(menuIndex, false);
579  }
580 
581  function loadAttributes() {
582  if (!menuModel || menuIndex == -1) return;
583  menuModel.loadExtendedAttributes(modelIndex, {'icon': 'icon'});
584  }
585  }
586  }
587 
588  Component {
589  id: mediaPayerMenu;
590 
591  Menus.MediaPlayerMenu {
592  objectName: "mediaPayerMenu"
593  property QtObject menuData: null
594  property var menuModel: menuFactory.menuModel
595  property int menuIndex: -1
596  property var actionState: menuData && menuData.actionState || undefined
597  property bool running: getExtendedProperty(actionState, "running", false)
598 
599  playerIcon: menuData && menuData.icon || "image://theme/stock_music"
600  playerName: menuData && menuData.label || i18n.tr("Nothing is playing")
601 
602  albumArt: getExtendedProperty(actionState, "art-url", "image://theme/stock_music")
603  song: getExtendedProperty(actionState, "title", "")
604  artist: getExtendedProperty(actionState, "artist", "")
605  album: getExtendedProperty(actionState, "album", "")
606  showTrack: running && (state == "Playing" || state == "Paused")
607  state: getExtendedProperty(actionState, "state", "")
608  enabled: menuData && menuData.sensitive || false
609  highlightWhenPressed: false
610  showDivider: false
611 
612  onTriggered: {
613  model.activate(modelIndex);
614  }
615  }
616  }
617 
618  Component {
619  id: playbackItemMenu;
620 
621  Menus.PlaybackItemMenu {
622  objectName: "playbackItemMenu"
623  property QtObject menuData: null
624  property var menuModel: menuFactory.menuModel
625  property int menuIndex: -1
626  property var extendedData: menuData && menuData.ext || undefined
627 
628  property var playAction: UnityMenuAction {
629  model: menuModel
630  index: menuIndex
631  name: getExtendedProperty(extendedData, "xCanonicalPlayAction", "")
632  }
633  property var nextAction: UnityMenuAction {
634  model: menuModel
635  index: menuIndex
636  name: getExtendedProperty(extendedData, "xCanonicalNextAction", "")
637  }
638  property var previousAction: UnityMenuAction {
639  model: menuModel
640  index: menuIndex
641  name: getExtendedProperty(extendedData, "xCanonicalPreviousAction", "")
642  }
643 
644  playing: playAction.state === "Playing"
645  canPlay: playAction.valid
646  canGoNext: nextAction.valid
647  canGoPrevious: previousAction.valid
648  enabled: menuData && menuData.sensitive || false
649  highlightWhenPressed: false
650 
651  onPlay: {
652  playAction.activate();
653  }
654  onNext: {
655  nextAction.activate();
656  }
657  onPrevious: {
658  previousAction.activate();
659  }
660  onMenuModelChanged: {
661  loadAttributes();
662  }
663  onMenuIndexChanged: {
664  loadAttributes();
665  }
666 
667  function loadAttributes() {
668  if (!menuModel || menuIndex == -1) return;
669  menuModel.loadExtendedAttributes(modelIndex, {'x-canonical-play-action': 'string',
670  'x-canonical-next-action': 'string',
671  'x-canonical-previous-action': 'string'});
672  }
673  }
674  }
675 
676  Component {
677  id: transferMenu
678 
679  Menus.TransferMenu {
680  objectName: "transferMenu"
681  id: transfer
682  property QtObject menuData: null
683  property var menuModel: menuFactory.menuModel
684  property int menuIndex: -1
685  property var extendedData: menuData && menuData.ext || undefined
686  property var uid: getExtendedProperty(extendedData, "xCanonicalUid", undefined)
687 
688  text: menuData && menuData.label || ""
689  iconSource: menuData && menuData.icon || "image://theme/transfer-none"
690  maximum: 1.0
691  enabled: menuData && menuData.sensitive || false
692  highlightWhenPressed: false
693  removable: true
694  confirmRemoval: true
695 
696  QDBusActionGroup {
697  id: actionGroup
698  busType: 1
699  busName: rootModel.busName
700  objectPath: rootModel.actions["indicator"]
701 
702  property var activateAction: action("activate-transfer")
703  property var cancelAction: action("cancel-transfer")
704  property var transferStateAction: uid !== undefined ? action("transfer-state."+uid) : null
705 
706  Component.onCompleted: actionGroup.start()
707  }
708 
709  property var transferState: {
710  if (actionGroup.transferStateAction === null) return undefined;
711  return actionGroup.transferStateAction.valid ? actionGroup.transferStateAction.state : undefined
712  }
713 
714  property var runningState : transferState !== undefined ? transferState["state"] : undefined
715  property var secondsLeft : transferState !== undefined ? transferState["seconds-left"] : undefined
716 
717  active: runningState !== undefined && runningState !== Menus.TransferState.Finished
718  progress: transferState !== undefined ? transferState["percent"] : 0.0
719 
720  // TODO - Should be in the SDK
721  property var timeRemaining: {
722  if (secondsLeft === undefined) return undefined;
723 
724  var remaining = "";
725  var hours = Math.floor(secondsLeft / (60 * 60));
726  var minutes = Math.floor(secondsLeft / 60) % 60;
727  var seconds = secondsLeft % 60;
728  if (hours > 0) {
729  remaining += hours + (hours == 1 ? " hour" : " hours");
730  }
731  if (minutes > 0) {
732  if (remaining != "") remaining += ", ";
733  remaining += minutes + (minutes == 1 ? " minute" : " minutes");
734  }
735  // don't include seconds if hours > 0
736  if (hours == 0 && minutes < 5 && seconds > 0) {
737  if (remaining != "") remaining += ", ";
738  remaining += seconds + (seconds == 1 ? " second" : " seconds");
739  }
740  if (remaining == "")
741  remaining = "0 seconds";
742  return remaining + " remaining";
743  }
744 
745  stateText: {
746  switch (runningState) {
747  case Menus.TransferState.Queued:
748  return i18n.tr("In queue…");
749  case Menus.TransferState.Hashing:
750  case Menus.TransferState.Processing:
751  case Menus.TransferState.Running:
752  return timeRemaining === undefined ? i18n.tr("Downloading") : timeRemaining;
753  case Menus.TransferState.Paused:
754  return i18n.tr("Paused, tap to resume");
755  case Menus.TransferState.Canceled:
756  return i18n.tr("Canceled");
757  case Menus.TransferState.Finished:
758  return i18n.tr("Finished");
759  case Menus.TransferState.Error:
760  return i18n.tr("Failed, tap to retry");
761  }
762  return "";
763  }
764 
765  onMenuModelChanged: {
766  loadAttributes();
767  }
768  onMenuIndexChanged: {
769  loadAttributes();
770  }
771  onTriggered: {
772  actionGroup.activateAction.activate(uid);
773  }
774  onItemRemoved: {
775  actionGroup.cancelAction.activate(uid);
776  }
777 
778  function loadAttributes() {
779  if (!menuModel || menuIndex == -1) return;
780  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-uid': 'string'});
781  }
782  }
783  }
784 
785  Component {
786  id: buttonSectionMenu;
787 
788  Menus.StandardMenu {
789  objectName: "buttonSectionMenu"
790  property QtObject menuData: null
791  property var menuModel: menuFactory.menuModel
792  property int menuIndex: -1
793  property var extendedData: menuData && menuData.ext || undefined
794 
795  iconSource: menuData && menuData.icon || ""
796  enabled: menuData && menuData.sensitive || false
797  highlightWhenPressed: false
798  text: menuData && menuData.label || ""
799  foregroundColor: Theme.palette.normal.backgroundText
800 
801  onMenuModelChanged: {
802  loadAttributes();
803  }
804  onMenuIndexChanged: {
805  loadAttributes();
806  }
807  function loadAttributes() {
808  if (!menuModel || menuIndex == -1) return;
809  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
810  }
811 
812  component: Component {
813  Button {
814  objectName: "buttonSectionMenuControl"
815  text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
816 
817  onClicked: {
818  menuModel.activate(menuIndex);
819  }
820  }
821  }
822  }
823  }
824 
825  function load(modelData, context) {
826  if (modelData.type !== undefined && modelData.type !== "") {
827  var component = undefined;
828 
829  var contextComponents = _map[context];
830  if (contextComponents !== undefined) {
831  component = contextComponents[modelData.type];
832  }
833 
834  if (component === undefined) {
835  component = _map["default"][modelData.type];
836  }
837  if (component !== undefined) {
838  return component;
839  }
840  console.debug("Don't know how to make " + modelData.type + " for " + context);
841  }
842  if (modelData.isCheck || modelData.isRadio) {
843  return checkableMenu;
844  }
845  if (modelData.isSeparator) {
846  return separatorMenu;
847  }
848  return standardMenu;
849  }
850 }