diff options
Diffstat (limited to 'framework/domain/accountfactory.cpp')
-rw-r--r-- | framework/domain/accountfactory.cpp | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp index d54f70a2..af37710a 100644 --- a/framework/domain/accountfactory.cpp +++ b/framework/domain/accountfactory.cpp | |||
@@ -18,11 +18,11 @@ | |||
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 | 26 | ||
27 | AccountFactory::AccountFactory(QObject *parent) | 27 | AccountFactory::AccountFactory(QObject *parent) |
28 | : QObject(parent) | 28 | : QObject(parent) |
@@ -30,19 +30,11 @@ AccountFactory::AccountFactory(QObject *parent) | |||
30 | 30 | ||
31 | } | 31 | } |
32 | 32 | ||
33 | QString AccountFactory::name() const | 33 | void AccountFactory::setAccountId(const QString &accountId) |
34 | { | 34 | { |
35 | return "Maildir"; | 35 | qWarning() << "setting account id: " << accountId; |
36 | } | 36 | mAccountId = accountId; |
37 | 37 | loadPackage(); | |
38 | QString AccountFactory::icon() const | ||
39 | { | ||
40 | return "icon"; | ||
41 | } | ||
42 | |||
43 | QVariant AccountFactory::ui() const | ||
44 | { | ||
45 | return createComponent(getAccountType()); | ||
46 | } | 38 | } |
47 | 39 | ||
48 | QByteArray AccountFactory::getAccountType() const | 40 | QByteArray AccountFactory::getAccountType() const |
@@ -50,23 +42,13 @@ QByteArray AccountFactory::getAccountType() const | |||
50 | return "maildir"; | 42 | return "maildir"; |
51 | } | 43 | } |
52 | 44 | ||
53 | QString AccountFactory::uiPath() const | 45 | void AccountFactory::loadPackage() |
54 | { | 46 | { |
55 | auto accountType = getAccountType(); | 47 | auto accountType = getAccountType(); |
56 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); | 48 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); |
57 | Q_ASSERT(package.isValid()); | 49 | Q_ASSERT(package.isValid()); |
58 | return package.filePath("mainscript"); | 50 | mUiPath = package.filePath("mainscript"); |
59 | } | 51 | mName = package.metadata().name(); |
60 | 52 | mIcon = package.metadata().iconName(); | |
61 | QVariant AccountFactory::createComponent(const QByteArray &accountType) const const | 53 | emit accountLoaded(); |
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 | } | 54 | } |