diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/domain/accountfactory.cpp | 40 | ||||
-rw-r--r-- | framework/domain/accountfactory.h | 22 |
2 files changed, 23 insertions, 39 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 | } |
diff --git a/framework/domain/accountfactory.h b/framework/domain/accountfactory.h index 0c6afe50..1da32885 100644 --- a/framework/domain/accountfactory.h +++ b/framework/domain/accountfactory.h | |||
@@ -28,21 +28,23 @@ | |||
28 | class AccountFactory : public QObject | 28 | class AccountFactory : public QObject |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | Q_PROPERTY(QString accountId MEMBER mAccountId); | 31 | Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId); |
32 | Q_PROPERTY(QString name READ name); | 32 | Q_PROPERTY(QString name MEMBER mName NOTIFY accountLoaded); |
33 | Q_PROPERTY(QString icon READ icon); | 33 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); |
34 | Q_PROPERTY(QVariant ui READ ui); | 34 | Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); |
35 | Q_PROPERTY(QString uiPath READ uiPath); | ||
36 | public: | 35 | public: |
37 | explicit AccountFactory(QObject *parent = Q_NULLPTR); | 36 | explicit AccountFactory(QObject *parent = Q_NULLPTR); |
38 | 37 | ||
39 | QString name() const; | 38 | void setAccountId(const QString &); |
40 | QString icon() const; | 39 | |
41 | QVariant ui() const; | 40 | signals: |
42 | QString uiPath() const; | 41 | void accountLoaded(); |
43 | 42 | ||
44 | Q_INVOKABLE QVariant createComponent(const QByteArray &accountType) const; | ||
45 | private: | 43 | private: |
44 | void loadPackage(); | ||
46 | QByteArray getAccountType() const; | 45 | QByteArray getAccountType() const; |
47 | QString mAccountId; | 46 | QString mAccountId; |
47 | QString mName; | ||
48 | QString mIcon; | ||
49 | QString mUiPath; | ||
48 | }; | 50 | }; |