1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/*
* sony.cpp
*
* Copyright (c) 2002 Paul Campbell <[email protected]>
*
* Requires the TQt widget libraries, available at no cost at
* http://www.troll.no/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// my headers:
#include "sony.h"
#include "version.h"
#include "portable.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
// other KDE headers:
#include <tdelocale.h>
#include <tdeconfig.h>
#include <knuminput.h>
#include <kiconloader.h>
#include <kicondialog.h>
#include <tdeapplication.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <tdemessagebox.h>
#include <krichtextlabel.h>
// other TQt headers:
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqhbox.h>
#include <tqvgroupbox.h>
#include <tqgrid.h>
#include <tqpushbutton.h>
#include <tqslider.h>
#include <tqtooltip.h>
extern void wake_laptop_daemon();
SonyConfig::SonyConfig(TQWidget * parent, const char *name)
: TDECModule(parent, name)
{
TDEGlobal::locale()->insertCatalogue("klaptopdaemon"); // For translation of klaptopdaemon messages
config = new TDEConfig("kcmlaptoprc");
TQVBoxLayout *top_layout = new TQVBoxLayout( this, KDialog::marginHint(),
KDialog::spacingHint() );
// TODO: remove linefeed from string, can't do it right now coz we have a string freeze
top_layout->addWidget(new KRichTextLabel(i18n("This panel allows you to control some of the features of the\n"
"'sonypi' device for your laptop - you should not enable the options below if you\nalso "
"use the 'sonypid' program in your system").replace("\n", " "), this));
enableScrollBar = new TQCheckBox( i18n("Enable &scroll bar"), this );
TQToolTip::add( enableScrollBar, i18n( "When checked this box enables the scrollbar so that it works under TDE" ) );
top_layout->addWidget( enableScrollBar );
connect( enableScrollBar, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()) );
enableMiddleEmulation = new TQCheckBox( i18n("&Emulate middle mouse button with scroll bar press"), this );
TQToolTip::add( enableMiddleEmulation, i18n( "When checked this box enables pressing the scroll bar to act in the same way as pressing the middle button on a 3 button mouse" ) );
top_layout->addWidget( enableMiddleEmulation );
connect( enableMiddleEmulation, TQT_SIGNAL(clicked()), this, TQT_SLOT(configChanged()) );
if (::access("/dev/sonypi", R_OK) != 0) {
enableMiddleEmulation->setEnabled(0);
enableScrollBar->setEnabled(0);
// TODO: remove linefeed from string, can't do it right now coz we have a string freeze
top_layout->addWidget(new KRichTextLabel(i18n("The /dev/sonypi is not accessable, if you wish to use the above features its\n"
"protections need to be changed. Clicking on the button below will change them\n").replace("\n", " "), this));
TQHBoxLayout *ll = new TQHBoxLayout();
TQPushButton *setupButton = new TQPushButton(i18n("Setup /dev/sonypi"), this);
connect( setupButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(setupHelper()) );
TQToolTip::add( setupButton, i18n( "This button can be used to enable the sony specific features" ) );
ll->addStretch(2);
ll->addWidget(setupButton);
ll->addStretch(8);
top_layout->addLayout(ll);
}
top_layout->addStretch(1);
top_layout->addWidget( new TQLabel( i18n("Version: %1").arg(LAPTOP_VERSION), this), 0, TQt::AlignRight );
load();
}
void SonyConfig::setupHelper()
{
TQString tdesu = TDEStandardDirs::findExe("tdesu");
if (!tdesu.isEmpty()) {
int rc = KMessageBox::warningContinueCancel(0,
i18n("You will need to supply a root password "
"to allow the protections of /dev/sonypi to be changed."),
i18n("KLaptopDaemon"), KStdGuiItem::cont(),
"");
if (rc == KMessageBox::Continue) {
TDEProcess proc;
proc << tdesu;
proc << "-u";
proc << "root";
proc << "chmod +r /dev/sonypi";
proc.start(TDEProcess::Block); // run it sync so has_acpi below sees the results
}
} else {
KMessageBox::sorry(0, i18n("The /dev/sonypi protections cannot be changed because tdesu cannot be found. Please make sure that it is installed correctly."),
i18n("KLaptopDaemon"));
}
bool enable = ::access("/dev/sonypi", R_OK) == 0;
enableMiddleEmulation->setEnabled(enable);
enableScrollBar->setEnabled(enable);
wake_laptop_daemon();
}
SonyConfig::~SonyConfig()
{
delete config;
}
void SonyConfig::save()
{
enablescrollbar = enableScrollBar->isChecked();
middleemulation = enableMiddleEmulation->isChecked();
config->setGroup("SonyDefault");
config->writeEntry("EnableScrollBar", enablescrollbar);
config->writeEntry("EnableMiddleEmulation", middleemulation);
config->sync();
changed(false);
wake_laptop_daemon();
}
void SonyConfig::load()
{
load( false );
}
void SonyConfig::load(bool useDefaults)
{
config->setReadDefaults( useDefaults );
config->setGroup("SonyDefault");
enablescrollbar = config->readBoolEntry("EnableScrollBar", false);
enableScrollBar->setChecked(enablescrollbar);
middleemulation = config->readBoolEntry("EnableMiddleEmulation", false);
enableMiddleEmulation->setChecked(middleemulation);
emit changed( useDefaults );
}
void SonyConfig::defaults()
{
load( true );
}
void SonyConfig::configChanged()
{
emit changed(true);
}
TQString SonyConfig::quickHelp() const
{
return i18n("<h1>Sony Laptop Hardware Setup</h1>This module allows you to configure "
"some Sony laptop hardware for your system");
}
void SonyConfig::slotStartMonitor()
{
wake_laptop_daemon();
}
#include "sony.moc"
|