blob: a2d7b5ab2782d8c57bd3c931762271bb1fa336ec (
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
|
#include <QtCore/QDebug>
#include <QtCore/QPluginLoader>
#include <QtCore/QSettings>
#include <QtCore/QDir>
#include <sowatch.h>
#include "daemon.h"
using namespace sowatch;
Daemon::Daemon(QObject *parent) :
QObject(parent)
{
loadDrivers();
loadWatches();
loadWatchlets();
}
void Daemon::loadDrivers()
{
QDir dir(SOWATCH_DRIVERS_DIR);
foreach (QString file, dir.entryList(QDir::Files)) {
QPluginLoader loader(dir.absoluteFilePath(file));
QObject *pluginObj = loader.instance();
if (pluginObj) {
WatchPluginInterface *plugin = qobject_cast<WatchPluginInterface*>(pluginObj);
if (plugin) {
QStringList drivers = plugin->drivers();
foreach (const QString& driver, drivers) {
_drivers[driver] = plugin;
}
}
} else {
qWarning() << "Invalid plugin" << file;
}
}
qDebug() << "loaded drivers" << _drivers.keys();
}
void Daemon::loadWatches()
{
QSettings settings;
int size = settings.beginReadArray("watches");
for (int i = 0; i < size; i++) {
settings.setArrayIndex(i);
QString driver = settings.value("driver").toString().toLower();
WatchPluginInterface *plugin = _drivers[driver];
if (plugin) {
Watch *watch = plugin->getWatch(driver, settings, this);
if (watch) {
_watches.append(watch);
} else {
qWarning() << "Driver" << driver << "refused to getWatch";
}
} else {
qWarning() << "Invalid driver" << driver;
}
}
settings.endArray();
qDebug() << "handling" << _watches.size() << "watches";
}
void Daemon::loadWatchlets()
{
#if 0
QDir dir(SOWATCH_WATCHLETS_DIR);
foreach (QString file, dir.entryList(QDir::Files)) {
QPluginLoader loader(dir.absoluteFilePath(file));
QObject *pluginObj = loader.instance();
if (pluginObj) {
WatchPluginInterface *plugin = qobject_cast<WatchPluginInterface*>(pluginObj);
if (plugin) {
QStringList drivers = plugin->drivers();
foreach (const QString& driver, drivers) {
_drivers[driver] = plugin;
}
}
}
}
#endif
}
|