1 #include "pollingwatcher.h"
8 #include "playerfactory.h"
10 PollingWatcher::PollingWatcher(QObject
* parent
)
14 setObjectName("PollingWatcher");
17 QList
<Player::Ptr
> PollingWatcher::players()
19 return m_players
.values();
22 void PollingWatcher::addFactory(PollingPlayerFactory
* factory
)
24 if (factory
->exists()) {
25 Player::Ptr player
= factory
->create();
26 if (!player
.isNull()) {
27 m_players
.insert(player
);
28 m_usedFactories
.insert(factory
);
29 emit
newPlayer(player
);
31 kWarning() << "Failed to create a player";
32 m_polledFactories
.insert(factory
);
35 m_polledFactories
.insert(factory
);
38 m_timer
= new QTimer(this);
39 m_timer
->setInterval(5000);
40 connect(m_timer
, SIGNAL(timeout()), this, SLOT(checkPlayers()));
45 void PollingWatcher::checkPlayers()
47 foreach (Player::Ptr player
, m_players
) {
48 if (!player
->isRunning()) {
49 m_players
.remove(player
);
50 PollingPlayerFactory
* factory
=
51 qobject_cast
<PollingPlayerFactory
*>(player
->factory());
53 m_usedFactories
.remove(factory
);
54 m_polledFactories
.insert(factory
);
56 kWarning() << "Missing factory for player" << player
->name();
58 emit
playerDisappeared(player
);
61 foreach (PollingPlayerFactory
* factory
, m_polledFactories
) {
62 if (factory
->exists()) {
63 Player::Ptr player
= factory
->create();
64 if (!player
.isNull()) {
65 m_players
.insert(player
);
66 m_polledFactories
.remove(factory
);
67 m_usedFactories
.insert(factory
);
68 emit
newPlayer(player
);
70 kWarning() << "Failed to create a player";