summaryrefslogtreecommitdiff
path: root/libsowatch/allwatchscanner.cpp
blob: b01ad059815f52304f79cdfd4116209b1a727187 (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
#include <QtCore/QDebug>

#include "registry.h"
#include "watchplugininterface.h"
#include "allwatchscanner.h"

using namespace sowatch;

AllWatchScanner::AllWatchScanner(QObject *parent) :
	WatchScanner(parent), _finishedCount(0)
{
	QList<WatchPluginInterface*> plugins = Registry::registry()->getWatchPlugins();
	foreach (WatchPluginInterface* driver, plugins) {
		WatchScanner* scanner = driver->getScanner(this);
		if (scanner) {
			_scanners += scanner;
			connect(scanner, SIGNAL(finished()), this, SLOT(handleFinished()));
			connect(scanner, SIGNAL(watchFound(QVariantMap)),
			        this, SIGNAL(watchFound(QVariantMap)));
		}
	}
}

void AllWatchScanner::start()
{
	_finishedCount = 0;
	if (_scanners.empty()) {
		emit finished();
	} else {
		foreach (WatchScanner* scanner, _scanners) {
			scanner->start();
		}
		emit started();
	}
}

void AllWatchScanner::handleFinished()
{
	qDebug() << "one finished";
	_finishedCount++;
	if (_finishedCount >= _scanners.length()) {
		qDebug() << "all finished";
		emit finished();
		_finishedCount = 0;
	}
}