@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013,2015 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -31,7 +31,8 @@ Item {
3131 property var rootModel: null
3232 property var menuModel: null
3333
34− property var _map: {
34+ property var _userMap: null
35+ readonly property var _typeToComponent: {
3536 "default": {
3637 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
3738 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
@@ -69,11 +70,62 @@ Item {
6970 "indicator.guest-menu-item": Platform.isPC ? userMenuItem : null,
7071 "com.canonical.indicator.switch": Math.min(Screen.width, Screen.height) > units.gu(60) ? switchMenu : null // Desktop mode switch
7172 },
72− "indicator-messages" : {
73− "com.canonical.indicator.button" : messagesButtonMenu
73+ "indicator-messages": {
74+ "com.canonical.indicator.button": messagesButtonMenu
7475 }
7576 }
7677
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
84+ },
85+ "indicator-keyboard": {
86+ "indicator.map": null,
87+ "indicator.chart": null
88+ }
89+ }
90+
91+ function getComponentForIndicatorEntryType(indicator, type) {
92+ var component = undefined;
93+ var map = _userMap || _typeToComponent
94+ var indicatorComponents = map[indicator];
95+
96+ if (type === undefined || type === "") {
97+ return component
98+ }
99+
100+ if (indicatorComponents !== undefined) {
101+ component = indicatorComponents[type];
102+ }
103+
104+ if (component === undefined) {
105+ component = map["default"][type];
106+ }
107+
108+ if (component === undefined) {
109+ console.debug("Don't know how to make " + modelData.type + " for " + indicator);
110+ }
111+
112+ return component
113+ }
114+
115+ function getComponentForIndicatorEntryAction(indicator, action) {
116+ var component = undefined;
117+ var indicatorFilter = _action_filter_map[indicator]
118+
119+ if (action === undefined || action === "") {
120+ return component
121+ }
122+
123+ if (indicatorFilter !== undefined) {
124+ component = indicatorFilter[action];
125+ }
126+ return component
127+ }
128+
77129 function getExtendedProperty(object, propertyName, defaultValue) {
78130 if (object && object.hasOwnProperty(propertyName)) {
79131 return object[propertyName];
@@ -102,7 +154,6 @@ Item {
102154 property var serverValue: getExtendedProperty(menuData, "actionState", undefined)
103155
104156 text: menuData && menuData.label || ""
105− iconSource: menuData && menuData.icon || ""
106157 minIcon: getExtendedProperty(extendedData, "minIcon", "")
107158 maxIcon: getExtendedProperty(extendedData, "maxIcon", "")
108159
@@ -182,29 +233,20 @@ Item {
182233 Component {
183234 id: messagesButtonMenu;
184235
185− Item {
236+ Menus.BaseLayoutMenu {
186237 objectName: "messagesButtonMenu"
187238 property QtObject menuData: null
188239 property var menuModel: menuFactory.menuModel
189240 property int menuIndex: -1
190241
191− implicitHeight: units.gu(5)
242+ highlightWhenPressed: false
192243 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
193248
194− Label {
195− id: buttonMenuLabel
196− text: menuData && menuData.label || ""
197− anchors.centerIn: parent
198− font.bold: true
199− }
200−
201− MouseArea {
202− anchors {
203− fill: buttonMenuLabel
204− margins: units.gu(-1)
205− }
206− onClicked: menuModel.activate(menuIndex);
207− }
249+ onClicked: menuModel.activate(menuIndex);
208250 }
209251 }
210252
@@ -233,11 +275,6 @@ Item {
233275 iconSource: menuData && menuData.icon || ""
234276 value : menuData && menuData.actionState || 0.0
235277 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
241278 }
242279 }
243280
@@ -257,52 +294,41 @@ Item {
257294 onTriggered: {
258295 menuModel.activate(menuIndex);
259296 }
260−
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
266− Component {
267− id: buttonForSettings
268− Icon {
269− name: "settings"
270− height: units.gu(3)
271− width: height
272− color: theme.palette.normal.backgroundText
273− }
274− }
275297 }
276298 }
277299
278300 Component {
279301 id: linkMenu;
280302
281− Menus.StandardMenu {
303+ Menus.BaseLayoutMenu {
282304 objectName: "linkMenu"
283305 property QtObject menuData: null
284306 property int menuIndex: -1
285307
286308 text: menuData && menuData.label || ""
287− iconSource: menuData && menuData.icon || ""
288309 enabled: menuData && menuData.sensitive || false
310+ backColor: Qt.rgba(1,1,1,0.07)
289311 highlightWhenPressed: false
290312
291313 onTriggered: {
292314 menuModel.activate(menuIndex);
293315 }
294316
295− backColor: Qt.rgba(1,1,1,0.07)
296−
297− component: menuData.icon ? icon : undefined
298− Component {
299− id: icon
300− Icon {
301− source: menuData.icon
302− height: units.gu(3)
303− width: height
304− color: theme.palette.normal.backgroundText
317+ slots: Icon {
318+ source: {
319+ if (menuData) {
320+ if (menuData.icon && menuData.icon != "") {
321+ return menuData.icon
322+ } else if (menuData.action.indexOf("settings") > -1) {
323+ return "image://theme/settings"
324+ }
325+ }
326+ return ""
305327 }
328+ height: units.gu(3)
329+ width: height
330+ color: theme.palette.normal.backgroundText
331+ SlotsLayout.position: SlotsLayout.Trailing
306332 }
307333 }
308334 }
@@ -769,7 +795,6 @@ Item {
769795 state: getExtendedProperty(actionState, "state", "")
770796 enabled: menuData && menuData.sensitive || false
771797 highlightWhenPressed: false
772− showDivider: false
773798
774799 onTriggered: {
775800 model.activate(modelIndex);
@@ -972,116 +997,43 @@ Item {
972997 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
973998 }
974999
975− component: Component {
976− Button {
977− objectName: "buttonSectionMenuControl"
978− text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
1000+ slots: Button {
1001+ objectName: "buttonSectionMenuControl"
1002+ text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
9791003
980− onClicked: {
981− menuModel.activate(menuIndex);
982− }
1004+ onClicked: {
1005+ menuModel.activate(menuIndex);
9831006 }
9841007 }
9851008 }
9861009 }
9871010
988− Component {
989− id: keymapMenu;
990−
991− // FIXME this should use a "radio button" menu, once we have it in the SDK
992− ListItems.Empty {
993− id: checkItem
994− objectName: "keymapMenu"
995− property QtObject menuData: null
996− property int menuIndex: -1
997− readonly property bool serverChecked: menuData && menuData.isToggled || false
998−
999− enabled: menuData && menuData.sensitive || false
1000− highlightWhenPressed: false
1001− __acceptEvents: !serverChecked
1002−
1003− CheckBox {
1004− id: checkbox
1005− __acceptEvents: !checkItem.serverChecked
1006− anchors {
1007− left: parent.left
1008− leftMargin: checkItem.__contentsMargins
1009− verticalCenter: parent.verticalCenter
1010− }
1011− }
1012−
1013− ServerPropertySynchroniser {
1014− objectName: "sync"
1015− syncTimeout: Utils.Constants.indicatorValueTimeout
1016−
1017− serverTarget: checkItem
1018− serverProperty: "serverChecked"
1019− userTarget: checkbox
1020− userProperty: "checked"
1021−
1022− onSyncTriggered: {
1023− menuModel.activate(checkItem.menuIndex);
1024− }
1025− }
1026−
1027− Label {
1028− id: label
1029− anchors {
1030− left: checkbox.right
1031− leftMargin: checkItem.__contentsMargins
1032− right: parent.right
1033− rightMargin: checkItem.__contentsMargins
1034− verticalCenter: parent.verticalCenter
1035− }
1036− elide: Text.ElideRight
1037− text: checkItem.menuData && checkItem.menuData.label || ""
1038− }
1039−
1040− onClicked: menuModel.activate(menuIndex);
1041− }
1042− }
1043−
10441011 function load(modelData, context) {
1045− // tweak indicator-session items
1046− if (context === "indicator-session") {
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
1051− }
1012+ if (context && context.indexOf("fake-") == 0) {
1013+ context = context.substring("fake-".length)
10521014 }
10531015
1054− // specialize for indicator-keyboard
1055− if (context === "indicator-keyboard") {
1056− if (modelData.isRadio) {
1057− return keymapMenu;
1058− } else if (modelData.action === "indicator.map" || modelData.action === "indicator.chart") {
1059− return null; // map and chart not available
1060− }
1016+ var component = getComponentForIndicatorEntryAction(context, modelData.action)
1017+ if (component !== undefined) {
1018+ return component
10611019 }
10621020
1063− if (modelData.type !== undefined && modelData.type !== "") {
1064− var component = undefined;
1065−
1066− var contextComponents = _map[context];
1067− if (contextComponents !== undefined) {
1068− component = contextComponents[modelData.type];
1069− }
1070−
1071− if (component === undefined) {
1072− component = _map["default"][modelData.type];
1073− }
1074− if (component !== undefined) {
1075− return component;
1076− }
1077− console.debug("Don't know how to make " + modelData.type + " for " + context);
1021+ component = getComponentForIndicatorEntryType(context, modelData.type)
1022+ if (component !== undefined) {
1023+ return component;
10781024 }
1025+
10791026 if (modelData.isCheck || modelData.isRadio) {
10801027 return checkableMenu;
10811028 }
10821029 if (modelData.isSeparator) {
10831030 return separatorMenu;
10841031 }
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.
1035+ return linkMenu;
1036+ }
10851037 return standardMenu;
10861038 }
10871039}