on db3f060 help sign in
unity8/plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml
172 lines 7.2 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: menuItem
28 property var actionsDescription: menu ? menu.ext.xCanonicalMessageActions : undefined
30 implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
32 property var model: null
34 Loader {
35 id: contents
36 anchors.fill: parent
38 sourceComponent: loadMessage(actionsDescription);
40 Component {
41 id: simpleTextMessage
42 SimpleTextMessage {
43 // text
44 title: menu && menu.label ? menu.label : ""
45 time: menu ? menu.ext.xCanonicalTime : 0
46 message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
47 // icons
48 avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
49 appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
51 onActivateApp: {
52 menuItem.model.activate(modelIndex, true);
53 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
54 }
55 onDismiss: {
56 menuItem.model.activate(modelIndex, false);
57 }
59 menuSelected: menuItem.menuSelected
60 onSelectMenu: menuItem.selectMenu()
61 onDeselectMenu: menuItem.deselectMenu()
62 }
63 }
64 Component {
65 id: textMessage
66 TextMessage {
67 property var replyAction: QMenuModel.UnityMenuAction {
68 model: menuItem.model
69 index: modelIndex
70 name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
71 }
73 // text
74 title: menu && menu.label ? menu.label : ""
75 time: menu ? menu.ext.xCanonicalTime : 0
76 message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
77 replyButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Send"
78 // icons
79 avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
80 appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
81 // actions
82 replyEnabled: replyAction.valid && replyAction.enabled
84 onActivateApp: {
85 menuItem.model.activate(modelIndex, true);
86 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
87 }
88 onDismiss: {
89 menuItem.model.activate(modelIndex, false);
90 }
91 onReply: {
92 replyAction.activate(value);
93 }
95 menuSelected: menuItem.menuSelected
96 onSelectMenu: menuItem.selectMenu()
97 onDeselectMenu: menuItem.deselectMenu()
98 }
99 }
100 Component {
101 id: snapDecision
102 SnapDecision {
103 property var activateAction: QMenuModel.UnityMenuAction {
104 model: menuItem.model
105 index: modelIndex
106 name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
107 }
108 property var replyAction: QMenuModel.UnityMenuAction {
109 model: menuItem.model
110 index: modelIndex
111 name: menu && actionsDescription[1].name ? actionsDescription[1].name : ""
112 }
114 // text
115 title: menu && menu.label ? menu.label : ""
116 time: menu ? menu.ext.xCanonicalTime : ""
117 message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
118 actionButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Call back"
119 replyButtonText: actionsDescription && actionsDescription[1].label ? actionsDescription[1].label : "Send"
120 replyMessages: actionsDescription && actionsDescription[1]["parameter-hint"] ? actionsDescription[1]["parameter-hint"] : ""
121 // icons
122 avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
123 appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
124 // actions
125 activateEnabled: activateAction.valid && activateAction.enabled
126 replyEnabled: replyAction.valid && replyAction.enabled
128 onActivateApp: {
129 menuItem.model.activate(modelIndex, true);
130 shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
131 }
132 onDismiss: {
133 menuItem.model.activate(modelIndex, false);
134 }
135 onActivate: {
136 activateAction.activate();
137 }
138 onReply: {
139 replyAction.activate(value);
140 }
142 menuSelected: menuItem.menuSelected
143 onSelectMenu: menuItem.selectMenu()
144 onDeselectMenu: menuItem.deselectMenu()
145 }
146 }
147 }
149 function loadMessage(actions)
150 {
151 var parameterType = ""
152 for (var actIndex in actions) {
153 var desc = actions[actIndex];
154 if (desc["parameter-type"] !== undefined) {
155 parameterType += desc["parameter-type"];
156 } else {
157 parameterType += "_";
158 }
159 }
161 if (parameterType === "") {
162 return simpleTextMessage;
163 } else if (parameterType === "s") {
164 return textMessage;
165 } else if (parameterType === "_s") {
166 return snapDecision;
167 } else {
168 console.debug("Unknown paramater type: " + parameterType);
169 }
170 return undefined;
171 }