22 import Ubuntu.Components 0.1
23 import Ubuntu.Settings.Menus 0.1 as Menus
24 import QMenuModel 0.1 as QMenuModel
25 import Utils 0.1 as Utils
28 id: messageFactoryItem
29 property var menuModel: null
30 property QtObject menuData: null
31 property int menuIndex: -1
33 property bool selected:
false
37 property var extendedData: menuData && menuData.ext || undefined
38 property var actionsDescription: getExtendedProperty(extendedData,
"xCanonicalMessageActions", undefined)
41 property var timeFormatter: Utils.TimeFormatter {
42 time: getExtendedProperty(extendedData,
"xCanonicalTime", 0)
43 format: "hh:mm - MMM dd"
53 function loadAttributes() {
54 if (!menuModel || menuIndex == -1)
return;
55 menuModel.loadExtendedAttributes(menuIndex, {
'x-canonical-time':
'int64',
56 'x-canonical-text':
'string',
57 'x-canonical-message-actions':
'variant',
59 'x-canonical-app-icon':
'icon'});
62 function getExtendedProperty(
object, propertyName, defaultValue) {
63 if (
object &&
object.hasOwnProperty(propertyName)) {
64 return object[propertyName];
69 implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
76 sourceComponent: loadMessage(actionsDescription);
81 Menus.SimpleTextMessageMenu {
83 objectName:
"simpleTextMessage"
85 title: menuData && menuData.label ||
""
86 time: timeFormatter.timeString
87 message: getExtendedProperty(extendedData,
"xCanonicalText",
"")
89 avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
90 appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
92 enabled: menuData && menuData.sensitive || false
94 selected: messageFactoryItem.selected
97 menuModel.activate(menuIndex,
true);
100 menuModel.activate(menuIndex,
false);
110 backgroundIndicator: RemoveBackground {
111 state: message.swipingState
119 Menus.TextMessageMenu {
121 objectName:
"textMessage"
122 property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
124 property var replyAction: QMenuModel.UnityMenuAction {
127 name: getExtendedProperty(replyActionDescription,
"name",
"")
131 title: menuData && menuData.label ||
""
132 time: timeFormatter.timeString
133 message: getExtendedProperty(extendedData,
"xCanonicalText",
"")
134 replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
136 avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
137 appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
139 replyEnabled: replyAction.valid && replyAction.enabled
140 enabled: menuData && menuData.sensitive || false
142 selected: messageFactoryItem.selected
145 menuModel.activate(menuIndex,
true);
148 menuModel.activate(menuIndex,
false);
151 replyAction.activate(value);
161 backgroundIndicator: RemoveBackground {
162 state: message.swipingState
169 Menus.SnapDecisionMenu {
171 objectName:
"snapDecision"
172 property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
173 property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
175 property var activateAction: QMenuModel.UnityMenuAction {
178 name: getExtendedProperty(activateActionDescription,
"name",
"")
180 property var replyAction: QMenuModel.UnityMenuAction {
183 name: getExtendedProperty(replyActionDescription,
"name",
"")
187 title: menuData && menuData.label ||
""
188 time: timeFormatter.timeString
189 message: getExtendedProperty(extendedData,
"xCanonicalText",
"")
190 actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
191 replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
192 replyMessages: getExtendedProperty(replyActionDescription, "parameter-hint", "")
194 avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
195 appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
197 activateEnabled: activateAction.valid && activateAction.enabled
198 replyEnabled: replyAction.valid && replyAction.enabled
199 enabled: menuData && menuData.sensitive || false
201 selected: messageFactoryItem.selected
204 menuModel.activate(menuIndex,
true);
207 menuModel.activate(menuIndex,
false);
210 activateAction.activate();
213 replyAction.activate(value);
223 backgroundIndicator: RemoveBackground {
224 state: message.swipingState
230 function loadMessage(actions)
232 var parameterType =
""
233 for (var actIndex in actions) {
234 var desc = actions[actIndex];
235 if (desc[
"parameter-type"] !== undefined) {
236 parameterType += desc[
"parameter-type"];
238 parameterType +=
"_";
242 if (parameterType ===
"") {
243 return simpleTextMessage;
244 }
else if (parameterType ===
"s") {
246 }
else if (parameterType ===
"_s") {
249 console.debug(
"Unknown paramater type: " + parameterType);