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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/**
* Copyright (c) 2000 Matthias Elter <[email protected]>
*
* 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 <tqgroupbox.h>
#include <tqlayout.h>
#include <tqwhatsthis.h>
#include <tqcheckbox.h>
#include <tqslider.h>
#include <tdeapplication.h>
#include <tdeglobal.h>
#include <dcopclient.h>
#include <tdelocale.h>
#include <kdialog.h>
#include <klineedit.h>
#include <knuminput.h>
#include <tdeconfig.h>
#include <netwm.h>
#include "desktop.h"
#include "desktop.moc"
extern "C"
{
TDE_EXPORT TDECModule *create_virtualdesktops(TQWidget *parent, const char * /*name*/)
{
return new KDesktopConfig(parent, "kcmkonq");
}
}
// I'm using lineedits by intention as it makes sence to be able
// to see all desktop names at the same time. It also makes sense to
// be able to TAB through those line edits fast. So don't send me mails
// asking why I did not implement a more intelligent/smaller GUI.
KDesktopConfig::KDesktopConfig(TQWidget *parent, const char * /*name*/)
: TDECModule(parent, "kcmkonq")
{
setQuickHelp( i18n("<h1>Multiple Desktops</h1>In this module, you can configure how many virtual desktops you want and how these should be labeled."));
Q_ASSERT(maxDesktops % 2 == 0);
TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
// number group
TQGroupBox *number_group = new TQGroupBox(this);
TQHBoxLayout *lay = new TQHBoxLayout(number_group,
KDialog::marginHint(),
KDialog::spacingHint());
TQLabel *label = new TQLabel(i18n("N&umber of desktops: "), number_group);
_numInput = new KIntNumInput(4, number_group);
_numInput->setRange(1, maxDesktops, 1, true);
connect(_numInput, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(slotValueChanged(int)));
connect(_numInput, TQ_SIGNAL(valueChanged(int)), TQ_SLOT( changed() ));
label->setBuddy( _numInput );
TQString wtstr = i18n( "Here you can set how many virtual desktops you want on your TDE desktop. Move the slider to change the value." );
TQWhatsThis::add( label, wtstr );
TQWhatsThis::add( _numInput, wtstr );
lay->addWidget(label);
lay->addWidget(_numInput);
lay->setStretchFactor( _numInput, 2 );
layout->addWidget(number_group);
// name group
TQGroupBox *name_group = new TQGroupBox(i18n("Desktop &Names"), this);
name_group->setColumnLayout(4, TQt::Horizontal);
for(int i = 0; i < (maxDesktops/2); i++)
{
_nameLabel[i] = new TQLabel(i18n("Desktop %1:").arg(i+1), name_group);
_nameInput[i] = new KLineEdit(name_group);
_nameLabel[i+(maxDesktops/2)] = new TQLabel(i18n("Desktop %1:").arg(i+(maxDesktops/2)+1), name_group);
_nameInput[i+(maxDesktops/2)] = new KLineEdit(name_group);
TQWhatsThis::add( _nameLabel[i], i18n( "Here you can enter the name for desktop %1" ).arg( i+1 ) );
TQWhatsThis::add( _nameInput[i], i18n( "Here you can enter the name for desktop %1" ).arg( i+1 ) );
TQWhatsThis::add( _nameLabel[i+(maxDesktops/2)], i18n( "Here you can enter the name for desktop %1" ).arg( i+(maxDesktops/2)+1 ) );
TQWhatsThis::add( _nameInput[i+(maxDesktops/2)], i18n( "Here you can enter the name for desktop %1" ).arg( i+(maxDesktops/2)+1 ) );
connect(_nameInput[i], TQ_SIGNAL(textChanged(const TQString&)),
TQ_SLOT( changed() ));
connect(_nameInput[i+(maxDesktops/2)], TQ_SIGNAL(textChanged(const TQString&)),
TQ_SLOT( changed() ));
}
for(int i = 1; i < maxDesktops; i++)
setTabOrder( _nameInput[i-1], _nameInput[i] );
layout->addWidget(name_group);
_wheelOption = new TQCheckBox(i18n("Mouse wheel over desktop background switches desktop"), this);
connect(_wheelOption,TQ_SIGNAL(toggled(bool)), TQ_SLOT( changed() ));
layout->addWidget(_wheelOption);
layout->addStretch(1);
load();
}
void KDesktopConfig::load()
{
load( false );
}
void KDesktopConfig::load( bool useDefaults )
{
// get number of desktops
NETRootInfo info( tqt_xdisplay(), NET::NumberOfDesktops | NET::DesktopNames );
int n = info.numberOfDesktops();
int konq_screen_number = 0;
if (tqt_xdisplay())
konq_screen_number = DefaultScreen(tqt_xdisplay());
TQCString groupname;
if (konq_screen_number == 0)
groupname = "Desktops";
else
groupname.sprintf("Desktops-screen-%d", konq_screen_number);
TDEConfig * twinconfig = new TDEConfig("twinrc");
twinconfig->setReadDefaults( useDefaults );
twinconfig->setGroup("Desktops");
for(int i = 1; i <= maxDesktops; i++)
{
TQString key_name(TQString("Name_") + TQString::number(i));
TQString name = TQString::fromUtf8(info.desktopName(i));
if (name.isEmpty()) // Get name from configuration if none is set in the WM.
{
name = twinconfig->readEntry(key_name, i18n("Desktop %1").arg(i));
}
_nameInput[i-1]->setText(name);
// Is this entry immutable or not in the range of configured desktops?
_labelImmutable[i - 1] = twinconfig->entryIsImmutable(key_name);
_nameInput[i-1]->setEnabled(i <= n && !_labelImmutable[i - 1]);
}
_numInput->setEnabled(!twinconfig->entryIsImmutable("Number"));
delete twinconfig;
twinconfig = 0;
TQString configfile;
if (konq_screen_number == 0)
configfile = "kdesktoprc";
else
configfile.sprintf("kdesktop-screen-%drc", konq_screen_number);
TDEConfig *config = new TDEConfig(configfile, false, false);
config->setReadDefaults( useDefaults );
config->setGroup("Mouse Buttons");
_wheelOption->setChecked(config->readBoolEntry("WheelSwitchesWorkspace",false));
_wheelOptionImmutable = config->entryIsImmutable("WheelSwitchesWorkspace");
if (_wheelOptionImmutable || n<2)
_wheelOption->setEnabled( false );
delete config;
config = 0;
_numInput->setValue(n);
emit changed( useDefaults );
}
void KDesktopConfig::save()
{
NETRootInfo info( tqt_xdisplay(), NET::NumberOfDesktops | NET::DesktopNames );
// set desktop names
for(int i = 1; i <= maxDesktops; i++)
{
info.setDesktopName(i, (_nameInput[i-1]->text()).utf8());
info.activate();
}
// set number of desktops
info.setNumberOfDesktops(_numInput->value());
info.activate();
XSync(tqt_xdisplay(), FALSE);
int konq_screen_number = 0;
if (tqt_xdisplay())
konq_screen_number = DefaultScreen(tqt_xdisplay());
TQCString appname;
if (konq_screen_number == 0)
appname = "kdesktop";
else
appname.sprintf("kdesktop-screen-%d", konq_screen_number);
TDEConfig *config = new TDEConfig(appname + "rc");
config->setGroup("Mouse Buttons");
config->writeEntry("WheelSwitchesWorkspace", _wheelOption->isChecked());
delete config;
// Tell kdesktop about the new config file
if ( !kapp->dcopClient()->isAttached() )
kapp->dcopClient()->attach();
TQByteArray data;
kapp->dcopClient()->send( appname, "KDesktopIface", "configure()", data );
emit changed(false);
}
void KDesktopConfig::defaults()
{
load( true );
}
void KDesktopConfig::slotValueChanged(int n)
{
for(int i = 0; i < maxDesktops; i++)
{ _nameInput[i]->setEnabled(i < n && !_labelImmutable[i]); }
if (!_wheelOptionImmutable)
{ _wheelOption->setEnabled(n>1); }
emit changed(true);
}
|