~ci-train-bot/dialer-app/dialer-app-ubuntu-zesty-2629

« back to all changes in this revision

Viewing changes to src/qml/SettingsPage/CallForwarding.qml

  • Committer: Bileto Bot
  • Author(s): Gustavo Pichorim Boiko, Tiago Salem Herrmann
  • Date: 2017-04-05 17:15:15 UTC
  • mfrom: (551.2.11 staging)
  • Revision ID: ci-train-bot@canonical.com-20170405171515-tgpo36boefh8ie0e
- Adapt to work with VOIP accounts.
- Install 'IM' account application file. Make sure that dialer-app appear on the application list for 'IM' services.
- Allow to expand the keypad.
- Move the phone settings from ubuntu-system-settings to dialer-app.

Approved by: Gustavo Pichorim Boiko, system-apps-ci-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of dialer-app
 
3
 *
 
4
 * Copyright (C) 2013-2017 Canonical Ltd.
 
5
 *
 
6
 * Contact:
 
7
 *     Sebastien Bacher <sebastien.bacher@canonical.com>
 
8
 *     Jonas G. Drange <jonas.drange@canonical.com>
 
9
 *
 
10
 * This program is free software: you can redistribute it and/or modify it
 
11
 * under the terms of the GNU General Public License version 3, as published
 
12
 * by the Free Software Foundation.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful, but
 
15
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
16
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
17
 * PURPOSE.  See the GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License along
 
20
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
 *
 
22
 * TODO: Add centrally stored setting for each call forwarding that describes a
 
23
 *       contact. lp:1467816
 
24
 *
 
25
 * TODO: If a setting failed to be set, the error text should be followed by
 
26
 *       “Contact {carrier name} for more information.”.
 
27
 */
 
28
 
 
29
import QtQuick 2.4
 
30
import QtContacts 5.0
 
31
import MeeGo.QOfono 0.2
 
32
import Ubuntu.Components 1.3
 
33
import Ubuntu.Components.ListItems 1.3 as ListItem
 
34
import Ubuntu.Components.Popups 1.3
 
35
import Ubuntu.Components.Themes.Ambiance 0.1
 
36
import Ubuntu.Content 1.3
 
37
import "callForwardingUtils.js" as Utils
 
38
 
 
39
Page {
 
40
    id: page
 
41
    objectName: "callForwardingPage"
 
42
    title: headerTitle
 
43
    property var sim
 
44
    property string headerTitle: i18n.tr("Call forwarding")
 
45
    property QtObject editing: null
 
46
    property QtObject activeItem: null
 
47
    property var activeTransfer
 
48
 
 
49
    header: PageHeader {
 
50
        id: pageHeader
 
51
        title: page.title
 
52
        flickable: flick
 
53
    }
 
54
 
 
55
    states: [
 
56
        State {
 
57
            name: "forwardBusy"
 
58
            PropertyChanges { target: fwdSomeTitle; enabled: false }
 
59
            PropertyChanges { target: fwdAll; enabled: false; }
 
60
            PropertyChanges { target: fwdBusy; enabled: false; }
 
61
            PropertyChanges { target: fwdLost; enabled: false; }
 
62
            PropertyChanges { target: fwdUnreachable; enabled: false; }
 
63
            when: fwdAll.busy || fwdBusy.busy || fwdLost.busy || fwdUnreachable.busy
 
64
        },
 
65
        State {
 
66
            name: "forwardFailed"
 
67
            PropertyChanges { target: fwdSomeTitle; enabled: false }
 
68
            PropertyChanges { target: fwdFailedLabel; visible: true }
 
69
            PropertyChanges { target: fwdAll; enabled: false; }
 
70
            PropertyChanges { target: fwdBusy; enabled: false; }
 
71
            PropertyChanges { target: fwdLost; enabled: false; }
 
72
            PropertyChanges { target: fwdUnreachable; enabled: false; }
 
73
        },
 
74
        State {
 
75
            name: "editing"
 
76
            PropertyChanges { target: fwdAll; enabled: false; explicit: true }
 
77
            PropertyChanges { target: fwdBusy; enabled: false; explicit: true }
 
78
            PropertyChanges { target: fwdLost; enabled: false; explicit: true }
 
79
            PropertyChanges { target: fwdUnreachable; enabled: false; explicit: true }
 
80
            PropertyChanges { target: fwdSomeTitle; enabled: false }
 
81
            StateChangeScript {
 
82
                name: "editingEnabled"
 
83
                script: {
 
84
                    editing.opacity = 1;
 
85
                    editing.enabled = true;
 
86
                }
 
87
            }
 
88
            when: editing !== null
 
89
        },
 
90
        State {
 
91
            name: "forwardAll"
 
92
            PropertyChanges { target: fwdSomeTitle; }
 
93
            PropertyChanges { target: fwdBusy; enabled: false; value: ""; checked: false }
 
94
            PropertyChanges { target: fwdLost; enabled: false; value: ""; checked: false }
 
95
            PropertyChanges { target: fwdUnreachable; enabled: false; value: ""; checked: false }
 
96
            when: fwdAll.value !== ""
 
97
        }
 
98
    ]
 
99
 
 
100
    Flickable {
 
101
        id: flick
 
102
 
 
103
        // this is necessary to avoid the page to appear below the header
 
104
        clip: true
 
105
        flickableDirection: Flickable.VerticalFlick
 
106
        anchors {
 
107
            fill: parent
 
108
            bottomMargin: keyboardButtons.height + keyboard.height
 
109
        }
 
110
        contentHeight: contents.height + units.gu(2)
 
111
        contentWidth: parent.width
 
112
 
 
113
        // after add a new field we need to wait for the contentHeight to
 
114
        // change to scroll to the correct position
 
115
        onContentHeightChanged: Utils.show(page.activeItem)
 
116
 
 
117
        Column {
 
118
            id: contents
 
119
            anchors { left: parent.left; right: parent.right }
 
120
            spacing: units.gu(1)
 
121
 
 
122
            CallForwardItem {
 
123
                id: fwdAll
 
124
                anchors { left: parent.left; right: parent.right }
 
125
                rule: "voiceUnconditional"
 
126
                callForwarding: callForwarding
 
127
                text: i18n.tr("Forward every incoming call")
 
128
                onEnteredEditMode: {page.editing = fwdAll; Utils.show(field)}
 
129
                onLeftEditMode: page.editing = null
 
130
            }
 
131
 
 
132
            Label {
 
133
                id: fwdAllCaption
 
134
                anchors {
 
135
                    left: parent.left; right: parent.right; margins: units.gu(1)
 
136
                }
 
137
                width: parent.width
 
138
                wrapMode: Text.WordWrap
 
139
                fontSize: "small"
 
140
                horizontalAlignment: Text.AlignHCenter
 
141
                verticalAlignment: Text.AlignVCenter
 
142
                text: i18n.tr("Redirects all phone calls to another number.")
 
143
                opacity: 0.8
 
144
            }
 
145
 
 
146
            Label {
 
147
                id: fwdFailedLabel
 
148
                anchors {
 
149
                    left: parent.left; right: parent.right; margins: units.gu(2)
 
150
                }
 
151
                width: parent.width
 
152
                wrapMode: Text.WordWrap
 
153
                visible: false
 
154
                text: i18n.tr("Call forwarding status can't be checked " +
 
155
                              "now. Try again later.")
 
156
                color: theme.palette.normal.negative
 
157
                horizontalAlignment: Text.AlignHCenter
 
158
            }
 
159
 
 
160
            SettingsItemTitle {
 
161
                id: fwdSomeTitle
 
162
                text: i18n.tr("Forward incoming calls when:")
 
163
            }
 
164
 
 
165
            CallForwardItem {
 
166
                id: fwdBusy
 
167
                objectName: "fwdBusy"
 
168
                anchors { left: parent.left; right: parent.right }
 
169
                callForwarding: callForwarding
 
170
                rule: "voiceBusy"
 
171
                text: i18n.tr("I'm on another call")
 
172
                onEnteredEditMode: {page.editing = fwdBusy; Utils.show(field)}
 
173
                onLeftEditMode: page.editing = null
 
174
            }
 
175
 
 
176
            CallForwardItem {
 
177
                id: fwdLost
 
178
                objectName: "fwdLost"
 
179
                anchors { left: parent.left; right: parent.right }
 
180
                callForwarding: callForwarding
 
181
                rule: "voiceNoReply"
 
182
                text: i18n.tr("I don't answer")
 
183
                onEnteredEditMode: {page.editing = fwdLost; Utils.show(field)}
 
184
                onLeftEditMode: page.editing = null
 
185
            }
 
186
 
 
187
            CallForwardItem {
 
188
                id: fwdUnreachable
 
189
                objectName: "fwdUnreachable"
 
190
                anchors { left: parent.left; right: parent.right }
 
191
                callForwarding: callForwarding
 
192
                rule: "voiceNotReachable"
 
193
                text: i18n.tr("My phone is unreachable")
 
194
                onEnteredEditMode: {
 
195
                    page.editing = fwdUnreachable;
 
196
                    Utils.show(field);
 
197
                }
 
198
                onLeftEditMode: page.editing = null
 
199
            }
 
200
        }
 
201
    } // Flickable
 
202
 
 
203
    Rectangle {
 
204
        id: keyboardButtons
 
205
        anchors {
 
206
            left: parent.left
 
207
            right: parent.right
 
208
            bottom: keyboard.top
 
209
        }
 
210
        color: Theme.palette.selected.background
 
211
        visible: editing !== null
 
212
        height: units.gu(6)
 
213
        Button {
 
214
            id: kbdContacts
 
215
            objectName: "contactsButton"
 
216
            anchors {
 
217
                left: parent.left
 
218
                leftMargin: units.gu(1)
 
219
                verticalCenter: parent.verticalCenter
 
220
            }
 
221
            activeFocusOnPress: false
 
222
            enabled: editing && !editing.busy
 
223
            text: i18n.tr("Contacts...")
 
224
            onClicked: page.activeTransfer = contactPicker.request()
 
225
        }
 
226
 
 
227
        Button {
 
228
            id: kbdCancel
 
229
            objectName: "cancelButton"
 
230
            anchors {
 
231
                right: kbdSet.left
 
232
                rightMargin: units.gu(1)
 
233
                verticalCenter: parent.verticalCenter
 
234
            }
 
235
            enabled: editing && !editing.busy
 
236
            text: i18n.tr("Cancel")
 
237
            onClicked: editing.cancel()
 
238
        }
 
239
 
 
240
        Button {
 
241
            id: kbdSet
 
242
            objectName: "setButton"
 
243
            anchors {
 
244
                right: parent.right
 
245
                rightMargin: units.gu(1)
 
246
                verticalCenter: parent.verticalCenter
 
247
            }
 
248
            enabled: editing && !editing.busy && editing.field.text
 
249
            text: i18n.tr("Set")
 
250
            activeFocusOnPress: false
 
251
            onClicked: editing.save()
 
252
        }
 
253
    }
 
254
 
 
255
    KeyboardRectangle {
 
256
        id: keyboard
 
257
        anchors.bottom: parent.bottom
 
258
        onHeightChanged: {
 
259
            if (page.activeItem) {
 
260
                Utils.show(page.activeItem);
 
261
            }
 
262
        }
 
263
    }
 
264
 
 
265
    Component {
 
266
        id: chooseNumberDialog
 
267
        Dialog {
 
268
            id: dialog
 
269
            property var contact
 
270
            title: i18n.tr("Please select a phone number")
 
271
 
 
272
            ListItem.ItemSelector {
 
273
                anchors {
 
274
                    left: parent.left
 
275
                    right: parent.right
 
276
                }
 
277
                activeFocusOnPress: false
 
278
                expanded: true
 
279
                text: i18n.tr("Numbers")
 
280
                model: contact.phoneNumbers
 
281
                selectedIndex: -1
 
282
                delegate: OptionSelectorDelegate {
 
283
                    text: modelData.number
 
284
                    activeFocusOnPress: false
 
285
                }
 
286
                onDelegateClicked: {
 
287
                    editing.field.text = contact.phoneNumbers[index].number;
 
288
                    PopupUtils.close(dialog);
 
289
                }
 
290
            }
 
291
        }
 
292
    }
 
293
 
 
294
    Component {
 
295
        id: hadNoNumberDialog
 
296
        Dialog {
 
297
            id: dialog
 
298
            title: i18n.tr("Could not forward to this contact")
 
299
            text: i18n.tr("Contact not associated with any phone number.")
 
300
            Button {
 
301
                text: i18n.tr("OK")
 
302
                activeFocusOnPress: false
 
303
                onClicked: PopupUtils.close(dialog)
 
304
            }
 
305
        }
 
306
    }
 
307
 
 
308
    VCardParser {
 
309
        id: contactParser
 
310
 
 
311
        function parseContact(vcardContact) {
 
312
            return vcardContact;
 
313
        }
 
314
 
 
315
        onVcardParsed: {
 
316
            var contact;
 
317
            if (contacts.length === 0) {
 
318
                console.warn('no contacts parsed');
 
319
                return;
 
320
            } else {
 
321
                contact = parseContact(contacts[0]);
 
322
                if (contact.phoneNumbers.length < 1) {
 
323
                    PopupUtils.open(hadNoNumberDialog);
 
324
                } else if (contact.phoneNumbers.length > 1) {
 
325
                    PopupUtils.open(chooseNumberDialog, page, {
 
326
                        'contact': contact
 
327
                    });
 
328
                } else {
 
329
                    editing.field.text = contact.phoneNumber.number;
 
330
                }
 
331
            }
 
332
        }
 
333
    }
 
334
 
 
335
    ContentTransferHint {
 
336
        id: importHint
 
337
        anchors.fill: parent
 
338
        activeTransfer: page.activeTransfer
 
339
    }
 
340
 
 
341
    ContentPeer {
 
342
        id: contactPicker
 
343
        contentType: ContentType.Contacts
 
344
        handler: ContentHandler.Source
 
345
        selectionType: ContentTransfer.Single
 
346
    }
 
347
 
 
348
    Connections {
 
349
        target: page.activeTransfer ? page.activeTransfer : null
 
350
        onStateChanged: {
 
351
            if (page.activeTransfer.state === ContentTransfer.Charged) {
 
352
                contactParser.vCardUrl = page.activeTransfer.items[0].url;
 
353
            }
 
354
        }
 
355
    }
 
356
 
 
357
    Connections {
 
358
        target: callForwarding
 
359
        onGetPropertiesFailed: page.state = "forwardFailed";
 
360
    }
 
361
 
 
362
    OfonoCallForwarding {
 
363
        id: callForwarding
 
364
        modemPath: sim.path
 
365
        function updateSummary () {
 
366
            var val;
 
367
 
 
368
            // Clear the summary and exit if any of the values are unknown.
 
369
            if (typeof voiceUnconditional === 'undefined' ||
 
370
                typeof voiceBusy === 'undefined' ||
 
371
                typeof voiceNoReply === 'undefined' ||
 
372
                typeof voiceNotReachable === 'undefined') {
 
373
                sim.setCallForwardingSummary('');
 
374
                return;
 
375
            }
 
376
 
 
377
            if (voiceUnconditional) {
 
378
                 val = i18n.tr("All calls");
 
379
            } else if (voiceBusy || voiceNoReply || voiceNotReachable) {
 
380
                val = i18n.tr("Some calls")
 
381
            } else {
 
382
                val = i18n.tr("Off")
 
383
            }
 
384
            sim.setCallForwardingSummary(val);
 
385
        }
 
386
 
 
387
        Component.onCompleted: updateSummary()
 
388
        onVoiceUnconditionalChanged: updateSummary()
 
389
        onVoiceBusyChanged: updateSummary()
 
390
        onVoiceNoReplyChanged: updateSummary()
 
391
        onVoiceNotReachableChanged: updateSummary()
 
392
    }
 
393
}