• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

pollingwatcher.cpp

Go to the documentation of this file.
00001 #include "pollingwatcher.h"
00002 
00003 #include <QTimer>
00004 
00005 #include <KDebug>
00006 
00007 #include "player.h"
00008 #include "playerfactory.h"
00009 
00010 PollingWatcher::PollingWatcher(QObject* parent)
00011     : QObject(parent),
00012       m_timer(0)
00013 {
00014 }
00015 
00016 QList<Player::Ptr> PollingWatcher::players()
00017 {
00018     return m_players.values();
00019 }
00020 
00021 void PollingWatcher::addFactory(PollingPlayerFactory* factory)
00022 {
00023     if (factory->exists()) {
00024         Player::Ptr player = factory->create();
00025         if (!player.isNull()) {
00026             m_players.insert(player);
00027             m_usedFactories.insert(factory);
00028             emit newPlayer(player);
00029         } else {
00030             kWarning() << "Failed to create a player";
00031             m_polledFactories.insert(factory);
00032         }
00033     } else {
00034         m_polledFactories.insert(factory);
00035     }
00036     if (!m_timer) {
00037         m_timer = new QTimer(this);
00038         m_timer->setInterval(5000);
00039         connect(m_timer, SIGNAL(timeout()), this, SLOT(checkPlayers()));
00040         m_timer->start();
00041     }
00042 }
00043 
00044 void PollingWatcher::checkPlayers()
00045 {
00046     foreach (Player::Ptr player, m_players) {
00047         if (!player->isRunning()) {
00048             m_players.remove(player);
00049             PollingPlayerFactory* factory =
00050                     qobject_cast<PollingPlayerFactory*>(player->factory());
00051             if (factory) {
00052                 m_usedFactories.remove(factory);
00053                 m_polledFactories.insert(factory);
00054             } else {
00055                 kWarning() << "Missing factory for player" << player->name();
00056             }
00057             emit playerDisappeared(player);
00058         }
00059     }
00060     foreach (PollingPlayerFactory* factory, m_polledFactories) {
00061         if (factory->exists()) {
00062             Player::Ptr player = factory->create();
00063             if (!player.isNull()) {
00064                 m_players.insert(player);
00065                 m_polledFactories.remove(factory);
00066                 m_usedFactories.insert(factory);
00067                 emit newPlayer(player);
00068             } else {
00069                 kWarning() << "Failed to create a player";
00070             }
00071         }
00072     }
00073     m_timer->start();
00074 }
00075 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal