2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Olivier Tilloy <olivier.tilloy@canonical.com>
22 import Ubuntu.Components 1.3
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 objectName: "messageItem"
30 property var menuModel: null
31 property QtObject menuData: null
32 property int menuIndex: -1
34 property bool selected: false
40 property var extendedData: menuData && menuData.ext || undefined
41 property var actionsDescription: getExtendedProperty(extendedData, "xCanonicalMessageActions", undefined)
42 property date time: new Date(getExtendedProperty(extendedData, "xCanonicalTime", 0) / 1000)
43 property string timeString: i18n.relativeDateTime(time)
46 frequency: LiveTimer.Relative
47 relativeTime: priv.time
48 onTrigger: priv.timeString = Qt.binding(function() { return i18n.relativeDateTime(priv.time); })
58 sourceComponent: loadMessage(priv.actionsDescription)
60 function loadMessage(actions)
62 var parameterType = ""
63 for (var actIndex in actions) {
64 var desc = actions[actIndex];
65 if (desc["parameter-type"] !== undefined) {
66 parameterType += desc["parameter-type"];
72 if (parameterType === "") {
74 } else if (parameterType === "s") {
76 } else if (parameterType === "_s") {
79 console.debug("Unknown paramater type: " + parameterType);
84 function loadAttributes() {
85 if (!menuModel || menuIndex == -1) return;
86 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
87 'x-canonical-text': 'string',
88 'x-canonical-message-actions': 'variant',
90 'x-canonical-app-icon': 'icon'});
93 function getExtendedProperty(object, propertyName, defaultValue) {
94 if (object && object.hasOwnProperty(propertyName)) {
95 return object[propertyName];
103 Menus.SimpleMessageMenu {
105 objectName: "simpleTextMessage"
107 title: menuData && menuData.label || ""
108 time: priv.timeString
109 body: getExtendedProperty(priv.extendedData, "xCanonicalText", "")
111 avatar: getExtendedProperty(priv.extendedData, "icon", "image://theme/contact")
112 icon: getExtendedProperty(priv.extendedData, "xCanonicalAppIcon", "image://theme/message")
114 enabled: menuData && menuData.sensitive || false
117 selected: messageFactoryItem.selected
120 menuModel.activate(menuIndex, true);
123 menuModel.activate(menuIndex, false);
138 Menus.TextMessageMenu {
140 objectName: "textMessage"
141 property var replyActionDescription: priv.actionsDescription && priv.actionsDescription.length > 0 ?
142 priv.actionsDescription[0] :
145 property var replyAction: QMenuModel.UnityMenuAction {
148 name: getExtendedProperty(replyActionDescription, "name", "")
152 title: menuData && menuData.label || ""
153 time: priv.timeString
154 body: getExtendedProperty(priv.extendedData, "xCanonicalText", "")
155 replyButtonText: getExtendedProperty(replyActionDescription, "label", i18n.ctr("Button: Send a reply message", "Send"))
156 replyHintText: i18n.ctr("Label: Hint in message indicator line edit", "Reply")
158 avatar: getExtendedProperty(priv.extendedData, "icon", "image://theme/contact")
159 icon: getExtendedProperty(priv.extendedData, "xCanonicalAppIcon", "image://theme/message")
161 replyEnabled: replyAction.valid && replyAction.enabled
162 enabled: menuData && menuData.sensitive || false
165 selected: messageFactoryItem.selected
166 highlightWhenPressed: false
169 menuModel.activate(menuIndex, true);
172 menuModel.activate(menuIndex, false);
175 replyAction.activate(value);
190 Menus.SnapDecisionMenu {
192 objectName: "snapDecision"
193 property var activateActionDescription: priv.actionsDescription && priv.actionsDescription.length > 0 ?
194 priv.actionsDescription[0] : undefined
195 property var replyActionDescription: priv.actionsDescription && priv.actionsDescription.length > 1 ?
196 priv.actionsDescription[1] : undefined
198 property var activateAction: QMenuModel.UnityMenuAction {
201 name: getExtendedProperty(activateActionDescription, "name", "")
203 property var replyAction: QMenuModel.UnityMenuAction {
206 name: getExtendedProperty(replyActionDescription, "name", "")
210 title: menuData && menuData.label || ""
211 time: priv.timeString
212 body: getExtendedProperty(priv.extendedData, "xCanonicalText", "")
213 actionButtonText: getExtendedProperty(activateActionDescription, "label", i18n.ctr("Button: Call back on phone", "Call back"))
214 replyButtonText: getExtendedProperty(replyActionDescription, "label", i18n.ctr("Button: Send a reply message", "Send"))
216 avatar: getExtendedProperty(priv.extendedData, "icon", "image://theme/contact")
217 icon: getExtendedProperty(priv.extendedData, "xCanonicalAppIcon", "image://theme/missed-call")
219 actionEnabled: activateAction.valid && activateAction.enabled
220 replyEnabled: replyAction.valid && replyAction.enabled
221 enabled: menuData && menuData.sensitive || false
224 selected: messageFactoryItem.selected
225 highlightWhenPressed: false
228 menuModel.activate(menuIndex, true);
231 menuModel.activate(menuIndex, false);
234 activateAction.activate();
237 replyAction.activate(value);