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

kmilo

asus.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE project
00003 
00004    Copyright (c) 2004 Chris Howells <howells@kde.org>
00005    Much code and ideas stolen from Jonathan Riddell's ThinkPad plugin
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; version
00010    2 of the License.
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 <kpluginfactory.h>
00025 #include <kpluginloader.h>
00026 #include <kconfig.h>
00027 #include <krun.h>
00028 #include <kurl.h>
00029 #include <kdebug.h>
00030 #include <klocale.h>
00031 
00032 #include <QFile>
00033 #include <QDir>
00034 
00035 #include "kmilointerface.h"
00036 
00037 #include "asus.h"
00038 
00039 #ifdef Q_OS_FREEBSD
00040 #include <sys/types.h>
00041 #include <sys/sysctl.h>
00042 #endif
00043 
00044 #define ROUND(x) (int(x + 0.5))
00045 
00046 namespace KMilo {
00047 
00048 AsusMonitor::AsusMonitor(QObject* parent, const QVariantList& args): Monitor(parent, args)
00049 {
00050 }
00051 
00052 AsusMonitor::~AsusMonitor()
00053 {
00054 }
00055 
00056 bool AsusMonitor::init()
00057 {
00058     kDebug() << "loading asus kmilo plugin" ;
00059 
00060 #ifdef Q_OS_FREEBSD
00061     /*
00062      * Check if the sysctls are in place by looking up their MIBs.
00063      * Caching the MIBs results in a major speedup.
00064      */
00065     size_t len = 4;
00066     if ( sysctlnametomib("hw.acpi.asus.lcd_brightness", brightness_mib, &len) == -1 ||
00067          sysctlnametomib("hw.acpi.asus.lcd_backlight", backlight_mib, &len) == -1 ||
00068          sysctlnametomib("hw.acpi.asus.video_output", video_mib, &len) == -1 )
00069     {
00070         kDebug() << "The driver's sysctls don't seem to exist, check that the acpi_asus module is loaded" ;
00071         return false;
00072     }
00073 #else
00074     // we need to read the /proc file system and store the current values into a struct
00075     QDir dir("/proc/acpi/asus");
00076     if (!dir.exists())
00077     {
00078         kDebug() << "/proc/acpi/asus doesn't exist, check that the asus_acpi module is loaded" ;
00079         return false;
00080     }
00081 #endif
00082     else
00083     {
00084         clearStruct(asus_state);
00085         clearStruct(last_asus_state);
00086         if (!readProc(&asus_state))
00087         {
00088             return false;
00089         }
00090     }
00091 
00092     return true;
00093 }
00094 
00095 Monitor::DisplayType AsusMonitor::poll()
00096 {
00097 
00098     // save last state and get new one
00099     memcpy(&last_asus_state, &asus_state, sizeof(asus_state_struct));
00100     readProc(&asus_state);
00101 
00102     Monitor::DisplayType pollResult = None;
00103 
00104     if (last_asus_state.brightness != asus_state.brightness)
00105     {
00106         pollResult = Brightness;
00107         float value = (float)asus_state.brightness / 15;
00108         m_progress = ROUND(value * 100);
00109     }
00110 
00111     if (last_asus_state.lcd != asus_state.lcd)
00112     {
00113         if (asus_state.lcd == 0)
00114         {
00115             _interface->displayText(i18n("Display changed: LCD off"));
00116         }
00117         else
00118         {
00119             _interface->displayText(i18n("Display changed: LCD on"));
00120         }
00121     }
00122 
00123     if (last_asus_state.display != asus_state.display)
00124     {
00125         switch (asus_state.display)
00126         {
00127             case 0:
00128                 _interface->displayText(i18n("Display changed: off"));
00129                 break;
00130             case 1:
00131                 _interface->displayText(i18n("Display changed: LCD on"));
00132                 break;
00133             case 2:
00134                 _interface->displayText(i18n("Display changed: CRT on"));
00135                 break;
00136             case 3:
00137                 _interface->displayText(i18n("Display changed: LCD and CRT on"));
00138                 break;
00139             case 4:
00140                 _interface->displayText(i18n("Display changed: TV out on"));
00141                 break;
00142             case 5:
00143                 _interface->displayText(i18n("Display changed: LCD and TV out on"));
00144                 break;
00145             case 6:
00146                 _interface->displayText(i18n("Display changed: CRT and TV out on"));
00147                 break;
00148             case 7:
00149                 _interface->displayText(i18n("Display changed: LCD, CRT and TV out on"));
00150                 break;
00151         }
00152     }
00153 
00154     return pollResult;
00155 }
00156 
00157 
00158 int AsusMonitor::progress() const
00159 {
00160     return m_progress;
00161 }
00162 
00163 bool AsusMonitor::readProc(asus_state_struct* asus_state)
00164 {
00165 #ifdef Q_OS_FREEBSD
00166     int value;
00167     size_t value_len = sizeof(value);
00168 
00169     if ( sysctl(brightness_mib, 4, &value, &value_len, NULL, 0) != -1 )
00170         asus_state->brightness = value;
00171 
00172     if ( sysctl(backlight_mib, 4, &value, &value_len, NULL, 0) != -1 )
00173         asus_state->lcd = value;
00174 
00175     if ( sysctl(video_mib, 4, &value, &value_len, NULL, 0) != -1 )
00176         asus_state->display = value;
00177 #else
00178     asus_state->brightness = readProcEntry(QString("brn"));
00179     asus_state->lcd = readProcEntry(QString("lcd"));
00180     //disabled because it does not yet work on my S5200N (asus_acpi bug)
00181     //asus_state->display = readProcEntry(QString("disp"));
00182     //FIXME
00183 #endif
00184     return true;
00185 }
00186 
00187 int AsusMonitor::readProcEntry(const QString &name)
00188 {
00189     QFile f(QString("/proc/acpi/asus/%1").arg(name));
00190 
00191     if (f.open(QIODevice::ReadOnly))
00192     {
00193         QString line;
00194         if ( !(line = f.readLine()).isNull())
00195         {
00196             line = line.trimmed();
00197             int value = line.section(' ', 0, 0).toInt();
00198             if (value > 0)
00199             {
00200                 return value;
00201             }
00202         }
00203     }
00204     return 0;
00205 }
00206 
00207 void AsusMonitor::clearStruct(asus_state_struct& asus_state)
00208 {
00209     asus_state.brightness = 0;
00210     asus_state.lcd = 0;
00211     asus_state.display = 0;
00212 }
00213 
00214 }
00215 
00216 K_PLUGIN_FACTORY(KMiloAsusFactory, registerPlugin<KMilo::AsusMonitor>();)
00217 K_EXPORT_PLUGIN(KMiloAsusFactory("kmilo_asus"))
00218 

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