on xenial help sign in
Simplified MessageMenuItemFactory
commit8d05f2139aee7cdc2b16ccfb4a8ac96d80ddcf76 authorNick Dedekind <nick.dedekind@canonical.com> dateTue 9 Sep 2014, 14:40 (12 years ago) parent217aeab
1 file changed+151−155
qml/Panel/Indicators/MessageMenuItemFactory.qml+151−155
qml/Panel/Indicators/MessageMenuItemFactory.qml+151−155
@@ -24,8 +24,9 @@ import Ubuntu.Settings.Menus 0.1 as Menus
2424import QMenuModel 0.1 as QMenuModel
2525import Utils 0.1 as Utils
2626
27−Item {
27+Loader {
2828 id: messageFactoryItem
29+ objectName: "messageItem"
2930 property var menuModel: null
3031 property QtObject menuData: null
3132 property int menuIndex: -1
@@ -49,6 +50,32 @@ Item {
4950 loadAttributes();
5051 }
5152
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+
5279 function loadAttributes() {
5380 if (!menuModel || menuIndex == -1) return;
5481 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
@@ -65,175 +92,144 @@ Item {
6592 return defaultValue;
6693 }
6794
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 {
78− id: simpleMessage
79−
80− Menus.SimpleMessageMenu {
81− id: message
82− objectName: "simpleTextMessage"
83− // text
84− title: menuData && menuData.label || ""
85− time: timeFormatter.timeString
86− body: getExtendedProperty(extendedData, "xCanonicalText", "")
87− // icons
88− avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
89− icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
90− // actions
91− enabled: menuData && menuData.sensitive || false
92− removable: !selected
93− selected: messageFactoryItem.selected
94−
95− onIconActivated: {
96− menuModel.activate(menuIndex, true);
97− }
98− onDismissed: {
99− menuModel.activate(menuIndex, false);
100− }
101− onTriggered: {
102− if (selected) {
103− menuDeselected();
104− } else {
105− menuSelected();
106− }
95+ Component {
96+ id: simpleMessage
97+
98+ Menus.SimpleMessageMenu {
99+ id: message
100+ objectName: "simpleTextMessage"
101+ // text
102+ title: menuData && menuData.label || ""
103+ time: timeFormatter.timeString
104+ body: getExtendedProperty(extendedData, "xCanonicalText", "")
105+ // icons
106+ avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
107+ icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
108+ // actions
109+ enabled: menuData && menuData.sensitive || false
110+ removable: !selected
111+ selected: messageFactoryItem.selected
112+
113+ onIconActivated: {
114+ menuModel.activate(menuIndex, true);
115+ }
116+ onDismissed: {
117+ menuModel.activate(menuIndex, false);
118+ }
119+ onTriggered: {
120+ if (selected) {
121+ menuDeselected();
122+ } else {
123+ menuSelected();
107124 }
108125 }
109126 }
127+ }
110128
111− Component {
112− id: textMessage
129+ Component {
130+ id: textMessage
113131
114− Menus.TextMessageMenu {
115− id: message
116− objectName: "textMessage"
117− property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
132+ Menus.TextMessageMenu {
133+ id: message
134+ objectName: "textMessage"
135+ property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
118136
119− property var replyAction: QMenuModel.UnityMenuAction {
120− model: menuModel
121− index: menuIndex
122− 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− }
137+ property var replyAction: QMenuModel.UnityMenuAction {
138+ model: menuModel
139+ index: menuIndex
140+ name: getExtendedProperty(replyActionDescription, "name", "")
155141 }
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− }
176142
177− // text
178− title: menuData && menuData.label || ""
179− time: timeFormatter.timeString
180− body: getExtendedProperty(extendedData, "xCanonicalText", "")
181− actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
182− replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
183− // icons
184− avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
185− icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/missed-call")
186− // actions
187− actionEnabled: activateAction.valid && activateAction.enabled
188− replyEnabled: replyAction.valid && replyAction.enabled
189− enabled: menuData && menuData.sensitive || false
190− removable: !selected
191− selected: messageFactoryItem.selected
192−
193− onIconActivated: {
194− menuModel.activate(menuIndex, true);
195− }
196− onDismissed: {
197− menuModel.activate(menuIndex, false);
198− }
199− onActionActivated: {
200− activateAction.activate();
201− }
202− onReplied: {
203− replyAction.activate(value);
204− }
205− onTriggered: {
206− if (selected) {
207− menuDeselected();
208− } else {
209− menuSelected();
210− }
143+ // text
144+ title: menuData && menuData.label || ""
145+ time: timeFormatter.timeString
146+ body: getExtendedProperty(extendedData, "xCanonicalText", "")
147+ replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
148+ // icons
149+ avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
150+ icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
151+ // actions
152+ replyEnabled: replyAction.valid && replyAction.enabled
153+ enabled: menuData && menuData.sensitive || false
154+ removable: !selected
155+ selected: messageFactoryItem.selected
156+ highlightWhenPressed: false
157+
158+ onIconActivated: {
159+ menuModel.activate(menuIndex, true);
160+ }
161+ onDismissed: {
162+ menuModel.activate(menuIndex, false);
163+ }
164+ onReplied: {
165+ replyAction.activate(value);
166+ }
167+ onTriggered: {
168+ if (selected) {
169+ menuDeselected();
170+ } else {
171+ menuSelected();
211172 }
212173 }
213174 }
214175 }
215176
216− function loadMessage(actions)
217− {
218− var parameterType = ""
219− for (var actIndex in actions) {
220− var desc = actions[actIndex];
221− if (desc["parameter-type"] !== undefined) {
222− parameterType += desc["parameter-type"];
223− } else {
224− parameterType += "_";
177+ Component {
178+ id: snapDecision
179+
180+ Menus.SnapDecisionMenu {
181+ id: message
182+ objectName: "snapDecision"
183+ property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
184+ property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
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", "")
225195 }
226− }
227196
228− if (parameterType === "") {
229− return simpleMessage;
230− } else if (parameterType === "s") {
231− return textMessage;
232− } else if (parameterType === "_s") {
233− return snapDecision;
234− } else {
235− console.debug("Unknown paramater type: " + parameterType);
197+ // text
198+ title: menuData && menuData.label || ""
199+ time: timeFormatter.timeString
200+ body: getExtendedProperty(extendedData, "xCanonicalText", "")
201+ actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
202+ replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
203+ // icons
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+ }
236233 }
237− return undefined;
238234 }
239235}