~ubuntu-branches/ubuntu/vivid/messaging-app/vivid-proposed

« back to all changes in this revision

Viewing changes to src/qml/MessagesListView.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Bill Filler, Martin Pitt, David Planella, Tiago Salem Herrmann, Renato Araujo Oliveira Filho
  • Date: 2014-08-28 21:59:34 UTC
  • mfrom: (1.1.50)
  • Revision ID: package-import@ubuntu.com-20140828215934-eiuir7men7lmcyvy
Tags: 0.1+14.10.20140828.3-0ubuntu1
[ Bill Filler ]
* Mark the "Send" string for translation. This will require an update
  of the .pot file too.

[ Martin Pitt ]
* Update POT
* Do not mark single space for translation, and fix wrong macros in
  plural forms of "Attachments" strings.

[ David Planella ]
* Mark the "Send" string for translation. This will require an update
  of the .pot file too.

[ Tiago Salem Herrmann ]
* Use rich text to avoid parsing errors. (LP: #1320126)

[ Renato Araujo Oliveira Filho ]
* Show destination numbers on MessageInfoDialog. (LP: #1359843)
* Limit the size of memory used by images on MMSImage.qml. Removed
  scrollbar. Optimize messages page (Binding only message object
  property for loaders.) (LP: #1356539)
* Update vcard visual on text field (before send it) (LP: #1359351)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2012, 2013, 2014 Canonical Ltd.
 
3
 *
 
4
 * This file is part of messaging-app.
 
5
 *
 
6
 * messaging-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * messaging-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.2
 
20
 
 
21
import Ubuntu.Components 1.1
 
22
import Ubuntu.Contacts 0.1
 
23
import Ubuntu.History 0.1
 
24
 
 
25
import "dateUtils.js" as DateUtils
 
26
 
 
27
MultipleSelectionListView {
 
28
    id: root
 
29
 
 
30
    property var _currentSwipedItem: null
 
31
    property list<Action> _availableActions
 
32
 
 
33
    function updateSwippedItem(item)
 
34
    {
 
35
        if (item.swipping) {
 
36
            return
 
37
        }
 
38
 
 
39
        if (item.swipeState !== "Normal") {
 
40
            if (_currentSwipedItem !== item) {
 
41
                if (_currentSwipedItem) {
 
42
                    _currentSwipedItem.resetSwipe()
 
43
                }
 
44
                _currentSwipedItem = item
 
45
            }
 
46
        } else if (item.swipeState !== "Normal" && _currentSwipedItem === item) {
 
47
            _currentSwipedItem = null
 
48
        }
 
49
    }
 
50
 
 
51
    // fake bottomMargin
 
52
    header: Item {
 
53
        height: units.gu(1)
 
54
    }
 
55
    listModel: participants.length > 0 ? sortProxy : null
 
56
    verticalLayoutDirection: ListView.BottomToTop
 
57
    highlightFollowsCurrentItem: true
 
58
    currentIndex: 0
 
59
    _availableActions: [
 
60
        Action {
 
61
            id: reloadAction
 
62
 
 
63
            iconName: "reload"
 
64
            text: i18n.tr("Retry")
 
65
            onTriggered: value.resendMessage()
 
66
        },
 
67
        Action {
 
68
            id: copyAction
 
69
 
 
70
            iconName: "edit-copy"
 
71
            text: i18n.tr("Copy")
 
72
            onTriggered: value.copyMessage()
 
73
        },
 
74
        Action {
 
75
            id: infoAction
 
76
 
 
77
            iconName: "info"
 
78
            text: i18n.tr("Info")
 
79
            onTriggered: {
 
80
                var messageData = listModel.get(value._index)
 
81
                var messageType = messageData.textMessageAttachments.length > 0 ? i18n.tr("MMS") : i18n.tr("SMS")
 
82
                var messageInfo = {"type": messageType,
 
83
                                   "senderId": messageData.senderId,
 
84
                                   "timestamp": messageData.timestamp,
 
85
                                   "textReadTimestamp": messageData.textReadTimestamp,
 
86
                                   "status": messageData.textMessageStatus,
 
87
                                   "participants": messages.participants}
 
88
                messageInfoDialog.showMessageInfo(messageInfo)
 
89
            }
 
90
        }
 
91
    ]
 
92
 
 
93
    listDelegate: Column {
 
94
        id: messageDelegate
 
95
 
 
96
        // WORKAROUND: we can not use sections because the verticalLayoutDirection is ListView.BottomToTop the sections will appear
 
97
        // bellow the item
 
98
        MessageDateSection {
 
99
            text: visible ? DateUtils.friendlyDay(timestamp) : ""
 
100
            anchors {
 
101
                left: parent.left
 
102
                right: parent.right
 
103
                leftMargin: units.gu(2)
 
104
                rightMargin: units.gu(2)
 
105
            }
 
106
            visible: (index === root.count) || !DateUtils.areSameDay(sortProxy.get(index+1).timestamp, timestamp)
 
107
        }
 
108
 
 
109
        MessageDelegateFactory {
 
110
            objectName: "message%1".arg(index)
 
111
 
 
112
            incoming: senderId != "self"
 
113
            // TODO: we have several items inside
 
114
            selected: root.isSelected(messageDelegate)
 
115
            selectionMode: root.isInSelectionMode
 
116
            accountLabel: multipleAccounts ? telepathyHelper.accountForId(accountId).displayName : ""
 
117
            rightSideActions: {
 
118
                var actions = []
 
119
                if (textMessageStatus === HistoryThreadModel.MessageStatusPermanentlyFailed) {
 
120
                    actions.push(reloadAction)
 
121
                }
 
122
                actions.push(copyAction)
 
123
                actions.push(infoAction)
 
124
                return actions
 
125
            }
 
126
 
 
127
            // TODO: need select only the item
 
128
            onItemClicked: {
 
129
                if (root.isInSelectionMode) {
 
130
                    if (!root.selectItem(messageDelegate)) {
 
131
                        root.deselectItem(messageDelegate)
 
132
                    }
 
133
                }
 
134
            }
 
135
            onItemPressAndHold: {
 
136
                root.startSelection()
 
137
                root.selectItem(messageDelegate)
 
138
            }
 
139
            Component.onCompleted: {
 
140
                if (newEvent) {
 
141
                    messages.markMessageAsRead(accountId, threadId, eventId, type);
 
142
                }
 
143
            }
 
144
        }
 
145
    }
 
146
 
 
147
    onSelectionDone: {
 
148
        for (var i=0; i < items.count; i++) {
 
149
            var event = items.get(i).model
 
150
            eventModel.removeEvent(event.accountId, event.threadId, event.eventId, event.type)
 
151
        }
 
152
    }
 
153
 
 
154
    onCountChanged: {
 
155
        // list is in the bootom we should scroll to the new message
 
156
        if (Math.abs(height + contentY) < units.gu(3)) {
 
157
            currentIndex = 0
 
158
            positionViewAtBeginning()
 
159
        }
 
160
    }
 
161
 
 
162
    SortProxyModel {
 
163
        id: sortProxy
 
164
        sourceModel: eventModel.filter ? eventModel : null
 
165
        sortRole: HistoryEventModel.TimestampRole
 
166
        ascending: false
 
167
    }
 
168
}