diff options
Diffstat (limited to 'framework/domain/accountfactory.cpp')
-rw-r--r-- | framework/domain/accountfactory.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp new file mode 100644 index 00000000..d54f70a2 --- /dev/null +++ b/framework/domain/accountfactory.cpp | |||
@@ -0,0 +1,72 @@ | |||
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 <QQmlComponent> | ||
22 | #include <QQmlEngine> | ||
23 | #include <QDebug> | ||
24 | |||
25 | #include <KPackage/PackageLoader> | ||
26 | |||
27 | AccountFactory::AccountFactory(QObject *parent) | ||
28 | : QObject(parent) | ||
29 | { | ||
30 | |||
31 | } | ||
32 | |||
33 | QString AccountFactory::name() const | ||
34 | { | ||
35 | return "Maildir"; | ||
36 | } | ||
37 | |||
38 | QString AccountFactory::icon() const | ||
39 | { | ||
40 | return "icon"; | ||
41 | } | ||
42 | |||
43 | QVariant AccountFactory::ui() const | ||
44 | { | ||
45 | return createComponent(getAccountType()); | ||
46 | } | ||
47 | |||
48 | QByteArray AccountFactory::getAccountType() const | ||
49 | { | ||
50 | return "maildir"; | ||
51 | } | ||
52 | |||
53 | QString AccountFactory::uiPath() const | ||
54 | { | ||
55 | auto accountType = getAccountType(); | ||
56 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); | ||
57 | Q_ASSERT(package.isValid()); | ||
58 | return package.filePath("mainscript"); | ||
59 | } | ||
60 | |||
61 | QVariant AccountFactory::createComponent(const QByteArray &accountType) const const | ||
62 | { | ||
63 | qWarning() << "Trying to load accounts package " << accountType << mAccountId; | ||
64 | auto engine = qmlEngine(this); | ||
65 | Q_ASSERT(engine); | ||
66 | auto component = new QQmlComponent(engine, QUrl::fromLocalFile(uiPath()), QQmlComponent::PreferSynchronous); | ||
67 | for (const auto &error : component->errors()) { | ||
68 | qWarning() << error.toString(); | ||
69 | } | ||
70 | Q_ASSERT(component->isReady()); | ||
71 | return QVariant::fromValue(component); | ||
72 | } | ||