summaryrefslogtreecommitdiff
path: root/libsowatch/allwatchscanner.cpp
blob: 8a49b86f5c0f72ae52a7b993844a52220026a45a (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
#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()
{
	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();
	}
}