~ci-train-bot/messaging-app/messaging-app-ubuntu-zesty-2311.1

« back to all changes in this revision

Viewing changes to src/qml/SettingsPage.qml

  • Committer: Bileto Bot
  • Author(s): Gustavo Pichorim Boiko, Renato Araujo Oliveira Filho, Tiago Salem Herrmann
  • Date: 2017-03-20 17:38:13 UTC
  • mfrom: (639.16.24 19-configure_sort)
  • Revision ID: ci-train-bot@canonical.com-20170320173813-75wly9vsaax8rly6
Allow user to select the sort field for conversation list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import QtQuick 2.2
20
20
import Ubuntu.Components 1.3
21
21
import Ubuntu.OnlineAccounts.Client 0.1
 
22
import Qt.labs.settings 1.0
22
23
 
23
24
Page {
24
25
    id: settingsPage
25
26
    title: i18n.tr("Settings")
26
27
 
27
 
    property var setMethods: {
28
 
        "mmsEnabled": function(value) { telepathyHelper.mmsEnabled = value }/*,
29
 
        "characterCountEnabled": function(value) { msgSettings.showCharacterCount = value }*/
30
 
    }
31
 
    property var settingsModel: [
32
 
        { "name": "mmsEnabled",
33
 
          "description": i18n.tr("Enable MMS messages"),
34
 
          "property": telepathyHelper.mmsEnabled,
35
 
          "activatedFuncion": null
36
 
        },
37
 
        { "name": "addAccount",
38
 
          "description": i18n.tr("Add an online account"),
39
 
          "onActivated": "createAccount",
40
 
          "property": null
 
28
    function createAccount()
 
29
    {
 
30
        if (onlineAccountHelper.item)
 
31
            onlineAccountHelper.item.run()
 
32
    }
 
33
 
 
34
    readonly property var setMethods: {
 
35
        "mmsEnabled": function(value) { telepathyHelper.mmsEnabled = value },
 
36
        "threadSort": function(value) { mainView.sortThreadsBy = value },
 
37
        "compactView": function(value) { mainView.compactView = value }
 
38
        //"characterCountEnabled": function(value) { msgSettings.showCharacterCount = value }
 
39
    }
 
40
 
 
41
    property var sortByModel: {
 
42
        "timestamp": i18n.tr("Sort by timestamp"),
 
43
        "title": i18n.tr("Sort by title")
 
44
    }
 
45
 
 
46
    readonly property var settingsModel: [
 
47
        { "type": "boolean",
 
48
          "data": {"name": "mmsEnabled",
 
49
                   "description": i18n.tr("Enable MMS messages"),
 
50
                   "property": telepathyHelper.mmsEnabled,
 
51
                   "activatedFuncion": null,
 
52
                   "setMethod": "mmsEnabled"}
 
53
        },
 
54
        { "type": "boolean",
 
55
          "data": {"name": "compactView",
 
56
                   "description": i18n.tr("Simplified conversation view"),
 
57
                   "property": mainView.compactView,
 
58
                   "activatedFuncion": null,
 
59
                   "setMethod": "compactView"}
 
60
        },
 
61
        { "type": "action",
 
62
          "data": { "name": "addAccount",
 
63
                    "description": i18n.tr("Add an online account"),
 
64
                    "onActivated": "createAccount" }
 
65
        },       
 
66
        { "type": "options",
 
67
          "data": { "name": "threadSort",
 
68
                    "description": i18n.tr("Sort threads"),
 
69
                    "currentValue": mainView.sortTrheadsBy,
 
70
                    "subtitle": settingsPage.sortByModel[mainView.sortTrheadsBy],
 
71
                    "options": sortByModel,
 
72
                    "setMethod": "threadSort"}
41
73
        }
42
74
        /*,
43
75
        { "name": "characterCountEnabled",
82
114
        id: settingDelegate
83
115
        ListItem {
84
116
            onClicked: {
85
 
                if (checkbox.visible) {
86
 
                    checkbox.checked = !checkbox.checked
87
 
                } else {
88
 
                    settingsPage[modelData.onActivated]()
89
 
                }
 
117
                layoutDelegate.item.activate()
 
118
                settingsList.currentIndex = index
 
119
 
90
120
            }
91
121
            ListItemLayout {
92
 
                title.text: modelData.description
93
 
 
94
 
                CheckBox {
95
 
                    id: checkbox
96
 
                    objectName: modelData.name
97
 
 
98
 
                    visible: modelData.property !== null
99
 
                    SlotsLayout.position: SlotsLayout.trailing
100
 
                    checked: modelData.property
101
 
                    onCheckedChanged: {
102
 
                        if (checked != modelData.property) {
103
 
                            settingsPage.setMethods[modelData.name](checked)
 
122
                title.text: modelData.data.description
 
123
                subtitle.text: modelData.data.subtitle ? modelData.data.subtitle : ""
 
124
 
 
125
                Loader {
 
126
                    id: layoutDelegate
 
127
 
 
128
                    sourceComponent: {
 
129
                        switch(modelData.type) {
 
130
                        case "action":
 
131
                            return actionDelegate
 
132
                        case "boolean":
 
133
                            return booleanDelegate
 
134
                        case "options":
 
135
                            return optionsDelegate
104
136
                        }
105
137
                    }
106
 
                }
107
 
 
108
 
                ProgressionSlot {
109
 
                    visible: modelData.property === null
110
 
                }
111
 
            }
 
138
 
 
139
                    Binding {
 
140
                        target: layoutDelegate.item
 
141
                        property: "modelData"
 
142
                        value: modelData.data
 
143
                        when: layoutDelegate.status === Loader.Ready
 
144
                    }
 
145
                    Binding {
 
146
                        target: layoutDelegate.item
 
147
                        property: "index"
 
148
                        value: index
 
149
                        when: layoutDelegate.status === Loader.Ready
 
150
                    }
 
151
                }
 
152
            }
 
153
        }
 
154
    }
 
155
 
 
156
    Component {
 
157
        id: booleanDelegate
 
158
 
 
159
        CheckBox {
 
160
            id: checkbox
 
161
            objectName: modelData.name
 
162
 
 
163
            property var modelData: null
 
164
            property int index: -1
 
165
 
 
166
            function activate()
 
167
            {
 
168
                checkbox.checked = !checkbox.checked
 
169
            }
 
170
 
 
171
            SlotsLayout.position: SlotsLayout.Trailing
 
172
            checked: modelData.property
 
173
            onCheckedChanged: {
 
174
                if (checked != modelData.property) {
 
175
                    settingsPage.setMethods[modelData.setMethod](checked)
 
176
                }
 
177
            }
 
178
        }
 
179
    }
 
180
 
 
181
    Component {
 
182
        id: actionDelegate
 
183
 
 
184
        ProgressionSlot {
 
185
            id: progression
 
186
            objectName: modelData.name
 
187
 
 
188
            property var modelData: null
 
189
            property int index: -1
 
190
            function activate()
 
191
            {
 
192
                settingsPage[modelData.onActivated]()
 
193
            }
 
194
        }
 
195
    }
 
196
 
 
197
    Component {
 
198
        id: optionsDelegate
 
199
 
 
200
        ProgressionSlot {
 
201
            id: progression
 
202
            objectName: modelData.name
 
203
 
 
204
            property var modelData: null
 
205
            property int index: -1
 
206
            function activate()
 
207
            {
 
208
                pageStack.addPageToNextColumn(settingsPage, optionsDelegatePage,
 
209
                                              {"title": modelData.description,
 
210
                                               "model": modelData.options,
 
211
                                               "index": index,
 
212
                                               "currentIndex": modelData.currentValue,
 
213
                                               "setMethod": modelData.setMethod})
 
214
            }
 
215
        }
 
216
    }
 
217
 
 
218
    Component {
 
219
        id: optionsDelegatePage
 
220
 
 
221
        Page {
 
222
            id: optionsPage
 
223
 
 
224
            property alias title: pageHeader.title
 
225
            property var model
 
226
            property string currentIndex
 
227
            property string setMethod
 
228
            property int index: -1
 
229
 
 
230
            signal selected(string key)
 
231
 
 
232
            function indexOf(key) {
 
233
                return Object.keys(optionsPage.model).indexOf(key)
 
234
            }
 
235
 
 
236
            onSelected: {
 
237
                if (key !== "") {
 
238
                    settingsPage.setMethods[optionsPage.setMethod](key)
 
239
                }
 
240
                //WORKAROUND: re-set index of settings page because the list is
 
241
                // rebuild after a value change and that cause the index to reset to 0
 
242
                settingsList.currentIndex = index
 
243
                pageStack.removePages(optionsPage)
 
244
            }
 
245
 
 
246
            header: PageHeader {
 
247
                id: pageHeader
 
248
 
 
249
                leadingActionBar.actions: [
 
250
                    Action {
 
251
                       iconName: "back"
 
252
                       text: i18n.tr("Back")
 
253
                       shortcut: "Esc"
 
254
                       onTriggered: optionsPage.selected("")
 
255
                    }
 
256
                ]
 
257
                flickable: pageView
 
258
            }
 
259
 
 
260
            UbuntuListView {
 
261
                id: pageView
 
262
 
 
263
                model: Object.keys(optionsPage.model)
 
264
                anchors.fill: parent
 
265
                currentIndex: optionsPage.indexOf(optionsPage.currentIndex)
 
266
                delegate: ListItem {
 
267
                    ListItemLayout {
 
268
                        title.text: optionsPage.model[modelData]
 
269
                    }
 
270
                    onClicked: optionsPage.selected(modelData)
 
271
                }
 
272
            }
 
273
 
 
274
            onActiveChanged: this.forceActiveFocus()
112
275
        }
113
276
    }
114
277
 
139
302
        }
140
303
    }
141
304
 
142
 
    function createAccount()
143
 
    {
144
 
        if (onlineAccountHelper.item)
145
 
            onlineAccountHelper.item.run()
146
 
    }
147
 
 
148
305
    Loader {
149
306
        id: onlineAccountHelper
150
307
 
152
309
        asynchronous: true
153
310
        source: Qt.resolvedUrl("OnlineAccountsHelper.qml")
154
311
    }
155
 
 
156
 
 
157
312
}