on 60b2e49 help sign in
unity8/plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml
179 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 // Binding all properties for the item, to make sure that any change in the
41 // property will be propagated to the contents.item at any time
42 Binding {
43 target: contents.item
44 property: "menuSelected"
45 value: menuSelected
46 when: (contents.status == Loader.Ready)
47 }
49 Binding {
50 target: contents.item
51 property: "menu"
52 value: menu
53 when: (contents.status == Loader.Ready)
54 }
56 Connections {
57 target: contents.item ? contents.item : null
58 onSelectMenu: selectMenu()
59 onDeselectMenu: deselectMenu()
60 }
62 Component {
63 id: simpleTextMessage
64 SimpleTextMessage {
65 // text
66 title: menu && menu.label ? menu.label : ""
67 time: menu ? menu.ext.xCanonicalTime : 0
68 message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
69 // icons
70 avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
71 appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
73 onActivateApp: {
74 menuItem.model.activate(modelIndex, true);
75 }
76 onDismiss: {
77 menuItem.model.activate(modelIndex, false);
78 }
79 }
80 }
81 Component {
82 id: textMessage
83 TextMessage {
84 property var replyAction: QMenuModel.UnityMenuAction {
85 model: menuItem.model
86 index: modelIndex
87 name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
88 }
90 // text
91 title: menu && menu.label ? menu.label : ""
92 time: menu ? menu.ext.xCanonicalTime : 0
93 message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
94 replyButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Send"
95 // icons
96 avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
97 appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
98 // actions
99 replyEnabled: replyAction.valid && replyAction.enabled
101 onActivateApp: {
102 menuItem.model.activate(modelIndex, true);
103 }
104 onDismiss: {
105 menuItem.model.activate(modelIndex, false);
106 }
107 onReply: {
108 replyAction.activate(value);
109 }
110 }
111 }
112 Component {
113 id: snapDecision
114 SnapDecision {
115 property var activateAction: QMenuModel.UnityMenuAction {
116 model: menuItem.model
117 index: modelIndex
118 name: menu && actionsDescription[0].name ? actionsDescription[0].name : ""
119 }
120 property var replyAction: QMenuModel.UnityMenuAction {
121 model: menuItem.model
122 index: modelIndex
123 name: menu && actionsDescription[1].name ? actionsDescription[1].name : ""
124 }
126 // text
127 title: menu && menu.label ? menu.label : ""
128 time: menu ? menu.ext.xCanonicalTime : ""
129 message: menu && menu.ext.xCanonicalText ? menu.ext.xCanonicalText : ""
130 actionButtonText: actionsDescription && actionsDescription[0].label ? actionsDescription[0].label : "Call back"
131 replyButtonText: actionsDescription && actionsDescription[1].label ? actionsDescription[1].label : "Send"
132 replyMessages: actionsDescription && actionsDescription[1]["parameter-hint"] ? actionsDescription[1]["parameter-hint"] : ""
133 // icons
134 avatar: menu && menu.ext.icon !== undefined ? menu.ext.icon : "qrc:/indicators/artwork/messaging/default_contact.png"
135 appIcon: menu && menu.ext.xCanonicalAppIcon !== undefined ? menu.ext.xCanonicalAppIcon : "qrc:/indicators/artwork/messaging/default_app.svg"
136 // actions
137 activateEnabled: activateAction.valid && activateAction.enabled
138 replyEnabled: replyAction.valid && replyAction.enabled
140 onActivateApp: {
141 menuItem.model.activate(modelIndex, true);
142 }
143 onDismiss: {
144 menuItem.model.activate(modelIndex, false);
145 }
146 onActivate: {
147 activateAction.activate();
148 }
149 onReply: {
150 replyAction.activate(value);
151 }
152 }
153 }
154 }
156 function loadMessage(actions)
157 {
158 var parameterType = ""
159 for (var actIndex in actions) {
160 var desc = actions[actIndex];
161 if (desc["parameter-type"] !== undefined) {
162 parameterType += desc["parameter-type"];
163 } else {
164 parameterType += "_";
165 }
166 }
168 if (parameterType === "") {
169 return simpleTextMessage;
170 } else if (parameterType === "s") {
171 return textMessage;
172 } else if (parameterType === "_s") {
173 return snapDecision;
174 } else {
175 console.debug("Unknown paramater type: " + parameterType);
176 }
177 return undefined;
178 }