on 42b1bfc help sign in
106 lines 4.1 kB history raw
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 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
20import QtQuick 2.0
21import IndicatorsClient 0.1 as IC
22import IndicatorsClient.Messaging 0.1 as ICMessaging
23import IndicatorsClient.Network 0.1 as ICNetwork
25Item {
26 id: __menuFactory
28 property QtObject menu
29 property QtObject listView
30 property QtObject actionGroup
31 property bool isCurrentItem
32 readonly property bool empty: (__loader.item !== undefined && __loader.status == Loader.Ready) ? __loader.item.state === "EMPTY" : true
34 implicitHeight: (__loader.status === Loader.Ready) ? __loader.item.implicitHeight : 0
36 signal selectItem(int targetIndex)
38 property var _map: {
39 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
40 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
42 "com.canonical.indicator.button" : buttonMenu,
43 "com.canonical.indicator.div" : divMenu,
44 "com.canonical.indicator.section" : sectionMenu,
45 "com.canonical.indicator.progress" : progressMenu,
46 "com.canonical.indicator.slider" : sliderMenu,
47 "com.canonical.indicator.switch" : switchMenu,
49 "com.canonical.indicator.messages.messageitem" : messageItem,
50 "com.canonical.indicator.messages.snapdecision" : snapDecision,
51 "com.canonical.indicator.messages.sourceitem" : groupedMessage,
53 "unity.widget.systemsettings.tablet.sectiontitle" : wifiSection,
54 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
55 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
56 }
58 Component { id: sliderMenu; IC.SliderMenu {} }
59 Component { id: switchMenu; IC.SwitchMenu {} }
60 Component { id: buttonMenu; IC.ButtonMenu {} }
61 Component { id: divMenu; IC.DivMenu {} }
62 Component { id: sectionMenu; IC.SectionMenu {} }
63 Component { id: progressMenu; IC.ProgressMenu {} }
64 Component { id: messageItem; ICMessaging.MessageItem {} }
65 Component { id: snapDecision; ICMessaging.SnapDecision {} }
66 Component { id: groupedMessage; ICMessaging.GroupedMessage {} }
67 Component { id: wifiSection; ICNetwork.WifiSection {} }
68 Component { id: accessPoint; ICNetwork.AccessPoint {} }
69 Component { id: indicatorMenu; IC.Menu {} }
71 Loader {
72 id: __loader
73 anchors.fill: parent
74 asynchronous: true
75 sourceComponent: {
76 if (!__menuFactory.menu || !__menuFactory.menu.extra) {
77 return undefined
78 }
80 var widgetType = __menuFactory.menu.extra.canonical_type
81 if (widgetType) {
82 return _map[widgetType]
83 }
84 else {
85 if (widgetType === "com.canonical.indicator.root") {
86 return undefined
87 // Try discovery the item based on the basic properties
88 } else if (menu.hasSection) {
89 return sectionMenu
90 }
91 else {
92 return indicatorMenu
93 }
94 }
95 return undefined
96 }
98 onStatusChanged: {
99 if (status == Loader.Ready) {
100 item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
101 item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
102 item.menu = Qt.binding(function() { return __menuFactory.menu; });
103 }
104 }
105 }