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