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 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 objectName: "messageItem"
30 property var menuModel: null
31 property QtObject menuData: null
32 property int menuIndex: -1
34 property bool selected: false
38 property var extendedData: menuData && menuData.ext || undefined
39 property var actionsDescription: getExtendedProperty(extendedData, "xCanonicalMessageActions", undefined)
41 // TODO - bug #1260728
42 property var timeFormatter: Utils.RelativeTimeFormatter {
43 time: getExtendedProperty(extendedData, "xCanonicalTime", 0) / 1000000
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"];
67 if (parameterType === "") {
69 } else if (parameterType === "s") {
71 } else if (parameterType === "_s") {
74 console.debug("Unknown paramater type: " + parameterType);
79 function loadAttributes() {
80 if (!menuModel || menuIndex == -1) return;
81 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
82 'x-canonical-text': 'string',
83 'x-canonical-message-actions': 'variant',
85 'x-canonical-app-icon': 'icon'});
88 function getExtendedProperty(object, propertyName, defaultValue) {
89 if (object && object.hasOwnProperty(propertyName)) {
90 return object[propertyName];
98 Menus.SimpleMessageMenu {
100 objectName: "simpleTextMessage"
102 title: menuData && menuData.label || ""
103 time: timeFormatter.timeString
104 body: getExtendedProperty(extendedData, "xCanonicalText", "")
106 avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
107 icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
109 enabled: menuData && menuData.sensitive || false
112 selected: messageFactoryItem.selected
115 menuModel.activate(menuIndex, true);
118 menuModel.activate(menuIndex, false);
133 Menus.TextMessageMenu {
135 objectName: "textMessage"
136 property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
138 property var replyAction: QMenuModel.UnityMenuAction {
141 name: getExtendedProperty(replyActionDescription, "name", "")
145 title: menuData && menuData.label || ""
146 time: timeFormatter.timeString
147 body: getExtendedProperty(extendedData, "xCanonicalText", "")
148 replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
149 replyHintText: i18n.ctr("Label: Hint in message indicator line edit", "Reply")
151 avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
152 icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
154 replyEnabled: replyAction.valid && replyAction.enabled
155 enabled: menuData && menuData.sensitive || false
158 selected: messageFactoryItem.selected
159 highlightWhenPressed: false
162 menuModel.activate(menuIndex, true);
165 menuModel.activate(menuIndex, false);
168 replyAction.activate(value);
183 Menus.SnapDecisionMenu {
185 objectName: "snapDecision"
186 property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
187 property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
189 property var activateAction: QMenuModel.UnityMenuAction {
192 name: getExtendedProperty(activateActionDescription, "name", "")
194 property var replyAction: QMenuModel.UnityMenuAction {
197 name: getExtendedProperty(replyActionDescription, "name", "")
201 title: menuData && menuData.label || ""
202 time: timeFormatter.timeString
203 body: getExtendedProperty(extendedData, "xCanonicalText", "")
204 actionButtonText: getExtendedProperty(activateActionDescription, "label", i18n.tr("Call back"))
205 replyButtonText: getExtendedProperty(replyActionDescription, "label", i18n.tr("Send"))
207 avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
208 icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/missed-call")
210 actionEnabled: activateAction.valid && activateAction.enabled
211 replyEnabled: replyAction.valid && replyAction.enabled
212 enabled: menuData && menuData.sensitive || false
215 selected: messageFactoryItem.selected
216 highlightWhenPressed: false
219 menuModel.activate(menuIndex, true);
222 menuModel.activate(menuIndex, false);
225 activateAction.activate();
228 replyAction.activate(value);