diff options
Diffstat (limited to 'framework/src/accounts/accountfactory.cpp')
-rw-r--r-- | framework/src/accounts/accountfactory.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/framework/src/accounts/accountfactory.cpp b/framework/src/accounts/accountfactory.cpp new file mode 100644 index 00000000..9dbb402b --- /dev/null +++ b/framework/src/accounts/accountfactory.cpp | |||
@@ -0,0 +1,71 @@ | |||
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 | .then([this](const Sink::ApplicationDomain::SinkAccount &account) { | ||
48 | mAccountType = account.getProperty("type").toByteArray(); | ||
49 | loadPackage(); | ||
50 | }).exec(); | ||
51 | } | ||
52 | |||
53 | void AccountFactory::setAccountType(const QString &type) | ||
54 | { | ||
55 | mAccountType = type.toLatin1(); | ||
56 | loadPackage(); | ||
57 | } | ||
58 | |||
59 | void AccountFactory::loadPackage() | ||
60 | { | ||
61 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType); | ||
62 | if (!package.isValid()) { | ||
63 | qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType; | ||
64 | return; | ||
65 | } | ||
66 | Q_ASSERT(package.isValid()); | ||
67 | mUiPath = package.filePath("mainscript"); | ||
68 | mName = package.metadata().name(); | ||
69 | mIcon = package.metadata().iconName(); | ||
70 | emit accountLoaded(); | ||
71 | } | ||