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")
150 avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
151 icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/message")
153 replyEnabled: replyAction.valid && replyAction.enabled
154 enabled: menuData && menuData.sensitive || false
157 selected: messageFactoryItem.selected
158 highlightWhenPressed: false
161 menuModel.activate(menuIndex, true);
164 menuModel.activate(menuIndex, false);
167 replyAction.activate(value);
182 Menus.SnapDecisionMenu {
184 objectName: "snapDecision"
185 property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
186 property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
188 property var activateAction: QMenuModel.UnityMenuAction {
191 name: getExtendedProperty(activateActionDescription, "name", "")
193 property var replyAction: QMenuModel.UnityMenuAction {
196 name: getExtendedProperty(replyActionDescription, "name", "")
200 title: menuData && menuData.label || ""
201 time: timeFormatter.timeString
202 body: getExtendedProperty(extendedData, "xCanonicalText", "")
203 actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
204 replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
206 avatar: getExtendedProperty(extendedData, "icon", "image://theme/contact")
207 icon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "image://theme/missed-call")
209 actionEnabled: activateAction.valid && activateAction.enabled
210 replyEnabled: replyAction.valid && replyAction.enabled
211 enabled: menuData && menuData.sensitive || false
214 selected: messageFactoryItem.selected
215 highlightWhenPressed: false
218 menuModel.activate(menuIndex, true);
221 menuModel.activate(menuIndex, false);
224 activateAction.activate();
227 replyAction.activate(value);