Changeset View
Changeset View
Standalone View
Standalone View
src/kcm/package/contents/ui/AvailableServices.qml
Show All 16 Lines | |||||
17 | * Free Software Foundation, Inc., | 17 | * Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.7 | 21 | import QtQuick 2.7 | ||
22 | import QtQuick.Layouts 1.11 | 22 | import QtQuick.Layouts 1.11 | ||
23 | import QtQuick.Controls 2.0 as Controls | 23 | import QtQuick.Controls 2.0 as Controls | ||
24 | import org.kde.kirigami 2.4 as Kirigami | 24 | import org.kde.kirigami 2.4 as Kirigami | ||
25 | import org.kde.kaccounts 1.1 as KAccounts | 25 | import org.kde.kaccounts 1.2 as KAccounts | ||
26 | import org.kde.kcm 1.2 | 26 | import org.kde.kcm 1.2 | ||
27 | import Ubuntu.OnlineAccounts 0.1 as OA | | |||
28 | 27 | | |||
29 | ScrollViewKCM { | 28 | SimpleKCM { | ||
30 | id: component; | 29 | id: component; | ||
31 | 30 | | |||
32 | title: i18n("Available Services") | 31 | title: i18n("Available Services") | ||
33 | 32 | | |||
34 | property alias accountId: servicesModel.accountId | 33 | property alias model: servicesList.model | ||
35 | 34 | | |||
36 | view: ListView { | 35 | header: RowLayout { | ||
37 | model: OA.AccountServiceModel { | 36 | Layout.fillWidth: true | ||
38 | id: servicesModel | 37 | Layout.margins: Kirigami.Units.smallSpacing | ||
39 | includeDisabled: true | 38 | spacing: Kirigami.Units.smallSpacing | ||
40 | function refreshData() { | 39 | Kirigami.Icon { | ||
41 | // Because AccountServiceModel seems to not pick this up itself, we'll reset the model... like so, because there's no reset | 40 | source: model.accountIconName | ||
42 | var oldId = component.accountId; | 41 | Layout.preferredWidth: Kirigami.Units.iconSizes.large | ||
43 | component.accountId = ""; | 42 | Layout.preferredHeight: Kirigami.Units.iconSizes.large | ||
44 | component.accountId = oldId; | | |||
45 | } | 43 | } | ||
44 | Controls.Label { | ||||
45 | Layout.fillWidth: true | ||||
46 | text: { | ||||
47 | if (model.accountDisplayName.length > 0 && model.accountProviderName.length > 0) { | ||||
48 | return i18n("%1 (%2)", model.accountDisplayName, model.accountProviderName) | ||||
49 | } else if (model.accountDisplayName.length > 0) { | ||||
50 | return model.accountDisplayName | ||||
51 | } else { | ||||
52 | return i18n("%1 account", model.accountProviderName) | ||||
53 | } | ||||
54 | } | ||||
55 | } | ||||
56 | } | ||||
57 | contentItem: Kirigami.FormLayout { | ||||
58 | Layout.fillWidth: true | ||||
59 | Item { | ||||
60 | visible: servicesList.count === 0 | ||||
61 | Layout.fillWidth: true | ||||
62 | height: Kirigami.Units.largeSpacing | ||||
63 | } | ||||
64 | Kirigami.AbstractCard { | ||||
65 | Layout.fillWidth: true | ||||
66 | visible: servicesList.count === 0 | ||||
67 | header: Kirigami.Heading { | ||||
68 | text: i18nc("Heading for a box informing the user there are no configuration points in this account", "No Services") | ||||
69 | } | ||||
70 | contentItem: Controls.Label { | ||||
71 | verticalAlignment: Text.AlignVCenter | ||||
72 | horizontalAlignment: Text.AlignHCenter | ||||
73 | wrapMode: Text.Wrap | ||||
74 | text: i18nc("A text shown when an account has no configurable services", "This account has no services available for configuration") | ||||
46 | } | 75 | } | ||
47 | delegate: Kirigami.AbstractListItem { | 76 | } | ||
48 | width: parent.width | 77 | Repeater { | ||
49 | Controls.CheckBox { | 78 | id: servicesList | ||
79 | delegate: Controls.CheckBox { | ||||
50 | id: serviceCheck | 80 | id: serviceCheck | ||
51 | text: model.serviceName | 81 | Kirigami.FormData.label: model.displayName + "\n" + model.description | ||
52 | checked: model.enabled | 82 | checked: model.enabled | ||
53 | Binding { | 83 | Binding { | ||
54 | target: serviceCheck | 84 | target: serviceCheck | ||
55 | property: "checked" | 85 | property: "checked" | ||
56 | value: model.enabled | 86 | value: model.enabled | ||
57 | } | 87 | } | ||
58 | onClicked: { | 88 | onClicked: { | ||
59 | var job = jobComponent.createObject(component, { "accountId": component.accountId, "serviceId": model.serviceName, "serviceEnabled": !model.enabled }) | 89 | var job = jobComponent.createObject(component, { "accountId": servicesList.model.accountId, "serviceId": model.name, "serviceEnabled": !model.enabled }) | ||
60 | job.result.connect(servicesModel.refreshData); | | |||
61 | job.start() | 90 | job.start() | ||
62 | } | 91 | } | ||
63 | } | 92 | } | ||
64 | } | 93 | } | ||
65 | Controls.Label { | 94 | } | ||
66 | anchors.fill: parent | 95 | footer: RowLayout { | ||
67 | verticalAlignment: Text.AlignVCenter | 96 | Controls.Button { | ||
68 | horizontalAlignment: Text.AlignHCenter | 97 | Layout.alignment: Qt.AlignRight | ||
69 | wrapMode: Text.Wrap | 98 | text: i18n("Remove This Account") | ||
70 | visible: parent.count === 0 | 99 | icon.name: "edit-delete-remove" | ||
71 | opacity: 0.5 | 100 | onClicked: { | ||
72 | text: i18nc("A text shown when an account has no configurable services", "(No services for this account)") | 101 | accountRemovalDlg.accountId = servicesList.model.accountId; | ||
102 | accountRemovalDlg.displayName = servicesList.model.accountDisplayName; | ||||
103 | accountRemovalDlg.providerName = servicesList.model.accountProviderName; | ||||
104 | accountRemovalDlg.open(); | ||||
105 | } | ||||
73 | } | 106 | } | ||
74 | } | 107 | } | ||
75 | Component { | 108 | Component { | ||
76 | id: jobComponent | 109 | id: jobComponent | ||
77 | KAccounts.AccountServiceToggle { } | 110 | KAccounts.AccountServiceToggle { } | ||
78 | } | 111 | } | ||
112 | MessageBoxSheet { | ||||
113 | id: accountRemovalDlg | ||||
114 | parent: component | ||||
115 | property int accountId | ||||
116 | property string displayName | ||||
117 | property string providerName | ||||
118 | title: i18nc("The title for a dialog which lets you remove an account", "Remove Account?") | ||||
119 | text: { | ||||
120 | if (accountRemovalDlg.displayName.length > 0 && accountRemovalDlg.providerName.length > 0) { | ||||
121 | return i18nc("The text for a dialog which lets you remove an account when both provider name and account name are available", "Are you sure you wish to remove the \"%1\" account \"%2\"?", accountRemovalDlg.providerName, accountRemovalDlg.displayName) | ||||
122 | } else if (accountRemovalDlg.displayName.length > 0) { | ||||
123 | return i18nc("The text for a dialog which lets you remove an account when only the account name is available", "Are you sure you wish to remove the account \"%1\"?", accountRemovalDlg.displayName) | ||||
124 | } else { | ||||
125 | return i18nc("The text for a dialog which lets you remove an account when only the provider name is available", "Are you sure you wish to remove this \"%1\" account?", accountRemovalDlg.providerName) | ||||
126 | } | ||||
127 | } | ||||
128 | actions: [ | ||||
129 | Kirigami.Action { | ||||
130 | text: i18nc("The label for a button which will cause the removal of a specified account", "Remove Account") | ||||
131 | onTriggered: { | ||||
132 | var job = accountRemovalJob.createObject(kaccountsRoot, { "accountId": accountRemovalDlg.accountId }); | ||||
133 | job.start(); | ||||
134 | } | ||||
135 | } | ||||
136 | ] | ||||
137 | } | ||||
138 | Component { | ||||
139 | id: accountRemovalJob | ||||
140 | KAccounts.RemoveAccount { | ||||
141 | onFinished: { | ||||
142 | kcm.pop(); | ||||
143 | } | ||||
144 | } | ||||
145 | } | ||||
79 | } | 146 | } |