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
|
/*
* main.cpp
*
* Copyright (C) 2004 Jonathan Riddell <jr@jriddell.org>
*
* Based on kcm_kvaio
* Copyright (C) 2003 Mirko Boehm (mirko@kde.org)
*
* 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.
*
*/
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqfile.h>
#include <tqbuttongroup.h>
#include <dcopclient.h>
#include <kgenericfactory.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include <tdeconfig.h>
#include <kurlrequester.h>
#include <tdecmodule.h>
#ifdef Q_OS_FREEBSD
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#include "kcmthinkpad_general.h"
#include <dcopclient.h>
#include "main.h"
#include "main.moc"
typedef KGenericFactory<KCMThinkpadModule, TQWidget> KCMThinkpadModuleFactory;
K_EXPORT_COMPONENT_FACTORY( kcm_thinkpad, KCMThinkpadModuleFactory("kcmthinkpad"))
#define CONFIG_FILE "kmilodrc"
KCMThinkpadModule::KCMThinkpadModule(TQWidget* parent, const char* name, const TQStringList&)
: TDECModule(KCMThinkpadModuleFactory::instance(), parent, name) {
TDEAboutData* about =
new TDEAboutData(I18N_NOOP("kcmthinkpad"),
I18N_NOOP("TDE Control Module for IBM Thinkpad "
"Laptop Hardware"),
0, 0, TDEAboutData::License_GPL,
"(c) 2004 Jonathan Riddell");
about->addAuthor("Jonathan Riddell",
I18N_NOOP("Original author"),
"jr@jriddell.org");
setAboutData( about );
TQVBoxLayout* layout = new TQVBoxLayout(this);
m_KCMThinkpadGeneral = new KCMThinkpadGeneral(this);
layout->addWidget( m_KCMThinkpadGeneral );
layout->addStretch();
load();
//try and open /dev/nvram
m_nvramReadable = false;
m_nvramWriteable = false;
#ifdef Q_OS_FREEBSD
// Look if the sysctl tree of acpi_ibm is in place
u_int n = 0;
size_t len = sizeof(n);
if (m_nvramReadable = ( sysctlbyname("dev.acpi_ibm.0.volume", &n, &len, NULL, 0) != -1 ))
m_nvramWriteable = ( sysctlbyname("dev.acpi_ibm.0.volume", NULL, NULL, &n, len) != -1 );
if (!m_nvramReadable) {
setButtons(buttons() & ~Default);
m_KCMThinkpadGeneral->bgGeneral->setEnabled(false);
m_KCMThinkpadGeneral->tlOff->setText(i18n("In order to use the Thinkpad Buttons KMilo Plugin, "
"you have to load the acpi_ibm(4) driver."));
} else if (!m_nvramWriteable) {
m_KCMThinkpadGeneral->tlOff->setText(i18n("Could not write to dev.acpi_ibm.0.volume. "
"Using software volume, required for "
"R30/R31 models, or using a custom volume "
"change step is disabled."));
#else
TQFile nvramFile(m_nvramFile);
if ( nvramFile.open(IO_ReadOnly) ) {
m_nvramReadable = true;
nvramFile.close();
}
if ( nvramFile.open(IO_WriteOnly) ) {
m_nvramWriteable = true;
nvramFile.close();
}
if (!m_nvramReadable) {
setButtons(buttons() & ~Default);
m_KCMThinkpadGeneral->bgGeneral->setEnabled(false);
} else if (!m_nvramWriteable) {
m_KCMThinkpadGeneral->tlOff->setText(i18n("Could not write to %1. "
"To use the software volume, required for "
"R30/R31 models and to use a custom volume "
"change step, set the nvram device to world "
"writeable: <em>chmod 666 "
"/dev/nvram</em>").arg(m_nvramFile));
#endif
} else {
m_KCMThinkpadGeneral->tlOff->setText(i18n("Thinkpad Buttons KMilo Plugin Ready For Configuration"));
}
connect( m_KCMThinkpadGeneral, TQT_SIGNAL(changed()), TQT_SLOT(changed()));
}
void KCMThinkpadModule::save() {
if (!m_nvramReadable) {
return;
}
DCOPClient client;
TDEConfig config(CONFIG_FILE);
config.setGroup("thinkpad");
config.writeEntry("run", m_KCMThinkpadGeneral->mCbRun->isChecked());
config.writeEntry("softwareVolume", m_KCMThinkpadGeneral->mCbSoftwareVolume->isChecked());
config.writeEntry("volumeStep", m_KCMThinkpadGeneral->mSpinboxVolumeStep->value());
config.writeEntry("buttonThinkpad", m_KCMThinkpadGeneral->commandExec->url());
config.writeEntry("buttonHome", m_KCMThinkpadGeneral->commandExecHome->url());
config.writeEntry("buttonSearch", m_KCMThinkpadGeneral->commandExecSearch->url());
config.writeEntry("buttonMail", m_KCMThinkpadGeneral->commandExecMail->url());
config.writeEntry("buttonZoom", m_KCMThinkpadGeneral->commandExecZoom->url());
config.sync();
if (client.attach()) {
TQByteArray data, replyData;
TQCString replyType;
if (!client.call("kded", "kmilod", "reconfigure()", data, replyType, replyData)) {
kdDebug() << "KCMThinkpad::showTextMsg: "
<< "there was an error using DCOP on kmilod::reconfigure()." << endl;
}
} else {
kdDebug() << "KCMThinkpadModule: cannot attach to DCOP server, "
<< "no automatic config update." << endl;
}
}
void KCMThinkpadModule::load() {
load( false );
}
void KCMThinkpadModule::load(bool useDefaults) {
TDEConfig config(CONFIG_FILE);
config.setReadDefaults( useDefaults );
config.setGroup("thinkpad");
m_KCMThinkpadGeneral->mCbRun->setChecked(config.readBoolEntry("run", false));
m_KCMThinkpadGeneral->mCbSoftwareVolume->setChecked(config.readBoolEntry("softwareVolume", true));
m_KCMThinkpadGeneral->mSpinboxVolumeStep->setValue(config.readNumEntry("volumeStep", 14));
m_KCMThinkpadGeneral->commandExec->setURL(config.readEntry("buttonThinkpad", KDE_BINDIR "/konsole"));
m_KCMThinkpadGeneral->commandExecHome->setURL(config.readEntry("buttonHome", KDE_BINDIR "/konqueror"));
m_KCMThinkpadGeneral->commandExecSearch->setURL(config.readEntry("buttonSearch", KDE_BINDIR "/kfind"));
m_KCMThinkpadGeneral->commandExecMail->setURL(config.readEntry("buttonMail", KDE_BINDIR "/kmail"));
m_KCMThinkpadGeneral->commandExecZoom->setURL(config.readEntry("buttonZoom", KDE_BINDIR "/ksnapshot"));
m_nvramFile = config.readEntry("nvram", "/dev/nvram");
emit changed( useDefaults );
}
void KCMThinkpadModule::defaults() {
load( true );
}
|