~rpadovani/telegram-app/improveTextAreaDialogPage

« back to all changes in this revision

Viewing changes to ui/ProfilePage.qml

  • Committer: Riccardo Padovani
  • Date: 2014-10-06 10:49:57 UTC
  • mfrom: (93.1.2 telegram-app-dev)
  • Revision ID: riccardo@rpadovani.com-20141006104957-k2mlk2397dxtii7t
MergedĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 1.1
 
3
import QtQuick.Layouts 1.1
 
4
import Ubuntu.Components.ListItems 1.0 as ListItem
 
5
import "../components"
 
6
import "../components/TelegramColors.js" as TelegramColors
 
7
import "../js/avatar.js" as Avatar
 
8
import "../js/time.js" as Time
 
9
import Telegram 0.1
 
10
 
 
11
TelegramPage {
 
12
    id: profilePage
 
13
 
 
14
    property int userId: 0
 
15
 
 
16
    property alias lastSeen: lastSeenText.text
 
17
 
 
18
    signal getUserAnswer(ContactItem user);
 
19
 
 
20
    function getUserInfo() {
 
21
        telegramClient.getUser(userId);
 
22
    }
 
23
 
 
24
    function updateFromContact(user) {
 
25
        contactNameText.text = user.firstName + " " + user.lastName;
 
26
        phone.text  = user.phone;
 
27
 
 
28
        if (user.hasOwnProperty("online") && user.online) {
 
29
            lastSeen = i18n.tr("online");
 
30
        } else if (user.hasOwnProperty("lastSeenOnline")) {
 
31
            var lastSeenTime = Time.formatLastSeen(user.lastSeenOnline * 1000);
 
32
            lastSeen = i18n.tr("last seen %1").arg(lastSeenTime);
 
33
        }
 
34
 
 
35
        if (user.hasOwnProperty("thumbnail") && user.thumbnail.length > 0) {
 
36
            photoImage.source = user.thumbnail;
 
37
        } else if (user.hasOwnProperty(id)) {
 
38
            photoImage.source = "../images/" + Avatar.getAvatar(user.id);
 
39
        }
 
40
    }
 
41
 
 
42
    function openSimpleChat(title, id) {
 
43
        while (pageStack.depth !== 1) {
 
44
            pageStack.pop();
 
45
        }
 
46
        openChat(title, id, TLInputPeer.TypeInputPeerContact);
 
47
    }
 
48
 
 
49
    Component.onCompleted: {
 
50
        telegramClient.getUserAnswer.connect(profilePage.getUserAnswer);
 
51
        getUserInfo();
 
52
    }
 
53
 
 
54
    Component.onDestruction: {
 
55
        telegramClient.getUserAnswer.disconnect(profilePage.getUserAnswer);
 
56
    }
 
57
 
 
58
    onGetUserAnswer: {
 
59
        if (user.id !== userId) return;
 
60
        updateFromContact(user);
 
61
    }
 
62
 
 
63
    title: i18n.tr("Contact Info")
 
64
 
 
65
    body: Item {
 
66
        anchors.fill: parent
 
67
 
 
68
        Row {
 
69
            id: contactHeaderRow
 
70
 
 
71
            anchors {
 
72
                top: parent.top
 
73
                left: parent.left
 
74
                right: parent.right
 
75
                margins: units.gu(2)
 
76
            }
 
77
 
 
78
            spacing: units.gu(2)
 
79
 
 
80
            Image {
 
81
                id: photoImage
 
82
                width: source == "" || source === undefined ? 0 : units.gu(8);
 
83
                height: width
 
84
                asynchronous: true
 
85
                fillMode: Image.PreserveAspectCrop
 
86
                source: "../images/user_blue.png"
 
87
            }
 
88
 
 
89
            Column {
 
90
                id: contactDetails
 
91
 
 
92
                spacing: units.gu(1)
 
93
                width: parent.width - photoImage.width
 
94
                anchors.verticalCenter: photoImage.verticalCenter
 
95
 
 
96
                Label {
 
97
                    id: contactNameText
 
98
                    font.bold: true
 
99
                    fontSize: "large"
 
100
                    color: TelegramColors.black
 
101
                    text: i18n.tr("Unknown")
 
102
                }
 
103
 
 
104
                Label {
 
105
                    id: lastSeenText
 
106
                    color: TelegramColors.grey
 
107
                    text: i18n.tr("last seen - unknown")
 
108
                }
 
109
            }
 
110
        }
 
111
 
 
112
        ListItem.Header {
 
113
            id: phoneHeader
 
114
            text: i18n.tr("Phone Number")
 
115
            visible: phoneRow.visible
 
116
            anchors.top: contactHeaderRow.bottom
 
117
            anchors.topMargin: units.gu(2)
 
118
        }
 
119
 
 
120
        RowLayout {
 
121
            id: phoneRow
 
122
 
 
123
            visible: phone.text !== i18n.tr("Unknown") && phone.text !== ""
 
124
 
 
125
            anchors {
 
126
                left: parent.left
 
127
                leftMargin: units.gu(2)
 
128
                right: parent.right
 
129
                rightMargin: units.gu(2)
 
130
                top: phoneHeader.bottom
 
131
            }
 
132
 
 
133
            Label {
 
134
                id: phone
 
135
                text: i18n.tr("Unknown")
 
136
                Layout.fillWidth: true
 
137
            }
 
138
 
 
139
            AbstractButton {
 
140
                id: callAction
 
141
                width: units.gu(5)
 
142
                height: width
 
143
                Icon {
 
144
                    width: units.gu(4)
 
145
                    height: width
 
146
                    anchors.centerIn: parent
 
147
                    source: Qt.resolvedUrl("../images/call.png")
 
148
                }
 
149
                onClicked: {
 
150
                    Qt.openUrlExternally("tel:///" + phone.text)
 
151
                }
 
152
            }
 
153
 
 
154
            AbstractButton {
 
155
                id: msgAction
 
156
                width: units.gu(5)
 
157
                height: width
 
158
                Icon {
 
159
                    width: units.gu(4)
 
160
                    height: width
 
161
                    anchors.centerIn: parent
 
162
                    source: Qt.resolvedUrl("../images/ic_profile_send_message.png")
 
163
                }
 
164
                onClicked: {
 
165
                    openSimpleChat(contactNameText.text, userId)
 
166
                }
 
167
            }
 
168
        }
 
169
    }
 
170
}