Dekko
Loading...
Searching...
No Matches
ItemRegistry.h
1/* Copyright (C) 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef ITEMREGISTRY_H
19#define ITEMREGISTRY_H
20
21#include <QLoggingCategory>
22#include <QObject>
23#include <QPointer>
24#include <QQuickItem>
25#include <QQmlListProperty>
26#include "PluginIncubator.h"
27
28Q_DECLARE_LOGGING_CATEGORY(PLUGIN_ITEM_REGISTRY)
29
30class ItemRegistry : public QObject
31{
32 Q_OBJECT
33 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
34 Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged)
35 Q_PROPERTY(QQmlListProperty<QQuickItem> defaultItems READ defaultItems)
36 Q_PROPERTY(LoadMode loadMode READ loadMode WRITE setLoadMode NOTIFY loadModeChanged)
37 Q_PROPERTY(QString pluginId MEMBER m_pluginId)
38 // Should plugins be loaded asynchonously. Default items are always created synchronously
39 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asyncChanged)
40 Q_ENUMS(LoadMode)
41
42public:
43 explicit ItemRegistry(QObject *parent = 0);
44
45 enum LoadMode {
46 DefaultOnly,
47 LoadFirstEnabled,
48 LoadLastEnabled,
49 LoadAll,
50 LoadById // will fallback to default if a plugin with id doesn't exist.
51 };
52
53 QQuickItem *target() const;
54 QString location() const;
55 QQmlListProperty<QQuickItem> defaultItems();
56
57 LoadMode loadMode() const;
58 bool asynchronous() const;
59
60 Q_INVOKABLE QString findFirstEnabled(const QString &location);
61
62signals:
63 void targetChanged(QQuickItem *target);
64 void locationChanged(QString location);
65 void loadModeChanged(LoadMode loadMode);
66
67 void asyncChanged(bool asynchronous);
68
69public slots:
70 void setTarget(QQuickItem *target);
71 void setLocation(QString location);
72 void setLoadMode(LoadMode loadMode);
73 void setAsynchronous(bool asynchronous);
74
75private slots:
76 void loadIfPossible();
77 void reparentItemToTarget(QQuickItem *item);
78 void reparentItemsToTarget(QList<QQuickItem *> items);
79 QQuickItem *createItemFromUrl(const QString &itemUrl);
80 void createItemAsync(const QString &itemUrl);
81 void asyncItemReady();
82 void handleIncubatorError();
83
84private:
85 LoadMode m_loadMode;
86 QPointer<QQuickItem> m_target;
87 QString m_location;
88 QList<QQuickItem *> m_defaultItems;
89 QString m_pluginId;
90 bool m_asynchronous;
91 IncubatorList m_incubators;
92};
93
94#endif // ITEMREGISTRY_H