on xenial help sign in
Indicator visibility based on connection state with backend. Filter invisible indicators from tab model.
commit9149a617fc10aa2fe1214a32728d32e8fa47c325 authorNick Dedekind <nicholas.dedekind@gmail.com> dateThu 15 Aug 2013, 17:04 (13 years ago) parentf4717ef
11 files changed+53−16
Panel/IndicatorItem.qml+3−2 Panel/IndicatorRow.qml+5 Panel/Indicators.qml+16−2 Panel/Indicators/DatetimeIndicatorWidget.qml+4−2 Panel/Indicators/DefaultIndicatorWidget.qml+1 Panel/Indicators/NetworkIndicatorWidget.qml+3 Panel/Indicators/SoundIndicatorWidget.qml+1 Panel/MenuContent.qml+17−5 plugins/Unity/Indicators/qml/IndicatorBase.qml−3 plugins/Unity/Indicators/qml/IndicatorWidget.qml+1 plugins/Unity/IndicatorsLegacy/qml/IndicatorWidget.qml+2−2
Panel/IndicatorItem.qml+3−2
@@ -26,13 +26,14 @@ Item {
2626 property bool highlighted: false
2727 property bool dimmed: false
2828 property var indicatorProperties: undefined
29+ property bool indicatorVisible: loader.item != undefined && loader.status == Loader.Ready ? loader.item.enabled : false
2930
3031 opacity: dimmed ? 0.4 : 1
3132 Behavior on opacity { StandardAnimation {} }
3233
3334 // only visible when non-empty
34− visible: loader.item != undefined && loader.status == Loader.Ready ? loader.item.enabled : false
35− width: visible ? loader.item.width : 0
35+ visible: indicatorVisible
36+ width: indicatorVisible ? loader.item.width : 0
3637
3738 Loader {
3839 id: loader
Panel/IndicatorRow.qml+5
@@ -16,6 +16,7 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
19+import Unity.Indicators 0.1 as Indicators
1920import "../Components"
2021
2122Item {
@@ -70,6 +71,10 @@ Item {
7071
7172 widgetSource: model.widgetSource
7273 indicatorProperties : model.indicatorProperties
74+
75+ onIndicatorVisibleChanged: {
76+ indicatorsModel.setData(index, indicatorVisible, Indicators.IndicatorsModelRole.IsVisible);
77+ }
7378 }
7479
7580 opacity: {
Panel/Indicators.qml+16−2
@@ -180,9 +180,16 @@ Showable {
180180 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
181181
182182 Connections {
183− target: indicatorRow
183+ property bool enableIndexChangeSignal: true
184+
185+ target: enableIndexChangeSignal ? indicatorRow : null
184186 onCurrentItemIndexChanged: {
187+ var oldActive = enableIndexChangeSignal;
188+ enableIndexChangeSignal = false;
189+
185190 menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex);
191+
192+ enableIndexChangeSignal = oldActive;
186193 }
187194 }
188195
@@ -254,9 +261,16 @@ Showable {
254261 state: indicators.state
255262
256263 Connections {
257− target: menuContent
264+ property bool enableIndexChangeSignal: true
265+
266+ target: enableIndexChangeSignal ? menuContent : null
258267 onCurrentMenuIndexChanged: {
268+ var oldActive = enableIndexChangeSignal;
269+ enableIndexChangeSignal = false;
270+
259271 indicatorRow.setCurrentItem(menuContent.currentMenuIndex);
272+
273+ enableIndexChangeSignal = oldActive;
260274 }
261275 }
262276 }
Panel/Indicators/DatetimeIndicatorWidget.qml+4−2
@@ -25,6 +25,7 @@ Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
2727 width: timeLabel.width + units.gu(1)
28+ rootMenuType: "com.canonical.indicator.root.time"
2829
2930 property alias label: timeLabel.text
3031
@@ -52,14 +53,15 @@ Indicators.IndicatorWidget {
5253
5354 onActionStateChanged: {
5455 if (action == undefined || !action.valid) {
56+ enabled = false;
5557 return;
5658 }
5759
5860 if (action.state == undefined) {
59− visible = false;
61+ enabled = false;
6062 return;
6163 }
6264
63− indicatorWidget.visible = action.state[3];
65+ enabled = action.state[3];
6466 }
6567}
Panel/Indicators/DefaultIndicatorWidget.qml+1
@@ -63,6 +63,7 @@ Indicators.IndicatorWidget {
6363
6464 onActionStateChanged: {
6565 if (action == undefined || !action.valid) {
66+ enabled = false;
6667 return;
6768 }
6869
Panel/Indicators/NetworkIndicatorWidget.qml+3
@@ -43,14 +43,17 @@ Indicators.IndicatorWidget {
4343
4444 onActionStateChanged: {
4545 if (action == undefined || !action.valid) {
46+ enabled = false;
4647 return;
4748 }
4849
4950 if (action.state == undefined) {
51+ enabled = false;
5052 connectionState = 0;
5153 return;
5254 }
5355
56+ enabled = true;
5457 connectionState = action.state[Indicators.NetworkActionState.Connection];
5558 if (connectionState == Indicators.NetworkConnection.Activated) {
5659 signalStrength = action.state[Indicators.NetworkActionState.SignalStrength];
Panel/Indicators/SoundIndicatorWidget.qml+1
@@ -22,4 +22,5 @@ import QtQuick 2.0
2222DefaultIndicatorWidget {
2323 // default the icon so we have something to show when we don't have the bus.
2424 iconSource: "image://gicon/audio-volume-high"
25+ enabled: true
2526}
Panel/MenuContent.qml+17−5
@@ -17,6 +17,7 @@
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Unity.Indicators 0.1 as Indicators
20+import Utils 0.1
2021import "../Components"
2122
2223// FIXME : We dont want to use MainView.
@@ -27,7 +28,7 @@ MainView {
2728
2829 property QtObject indicatorsModel: null
2930 property bool __contentActive: false
30− readonly property int currentMenuIndex : tabs.selectedTabIndex
31+ readonly property int currentMenuIndex : filteredIndicators.mapToSource(tabs.selectedTabIndex)
3132 backgroundColor: "#221e1c" // FIXME not in palette yet
3233 property int contentReleaseInterval: 20000
3334 property bool activeHeader: false
@@ -36,11 +37,13 @@ MainView {
3637 height: units.gu(42)
3738
3839 function setCurrentMenuIndex(index) {
39− if (currentMenuIndex !== index) {
40− if (currentMenuIndex == -1) {
40+ var filteredIndex = filteredIndicators.mapFromSource(index)
41+
42+ if (tabs.selectedTabIndex !== filteredIndex) {
43+ if (tabs.selectedTabIndex == -1) {
4144 tabs.tabBar.animate = false;
4245 }
43− tabs.selectedTabIndex = index;
46+ tabs.selectedTabIndex = filteredIndex;
4447 tabs.tabBar.animate = true;
4548 }
4649 }
@@ -61,6 +64,15 @@ MainView {
6164 tabs.tabBar.alwaysSelectionMode = activeHeader;
6265 }
6366
67+ SortFilterProxyModel {
68+ id: filteredIndicators
69+ model: indicatorsModel
70+ dynamicSortFilter: true
71+
72+ filterRole: Indicators.IndicatorsModelRole.IsVisible
73+ filterRegExp: RegExp("^true$")
74+ }
75+
6476 Tabs {
6577 id: tabs
6678 objectName: "tabs"
@@ -69,7 +81,7 @@ MainView {
6981
7082 Repeater {
7183 id: repeater
72− model: indicatorsModel
84+ model: filteredIndicators
7385 objectName: "menus"
7486
7587 // FIXME: This is needed because tabs dont handle repeaters well.
plugins/Unity/Indicators/qml/IndicatorBase.qml−3
@@ -39,9 +39,6 @@ Item {
3939
4040 property string deviceMenuObjectPath: menuObjectPaths.hasOwnProperty(device) ? menuObjectPaths[device] : ""
4141
42− signal actionGroupUpdated()
43− signal modelUpdated()
44−
4542 property alias menuModel: cachedModel.model
4643
4744 CachedUnityMenuModel {
plugins/Unity/Indicators/qml/IndicatorWidget.qml+1
@@ -24,6 +24,7 @@ IndicatorBase {
2424 id: indicatorWidget
2525
2626 active: true
27+ enabled: false
2728 property int iconSize: height - units.gu(0.5)
2829
2930 property var actionState: Indicators.RootActionState {
plugins/Unity/IndicatorsLegacy/qml/IndicatorWidget.qml+2−2
@@ -23,7 +23,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
2323IndicatorBase {
2424 id: indicatorWidget
2525
26−// enabled: false // FIXME : should be disabled until bus available when we have desktop indicators
26+ enabled: false // FIXME : should be disabled until bus available when we have desktop indicators
2727 property var action: undefined
2828 property bool started: (busType != 0) && (busName != "") && (deviceMenuObjectPath != "")
2929 property int iconSize: height - units.gu(0.5)
@@ -40,7 +40,6 @@ IndicatorBase {
4040 actionGroup.stop();
4141 }
4242 }
43− onActionChanged: actionStateChanged()
4443 onActionGroupUpdated: update_state()
4544 onModelUpdated: update_state()
4645
@@ -57,6 +56,7 @@ IndicatorBase {
5756
5857 if (extra.canonical_type === rootMenuType) {
5958 action = actionGroup.action(proxyModel.data(0, Indicators.FlatMenuProxyModelRole.Action));
59+ actionStateChanged();
6060 }
6161 }
6262