on xenial help sign in
Simplified MessageMenuItemFactory
8d05f21Nick Dedekind
qml/Panel/Indicators/MessageMenuItemFactory.qml+151−155
@@ -24,8 +24,9 @@ import Ubuntu.Settings.Menus 0.1 as Menus
24import QMenuModel 0.1 as QMenuModel
24import QMenuModel 0.1 as QMenuModel
25import Utils 0.1 as Utils
25import Utils 0.1 as Utils
26
26
27−Item {
27+Loader {
28 id: messageFactoryItem
28 id: messageFactoryItem
29+ objectName: "messageItem"
29 property var menuModel: null
30 property var menuModel: null
30 property QtObject menuData: null
31 property QtObject menuData: null
31 property int menuIndex: -1
32 property int menuIndex: -1
@@ -49,6 +50,32 @@ Item {
49 loadAttributes();
50 loadAttributes();
50 }
51 }
51
52
53+ sourceComponent: loadMessage(actionsDescription)
54+
55+ function loadMessage(actions)
56+ {
57+ var parameterType = ""
58+ for (var actIndex in actions) {
59+ var desc = actions[actIndex];
60+ if (desc["parameter-type"] !== undefined) {
61+ parameterType += desc["parameter-type"];
62+ } else {
63+ parameterType += "_";
64+ }
65+ }
66+
67+ if (parameterType === "") {
68+ return simpleMessage;
69+ } else if (parameterType === "s") {
70+ return textMessage;
71+ } else if (parameterType === "_s") {
72+ return snapDecision;
73+ } else {
74+ console.debug("Unknown paramater type: " + parameterType);
75+ }
76+ return undefined;
77+ }
78+
52 function loadAttributes() {
79 function loadAttributes() {
53 if (!menuModel || menuIndex == -1) return;
80 if (!menuModel || menuIndex == -1) return;
54 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
81 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
@@ -65,175 +92,144 @@ Item {
65 return defaultValue;
92 return defaultValue;
66 }
93 }
67
94
68− implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
69−
70− Loader {
71− id: contents
72− objectName: "loader"
73− anchors.fill: parent
74−
75− sourceComponent: loadMessage(actionsDescription);
76−
77− Component {
95+ Component {
78− id: simpleMessage
96+ id: simpleMessage
79−
97+
80− Menus.SimpleMessageMenu {
98+ Menus.SimpleMessageMenu {
81− id: message
99+ id: message
82− objectName: "simpleTextMessage"
100+ objectName: "simpleTextMessage"
83− // text
101+ // text
84− title: menuData && menuData.label || ""
102+ title: menuData && menuData.label || ""
85− time: timeFormatter.timeString
103+ time: timeFormatter.timeString
86− body: getExtendedProperty(extendedData, "xCanonicalText", "")
104+ body: getExtendedProperty(extendedData, "xCanonicalText", "")
87− // icons
105+ // icons
88− avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
106+ avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
89− icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
107+ icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
90− // actions
108+ // actions
91− enabled: menuData && menuData.sensitive || false
109+ enabled: menuData && menuData.sensitive || false
92− removable: !selected
110+ removable: !selected
93− selected: messageFactoryItem.selected
111+ selected: messageFactoryItem.selected
94−
112+
95− onIconActivated: {
113+ onIconActivated: {
96− menuModel.activate(menuIndex, true);
114+ menuModel.activate(menuIndex, true);
97− }
115+ }
98− onDismissed: {
116+ onDismissed: {
99− menuModel.activate(menuIndex, false);
117+ menuModel.activate(menuIndex, false);
100− }
118+ }
101− onTriggered: {
119+ onTriggered: {
102− if (selected) {
120+ if (selected) {
103− menuDeselected();
121+ menuDeselected();
104− } else {
122+ } else {
105− menuSelected();
123+ menuSelected();
106− }
107 }
124 }
108 }
125 }
109 }
126 }
127+ }
110
128
111− Component {
129+ Component {
112− id: textMessage
130+ id: textMessage
113
131
114− Menus.TextMessageMenu {
132+ Menus.TextMessageMenu {
115− id: message
133+ id: message
116− objectName: "textMessage"
134+ objectName: "textMessage"
117− property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
135+ property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
118
136
119− property var replyAction: QMenuModel.UnityMenuAction {
137+ property var replyAction: QMenuModel.UnityMenuAction {
120− model: menuModel
138+ model: menuModel
121− index: menuIndex
139+ index: menuIndex
122− name: getExtendedProperty(replyActionDescription, "name", "")
140+ name: getExtendedProperty(replyActionDescription, "name", "")
123− }
124−
125− // text
126− title: menuData && menuData.label || ""
127− time: timeFormatter.timeString
128− body: getExtendedProperty(extendedData, "xCanonicalText", "")
129− replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
130− // icons
131− avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
132− icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
133− // actions
134− replyEnabled: replyAction.valid && replyAction.enabled
135− enabled: menuData && menuData.sensitive || false
136− removable: !selected
137− selected: messageFactoryItem.selected
138−
139− onIconActivated: {
140− menuModel.activate(menuIndex, true);
141− }
142− onDismissed: {
143− menuModel.activate(menuIndex, false);
144− }
145− onReplied: {
146− replyAction.activate(value);
147− }
148− onTriggered: {
149− if (selected) {
150− menuDeselected();
151− } else {
152− menuSelected();
153− }
154− }
155 }
141 }
156− }
157− Component {
158− id: snapDecision
159−
160− Menus.SnapDecisionMenu {
161− id: message
162− objectName: "snapDecision"
163− property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
164− property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
165−
166− property var activateAction: QMenuModel.UnityMenuAction {
167− model: menuModel
168− index: menuIndex
169− name: getExtendedProperty(activateActionDescription, "name", "")
170− }
171− property var replyAction: QMenuModel.UnityMenuAction {
172− model: menuModel
173− index: menuIndex
174− name: getExtendedProperty(replyActionDescription, "name", "")
175− }
176
142
177− // text
143+ // text
178− title: menuData && menuData.label || ""
144+ title: menuData && menuData.label || ""
179− time: timeFormatter.timeString
145+ time: timeFormatter.timeString
180− body: getExtendedProperty(extendedData, "xCanonicalText", "")
146+ body: getExtendedProperty(extendedData, "xCanonicalText", "")
181− actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
182− replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
147+ replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
183− // icons
148+ // icons
184− avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
149+ avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
185− icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/missed-call")
150+ icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
186− // actions
151+ // actions
187− actionEnabled: activateAction.valid && activateAction.enabled
188− replyEnabled: replyAction.valid && replyAction.enabled
152+ replyEnabled: replyAction.valid && replyAction.enabled
189− enabled: menuData && menuData.sensitive || false
153+ enabled: menuData && menuData.sensitive || false
190− removable: !selected
154+ removable: !selected
191− selected: messageFactoryItem.selected
155+ selected: messageFactoryItem.selected
192−
156+ highlightWhenPressed: false
157+
193− onIconActivated: {
158+ onIconActivated: {
194− menuModel.activate(menuIndex, true);
159+ menuModel.activate(menuIndex, true);
195− }
160+ }
196− onDismissed: {
161+ onDismissed: {
197− menuModel.activate(menuIndex, false);
162+ menuModel.activate(menuIndex, false);
198− }
199− onActionActivated: {
200− activateAction.activate();
201− }
163+ }
202− onReplied: {
164+ onReplied: {
203− replyAction.activate(value);
165+ replyAction.activate(value);
204− }
166+ }
205− onTriggered: {
167+ onTriggered: {
206− if (selected) {
168+ if (selected) {
207− menuDeselected();
169+ menuDeselected();
208− } else {
170+ } else {
209− menuSelected();
171+ menuSelected();
210− }
211 }
172 }
212 }
173 }
213 }
174 }
214 }
175 }
215
176
216− function loadMessage(actions)
177+ Component {
217− {
178+ id: snapDecision
218− var parameterType = ""
179+
219− for (var actIndex in actions) {
180+ Menus.SnapDecisionMenu {
220− var desc = actions[actIndex];
181+ id: message
221− if (desc["parameter-type"] !== undefined) {
182+ objectName: "snapDecision"
222− parameterType += desc["parameter-type"];
183+ property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
223− } else {
184+ property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
224− parameterType += "_";
185+
186+ property var activateAction: QMenuModel.UnityMenuAction {
187+ model: menuModel
188+ index: menuIndex
189+ name: getExtendedProperty(activateActionDescription, "name", "")
190+ }
191+ property var replyAction: QMenuModel.UnityMenuAction {
192+ model: menuModel
193+ index: menuIndex
194+ name: getExtendedProperty(replyActionDescription, "name", "")
225 }
195 }
226− }
227
196
228− if (parameterType === "") {
197+ // text
229− return simpleMessage;
198+ title: menuData && menuData.label || ""
230− } else if (parameterType === "s") {
199+ time: timeFormatter.timeString
231− return textMessage;
200+ body: getExtendedProperty(extendedData, "xCanonicalText", "")
232− } else if (parameterType === "_s") {
201+ actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
233− return snapDecision;
202+ replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
234− } else {
203+ // icons
235− console.debug("Unknown paramater type: " + parameterType);
204+ avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
205+ icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/missed-call")
206+ // actions
207+ actionEnabled: activateAction.valid && activateAction.enabled
208+ replyEnabled: replyAction.valid && replyAction.enabled
209+ enabled: menuData && menuData.sensitive || false
210+ removable: !selected
211+ selected: messageFactoryItem.selected
212+ highlightWhenPressed: false
213+
214+ onIconActivated: {
215+ menuModel.activate(menuIndex, true);
216+ }
217+ onDismissed: {
218+ menuModel.activate(menuIndex, false);
219+ }
220+ onActionActivated: {
221+ activateAction.activate();
222+ }
223+ onReplied: {
224+ replyAction.activate(value);
225+ }
226+ onTriggered: {
227+ if (selected) {
228+ menuDeselected();
229+ } else {
230+ menuSelected();
231+ }
232+ }
236 }
233 }
237− return undefined;
238 }
234 }
239}
235}