add more spacing
[personal-kdebase.git] / workspace / kwin / kcmkwin / kwindesktop / desktop.cpp
blob811682a85298a9a159442c5ebf7a6392aee0b4f7
1 // -*- c-basic-offset: 2 -*-
2 /**
3 * Copyright (c) 2000 Matthias Elter <elter@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 // Own
21 #include "desktop.h"
23 // Qt
24 #include <QtDBus/QDBusInterface>
25 #include <QtGui/QBoxLayout>
26 #include <QtGui/QCheckBox>
27 #include <QtGui/QLabel>
28 #include <QtGui/QFormLayout>
29 #include <QtGui/QSlider>
30 #include <QGroupBox>
32 #ifdef Q_WS_X11
33 #include <QX11Info>
34 #endif
36 // KDE
37 #include <kglobal.h>
38 #include <klocale.h>
39 #include <kdialog.h>
40 #include <klineedit.h>
41 #include <knuminput.h>
42 #include <kconfig.h>
43 #include <kconfiggroup.h>
44 #include <kgenericfactory.h>
46 #include <netwm.h>
48 K_PLUGIN_FACTORY(KWinKcmFactory,
49 registerPlugin<KDesktopConfig>();
51 K_EXPORT_PLUGIN(KWinKcmFactory("kcm_kwindesktop"))
53 #if 0
54 #include "kdesktop_interface.h"
55 #endif
57 // I'm using lineedits by intention as it makes sence to be able
58 // to see all desktop names at the same time. It also makes sense to
59 // be able to TAB through those line edits fast. So don't send me mails
60 // asking why I did not implement a more intelligent/smaller GUI.
62 KDesktopConfig::KDesktopConfig(QWidget *parent, const QVariantList &)
63 : KCModule(KWinKcmFactory::componentData(), parent)
66 setQuickHelp( i18n("<h1>Multiple Desktops</h1>In this module, you can configure how many virtual desktops you want and how these should be labeled."));
68 Q_ASSERT(maxDesktops % 2 == 0);
70 QVBoxLayout *layout = new QVBoxLayout(this);
71 layout->setMargin(0);
72 layout->setSpacing(KDialog::spacingHint());
74 QHBoxLayout *lay = new QHBoxLayout();
75 lay->setMargin(KDialog::marginHint());
76 lay->setSpacing(KDialog::spacingHint());
78 QLabel *label = new QLabel(i18n("N&umber of desktops: "), this);
79 _numInput = new KIntNumInput(4, this);
80 _numInput->setRange(1, maxDesktops, 1);
81 connect(_numInput, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
82 connect(_numInput, SIGNAL(valueChanged(int)), SLOT( changed() ));
83 label->setBuddy( _numInput );
84 QString wtstr = i18n( "Here you can set how many virtual desktops you want on your KDE desktop. Move the slider to change the value." );
85 label->setWhatsThis( wtstr );
86 _numInput->setWhatsThis( wtstr );
87 //QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
89 lay->addWidget(label);
90 lay->addWidget(_numInput);
91 //lay->addItem(horizontalSpacer);
92 lay->setStretchFactor( _numInput, 2 );
94 layout->addLayout(lay);
96 // name group
97 QGroupBox *name_group = new QGroupBox(i18n("Desktop &Names"), this);
98 QGridLayout *namesLayout = new QGridLayout;
99 name_group->setLayout(namesLayout);
100 for(int i = 0; i < maxDesktops; i++)
102 _nameLabel[i] = new QLabel(i18n("Desktop %1:", i+1), name_group);
103 _nameInput[i] = new KLineEdit(name_group);
104 _nameLabel[i]->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
105 _nameLabel[i]->setWhatsThis( i18n( "Here you can enter the name for desktop %1", i+1 ) );
106 _nameInput[i]->setWhatsThis( i18n( "Here you can enter the name for desktop %1", i+1 ) );
108 connect(_nameInput[i], SIGNAL(textChanged(const QString&)),
109 SLOT( changed() ));
110 namesLayout->addWidget(_nameLabel[i], i, 0, 1, 1);
111 namesLayout->addWidget(_nameInput[i], i, 1, 1, 1);
114 for(int i = 1; i < maxDesktops; i++)
115 setTabOrder( _nameInput[i-1], _nameInput[i] );
117 layout->addWidget(name_group);
119 #if 0
120 _wheelOption = new QCheckBox(i18n("Mouse wheel over desktop background switches desktop"), this);
121 connect(_wheelOption,SIGNAL(toggled(bool)), SLOT( changed() ));
123 layout->addWidget(_wheelOption);
124 #endif
125 layout->addStretch(1);
127 // Begin check for immutable
128 #ifdef Q_WS_X11
129 int kwin_screen_number = DefaultScreen(QX11Info::display());
130 #else
131 int kwin_screen_number = 0;
132 #endif
134 KSharedConfig::Ptr config = KSharedConfig::openConfig( "kwinrc" );
136 QByteArray groupname;
137 if (kwin_screen_number == 0)
138 groupname = "Desktops";
139 else
140 groupname = "Desktops-screen-" + QByteArray::number ( kwin_screen_number );
142 if (config->isGroupImmutable(groupname))
144 name_group->setEnabled(false);
145 //number of desktops widgets
146 label->setEnabled(false);
147 _numInput->setEnabled(false);
149 else
151 KConfigGroup cfgGroup(config.data(), groupname.constData());
152 if (cfgGroup.isEntryImmutable("Number"))
154 //number of desktops widgets
155 label->setEnabled(false);
156 _numInput->setEnabled(false);
159 // End check for immutable
161 load();
164 void KDesktopConfig::load()
166 #ifdef Q_WS_X11
167 // get number of desktops
168 NETRootInfo info( QX11Info::display(), NET::NumberOfDesktops | NET::DesktopNames );
169 int n = info.numberOfDesktops();
171 _numInput->setValue(n);
173 for(int i = 1; i <= maxDesktops; i++)
175 QString name = QString::fromUtf8(info.desktopName(i));
176 _nameInput[i-1]->setText(name);
179 for(int i = 1; i <= maxDesktops; i++)
181 _nameLabel[i-1]->setVisible(i <= n);
182 _nameInput[i-1]->setVisible(i <= n);
184 emit changed(false);
186 #if 0
187 KSharedConfig::Ptr desktopConfig = KSharedConfig::openConfig("kdesktoprc", KConfig::NoGlobals);
188 desktopConfig->setGroup("Mouse Buttons");
189 _wheelOption->setChecked(desktopConfig->readEntry("WheelSwitchesWorkspace", false));
191 _wheelOptionImmutable = desktopConfig->isEntryImmutable("WheelSwitchesWorkspace");
193 if (_wheelOptionImmutable || n<2)
194 _wheelOption->setEnabled(false);
195 #endif
196 #else
197 _numInput->setValue(1);
198 #endif
201 void KDesktopConfig::save()
203 #ifdef Q_WS_X11
204 NETRootInfo info( QX11Info::display(), NET::NumberOfDesktops | NET::DesktopNames );
205 // set desktop names
206 for(int i = 1; i <= maxDesktops; i++)
208 info.setDesktopName(i, (_nameInput[i-1]->text()).toUtf8());
209 info.activate();
211 // set number of desktops
212 info.setNumberOfDesktops(_numInput->value());
213 info.activate();
215 XSync(QX11Info::display(), false);
217 #if 0
218 KSharedConfig::Ptr desktopConfig = KSharedConfig::openConfig("kdesktoprc");
219 desktopConfig->setGroup("Mouse Buttons");
220 desktopConfig->writeEntry("WheelSwitchesWorkspace", _wheelOption->isChecked());
222 // Tell kdesktop about the new config file
223 int konq_screen_number = 0;
224 if (QX11Info::display())
225 konq_screen_number = DefaultScreen(QX11Info::display());
227 QByteArray appname;
228 if (konq_screen_number == 0)
229 appname = "org.kde.kdesktop";
230 else
231 appname = "org.kde.kdesktop-screen-" + QByteArray::number( konq_screen_number );
233 org::kde::kdesktop::Desktop desktop(appname, "/Desktop", QDBusConnection::sessionBus());
234 desktop.configure();
235 #endif
237 emit changed(false);
238 #endif
241 void KDesktopConfig::defaults()
243 int n = 4;
244 _numInput->setValue(n);
246 for(int i = 0; i < maxDesktops; i++)
247 _nameInput[i]->setText(i18n("Desktop %1", i+1));
249 for(int i = 0; i < maxDesktops; i++)
251 _nameLabel[i]->setVisible(i < n);
252 _nameInput[i]->setVisible(i < n);
255 #if 0
256 _wheelOption->setChecked(false);
257 if (!_wheelOptionImmutable)
258 _wheelOption->setEnabled(true);
259 #endif
261 emit changed(false);
264 void KDesktopConfig::slotValueChanged(int n)
266 for(int i = 0; i < maxDesktops; i++)
268 _nameLabel[i]->setVisible(i < n);
269 _nameInput[i]->setVisible(i < n);
270 if(i<n && _nameInput[i]->text().isEmpty())
271 _nameInput[i]->setText(i18n("Desktop %1", i+1));
273 #if 0
274 if (!_wheelOptionImmutable)
275 _wheelOption->setEnabled(n>1);
276 #endif
277 emit changed(true);
280 #include "desktop.moc"