blob: ad49995bee2d7123f3bddc3c1d35e8a931a95b75 (
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
|
#include "watch.h"
#include "watchlet.h"
#include "watchserver.h"
using namespace sowatch;
WatchServer::WatchServer(Watch* watch, QObject* parent) :
QObject(parent), _watch(watch), _currentWatchlet(0)
{
connect(_watch, SIGNAL(connected()), SLOT(watchConnected()));
connect(_watch, SIGNAL(disconnected()), SLOT(watchDisconnected()));
}
Watch* WatchServer::watch()
{
return _watch;
}
void WatchServer::runWatchlet(const QString& id)
{
if (_currentWatchlet) {
closeWatchlet();
}
_currentWatchlet = watchlets[id];
if (_watch->isConnected()) {
_currentWatchlet->activate();
}
}
void WatchServer::closeWatchlet()
{
Q_ASSERT(_currentWatchlet != 0);
if (_watch->isConnected()) {
_currentWatchlet->deactivate();
}
_currentWatchlet = 0;
}
void WatchServer::registerWatchlet(Watchlet *watchlet)
{
Q_ASSERT(watchlet->_server == this);
watchlets[watchlet->id()] = watchlet;
}
void WatchServer::watchConnected()
{
if (_currentWatchlet) {
_currentWatchlet->activate();
}
}
void WatchServer::watchDisconnected()
{
if (_currentWatchlet) {
_currentWatchlet->deactivate();
}
}
|