| 1 |
/* |
| 2 |
* Copyright (C) 2015 Canonical, Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import QtContacts 5.0 |
| 19 |
|
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import Lomiri.Components.ListItems 1.3 as ListItems |
| 22 |
import Lomiri.Contacts 0.1 as ContactsUI |
| 23 |
import Lomiri.Components.Popups 1.3 |
| 24 |
|
| 25 |
import Buteo 0.1 |
| 26 |
|
| 27 |
Page { |
| 28 |
id: root |
| 29 |
objectName: "settingsPage" |
| 30 |
|
| 31 |
property var contactListModel |
| 32 |
|
| 33 |
header: PageHeader { |
| 34 |
id: pageHeader |
| 35 |
|
| 36 |
title: i18n.tr("Settings") |
| 37 |
flickable: null |
| 38 |
} |
| 39 |
|
| 40 |
ContactsUI.SIMList { |
| 41 |
id: simList |
| 42 |
} |
| 43 |
|
| 44 |
MyselfPhoneNumbersModel { |
| 45 |
id: myself |
| 46 |
} |
| 47 |
|
| 48 |
Flickable { |
| 49 |
id: numberFlickable |
| 50 |
contentHeight: childrenRect.height |
| 51 |
anchors { |
| 52 |
top: pageHeader.bottom |
| 53 |
left: parent.left |
| 54 |
right: parent.right |
| 55 |
bottom: parent.bottom |
| 56 |
} |
| 57 |
clip: true |
| 58 |
|
| 59 |
Column { |
| 60 |
anchors{ |
| 61 |
left: parent.left |
| 62 |
right: parent.right |
| 63 |
} |
| 64 |
height: childrenRect.height + units.gu(4) |
| 65 |
|
| 66 |
Repeater { |
| 67 |
anchors { |
| 68 |
left: parent.left |
| 69 |
right: parent.right |
| 70 |
} |
| 71 |
model: myself |
| 72 |
delegate: ListItems.Subtitled { |
| 73 |
text: phoneNumber.length > 0 ? i18n.tr("My phone number: %1").arg(phoneNumber) : i18n.tr("Could not read phone number from SIM card") |
| 74 |
subText: network != "" ? network : i18n.tr("SIM %1").arg(index) |
| 75 |
} |
| 76 |
onCountChanged: numberFlickable.contentY = 0 |
| 77 |
} |
| 78 |
|
| 79 |
ListItems.Standard { |
| 80 |
id: mynumbersPlaceHolder |
| 81 |
text: i18n.dtr("lomiri-addressbook-app", "Reading my phone number(s)...") |
| 82 |
visible: myself.count == 0 |
| 83 |
} |
| 84 |
|
| 85 |
Repeater { |
| 86 |
model: onlineAccountsHelper.providerModel |
| 87 |
|
| 88 |
ListItems.Standard { |
| 89 |
id: addAccountItem |
| 90 |
property bool selected: (activeFocus && pageStack.hasKeyboard) |
| 91 |
|
| 92 |
function activate() |
| 93 |
{ |
| 94 |
onlineAccountsHelper.setupExec(model.providerId) |
| 95 |
} |
| 96 |
|
| 97 |
text: i18n.tr("Add %1 account").arg(model.displayName) |
| 98 |
progression: true |
| 99 |
enabled: buteoSync.serviceAvailable |
| 100 |
|
| 101 |
onClicked: activate() |
| 102 |
Keys.onRightPressed: activate() |
| 103 |
Keys.onDownPressed: { |
| 104 |
if (importFromSimItem.enabled) { |
| 105 |
importFromSimItem.forceActiveFocus() |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
ListItems.Standard { |
| 111 |
id: importFromSimItem |
| 112 |
|
| 113 |
property bool selected: (activeFocus && pageStack.hasKeyboard) |
| 114 |
|
| 115 |
function activate() |
| 116 |
{ |
| 117 |
pageStack.addPageToCurrentColumn(root, simCardImportPageComponent) |
| 118 |
} |
| 119 |
|
| 120 |
text: i18n.tr("Import from SIM") |
| 121 |
progression: true |
| 122 |
enabled: (simList.sims.length > 0) && (simList.present.length > 0) |
| 123 |
onClicked: importFromSimItem.activate() |
| 124 |
Keys.onRightPressed: importFromSimItem.activate() |
| 125 |
Keys.onUpPressed: addGoogleAccountItem.forceActiveFocus() |
| 126 |
Keys.onDownPressed: importFromVCFItem.forceActiveFocus() |
| 127 |
} |
| 128 |
|
| 129 |
ListItems.Standard { |
| 130 |
id: importFromVCFItem |
| 131 |
|
| 132 |
property bool selected: (activeFocus && pageStack.hasKeyboard) |
| 133 |
function activate() |
| 134 |
{ |
| 135 |
pageStack.addPageToCurrentColumn(root, importContactPageComponent) |
| 136 |
} |
| 137 |
text: i18n.tr("Import from vCard file") |
| 138 |
progression: true |
| 139 |
onClicked: importFromVCFItem.activate() |
| 140 |
Keys.onRightPressed: importFromVCFItem.activate() |
| 141 |
Keys.onUpPressed: importFromSimItem.forceActiveFocus() |
| 142 |
Keys.onDownPressed: exportAllContactsItem.forceActiveFocus() |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
ListItems.Standard { |
| 147 |
id: exportAllContactsItem |
| 148 |
|
| 149 |
property bool selected: (activeFocus && pageStack.hasKeyboard) |
| 150 |
|
| 151 |
function activate() |
| 152 |
{ |
| 153 |
pageStack.addPageToNextColumn(root, |
| 154 |
Qt.resolvedUrl("../ContactShare/ContactSharePage.qml"), |
| 155 |
{contactModel: root.contactListModel, |
| 156 |
contacts: root.contactListModel.contacts }) |
| 157 |
} |
| 158 |
|
| 159 |
text: i18n.tr("Export all contacts") |
| 160 |
progression: true |
| 161 |
onClicked: exportAllContactsItem.activate() |
| 162 |
Keys.onRightPressed: exportAllContactsItem.activate() |
| 163 |
Keys.onUpPressed: importFromVCFItem.forceActiveFocus() |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
SettingsDefaultSyncTarget { |
| 168 |
id: defaultSyncTarget |
| 169 |
onChanged: save() |
| 170 |
} |
| 171 |
|
| 172 |
ListItem { |
| 173 |
id: purgeContact |
| 174 |
|
| 175 |
height: purgeContactLayout.height + divider.height |
| 176 |
ListItemLayout { |
| 177 |
id: purgeContactLayout |
| 178 |
title.text: i18n.tr("Clean contact database") |
| 179 |
summary.text: i18n.tr("Remove contacts marked as deleted permanently") |
| 180 |
|
| 181 |
Button { |
| 182 |
text: i18n.tr("Purge") |
| 183 |
onClicked: { |
| 184 |
var dialog = PopupUtils.open(prePurgeDialog, root) |
| 185 |
dialog.accepted.connect( function() { |
| 186 |
PopupUtils.close(dialog) |
| 187 |
const result = application.purgeContacts("system-address-book") // only default |
| 188 |
PopupUtils.open(postPurgeDialog, root, { hasError: !result }) |
| 189 |
}) |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
ContactsUI.OnlineAccountsHelper { |
| 197 |
id: onlineAccountsHelper |
| 198 |
} |
| 199 |
|
| 200 |
Binding { |
| 201 |
target: pageStack |
| 202 |
property: 'bottomEdge' |
| 203 |
value: null |
| 204 |
} |
| 205 |
|
| 206 |
Component { |
| 207 |
id: simCardImportPageComponent |
| 208 |
|
| 209 |
ContactsUI.SIMCardImportPage { |
| 210 |
id: importFromSimPage |
| 211 |
|
| 212 |
objectName: "simCardImportPage" |
| 213 |
targetModel: root.contactListModel |
| 214 |
sims: simList.sims |
| 215 |
onImportCompleted: pageStack.removePages(root) |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
Component { |
| 220 |
id: importContactPageComponent |
| 221 |
ContactsUI.ContactImportPage { |
| 222 |
id: importFromVCF |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
Component { |
| 227 |
id: prePurgeDialog |
| 228 |
Dialog { |
| 229 |
id: purgeDialog |
| 230 |
|
| 231 |
signal accepted() |
| 232 |
|
| 233 |
title: i18n.dtr("address-book-app", "Contacts Purge") |
| 234 |
|
| 235 |
text: { |
| 236 |
i18n.dtr("address-book-app", "This will definitely remove contacts mark as deleted from the database") |
| 237 |
} |
| 238 |
|
| 239 |
Button { |
| 240 |
id: acceptButton |
| 241 |
objectName: "removeContactsDialog.Yes" |
| 242 |
anchors { |
| 243 |
left: parent.left |
| 244 |
right: parent.right |
| 245 |
margins: units.gu(1) |
| 246 |
} |
| 247 |
text: i18n.dtr("address-book-app", "Remove") |
| 248 |
color: theme.palette.normal.negative |
| 249 |
action: Action { |
| 250 |
shortcut: "return" |
| 251 |
onTriggered: purgeDialog.accepted() |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
Button { |
| 256 |
id: cancelButton |
| 257 |
objectName: "removeContactsDialog.No" |
| 258 |
anchors { |
| 259 |
left: parent.left |
| 260 |
right: parent.right |
| 261 |
margins: units.gu(1) |
| 262 |
} |
| 263 |
text: i18n.dtr("address-book-app", "Cancel") |
| 264 |
action: Action { |
| 265 |
shortcut: "esc" |
| 266 |
onTriggered: PopupUtils.close(purgeDialog) |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
Component { |
| 273 |
id: postPurgeDialog |
| 274 |
Dialog { |
| 275 |
id: purgeDialog |
| 276 |
property bool hasError: false |
| 277 |
|
| 278 |
title: i18n.dtr("address-book-app", "Contacts Purge") |
| 279 |
|
| 280 |
text: { |
| 281 |
if (hasError) { |
| 282 |
return i18n.dtr("address-book-app", "An error occured, please check the logs") |
| 283 |
} else { |
| 284 |
return i18n.dtr("address-book-app", "Purge done") |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
Button { |
| 289 |
text: i18n.dtr("address-book-app", "ok") |
| 290 |
onTriggered: PopupUtils.close(purgeDialog) |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
ButeoSync { |
| 296 |
id: buteoSync |
| 297 |
} |
| 298 |
|
| 299 |
Keys.onDownPressed: addGoogleAccountItem.forceActiveFocus() |
| 300 |
Keys.onRightPressed: addGoogleAccountItem.forceActiveFocus() |
| 301 |
Keys.onLeftPressed: pageStack.removePages(root) |
| 302 |
Keys.onEscapePressed: pageStack.removePages(root) |
| 303 |
onActiveChanged: { |
| 304 |
if (active) { |
| 305 |
root.forceActiveFocus() |
| 306 |
defaultSyncTarget.update() |
| 307 |
} |
| 308 |
} |
| 309 |
} |