on xenial help sign in
Multiple icon/label support for indicators.
aee304fNick Dedekind
Panel/Indicators/DefaultIndicatorWidget.qml+1−1
@@ -24,7 +24,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
24Indicators.IndicatorWidget {
24Indicators.IndicatorWidget {
25 id: indicatorWidget
25 id: indicatorWidget
26
26
27− width: itemRow.width + units.gu(1)
27+ width: itemRow.width + units.gu(0.5)
28
28
29 property alias label: itemLabel.text
29 property alias label: itemLabel.text
30 property alias iconSource: itemImage.source
30 property alias iconSource: itemImage.source
Panel/Indicators/DefaultIndicatorWidget2.qml+43−16
@@ -24,10 +24,11 @@ import Unity.Indicators 0.1 as Indicators
24Indicators.IndicatorWidget {
24Indicators.IndicatorWidget {
25 id: indicatorWidget
25 id: indicatorWidget
26
26
27− width: itemRow.width + units.gu(1)
27+ width: itemRow.width + units.gu(0.5)
28
28
29− property alias label: itemLabel.text
29+ property alias leftLabel: itemLeftLabel.text
30− property alias iconSource: itemImage.source
30+ property alias rightLabel: itemRightLabel.text
31+ property var icons: undefined
31
32
32 Row {
33 Row {
33 id: itemRow
34 id: itemRow
@@ -39,19 +40,43 @@ Indicators.IndicatorWidget {
39 }
40 }
40 spacing: units.gu(0.5)
41 spacing: units.gu(0.5)
41
42
42− // FIXME : Should us Ubuntu.Icon . results in low res images
43+ Label {
43− Image {
44+ id: itemLeftLabel
44− id: itemImage
45− objectName: "itemImage"
45+ objectName: "leftLabel"
46− visible: source != ""
46+ color: Theme.palette.selected.backgroundText
47− height: indicatorWidget.iconSize
47+ opacity: 0.8
48− width: indicatorWidget.iconSize
48+ font.family: "Ubuntu"
49+ fontSize: "medium"
49 anchors.verticalCenter: parent.verticalCenter
50 anchors.verticalCenter: parent.verticalCenter
51+ visible: text != ""
52+ }
53+
54+ Row {
55+ width: childrenRect.width
56+ anchors {
57+ top: parent.top
58+ bottom: parent.bottom
59+ }
60+ spacing: units.gu(0.5)
61+
62+ Repeater {
63+ model: indicatorWidget.icons
64+
65+ Image {
66+ id: itemImage
67+ objectName: "itemImage"
68+ visible: source != ""
69+ source: modelData
70+ height: indicatorWidget.iconSize
71+ width: indicatorWidget.iconSize
72+ anchors.verticalCenter: parent.verticalCenter
73+ }
74+ }
50 }
75 }
51
76
52 Label {
77 Label {
53− id: itemLabel
78+ id: itemRightLabel
54− objectName: "itemLabel"
79+ objectName: "rightLabel"
55 color: Theme.palette.selected.backgroundText
80 color: Theme.palette.selected.backgroundText
56 opacity: 0.8
81 opacity: 0.8
57 font.family: "Ubuntu"
82 font.family: "Ubuntu"
@@ -63,14 +88,16 @@ Indicators.IndicatorWidget {
63
88
64 onActionStateChanged: {
89 onActionStateChanged: {
65 if (actionState == undefined) {
90 if (actionState == undefined) {
66− label = "";
91+ leftLabel = "";
67− iconSource = "";
92+ rightLabel = "";
93+ icons = undefined;
68 enabled = false;
94 enabled = false;
69 return;
95 return;
70 }
96 }
71
97
72− label = actionState.label;
98+ leftLabel = actionState.leftLabel ? actionState.leftLabel : "";
99+ rightLabel = actionState.rightLabel ? actionState.rightLabel : "";
73− iconSource = actionState.icon;
100+ icons = actionState.icons;
74 enabled = actionState.visible;
101 enabled = actionState.visible;
75 }
102 }
76}
103}
Panel/Indicators/NetworkIndicatorWidget.qml+1−1
@@ -24,7 +24,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
24Indicators.IndicatorWidget {
24Indicators.IndicatorWidget {
25 id: indicatorWidget
25 id: indicatorWidget
26
26
27− width: networkIcon.width + units.gu(1)
27+ width: networkIcon.width + units.gu(0.5)
28
28
29 property int signalStrength: 0
29 property int signalStrength: 0
30 property int connectionState: Indicators.NetworkConnection.Initial
30 property int connectionState: Indicators.NetworkConnection.Initial
plugins/Unity/Indicators/rootactionstate.cpp+44−14
@@ -108,25 +108,32 @@ bool RootActionState::isValid() const
108 return m_menu && m_menu->rowCount() > 0;
108 return m_menu && m_menu->rowCount() > 0;
109}
109}
110
110
111−QString RootActionState::label() const
111+QString RootActionState::leftLabel() const
112{
112{
113 if (!isValid()) return QString();
113 if (!isValid()) return QString();
114
114
115− return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
115+ return m_cachedState.value("pre-label", QVariant::fromValue(QString())).toString();
116}
116}
117
117
118−QString RootActionState::icon() const
118+QString RootActionState::rightLabel() const
119{
119{
120 if (!isValid()) return QString();
120 if (!isValid()) return QString();
121
121
122− return m_cachedState.value("icon", QVariant::fromValue(QString())).toString();
122+ return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
123+}
124+
125+QStringList RootActionState::icons() const
126+{
127+ if (!isValid()) return QStringList();
128+
129+ return m_cachedState.value("icons", QVariant::fromValue(QStringList())).toStringList();
123}
130}
124
131
125QString RootActionState::accessibleName() const
132QString RootActionState::accessibleName() const
126{
133{
127 if (!isValid()) return QString();
134 if (!isValid()) return QString();
128
135
129− return m_cachedState.value("accessible-name", QVariant::fromValue(QString())).toString();
136+ return m_cachedState.value("accessible-desc", QVariant::fromValue(QString())).toString();
130}
137}
131
138
132bool RootActionState::isVisible() const
139bool RootActionState::isVisible() const
@@ -198,16 +205,39 @@ QVariant RootActionState::toQVariant(GVariant* state) const
198 while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue))
205 while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue))
199 {
206 {
200 QString str = QString::fromUtf8(key);
207 QString str = QString::fromUtf8(key);
201− if (str == "icon") {
208+ if (str == "icon" && !qmap.contains("icons")) {
209+ QStringList icons;
210+
202 // FIXME - should be sending a url.
211 // FIXME - should be sending a url.
203− GIcon *icon = g_icon_deserialize (vvalue);
212+ GIcon *gicon = g_icon_deserialize (vvalue);
204− if (icon) {
213+ if (gicon) {
205− qmap.insert(str, iconUri(icon));
214+ icons << iconUri(gicon);
206− g_object_unref (icon);
215+ g_object_unref (gicon);
207 }
216 }
208− else {
209− qmap.insert(str, QVariant(""));
217+ qmap.insert("icons", icons);
218+
219+ } else if (str == "icons") {
220+
221+ QStringList icons;
222+
223+ if (g_variant_type_is_array(g_variant_get_type(vvalue))) {
224+
225+
226+ for (int i = 0, iMax = g_variant_n_children(vvalue); i < iMax; i++) {
227+ GVariant *child = g_variant_get_child_value(vvalue, i);
228+
229+ // FIXME - should be sending a url.
230+ GIcon *gicon = g_icon_deserialize (child);
231+ if (gicon) {
232+ icons << iconUri(gicon);
233+ g_object_unref (gicon);
234+ }
235+ g_variant_unref(child);
236+ }
210 }
237 }
238+ // will overwrite icon.
239+ qmap.insert("icons", icons);
240+
211 } else {
241 } else {
212 qmap.insert(str, ActionStateParser::toQVariant(vvalue));
242 qmap.insert(str, ActionStateParser::toQVariant(vvalue));
213 }
243 }
@@ -230,12 +260,12 @@ QVariant RootActionState::toQVariant(GVariant* state) const
230 &visible);
260 &visible);
231
261
232 qmap["label"] = label ? QString::fromUtf8(label) : "";
262 qmap["label"] = label ? QString::fromUtf8(label) : "";
233− qmap["accessible-name"] = accessible_name ? QString::fromUtf8(accessible_name) : "";
263+ qmap["accessible-desc"] = accessible_name ? QString::fromUtf8(accessible_name) : "";
234 qmap["visible"] = visible;
264 qmap["visible"] = visible;
235
265
236 gicon = g_icon_new_for_string (icon, NULL);
266 gicon = g_icon_new_for_string (icon, NULL);
237 if (gicon) {
267 if (gicon) {
238− qmap["icon"] = iconUri(gicon);
268+ qmap["icons"] = QStringList() << iconUri(gicon);
239 g_object_unref (gicon);
269 g_object_unref (gicon);
240 }
270 }
241
271
plugins/Unity/Indicators/rootactionstate.h+9−6
@@ -32,8 +32,9 @@ class UNITYINDICATORS_EXPORT RootActionState : public ActionStateParser
32 Q_PROPERTY(UnityMenuModel* menu READ menu WRITE setMenu NOTIFY menuChanged)
32 Q_PROPERTY(UnityMenuModel* menu READ menu WRITE setMenu NOTIFY menuChanged)
33
33
34 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
34 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
35− Q_PROPERTY(QString label READ label NOTIFY labelChanged)
35+ Q_PROPERTY(QString leftLabel READ leftLabel NOTIFY leftLabelChanged)
36− Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
36+ Q_PROPERTY(QString rightLabel READ rightLabel NOTIFY rightLabelChanged)
37+ Q_PROPERTY(QStringList icons READ icons NOTIFY iconsChanged)
37 Q_PROPERTY(QString accessibleName READ accessibleName NOTIFY accessibleNameChanged)
38 Q_PROPERTY(QString accessibleName READ accessibleName NOTIFY accessibleNameChanged)
38 Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
39 Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
39public:
40public:
@@ -47,8 +48,9 @@ public:
47 void setIndex(int index);
48 void setIndex(int index);
48
49
49 bool isValid() const;
50 bool isValid() const;
50− QString label() const;
51+ QString leftLabel() const;
51− QString icon() const;
52+ QString rightLabel() const;
53+ QStringList icons() const;
52 QString accessibleName() const;
54 QString accessibleName() const;
53 bool isVisible() const;
55 bool isVisible() const;
54
56
@@ -62,8 +64,9 @@ Q_SIGNALS:
62 void indexChanged();
64 void indexChanged();
63
65
64 void validChanged();
66 void validChanged();
65− void labelChanged();
67+ void leftLabelChanged();
66− void iconChanged();
68+ void rightLabelChanged();
69+ void iconsChanged();
67 void accessibleNameChanged();
70 void accessibleNameChanged();
68 void visibleChanged();
71 void visibleChanged();
69
72