| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015 Canonical Ltd. |
| 3 |
* |
| 4 |
* Contact: Alberto Mardegan <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify it |
| 7 |
* under the terms of the GNU General Public License version 3, as published |
| 8 |
* by the Free Software Foundation. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranties of |
| 12 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 13 |
* PURPOSE. See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
import QtQuick 2.9 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import SSO.OnlineAccounts 0.1 |
| 22 |
import Lomiri.OnlineAccounts.Plugin 1.0 |
| 23 |
|
| 24 |
Column { |
| 25 |
id: root |
| 26 |
|
| 27 |
signal providerClicked(string providerId) |
| 28 |
|
| 29 |
anchors.left: parent.left |
| 30 |
anchors.right: parent.right |
| 31 |
|
| 32 |
ProviderModel { |
| 33 |
id: providerModel |
| 34 |
} |
| 35 |
|
| 36 |
ListModel { |
| 37 |
id: filteredProviderModel |
| 38 |
function populate() { |
| 39 |
var length = providerModel.count |
| 40 |
var usefulProviders = ApplicationManager.usefulProviders() |
| 41 |
for (var i = 0; i < length; i++) { |
| 42 |
var providerId = providerModel.get(i, "providerId") |
| 43 |
if (usefulProviders.indexOf(providerId) < 0) continue |
| 44 |
var provider = { |
| 45 |
"providerId": providerId, |
| 46 |
"displayName": providerModel.get(i, "displayName"), |
| 47 |
"iconName": providerModel.get(i, "iconName"), |
| 48 |
"isSingleAccount": providerModel.get(i, "isSingleAccount"), |
| 49 |
"translations": providerModel.get(i, "translations") |
| 50 |
} |
| 51 |
filteredProviderModel.append(provider) |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
Repeater { |
| 57 |
id: repeater |
| 58 |
model: filteredProviderModel |
| 59 |
|
| 60 |
delegate: ListItem { |
| 61 |
id: provider |
| 62 |
|
| 63 |
enabled: accountModel === null || accountModel.count === 0 |
| 64 |
property string iconSource: model.iconName.indexOf("/") === 0 ? |
| 65 |
model.iconName : "image://theme/" + model.iconName |
| 66 |
|
| 67 |
property var accountModel: isSingleAccount ? createAccountModel(providerId) : null |
| 68 |
property bool activated: false |
| 69 |
|
| 70 |
function createAccountModel(providerId) { |
| 71 |
return accountModelComponent.createObject(this, { |
| 72 |
"provider": providerId |
| 73 |
}) |
| 74 |
} |
| 75 |
|
| 76 |
onClicked: { |
| 77 |
activated = true; |
| 78 |
root.providerClicked(providerId); |
| 79 |
} |
| 80 |
|
| 81 |
ListItemLayout { |
| 82 |
title.text: displayName |
| 83 |
|
| 84 |
LomiriShape { |
| 85 |
SlotsLayout.position: SlotsLayout.Leading |
| 86 |
height: Math.min(units.gu(5), provider.height - units.gu(1)) |
| 87 |
width: height |
| 88 |
source: Image { source: iconSource} |
| 89 |
} |
| 90 |
|
| 91 |
ActivityIndicator { |
| 92 |
SlotsLayout.position: SlotsLayout.Trailing |
| 93 |
running: provider.activated |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
Component { |
| 100 |
id: accountModelComponent |
| 101 |
AccountServiceModel { |
| 102 |
includeDisabled: true |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
Component.onCompleted: filteredProviderModel.populate() |
| 107 |
|
| 108 |
function clearPressedButtons() { |
| 109 |
for (var i = 0; i < repeater.count; i++) { |
| 110 |
repeater.itemAt(i).activated = false |
| 111 |
} |
| 112 |
} |
| 113 |
} |