on 78ee59a help sign in
unity8/plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml
197 lines 9.0 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Olivier Tilloy <olivier.tilloy@canonical.com>
19 */
21import QtQuick 2.0
22import Ubuntu.Components 0.1
23import Unity.Indicators 0.1 as Indicators
24import QMenuModel 0.1 as QMenuModel
26Indicators.BaseMenuItem {
27 id: messageFactoryItem
28 property var menuModel: null
29 property QtObject menuData: null
30 property var menuIndex: undefined
32 property var extAttrib: menuData && menuData.ext ? menuData.ext : undefined
33 property var actionsDescription: extAttrib && extAttrib.hasOwnProperty("xCanonicalMessageActions") ? extAttrib.xCanonicalMessageActions : undefined
35 onMenuModelChanged: {
36 loadAttributes();
37 }
38 onMenuIndexChanged: {
39 loadAttributes();
40 }
42 function loadAttributes() {
43 if (!menuModel || menuIndex == undefined) return;
45 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-time': 'int64',
46 'x-canonical-text': 'string',
47 'x-canonical-message-actions': 'variant',
48 'icon': 'icon',
49 'x-canonical-app-icon': 'icon'});
50 }
52 implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
54 Loader {
55 id: contents
56 anchors.fill: parent
58 sourceComponent: loadMessage(actionsDescription);
60 Component {
61 id: simpleTextMessage
62 SimpleTextMessage {
63 // text
64 title: menuData && menuData.label ? menuData.label : ""
65 time: extAttrib && extAttrib.hasOwnProperty("xCanonicalTime") ? extAttrib.xCanonicalTime : 0
66 message: extAttrib && extAttrib.hasOwnProperty("xCanonicalText") ? extAttrib.xCanonicalText : ""
67 // icons
68 avatar: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
69 appIcon: extAttrib && extAttrib.hasOwnProperty("xCanonicalAppIcon") ? extAttrib.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
71 onActivateApp: {
72 menuModel.activate(menuIndex, true);
73 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
74 }
75 onDismiss: {
76 menuModel.activate(menuIndex, false);
77 }
79 menuSelected: messageFactoryItem.menuSelected
80 onSelectMenu: messageFactoryItem.selectMenu()
81 onDeselectMenu: messageFactoryItem.deselectMenu()
82 }
83 }
84 Component {
85 id: textMessage
86 TextMessage {
87 property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
89 property var replyAction: QMenuModel.UnityMenuAction {
90 model: menuModel
91 index: menuIndex
92 name: replyActionDescription !== undefined ? replyActionDescription.name : ""
93 }
95 // text
96 title: menuData && menuData.label ? menuData.label : ""
97 time: extAttrib && extAttrib.hasOwnProperty("xCanonicalTime") ? extAttrib.xCanonicalTime : 0
98 message: extAttrib && extAttrib.hasOwnProperty("xCanonicalText") ? extAttrib.xCanonicalText : ""
99 replyButtonText: replyActionDescription !== undefined && replyActionDescription.hasOwnProperty("label") ? replyActionDescription.label : "Send"
100 // icons
101 avatar: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
102 appIcon: extAttrib && extAttrib.hasOwnProperty("xCanonicalAppIcon") ? extAttrib.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
103 // actions
104 replyEnabled: replyAction.valid && replyAction.enabled
106 onActivateApp: {
107 menuModel.activate(menuIndex, true);
108 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
109 }
110 onDismiss: {
111 menuModel.activate(menuIndex, false);
112 }
113 onReply: {
114 replyAction.activate(value);
115 }
117 menuSelected: messageFactoryItem.menuSelected
118 onSelectMenu: messageFactoryItem.selectMenu()
119 onDeselectMenu: messageFactoryItem.deselectMenu()
120 }
121 }
122 Component {
123 id: snapDecision
124 SnapDecision {
125 property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
126 property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
128 property var activateAction: QMenuModel.UnityMenuAction {
129 model: menuModel
130 index: menuIndex
131 name: activateActionDescription !== undefined ? activateActionDescription.name : ""
132 }
133 property var replyAction: QMenuModel.UnityMenuAction {
134 model: menuModel
135 index: menuIndex
136 name: replyActionDescription !== undefined ? replyActionDescription.name : ""
137 }
139 // text
140 title: menuData && menuData.label ? menuData.label : ""
141 time: extAttrib && extAttrib.hasOwnProperty("xCanonicalTime") ? extAttrib.xCanonicalTime : ""
142 message: extAttrib && extAttrib.hasOwnProperty("xCanonicalText") ? extAttrib.xCanonicalText : ""
143 actionButtonText: activateActionDescription !== undefined && activateActionDescription.hasOwnProperty("label") ? activateActionDescription.label : "Call back"
144 replyButtonText: replyActionDescription !== undefined && replyActionDescription.hasOwnProperty("label") ? replyActionDescription.label : "Send"
145 replyMessages: replyActionDescription !== undefined && replyActionDescription.hasOwnProperty("parameter-hint") ? replyActionDescription["parameter-hint"] : ""
146 // icons
147 avatar: extAttrib && extAttrib.hasOwnProperty("icon") ? extAttrib.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
148 appIcon: extAttrib && extAttrib.hasOwnProperty("xCanonicalAppIcon") ? extAttrib.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
149 // actions
150 activateEnabled: activateAction.valid && activateAction.enabled
151 replyEnabled: replyAction.valid && replyAction.enabled
153 onActivateApp: {
154 menuModel.activate(menuIndex, true);
155 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
156 }
157 onDismiss: {
158 menuModel.activate(menuIndex, false);
159 }
160 onActivate: {
161 activateAction.activate();
162 }
163 onReply: {
164 replyAction.activate(value);
165 }
167 menuSelected: messageFactoryItem.menuSelected
168 onSelectMenu: messageFactoryItem.selectMenu()
169 onDeselectMenu: messageFactoryItem.deselectMenu()
170 }
171 }
172 }
174 function loadMessage(actions)
175 {
176 var parameterType = ""
177 for (var actIndex in actions) {
178 var desc = actions[actIndex];
179 if (desc["parameter-type"] !== undefined) {
180 parameterType += desc["parameter-type"];
181 } else {
182 parameterType += "_";
183 }
184 }
186 if (parameterType === "") {
187 return simpleTextMessage;
188 } else if (parameterType === "s") {
189 return textMessage;
190 } else if (parameterType === "_s") {
191 return snapDecision;
192 } else {
193 console.debug("Unknown paramater type: " + parameterType);
194 }
195 return undefined;
196 }