@@ -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
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();
53+ sourceComponent: loadMessage(actionsDescription)
55+ function loadMessage(actions)
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"];
63+ parameterType += "_";
67+ if (parameterType === "") {
68+ return simpleMessage;
69+ } else if (parameterType === "s") {
71+ } else if (parameterType === "_s") {
74+ console.debug("Unknown paramater type: " + parameterType);
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;
68− implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
75− sourceComponent: loadMessage(actionsDescription);
77− Component {
95+ Component {
78− id: simpleMessage
96+ id: simpleMessage
80− Menus.SimpleMessageMenu {
98+ Menus.SimpleMessageMenu {
81− id: message
99+ id: message
82− objectName: "simpleTextMessage"
100+ objectName: "simpleTextMessage"
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
95− onIconActivated: {
113+ onIconActivated: {
96− menuModel.activate(menuIndex, true);
114+ menuModel.activate(menuIndex, true);
98− onDismissed: {
116+ onDismissed: {
99− menuModel.activate(menuIndex, false);
117+ menuModel.activate(menuIndex, false);
101− onTriggered: {
119+ onTriggered: {
102− if (selected) {
120+ if (selected) {
103− menuDeselected();
121+ menuDeselected();
104− } else {
122+ } else {
105− menuSelected();
123+ menuSelected();
111− Component {
129+ Component {
112− id: textMessage
130+ id: textMessage
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
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", "")
126− title: menuData && menuData.label || ""
127− time: timeFormatter.timeString
128− body: getExtendedProperty(extendedData, "xCanonicalText", "")
129− replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
131− avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
132− icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
134− replyEnabled: replyAction.valid && replyAction.enabled
135− enabled: menuData && menuData.sensitive || false
136− removable: !selected
137− selected: messageFactoryItem.selected
140− menuModel.activate(menuIndex, true);
143− menuModel.activate(menuIndex, false);
146− replyAction.activate(value);
160− Menus.SnapDecisionMenu {
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
166− property var activateAction: QMenuModel.UnityMenuAction {
169− name: getExtendedProperty(activateActionDescription, "name", "")
171− property var replyAction: QMenuModel.UnityMenuAction {
174− name: getExtendedProperty(replyActionDescription, "name", "")
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
193− onIconActivated: {
158+ onIconActivated: {
194− menuModel.activate(menuIndex, true);
159+ menuModel.activate(menuIndex, true);
196− onDismissed: {
161+ onDismissed: {
197− menuModel.activate(menuIndex, false);
162+ menuModel.activate(menuIndex, false);
199− onActionActivated: {
200− activateAction.activate();
202− onReplied: {
164+ onReplied: {
203− replyAction.activate(value);
165+ replyAction.activate(value);
205− onTriggered: {
167+ onTriggered: {
206− if (selected) {
168+ if (selected) {
207− menuDeselected();
169+ menuDeselected();
208− } else {
170+ } else {
209− menuSelected();
171+ menuSelected();
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 {
189+ name: getExtendedProperty(activateActionDescription, "name", "")
191+ property var replyAction: QMenuModel.UnityMenuAction {
194+ name: getExtendedProperty(replyActionDescription, "name", "")
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")
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
215+ menuModel.activate(menuIndex, true);
218+ menuModel.activate(menuIndex, false);
220+ onActionActivated: {
221+ activateAction.activate();
224+ replyAction.activate(value);