~libqtelegram-team/telegram-app/app-dev-remove-only-some-members

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import Ubuntu.Components.Popups 0.1
import "../components"
import "../js/version.js" as Version

TelegramPage {
    id: page
    title: i18n.tr("Settings");

    VisualItemModel {
        id: model

        ListItem.Header {
            text: i18n.tr("Your Phone Number")
        }

        ListItem.Standard {
            text: telegramClient.phoneNumber
            showDivider: false
        }

        ListItem.Header {
            text: i18n.tr("Settings")
        }

        ListItem.Standard {
            text: i18n.tr("Configure push")
            height: canConfigurePush() ? implicitHeight : 0
            enabled: isConnected
            progression: true
            onClicked: openPushDialog()

            function canConfigurePush() {
                if (pushClientLoader.status === Loader.Ready) {
                    return pushClient.registered === false;
                } else {
                    return false;
                }
            }
        }

        ListItem.Standard {
            text: i18n.tr("Terminate All Other Sessions")
            showDivider: false
            enabled: page.isConnected
            onClicked: PopupUtils.open(terminateSessionsDialogComponent)

            Component {
                id: terminateSessionsDialogComponent
                Dialog {
                    id: terminateSessionsDialog
                    title: i18n.tr("Telegram")
                    text: i18n.tr("Are you sure you want to terminate all other sessions?")
                    Button {
                        text: i18n.tr("OK")
                        color: UbuntuColors.orange
                        onClicked: {
                            console.log("Terminating all other sessions.");
                            PopupUtils.close(terminateSessionsDialog)
                            telegramClient.authResetAuthorizations();
                        }
                    }
                    Button {
                        text: i18n.tr("Cancel")
                        onClicked: PopupUtils.close(terminateSessionsDialog)
                    }
                }
            }
        }

        ListItem.Header {
            text: i18n.tr("Messages")
        }

        ListItem.ItemSelector {
            text: i18n.tr("Messages Text Size")
            showDivider: false

            model: [
                i18n.tr("Small"),
                i18n.tr("Medium"),
                i18n.tr("Large")
            ]

            selectedIndex: {
                console.log(userSettings.contents.fontSize)
                switch (userSettings.contents.fontSize) {
                    case "small": return 0;
                    case "medium": return 1;
                    case "large": return 2;
                }
            }

            onDelegateClicked: {
                switch (index) {
                    case 0: {
                        userSettings.set("fontSize", "small")
                        break;
                    }
                    case 1: {
                        userSettings.set("fontSize", "medium")
                        break;
                    }
                    case 2: {
                        userSettings.set("fontSize", "large")
                        break;
                    }
                }
            }
        }

        ListItem.Standard {
            text: i18n.tr("Send by Enter")
            showDivider: false

            Switch {
                id: checkbox
                checked: userSettings.contents.sendByEnter
                anchors {
                    right: parent.right
                    rightMargin: units.gu(2)
                    verticalCenter: parent.verticalCenter
                }

                onCheckedChanged: userSettings.set("sendByEnter", checked)
            }
        }

        ListItem.Header {
            text: i18n.tr("Support")
        }

        ListItem.Standard {
            text: i18n.tr("Telegram FAQ")
            onClicked: Qt.openUrlExternally("https://telegram.org/faq");
        }

        ListItem.Standard {
            showDivider: false
            text: i18n.tr("Ask a Question")
            // Can we go the Telegram route, or point people to askubuntu.com?
            onClicked: Qt.openUrlExternally("http://askubuntu.com/search?q=telegram");
        }

        TelegramButton {
            id: logOut
            anchors {
                left: parent.left
                right: parent.right
                margins: units.gu(2)
            }
            text: i18n.tr("Log Out")
            enabled: page.isConnected
            onClicked: PopupUtils.open(logOutDialogComponent)

            Component {
                id: logOutDialogComponent
                Dialog {
                    id: logOutDialog
                    title: i18n.tr("Telegram")
                    text: i18n.tr("Are you sure you want to log out?")
                    Button {
                        text: i18n.tr("OK")
                        color: UbuntuColors.orange
                        onClicked: {
                            console.log("Logging out.");
                            // Calling authLogOut here doesn't work.
                            // This seems to be an SDK bug.
                            logOutTimer.start();
                            PopupUtils.close(logOutDialog);
                        }
                    }
                    Button {
                        text: i18n.tr("Cancel")
                        onClicked: PopupUtils.close(logOutDialog)
                    }
                }
            }
        }

        ListItem.SingleControl {
            showDivider: false
            control: Label {
                id: version
                width: parent.width - units.gu(2)
                height: units.gu(4)
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                // TODO Add app version here below.
                // TRANSLATORS: the argument refers to the version of the app
                text: i18n.tr("Telegram for Ubuntu %1").arg(getVersionString());

                function getVersionString() {
                    var v = Version.version.split(".");
                    var major = v[0];
                    var minor = v[1];
                    var patch = v[2];
                    var revision = v.slice(3, v.length).join(".");

                    return "v" + major + "." + minor + "." + patch + " (" + revision + ")";
                }
            }
        }
    }

    body: ListView {
        anchors.fill: parent
        clip: true
        model: model
    }

    Timer {
        id: logOutTimer
        interval: 300
        repeat: false

        onTriggered: {
            pushClient.unregisterFromPush();

            userData.reset();
            telegramClient.authLogOut();
        }
    }
}