summaryrefslogtreecommitdiff
path: root/libsowatch/registry.h
blob: dab50095f195bf4c36ae04c502bda9ca8e03528a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef SOWATCH_REGISTRY_H
#define SOWATCH_REGISTRY_H

#include <QtCore/QPluginLoader>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QMap>
#include <QtCore/QFileSystemWatcher>
#include "sowatch_global.h"

namespace sowatch
{

class WatchPluginInterface;
class NotificationPluginInterface;
class WatchletPluginInterface;

class SOWATCH_EXPORT Registry : public QObject
{
	Q_OBJECT

public:
	static Registry* registry();

	inline QList<WatchPluginInterface*> getWatchPlugins() {
		return _drivers;
	}

	inline QList<NotificationPluginInterface*> getNotificationPlugins() {
		return _providers;
	}

	inline QList<WatchletPluginInterface*> getWatchletPlugins() {
		return _watchlets;
	}

	inline WatchPluginInterface* getWatchPlugin(const QString& id) {
		return _driverIds.value(id, 0);
	}

	inline NotificationPluginInterface* getNotificationPlugin(const QString& id) {
		return _providerIds.value(id, 0);
	}

	inline WatchletPluginInterface* getWatchletPlugin(const QString& id) {
		return _watchletIds.value(id, 0);
	}

	inline QStringList allWatchDrivers() const {
		return _driverIds.keys();
	}

	inline QStringList allNotificationProviders() const {
		return _providerIds.keys();
	}

	inline QStringList allWatchlets() const {
		return _watchletIds.keys();
	}

signals:
	void driverLoaded(const QString& id);
	void notificationProviderLoaded(const QString& id);
	void watchletLoaded(const QString& id);

	void driverUnloaded(const QString& id);
	void notificationProviderUnloaded(const QString& id);
	void watchletUnloaded(const QString& id);

protected:
	Registry();
	~Registry();

private:
	static Registry* singleRegistry;

	QFileSystemWatcher* _watcher;

	QList<WatchPluginInterface*> _drivers;
	QList<NotificationPluginInterface*> _providers;
	QList<WatchletPluginInterface*> _watchlets;

	QMap<QString, QPluginLoader*> _driverFiles;
	QMap<QString, QPluginLoader*> _providerFiles;
	QMap<QString, QPluginLoader*> _watchletFiles;

	QMap<QString, WatchPluginInterface*> _driverIds;
	QMap<QString, NotificationPluginInterface*> _providerIds;
	QMap<QString, WatchletPluginInterface*> _watchletIds;

	void loadDrivers();
	void loadNotificationProviders();
	void loadWatchlets();

	void loadDriver(const QString& file);
	void loadNotificationProvider(const QString& file);
	void loadWatchlet(const QString& file);

	void unloadDriver(QPluginLoader* loader);
	void unloadNotificationProvider(QPluginLoader* loader);
	void unloadWatchlet(QPluginLoader* loader);

private slots:
	void handlePluginDirectoryChanged(const QString& path);
	void handlePluginFileChanged(const QString& file);
};

}

#endif // SOWATCH_REGISTRY_H