1 // -*- c-basic-offset: 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.
24 #include <QtDBus/QDBusInterface>
25 #include <QtGui/QBoxLayout>
26 #include <QtGui/QCheckBox>
27 #include <QtGui/QLabel>
28 #include <QtGui/QFormLayout>
29 #include <QtGui/QSlider>
40 #include <klineedit.h>
41 #include <knuminput.h>
43 #include <kconfiggroup.h>
44 #include <kgenericfactory.h>
48 K_PLUGIN_FACTORY(KWinKcmFactory
,
49 registerPlugin
<KDesktopConfig
>();
51 K_EXPORT_PLUGIN(KWinKcmFactory("kcm_kwindesktop"))
54 #include "kdesktop_interface.h"
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);
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
);
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
&)),
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
);
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
);
125 layout
->addStretch(1);
127 // Begin check for immutable
129 int kwin_screen_number
= DefaultScreen(QX11Info::display());
131 int kwin_screen_number
= 0;
134 KSharedConfig::Ptr config
= KSharedConfig::openConfig( "kwinrc" );
136 QByteArray groupname
;
137 if (kwin_screen_number
== 0)
138 groupname
= "Desktops";
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);
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
164 void KDesktopConfig::load()
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
);
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);
197 _numInput
->setValue(1);
201 void KDesktopConfig::save()
204 NETRootInfo
info( QX11Info::display(), NET::NumberOfDesktops
| NET::DesktopNames
);
206 for(int i
= 1; i
<= maxDesktops
; i
++)
208 info
.setDesktopName(i
, (_nameInput
[i
-1]->text()).toUtf8());
211 // set number of desktops
212 info
.setNumberOfDesktops(_numInput
->value());
215 XSync(QX11Info::display(), false);
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());
228 if (konq_screen_number
== 0)
229 appname
= "org.kde.kdesktop";
231 appname
= "org.kde.kdesktop-screen-" + QByteArray::number( konq_screen_number
);
233 org::kde::kdesktop::Desktop
desktop(appname
, "/Desktop", QDBusConnection::sessionBus());
241 void KDesktopConfig::defaults()
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
);
256 _wheelOption
->setChecked(false);
257 if (!_wheelOptionImmutable
)
258 _wheelOption
->setEnabled(true);
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));
274 if (!_wheelOptionImmutable
)
275 _wheelOption
->setEnabled(n
>1);
280 #include "desktop.moc"