add more spacing
[personal-kdebase.git] / workspace / plasma / dataengines / nowplaying / playerinterface / pollingwatcher.cpp
blob0db906c393edd1e258e2019bf9a44842158791f9
1 #include "pollingwatcher.h"
3 #include <QTimer>
5 #include <KDebug>
7 #include "player.h"
8 #include "playerfactory.h"
10 PollingWatcher::PollingWatcher(QObject* parent)
11 : QObject(parent),
12 m_timer(0)
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);
30 } else {
31 kWarning() << "Failed to create a player";
32 m_polledFactories.insert(factory);
34 } else {
35 m_polledFactories.insert(factory);
37 if (!m_timer) {
38 m_timer = new QTimer(this);
39 m_timer->setInterval(5000);
40 connect(m_timer, SIGNAL(timeout()), this, SLOT(checkPlayers()));
41 m_timer->start();
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());
52 if (factory) {
53 m_usedFactories.remove(factory);
54 m_polledFactories.insert(factory);
55 } else {
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);
69 } else {
70 kWarning() << "Failed to create a player";
74 m_timer->start();