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