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

kmilo

kmilod.cpp

Go to the documentation of this file.
00001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 2; -*-
00002 /*
00003    This file is part of the KDE project
00004 
00005    Copyright (c) 2003 George Staikos <staikos@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 
00022 */
00023 
00024 #include "kmilod.h"
00025 #include "monitor.h"
00026 
00027 #include <QFile>
00028 #include <QPixmap>
00029 
00030 #include <klocale.h>
00031 #include <kdebug.h>
00032 #include <kservicetype.h>
00033 #include <kservice.h>
00034 #include <kconfig.h>
00035 #include <kparts/componentfactory.h>
00036 
00037 #include "kmilointerface.h"
00038 #include "kmilodadaptor.h"
00039 #include "defaultskin.h"
00040 #include <kpluginfactory.h>
00041 #include <kpluginloader.h>
00042 
00043 using namespace KMilo;
00044 
00045 K_PLUGIN_FACTORY(KMiloDFactory,
00046                  registerPlugin<KMiloD>();
00047     )
00048 K_EXPORT_PLUGIN(KMiloDFactory("kmilod"))
00049 
00050 KMiloD::KMiloD(QObject* parent, const QList<QVariant>&)
00051     : KDEDModule(parent), _interval(100)
00052 {
00053     new KmilodAdaptor(this);
00054     _miface = new KMiloInterface(this);
00055 
00056     // Create the display skin object
00057     _display = new DefaultSkin;
00058 
00059     bool shouldPoll = false;
00060 
00061     // Load the modules
00062     KService::List plugs = KServiceTypeTrader::self()->query("KMilo Plugin");
00063     for (KService::List::ConstIterator it = plugs.begin();
00064                         it != plugs.end(); ++it) {
00065         KService::Ptr service = *it;
00066         KMilo::Monitor *m = KService::createInstance<KMilo::Monitor>(service, 0);
00067         if (m) {
00068             m->setObjectName( service->desktopEntryName() );
00069             m->setInterface(_miface);
00070             if (m->init()) {
00071                 _monitors.append(m);
00072                 kDebug() << "KMilo loaded module "
00073                     << service->property("Name").toString()
00074                     << endl;
00075                 shouldPoll = shouldPoll || m->shouldPoll();
00076             } else {
00077                 delete m;
00078             }
00079         }
00080     }
00081 
00082     // Start the timer
00083     QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(doTimer()));
00084     if (shouldPoll) {
00085         _timer.start(_interval);
00086     }
00087 }
00088 
00089 
00090 KMiloD::~KMiloD()
00091 {
00092     _timer.stop();
00093 
00094     // Modules are automatically cleaned up when this is done.  It has
00095     // to be done before delete _display to avoid a race though.
00096     qDeleteAll(_monitors);
00097     _monitors.clear();
00098 
00099     delete _display;
00100     _display = 0L;
00101 
00102     delete _miface;
00103     _miface = 0L;
00104 }
00105 
00106 
00107 void KMiloD::setEnabled(bool enabled) {
00108     if (enabled) {
00109         enable();
00110     } else {
00111         disable();
00112     }
00113 }
00114 
00115 
00116 void KMiloD::enable() {
00117     if (!_monitors.isEmpty()) {
00118         _timer.setSingleShot(false);
00119         _timer.start(_interval);
00120     }
00121 }
00122 
00123 
00124 void KMiloD::disable() {
00125     _timer.stop();
00126 }
00127 
00128 
00129 bool KMiloD::enabled() const {
00130     return _timer.isActive();
00131 }
00132 
00133 
00134 int KMiloD::pollMilliSeconds() const {
00135     return _interval;
00136 }
00137 
00138 
00139 bool KMiloD::setPollMilliSeconds(int ms) {
00140     if (ms > 1000 || ms < 0) {
00141         return false;
00142     }
00143 
00144     if (!_monitors.isEmpty()) {
00145         _timer.setSingleShot(false);
00146         _timer.start(_interval);
00147     }
00148 
00149     _interval = ms;
00150 
00151 return true;
00152 }
00153 
00154 
00155 void KMiloD::doTimer() {
00156     // Iterate through all the modules we have and poll
00157     Q_FOREACH( KMilo::Monitor *m , _monitors ) {
00158         if (!m->shouldPoll()) {
00159             continue;
00160         }
00161 
00162         KMilo::Monitor::DisplayType dt = m->poll();
00163         switch (dt) {
00164             case KMilo::Monitor::Volume:
00165                 displayProgress(i18n("Volume"), m->progress());
00166                 break;
00167             case KMilo::Monitor::Brightness:
00168                 displayProgress(i18n("Brightness"), m->progress());
00169                 break;
00170             case KMilo::Monitor::Mute:
00171                 displayText(i18n("Muted"));
00172                 break;
00173             case KMilo::Monitor::Tap:
00174                 displayText(m->message());
00175                 break;
00176             case KMilo::Monitor::Sleep:
00177                 displayText(m->message());
00178                 break;
00179             case KMilo::Monitor::None:
00180                 // Do nothing
00181                 break;
00182             case KMilo::Monitor::Error:
00183                 {
00184                 // On error, remove the monitor and continue
00185                 _monitors.removeAll(m); // deletes m
00186                 }
00187                 break;
00188             default:
00189                 kWarning() << "Error in KMiloD.  Please report." ;
00190                 break;
00191         }
00192     }
00193 }
00194 
00195 
00196 void KMiloD::displayText(const QString& text) {
00197     _display->displayText(text, QPixmap());
00198 }
00199 
00200 
00201 void KMiloD::displayText(const QString& text, const QByteArray& customPixmap) {
00202         QPixmap icon;
00203         icon.loadFromData(customPixmap);
00204         displayText(text, icon);
00205 }
00206 
00207 void KMiloD::displayText(const QString& text, const QPixmap& customPixmap) {
00208         _display->displayText(text, customPixmap);
00209 }
00210 
00211 
00212 void KMiloD::displayProgress(const QString& text, int progress) {
00213     _display->displayProgress(text, progress, QPixmap());
00214 }
00215 
00216 void KMiloD::displayProgress(const QString& text, int progress, const QByteArray& customPixmap ) {
00217         QPixmap icon;
00218         icon.loadFromData(customPixmap);
00219     displayProgress(text,progress,icon );
00220 }
00221 
00222 void KMiloD::displayProgress(const QString& text, int progress, const QPixmap& customPixmap ) {
00223     _display->displayProgress(text, progress, customPixmap);
00224 }
00225 
00226 void KMiloD::reconfigure()
00227 {
00228     // load the kmilo configuration file:
00229     KConfig config("kmilodrc");
00230 
00231     KMilo::Monitor *monitor;
00232 
00233     Q_FOREACH( monitor , _monitors )
00234     {
00235         monitor->reconfigure(&config);
00236     }
00237 }
00238 
00239 #include "kmilod.moc"
00240 

kmilo

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils 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