• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

tdebacklightdevice.cpp
00001 /* This file is part of the TDE libraries
00002    Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
00003              (C) 2013 Golubev Alexander <fatzer2@gmail.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "tdebacklightdevice.h"
00021 
00022 #include <unistd.h>
00023 
00024 #include <tqfile.h>
00025 
00026 #include "config.h"
00027 
00028 // uPower
00029 #if defined(WITH_TDEHWLIB_DAEMONS)
00030     #include <tqdbusdata.h>
00031     #include <tqdbusmessage.h>
00032     #include <tqdbusproxy.h>
00033     #include <tqdbusvariant.h>
00034     #include <tqdbusconnection.h>
00035 #endif // defined(WITH_TDEHWLIB_DAEMONS)
00036 
00037 TDEBacklightDevice::TDEBacklightDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
00038 }
00039 
00040 TDEBacklightDevice::~TDEBacklightDevice() {
00041 }
00042 
00043 TDEDisplayPowerLevel::TDEDisplayPowerLevel TDEBacklightDevice::powerLevel() {
00044     return m_powerLevel;
00045 }
00046 
00047 void TDEBacklightDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl) {
00048     m_powerLevel = pl;
00049 }
00050 
00051 void TDEBacklightDevice::internalSetMaximumRawBrightness(int br) {
00052     m_maximumBrightness = br;
00053 }
00054 
00055 void TDEBacklightDevice::internalSetCurrentRawBrightness(int br) {
00056     m_currentBrightness = br;
00057 }
00058 
00059 int TDEBacklightDevice::brightnessSteps() {
00060     return m_maximumBrightness + 1;
00061 }
00062 
00063 double TDEBacklightDevice::brightnessPercent() {
00064     return (((m_currentBrightness*1.0)/m_maximumBrightness)*100.0);
00065 }
00066 
00067 bool TDEBacklightDevice::canSetBrightness() {
00068     TQString brightnessnode = systemPath() + "/brightness";
00069     int rval = access (brightnessnode.ascii(), W_OK);
00070     if (rval == 0) {
00071         return TRUE;
00072     }
00073 
00074 #ifdef WITH_TDEHWLIB_DAEMONS
00075     {
00076         TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
00077         if (dbusConn.isConnected()) {
00078             TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Brightness", dbusConn);
00079             if (hardwareControl.canSend()) {
00080                 // can set brightness?
00081                 TQValueList<TQT_DBusData> params;
00082                 params << TQT_DBusData::fromString(brightnessnode);
00083                 TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetBrightness", params);
00084                 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
00085                     return reply[0].toBool();
00086                 }
00087             }
00088         }
00089     }
00090 #endif // WITH_TDEHWLIB_DAEMONS
00091 
00092     return FALSE;
00093 }
00094 
00095 int TDEBacklightDevice::rawBrightness() {
00096     return m_currentBrightness;
00097 }
00098 
00099 void TDEBacklightDevice::setRawBrightness(int br) {
00100     bool setRawBrightnessDone = FALSE;
00101 
00102     TQString brightnessnode = systemPath() + "/brightness";
00103     TQString brightnessCommand = TQString("%1").arg(br);
00104     TQFile file( brightnessnode );
00105     if ( file.open( IO_WriteOnly ) ) {
00106         TQTextStream stream( &file );
00107         stream << brightnessCommand;
00108         file.close();
00109         setRawBrightnessDone = TRUE;
00110     }
00111 
00112 #ifdef WITH_TDEHWLIB_DAEMONS
00113     if ( !setRawBrightnessDone ) {
00114         TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
00115         if (dbusConn.isConnected()) {
00116             TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Brightness", dbusConn);
00117             if (hardwareControl.canSend()) {
00118                 // set brightness
00119                 TQValueList<TQT_DBusData> params;
00120                 params << TQT_DBusData::fromString(brightnessnode) << TQT_DBusData::fromString(brightnessCommand);
00121                 TQT_DBusMessage reply = hardwareControl.sendWithReply("SetBrightness", params);
00122                 if (reply.type() == TQT_DBusMessage::ReplyMessage) {
00123                     setRawBrightnessDone = TRUE;
00124                 }
00125             }
00126         }
00127     }
00128 #endif // WITH_TDEHWLIB_DAEMONS
00129 
00130 }
00131 
00132 #include "tdebacklightdevice.moc"

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.