summaryrefslogtreecommitdiffstats
path: root/framework/accounts/accountfactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/accounts/accountfactory.cpp')
-rw-r--r--framework/accounts/accountfactory.cpp65
1 files changed, 65 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
30AccountFactory::AccountFactory(QObject *parent)
31 : QObject(parent)
32{
33}
34
35QString AccountFactory::name() const
36{
37 if (mName.isEmpty()) {
38 return tr("Account");
39 }
40 return mName;
41}
42
43void 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
53void 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}