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

tdecore

  • tdecore
  • tdehw
tdebacklightdevice.cpp
1/* This file is part of the TDE libraries
2 Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
3 (C) 2013 Golubev Alexander <fatzer2@gmail.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "tdebacklightdevice.h"
21
22#include <unistd.h>
23
24#include <tqfile.h>
25
26#include "config.h"
27
28// uPower
29#if defined(WITH_TDEHWLIB_DAEMONS)
30 #include <tqdbusdata.h>
31 #include <tqdbusmessage.h>
32 #include <tqdbusproxy.h>
33 #include <tqdbusvariant.h>
34 #include <tqdbusconnection.h>
35#endif // defined(WITH_TDEHWLIB_DAEMONS)
36
37TDEBacklightDevice::TDEBacklightDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
38}
39
40TDEBacklightDevice::~TDEBacklightDevice() {
41}
42
43TDEDisplayPowerLevel::TDEDisplayPowerLevel TDEBacklightDevice::powerLevel() {
44 return m_powerLevel;
45}
46
47void TDEBacklightDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPowerLevel pl) {
48 m_powerLevel = pl;
49}
50
51void TDEBacklightDevice::internalSetMaximumRawBrightness(int br) {
52 m_maximumBrightness = br;
53}
54
55void TDEBacklightDevice::internalSetCurrentRawBrightness(int br) {
56 m_currentBrightness = br;
57}
58
59int TDEBacklightDevice::brightnessSteps() {
60 return m_maximumBrightness + 1;
61}
62
63double TDEBacklightDevice::brightnessPercent() {
64 return (((m_currentBrightness*1.0)/m_maximumBrightness)*100.0);
65}
66
67bool TDEBacklightDevice::canSetBrightness() {
68 TQString brightnessnode = systemPath() + "/brightness";
69 int rval = access (brightnessnode.ascii(), W_OK);
70 if (rval == 0) {
71 return true;
72 }
73
74#ifdef WITH_TDEHWLIB_DAEMONS
75 {
76 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
77 if (dbusConn.isConnected()) {
78 TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Brightness", dbusConn);
79 if (hardwareControl.canSend()) {
80 // can set brightness?
81 TQValueList<TQT_DBusData> params;
82 params << TQT_DBusData::fromString(brightnessnode);
83 TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetBrightness", params);
84 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
85 return reply[0].toBool();
86 }
87 }
88 }
89 }
90#endif // WITH_TDEHWLIB_DAEMONS
91
92 return false;
93}
94
95int TDEBacklightDevice::rawBrightness() {
96 return m_currentBrightness;
97}
98
99void TDEBacklightDevice::setRawBrightness(int br) {
100 bool setRawBrightnessDone = false;
101
102 TQString brightnessnode = systemPath() + "/brightness";
103 TQString brightnessCommand = TQString("%1").arg(br);
104 TQFile file( brightnessnode );
105 if ( file.open( IO_WriteOnly ) ) {
106 TQTextStream stream( &file );
107 stream << brightnessCommand;
108 file.close();
109 setRawBrightnessDone = true;
110 }
111
112#ifdef WITH_TDEHWLIB_DAEMONS
113 if ( !setRawBrightnessDone ) {
114 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
115 if (dbusConn.isConnected()) {
116 TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Brightness", dbusConn);
117 if (hardwareControl.canSend()) {
118 // set brightness
119 TQValueList<TQT_DBusData> params;
120 params << TQT_DBusData::fromString(brightnessnode) << TQT_DBusData::fromString(brightnessCommand);
121 TQT_DBusMessage reply = hardwareControl.sendWithReply("SetBrightness", params);
122 if (reply.type() == TQT_DBusMessage::ReplyMessage) {
123 setRawBrightnessDone = true;
124 }
125 }
126 }
127 }
128#endif // WITH_TDEHWLIB_DAEMONS
129
130}
131
132#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.9.4
This website is maintained by Timothy Pearson.