@@ -1,5 +1,5 @@
2− * Copyright 2013,2015 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -31,7 +31,8 @@ Item {
31 property var rootModel: null
31 property var rootModel: null
32 property var menuModel: null
32 property var menuModel: null
34− property var _map: {
34+ property var _userMap: null
35+ readonly property var _typeToComponent: {
35 "default": {
36 "default": {
36 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
37 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
37 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
38 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
@@ -69,11 +70,62 @@ Item {
69 "indicator.guest-menu-item": Platform.isPC ? userMenuItem : null,
70 "indicator.guest-menu-item": Platform.isPC ? userMenuItem : null,
70 "com.canonical.indicator.switch": Math.min(Screen.width, Screen.height) > units.gu(60) ? switchMenu : null // Desktop mode switch
71 "com.canonical.indicator.switch": Math.min(Screen.width, Screen.height) > units.gu(60) ? switchMenu : null // Desktop mode switch
72− "indicator-messages" : {
73+ "indicator-messages": {
73− "com.canonical.indicator.button" : messagesButtonMenu
74+ "com.canonical.indicator.button": messagesButtonMenu
78+ readonly property var _action_filter_map: {
79+ "indicator-session": {
80+ "indicator.logout": Platform.isPC ? undefined : null,
81+ "indicator.suspend": Platform.isPC ? undefined : null,
82+ "indicator.hibernate": Platform.isPC ? undefined : null,
83+ "indicator.reboot": Platform.isPC ? undefined : null
85+ "indicator-keyboard": {
86+ "indicator.map": null,
87+ "indicator.chart": null
91+ function getComponentForIndicatorEntryType(indicator, type) {
92+ var component = undefined;
93+ var map = _userMap || _typeToComponent
94+ var indicatorComponents = map[indicator];
96+ if (type === undefined || type === "") {
100+ if (indicatorComponents !== undefined) {
101+ component = indicatorComponents[type];
104+ if (component === undefined) {
105+ component = map["default"][type];
108+ if (component === undefined) {
109+ console.debug("Don't know how to make " + modelData.type + " for " + indicator);
115+ function getComponentForIndicatorEntryAction(indicator, action) {
116+ var component = undefined;
117+ var indicatorFilter = _action_filter_map[indicator]
119+ if (action === undefined || action === "") {
123+ if (indicatorFilter !== undefined) {
124+ component = indicatorFilter[action];
77 function getExtendedProperty(object, propertyName, defaultValue) {
129 function getExtendedProperty(object, propertyName, defaultValue) {
78 if (object && object.hasOwnProperty(propertyName)) {
130 if (object && object.hasOwnProperty(propertyName)) {
79 return object[propertyName];
131 return object[propertyName];
@@ -102,7 +154,6 @@ Item {
102 property var serverValue: getExtendedProperty(menuData, "actionState", undefined)
154 property var serverValue: getExtendedProperty(menuData, "actionState", undefined)
104 text: menuData && menuData.label || ""
156 text: menuData && menuData.label || ""
105− iconSource: menuData && menuData.icon || ""
106 minIcon: getExtendedProperty(extendedData, "minIcon", "")
157 minIcon: getExtendedProperty(extendedData, "minIcon", "")
107 maxIcon: getExtendedProperty(extendedData, "maxIcon", "")
158 maxIcon: getExtendedProperty(extendedData, "maxIcon", "")
@@ -182,29 +233,20 @@ Item {
182 Component {
233 Component {
183 id: messagesButtonMenu;
234 id: messagesButtonMenu;
185− Item {
236+ Menus.BaseLayoutMenu {
186 objectName: "messagesButtonMenu"
237 objectName: "messagesButtonMenu"
187 property QtObject menuData: null
238 property QtObject menuData: null
188 property var menuModel: menuFactory.menuModel
239 property var menuModel: menuFactory.menuModel
189 property int menuIndex: -1
240 property int menuIndex: -1
191− implicitHeight: units.gu(5)
242+ highlightWhenPressed: false
192 enabled: menuData && menuData.sensitive || false
243 enabled: menuData && menuData.sensitive || false
244+ text: menuData && menuData.label || ""
245+ title.color: theme.palette.selected.backgroundText
246+ title.horizontalAlignment: Text.AlignHCenter
247+ title.font.bold: true
196− text: menuData && menuData.label || ""
197− anchors.centerIn: parent
203− fill: buttonMenuLabel
204− margins: units.gu(-1)
206− onClicked: menuModel.activate(menuIndex);
249+ onClicked: menuModel.activate(menuIndex);
@@ -233,11 +275,6 @@ Item {
233 iconSource: menuData && menuData.icon || ""
275 iconSource: menuData && menuData.icon || ""
234 value : menuData && menuData.actionState || 0.0
276 value : menuData && menuData.actionState || 0.0
235 enabled: menuData && menuData.sensitive || false
277 enabled: menuData && menuData.sensitive || false
236− // FIXME: Because of this bug, setting it to the theme foreground color (white)
237− // currently doesn't work. Let's hack it to be "close enough"
238− // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1555784
239− foregroundColor: "#fffffe"
240− highlightWhenPressed: false
@@ -257,52 +294,41 @@ Item {
257 onTriggered: {
294 onTriggered: {
258 menuModel.activate(menuIndex);
295 menuModel.activate(menuIndex);
261− // FIXME : At the moment, the indicators aren't using
262− // com.canonical.indicators.link for settings menu. Need to fudge it.
263− property bool settingsMenu: menuData && menuData.action.indexOf("settings") > -1 || false
264− backColor: settingsMenu ? Qt.rgba(1,1,1,0.07) : "transparent"
265− component: settingsMenu ? buttonForSettings : undefined
267− id: buttonForSettings
272− color: theme.palette.normal.backgroundText
278 Component {
300 Component {
279 id: linkMenu;
301 id: linkMenu;
281− Menus.StandardMenu {
303+ Menus.BaseLayoutMenu {
282 objectName: "linkMenu"
304 objectName: "linkMenu"
283 property QtObject menuData: null
305 property QtObject menuData: null
284 property int menuIndex: -1
306 property int menuIndex: -1
286 text: menuData && menuData.label || ""
308 text: menuData && menuData.label || ""
287− iconSource: menuData && menuData.icon || ""
288 enabled: menuData && menuData.sensitive || false
309 enabled: menuData && menuData.sensitive || false
310+ backColor: Qt.rgba(1,1,1,0.07)
289 highlightWhenPressed: false
311 highlightWhenPressed: false
291 onTriggered: {
313 onTriggered: {
292 menuModel.activate(menuIndex);
314 menuModel.activate(menuIndex);
295− backColor: Qt.rgba(1,1,1,0.07)
297− component: menuData.icon ? icon : undefined
300− Icon {
317+ slots: Icon {
301− source: menuData.icon
320+ if (menuData.icon && menuData.icon != "") {
302− height: units.gu(3)
321+ return menuData.icon
303− width: height
322+ } else if (menuData.action.indexOf("settings") > -1) {
304− color: theme.palette.normal.backgroundText
323+ return "image://theme/settings"
330+ color: theme.palette.normal.backgroundText
331+ SlotsLayout.position: SlotsLayout.Trailing
@@ -769,7 +795,6 @@ Item {
769 state: getExtendedProperty(actionState, "state", "")
795 state: getExtendedProperty(actionState, "state", "")
770 enabled: menuData && menuData.sensitive || false
796 enabled: menuData && menuData.sensitive || false
771 highlightWhenPressed: false
797 highlightWhenPressed: false
774 onTriggered: {
799 onTriggered: {
775 model.activate(modelIndex);
800 model.activate(modelIndex);
@@ -972,116 +997,43 @@ Item {
972 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
997 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
975− component: Component {
976− Button {
1000+ slots: Button {
977− objectName: "buttonSectionMenuControl"
1001+ objectName: "buttonSectionMenuControl"
978− text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
1002+ text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
980− onClicked: {
1004+ onClicked: {
981− menuModel.activate(menuIndex);
1005+ menuModel.activate(menuIndex);
991− // FIXME this should use a "radio button" menu, once we have it in the SDK
994− objectName: "keymapMenu"
995− property QtObject menuData: null
996− property int menuIndex: -1
997− readonly property bool serverChecked: menuData && menuData.isToggled || false
999− enabled: menuData && menuData.sensitive || false
1000− highlightWhenPressed: false
1001− __acceptEvents: !serverChecked
1005− __acceptEvents: !checkItem.serverChecked
1008− leftMargin: checkItem.__contentsMargins
1009− verticalCenter: parent.verticalCenter
1013− ServerPropertySynchroniser {
1015− syncTimeout: Utils.Constants.indicatorValueTimeout
1017− serverTarget: checkItem
1018− serverProperty: "serverChecked"
1019− userTarget: checkbox
1020− userProperty: "checked"
1023− menuModel.activate(checkItem.menuIndex);
1030− left: checkbox.right
1031− leftMargin: checkItem.__contentsMargins
1032− right: parent.right
1033− rightMargin: checkItem.__contentsMargins
1034− verticalCenter: parent.verticalCenter
1036− elide: Text.ElideRight
1037− text: checkItem.menuData && checkItem.menuData.label || ""
1040− onClicked: menuModel.activate(menuIndex);
1044 function load(modelData, context) {
1011 function load(modelData, context) {
1045− // tweak indicator-session items
1012+ if (context && context.indexOf("fake-") == 0) {
1046− if (context === "indicator-session") {
1013+ context = context.substring("fake-".length)
1047− if ((modelData.action === "indicator.logout" || modelData.action === "indicator.suspend" || modelData.action === "indicator.hibernate" ||
1048− modelData.action === "indicator.reboot")
1049− && !Platform.isPC) {
1050− return null; // logout, suspend and hibernate hidden on devices
1054− // specialize for indicator-keyboard
1016+ var component = getComponentForIndicatorEntryAction(context, modelData.action)
1055− if (context === "indicator-keyboard") {
1017+ if (component !== undefined) {
1056− if (modelData.isRadio) {
1018+ return component
1058− } else if (modelData.action === "indicator.map" || modelData.action === "indicator.chart") {
1059− return null; // map and chart not available
1063− if (modelData.type !== undefined && modelData.type !== "") {
1021+ component = getComponentForIndicatorEntryType(context, modelData.type)
1064− var component = undefined;
1066− var contextComponents = _map[context];
1067− if (contextComponents !== undefined) {
1068− component = contextComponents[modelData.type];
1071− if (component === undefined) {
1072− component = _map["default"][modelData.type];
1074− if (component !== undefined) {
1022+ if (component !== undefined) {
1075− return component;
1023+ return component;
1077− console.debug("Don't know how to make " + modelData.type + " for " + context);
1079 if (modelData.isCheck || modelData.isRadio) {
1026 if (modelData.isCheck || modelData.isRadio) {
1080 return checkableMenu;
1027 return checkableMenu;
1082 if (modelData.isSeparator) {
1029 if (modelData.isSeparator) {
1083 return separatorMenu;
1030 return separatorMenu;
1032+ if (modelData.action !== undefined && modelData.action.indexOf("settings") > -1) {
1033+ // FIXME : At the moment, the indicators aren't using
1034+ // com.canonical.indicators.link for settings menu. Need to fudge it.
1085 return standardMenu;
1037 return standardMenu;