~ubuntu-branches/ubuntu/trusty/unity8/trusty-proposed

« back to all changes in this revision

Viewing changes to plugins/Unity/Indicators/Messaging/qml/MessageMenuItemFactory.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Nick Dedekind, Albert Astals, Mirco Müller, Andrea Cimitan, CI bot, Michał Karnicki
  • Date: 2014-01-29 16:11:20 UTC
  • mfrom: (1.1.62)
  • Revision ID: package-import@ubuntu.com-20140129161120-12chvzss1dghhsg5
Tags: 7.84+14.04.20140129-0ubuntu1
[ Nick Dedekind ]
* Added Panel/VisibleIndicatorsModel for use with both indicator row &
  menuContent. This removes the need to hide indicators in the row and
  map inicator indexes between row & content. Fixes the indicator
  highlight line offset not bound by listView position.
* Ported indicators to using ubuntu-settings-components

[ Albert Astals ]
* Prepend /sbin/ to initctl calls My phablet user does not have /sbin/
  in path and thus this calls fail
* Call updateDelegateCreationRange when it's needed It depends on
  other variables than the ones we were using to call it, so need to
  call it if these change too Device manual test, go to apps scope,
  scroll down so that only part of the installed apps collapsed
  category is shown, expand it, see how previously some icons were not
  painted and now they are

[ Mirco Müller ]
* Fixed the failure of notification autopilot-test
  test_sd_incoming_call.

[ Andrea Cimitan ]
* Add AP test for policykit/network manager, which was causing issues
  with nested mir

[ CI bot ]
* Resync trunk

[ Michał Karnicki ]
* Don't display artShape when artImage source not set.
* Fix FilterGrid rendering issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 */
20
 
 
21
 
import QtQuick 2.0
22
 
import Ubuntu.Components 0.1
23
 
import Unity.Indicators 0.1 as Indicators
24
 
import QMenuModel 0.1 as QMenuModel
25
 
 
26
 
Indicators.BaseMenuItem {
27
 
    id: messageFactoryItem
28
 
    property var menuModel: null
29
 
    property QtObject menuData: null
30
 
    property int menuIndex: -1
31
 
 
32
 
    property var extendedData: menuData && menuData.ext || undefined
33
 
    property var actionsDescription: getExtendedProperty(extendedData, "xCanonicalMessageActions", undefined)
34
 
 
35
 
    onMenuModelChanged: {
36
 
        loadAttributes();
37
 
    }
38
 
    onMenuIndexChanged: {
39
 
        loadAttributes();
40
 
    }
41
 
 
42
 
    function loadAttributes() {
43
 
        if (!menuModel || menuIndex == undefined) return;
44
 
 
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
 
    }
51
 
 
52
 
    function getExtendedProperty(object, propertyName, defaultValue) {
53
 
        if (object && object.hasOwnProperty(propertyName)) {
54
 
            return object[propertyName];
55
 
        }
56
 
        return defaultValue;
57
 
    }
58
 
 
59
 
    implicitHeight: contents.status == Loader.Ready ? contents.item.implicitHeight : 0
60
 
 
61
 
    Loader {
62
 
        id: contents
63
 
        objectName: "loader"
64
 
        anchors.fill: parent
65
 
 
66
 
        sourceComponent: loadMessage(actionsDescription);
67
 
 
68
 
        Component {
69
 
            id: simpleTextMessage
70
 
            SimpleTextMessage {
71
 
                objectName: "simpleTextMessage"
72
 
                // text
73
 
                title: menuData && menuData.label || ""
74
 
                time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
75
 
                message: getExtendedProperty(extendedData, "xCanonicalText", "")
76
 
                // icons
77
 
                avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
78
 
                appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
79
 
                // actions
80
 
                enabled: menuData && menuData.sensitive || false
81
 
 
82
 
                onActivateApp: {
83
 
                    menuModel.activate(menuIndex, true);
84
 
                    shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
85
 
                }
86
 
                onDismiss: {
87
 
                    menuModel.activate(menuIndex, false);
88
 
                }
89
 
 
90
 
                menuSelected: messageFactoryItem.menuSelected
91
 
                onSelectMenu: messageFactoryItem.selectMenu()
92
 
                onDeselectMenu: messageFactoryItem.deselectMenu()
93
 
            }
94
 
        }
95
 
        Component {
96
 
            id: textMessage
97
 
            TextMessage {
98
 
                objectName: "textMessage"
99
 
                property var replyActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
100
 
 
101
 
                property var replyAction: QMenuModel.UnityMenuAction {
102
 
                    model: menuModel
103
 
                    index: menuIndex
104
 
                    name: getExtendedProperty(replyActionDescription, "name", "")
105
 
                }
106
 
 
107
 
                // text
108
 
                title: menuData && menuData.label || ""
109
 
                time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
110
 
                message: getExtendedProperty(extendedData, "xCanonicalText", "")
111
 
                replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
112
 
                // icons
113
 
                avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
114
 
                appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
115
 
                // actions
116
 
                replyEnabled: replyAction.valid && replyAction.enabled
117
 
                enabled: menuData && menuData.sensitive || false
118
 
 
119
 
                onActivateApp: {
120
 
                    menuModel.activate(menuIndex, true);
121
 
                    shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
122
 
                }
123
 
                onDismiss: {
124
 
                    menuModel.activate(menuIndex, false);
125
 
                }
126
 
                onReply: {
127
 
                    replyAction.activate(value);
128
 
                }
129
 
 
130
 
                menuSelected: messageFactoryItem.menuSelected
131
 
                onSelectMenu: messageFactoryItem.selectMenu()
132
 
                onDeselectMenu: messageFactoryItem.deselectMenu()
133
 
            }
134
 
        }
135
 
        Component {
136
 
            id: snapDecision
137
 
            SnapDecision {
138
 
                objectName: "snapDecision"
139
 
                property var activateActionDescription: actionsDescription && actionsDescription.length > 0 ? actionsDescription[0] : undefined
140
 
                property var replyActionDescription: actionsDescription && actionsDescription.length > 1 ? actionsDescription[1] : undefined
141
 
 
142
 
                property var activateAction: QMenuModel.UnityMenuAction {
143
 
                    model: menuModel
144
 
                    index: menuIndex
145
 
                    name: getExtendedProperty(activateActionDescription, "name", "")
146
 
                }
147
 
                property var replyAction: QMenuModel.UnityMenuAction {
148
 
                    model: menuModel
149
 
                    index: menuIndex
150
 
                    name: getExtendedProperty(replyActionDescription, "name", "")
151
 
                }
152
 
 
153
 
                // text
154
 
                title: menuData && menuData.label || ""
155
 
                time: getExtendedProperty(extendedData, "xCanonicalTime", 0)
156
 
                message: getExtendedProperty(extendedData, "xCanonicalText", "")
157
 
                actionButtonText: getExtendedProperty(activateActionDescription, "label", "Call back")
158
 
                replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
159
 
                replyMessages: getExtendedProperty(replyActionDescription, "parameter-hint", "")
160
 
                // icons
161
 
                avatar: getExtendedProperty(extendedData, "icon", "qrc:/indicators/artwork/messaging/default_contact.png")
162
 
                appIcon: getExtendedProperty(extendedData, "xCanonicalAppIcon", "qrc:/indicators/artwork/messaging/default_app.svg")
163
 
                // actions
164
 
                activateEnabled: activateAction.valid && activateAction.enabled
165
 
                replyEnabled: replyAction.valid && replyAction.enabled
166
 
                enabled: menuData && menuData.sensitive || false
167
 
 
168
 
                onActivateApp: {
169
 
                    menuModel.activate(menuIndex, true);
170
 
                    shell.hideIndicatorMenu(UbuntuAnimation.FastDuration);
171
 
                }
172
 
                onDismiss: {
173
 
                    menuModel.activate(menuIndex, false);
174
 
                }
175
 
                onActivate: {
176
 
                    activateAction.activate();
177
 
                }
178
 
                onReply: {
179
 
                    replyAction.activate(value);
180
 
                }
181
 
 
182
 
                menuSelected: messageFactoryItem.menuSelected
183
 
                onSelectMenu: messageFactoryItem.selectMenu()
184
 
                onDeselectMenu: messageFactoryItem.deselectMenu()
185
 
            }
186
 
        }
187
 
    }
188
 
 
189
 
    function loadMessage(actions)
190
 
    {
191
 
        var parameterType = ""
192
 
        for (var actIndex in actions) {
193
 
            var desc = actions[actIndex];
194
 
            if (desc["parameter-type"] !== undefined) {
195
 
                parameterType += desc["parameter-type"];
196
 
            } else {
197
 
                parameterType += "_";
198
 
            }
199
 
        }
200
 
 
201
 
        if (parameterType === "") {
202
 
            return simpleTextMessage;
203
 
        } else if (parameterType === "s") {
204
 
            return textMessage;
205
 
        } else if (parameterType === "_s") {
206
 
            return snapDecision;
207
 
        } else {
208
 
            console.debug("Unknown paramater type: " + parameterType);
209
 
        }
210
 
        return undefined;
211
 
    }
212
 
}