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

kmilo

pb_monitor.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 Zack Rusin <staikos@kde.org>
00006    Pretty much ripped of from :
00007      George Staikos <staikos@kde.org> :)
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License as published by the Free Software Foundation; either
00012    version 2 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Library General Public License for more details.
00018 
00019    You should have received a copy of the GNU Library General Public License
00020    along with this library; see the file COPYING.LIB.  If not, write to
00021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022    Boston, MA 02110-1301, USA.
00023 
00024 */
00025 
00026 #include "pb_monitor.h"
00027 
00028 #include <kgenericfactory.h>
00029 #include <kdebug.h>
00030 
00031 #include <sys/types.h>
00032 #include <unistd.h>
00033 
00034 extern "C" {
00035 //Hack because of the fact that pbb author is using C++ keywords in the code
00036 //among which is "template"...
00037 #undef template
00038 #include <pbb.h>
00039 
00040 // TAG_BRIGHTNESS was renamed to TAG_LCDBRIGHTNESS in pbbuttons
00041 // 0.6.1-2
00042 #ifndef TAG_LCDBRIGHTNESS
00043 #define TAG_LCDBRIGHTNESS TAG_BRIGHTNESS
00044 #endif
00045 }
00046 
00047 #define BUFFERLEN   200
00048 const QString tpmodes[] = { I18N_NOOP("No Tap"), I18N_NOOP("Tap"), I18N_NOOP("Drag"), I18N_NOOP("Lock") };
00049 
00050 namespace KMilo {
00051 
00052 PowerBookMonitor::PowerBookMonitor(QObject *parent, const char *name,
00053                                    const QStringList& args)
00054     : Monitor(parent, name, args),
00055         m_progress( 0 )
00056 {
00057     init_libpbb();
00058 }
00059 
00060 PowerBookMonitor::~PowerBookMonitor()
00061 {
00062     ipc_exit();
00063 }
00064 
00065 
00066 bool PowerBookMonitor::init()
00067 {
00068 // pbbuttons 0.6.7 or newer
00069 #ifdef CLIENT_REGISTER
00070     return ( ipc_init( "kmilo", LIBMODE_CLIENT, CLIENT_REGISTER ) == 0 );
00071 #else
00072     return ( ipc_init( LIBMODE_CLIENT, 1 ) == 0 );
00073 #endif
00074 }
00075 
00076 
00077 Monitor::DisplayType PowerBookMonitor::poll()
00078 {
00079     Monitor::DisplayType rc = None;
00080     // Drain the queue, send the last message
00081     struct tagitem* tag = readMessage();
00082     m_message = QString();
00083     while ( tag && tag->tag != TAG_END ) {
00084         switch ( tag->tag ) {
00085         case TAG_VOLUME:
00086             rc = Monitor::Volume;
00087             m_progress = (int)tag->data;
00088             break;
00089         case TAG_MUTE:
00090             rc = Monitor::Mute;
00091             m_progress = (int)tag->data;
00092             break;
00093         case TAG_LCDBRIGHTNESS:
00094             rc = Monitor::Brightness;
00095             m_progress = ((int)tag->data)*100/15;
00096             break;
00097         case TAG_TPMODE:
00098             {
00099                 rc = Monitor::Tap;
00100                 QString marg =  tpmodes[ tag->data & 3 ];
00101                 m_message = i18n( "Operating mode set to: %1.", marg );
00102             }
00103             break;
00104         default:
00105             break;
00106         }
00107         ++tag;
00108     }
00109 
00110     if ( m_sleep ) {
00111         rc = Monitor::Sleep;
00112     }
00113 
00114     return rc;
00115 }
00116 
00117 
00118 int PowerBookMonitor::progress() const
00119 {
00120     return m_progress;
00121 }
00122 
00123 QString PowerBookMonitor::message() const
00124 {
00125     return m_message;
00126 }
00127 
00128 struct tagitem* PowerBookMonitor::readMessage()
00129 {
00130     char buffer[BUFFERLEN];
00131     m_sleep = false;
00132     if ( (ipc_receive(buffer, BUFFERLEN)) >=0 ) {
00133         if ( buffer ) {
00134             struct pbbmessage *msg = reinterpret_cast<struct pbbmessage*>( buffer );
00135             switch ( msg->action ) {
00136             case REGFAILED:
00137                 kDebug()<<"PBB registration failed";
00138                 break;
00139             case CLIENTEXIT:
00140                 kDebug()<<"PBB client exited";
00141                 break;
00142             case CHANGEVALUE:
00143                 return msg->taglist;
00144                 break;
00145             case WARNING:
00146                 if ( msg->taglist->data == 0 ) {
00147                     m_message = i18n( "The computer will sleep now." );
00148                 } else {
00149                     m_message = i18np( "The computer will sleep in %1 second.",
00150                               "The computer will sleep in %1 seconds.",
00151                               msg->taglist->data );
00152                 }
00153                 m_sleep = true;
00154                 kDebug()<<"PBB Warning";
00155                 break;
00156             }
00157         }
00158     }
00159     return 0;
00160 }
00161 
00162 }
00163 
00164 K_EXPORT_COMPONENT_FACTORY(kmilo_powerbook, KGenericFactory<KMilo::PowerBookMonitor>("kmilo_powerbook"))
00165 

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