diff options
author | Michael Bohlender <michael.bohlender@kdemail.net> | 2017-01-05 15:17:04 +0100 |
---|---|---|
committer | Michael Bohlender <michael.bohlender@kdemail.net> | 2017-01-05 15:17:04 +0100 |
commit | a2fda0ad4fc013e4f9dd7d68ce2ec5385c1717ce (patch) | |
tree | 3ca0df1d96c01baef1575b4d961365ed227531e1 /framework/accounts | |
parent | bc7879eca0d242934ec2051af93fd58b66845461 (diff) | |
download | kube-a2fda0ad4fc013e4f9dd7d68ce2ec5385c1717ce.tar.gz kube-a2fda0ad4fc013e4f9dd7d68ce2ec5385c1717ce.zip |
move accounts related files to seperate folder
Diffstat (limited to 'framework/accounts')
-rw-r--r-- | framework/accounts/accountfactory.cpp | 65 | ||||
-rw-r--r-- | framework/accounts/accountfactory.h | 51 | ||||
-rw-r--r-- | framework/accounts/accountsmodel.cpp | 82 | ||||
-rw-r--r-- | framework/accounts/accountsmodel.h | 56 |
4 files changed, 254 insertions, 0 deletions
diff --git a/framework/accounts/accountfactory.cpp b/framework/accounts/accountfactory.cpp new file mode 100644 index 00000000..182a0a1d --- /dev/null +++ b/framework/accounts/accountfactory.cpp | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsystems.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "accountfactory.h" | ||
20 | |||
21 | #include <QDebug> | ||
22 | |||
23 | #include <KPackage/PackageLoader> | ||
24 | #include <KPackage/Package> | ||
25 | #include <KPluginMetaData> | ||
26 | |||
27 | #include "settings/settings.h" | ||
28 | #include <sink/store.h> | ||
29 | |||
30 | AccountFactory::AccountFactory(QObject *parent) | ||
31 | : QObject(parent) | ||
32 | { | ||
33 | } | ||
34 | |||
35 | QString AccountFactory::name() const | ||
36 | { | ||
37 | if (mName.isEmpty()) { | ||
38 | return tr("Account"); | ||
39 | } | ||
40 | return mName; | ||
41 | } | ||
42 | |||
43 | void AccountFactory::setAccountId(const QString &accountId) | ||
44 | { | ||
45 | mAccountId = accountId; | ||
46 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query().filter(accountId.toUtf8())) | ||
47 | .syncThen<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { | ||
48 | mAccountType = account.getProperty("type").toByteArray(); | ||
49 | loadPackage(); | ||
50 | }).exec(); | ||
51 | } | ||
52 | |||
53 | void AccountFactory::loadPackage() | ||
54 | { | ||
55 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType); | ||
56 | if (!package.isValid()) { | ||
57 | qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType; | ||
58 | return; | ||
59 | } | ||
60 | Q_ASSERT(package.isValid()); | ||
61 | mUiPath = package.filePath("mainscript"); | ||
62 | mName = package.metadata().name(); | ||
63 | mIcon = package.metadata().iconName(); | ||
64 | emit accountLoaded(); | ||
65 | } | ||
diff --git a/framework/accounts/accountfactory.h b/framework/accounts/accountfactory.h new file mode 100644 index 00000000..047454ae --- /dev/null +++ b/framework/accounts/accountfactory.h | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsystems.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include <QObject> | ||
23 | #include <QVariant> | ||
24 | |||
25 | /** | ||
26 | * A factory to instantiate accountp plugins. | ||
27 | */ | ||
28 | class AccountFactory : public QObject | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId); | ||
32 | Q_PROPERTY(QString name MEMBER mName READ name NOTIFY accountLoaded); | ||
33 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); | ||
34 | Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); | ||
35 | public: | ||
36 | explicit AccountFactory(QObject *parent = Q_NULLPTR); | ||
37 | |||
38 | void setAccountId(const QString &); | ||
39 | QString name() const; | ||
40 | |||
41 | signals: | ||
42 | void accountLoaded(); | ||
43 | |||
44 | private: | ||
45 | void loadPackage(); | ||
46 | QString mAccountId; | ||
47 | QString mName; | ||
48 | QString mIcon; | ||
49 | QString mUiPath; | ||
50 | QByteArray mAccountType; | ||
51 | }; | ||
diff --git a/framework/accounts/accountsmodel.cpp b/framework/accounts/accountsmodel.cpp new file mode 100644 index 00000000..ea37784b --- /dev/null +++ b/framework/accounts/accountsmodel.cpp | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "accountsmodel.h" | ||
20 | #include <sink/store.h> | ||
21 | |||
22 | AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel() | ||
23 | { | ||
24 | Sink::Query query; | ||
25 | query.setFlags(Sink::Query::LiveQuery); | ||
26 | query.request<Sink::ApplicationDomain::SinkAccount::Name>(); | ||
27 | query.request<Sink::ApplicationDomain::SinkAccount::Icon>(); | ||
28 | query.request<Sink::ApplicationDomain::SinkAccount::Status>(); | ||
29 | runQuery(query); | ||
30 | } | ||
31 | |||
32 | AccountsModel::~AccountsModel() | ||
33 | { | ||
34 | |||
35 | } | ||
36 | |||
37 | QHash< int, QByteArray > AccountsModel::roleNames() const | ||
38 | { | ||
39 | QHash<int, QByteArray> roles; | ||
40 | |||
41 | roles[Name] = "name"; | ||
42 | roles[Icon] = "icon"; | ||
43 | roles[AccountId] = "accountId"; | ||
44 | roles[Status] = "status"; | ||
45 | roles[StatusIcon] = "statusIcon"; | ||
46 | roles[ShowStatus] = "showStatus"; | ||
47 | |||
48 | return roles; | ||
49 | } | ||
50 | |||
51 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const | ||
52 | { | ||
53 | auto srcIdx = mapToSource(idx); | ||
54 | auto account = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkAccount::Ptr>(); | ||
55 | switch (role) { | ||
56 | case Name: | ||
57 | return account->getName(); | ||
58 | case Icon: | ||
59 | return account->getIcon(); | ||
60 | case AccountId: | ||
61 | return account->identifier(); | ||
62 | case Status: | ||
63 | return account->getStatus(); | ||
64 | case StatusIcon: | ||
65 | if (account->getStatus() == Sink::ApplicationDomain::ErrorStatus) { | ||
66 | return "emblem-error"; | ||
67 | } else if (account->getStatus() == Sink::ApplicationDomain::BusyStatus) { | ||
68 | return "view-refresh"; | ||
69 | } else if (account->getStatus() == Sink::ApplicationDomain::ConnectedStatus) { | ||
70 | return "checkmark"; | ||
71 | } | ||
72 | case ShowStatus: | ||
73 | return (account->getStatus() != Sink::ApplicationDomain::OfflineStatus); | ||
74 | } | ||
75 | return QIdentityProxyModel::data(idx, role); | ||
76 | } | ||
77 | |||
78 | void AccountsModel::runQuery(const Sink::Query &query) | ||
79 | { | ||
80 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::SinkAccount>(query); | ||
81 | setSourceModel(mModel.data()); | ||
82 | } | ||
diff --git a/framework/accounts/accountsmodel.h b/framework/accounts/accountsmodel.h new file mode 100644 index 00000000..e3c08cd4 --- /dev/null +++ b/framework/accounts/accountsmodel.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include <QObject> | ||
23 | #include <QIdentityProxyModel> | ||
24 | #include <QSharedPointer> | ||
25 | #include <QStringList> | ||
26 | |||
27 | namespace Sink { | ||
28 | class Query; | ||
29 | } | ||
30 | |||
31 | class AccountsModel : public QIdentityProxyModel | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | |||
35 | public: | ||
36 | AccountsModel(QObject *parent = Q_NULLPTR); | ||
37 | ~AccountsModel(); | ||
38 | |||
39 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
40 | |||
41 | enum Roles { | ||
42 | Name = Qt::UserRole + 1, | ||
43 | Icon, | ||
44 | AccountId, | ||
45 | Status, | ||
46 | StatusIcon, | ||
47 | ShowStatus | ||
48 | }; | ||
49 | Q_ENUMS(Roles) | ||
50 | |||
51 | QHash<int, QByteArray> roleNames() const; | ||
52 | |||
53 | private: | ||
54 | void runQuery(const Sink::Query &query); | ||
55 | QSharedPointer<QAbstractItemModel> mModel; | ||
56 | }; | ||