2
* Copyright (C) 2009 Marco Martin <notmart@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "workspaceoptions.h"
21
#include "ui_mainpage.h"
23
#include <QDBusInterface>
25
#include <kmessagebox.h>
26
#include <kpluginfactory.h>
27
#include <kaboutdata.h>
28
#include <KStandardDirs>
32
using namespace KAuth;
34
K_PLUGIN_FACTORY(WorkspaceOptionsModuleFactory, registerPlugin<WorkspaceOptionsModule>();)
35
K_EXPORT_PLUGIN(WorkspaceOptionsModuleFactory("kcmworkspaceoptions"))
38
WorkspaceOptionsModule::WorkspaceOptionsModule(QWidget *parent, const QVariantList &)
39
: KCModule(WorkspaceOptionsModuleFactory::componentData(), parent),
40
m_kwinConfig( KSharedConfig::openConfig("kwinrc")),
41
m_ownConfig( KSharedConfig::openConfig("workspaceoptionsrc")),
42
m_plasmaDesktopAutostart("plasma-desktop"),
43
m_plasmaNetbookAutostart("plasma-netbook"),
44
m_krunnerAutostart("krunner"),
45
m_ui(new Ui::MainPage)
48
new KAboutData("kcmworkspaceoptions", 0, ki18n("Global options for the Plasma Workspace"),
49
0, KLocalizedString(), KAboutData::License_GPL,
50
ki18n("(c) 2009 Marco Martin"));
52
about->addAuthor(ki18n("Marco Martin"), ki18n("Maintainer"), "notmart@gmail.com");
56
setButtons(Help|Apply);
60
connect(m_ui->formFactor, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
61
connect(m_ui->dashboardMode, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
62
connect(m_ui->showToolTips, SIGNAL(toggled(bool)), this, SLOT(changed()));
63
connect(m_ui->formFactor, SIGNAL(currentIndexChanged(int)), this, SLOT(formFactorChanged(int)));
65
//enable the combobox if both plasma-desktop and plasma-netbook are present
66
if (KStandardDirs::findExe("plasma-desktop").isNull() || KStandardDirs::findExe("plasma-netbook").isNull()) {
67
m_ui->formFactor->setEnabled(false);
71
WorkspaceOptionsModule::~WorkspaceOptionsModule()
77
void WorkspaceOptionsModule::save()
80
KConfig config("plasmarc");
81
KConfigGroup cg(&config, "PlasmaToolTips");
82
cg.writeEntry("Delay", m_ui->showToolTips->isChecked() ? 0.7 : -1);
85
const bool isDesktop = m_ui->formFactor->currentIndex() == 0;
87
m_plasmaDesktopAutostart.setAutostarts(isDesktop);
88
m_plasmaDesktopAutostart.setStartPhase(KAutostart::BaseDesktop);
89
m_plasmaDesktopAutostart.setCommand("plasma-desktop");
90
m_plasmaDesktopAutostart.setAllowedEnvironments(QStringList()<<"KDE");
92
m_plasmaNetbookAutostart.setAutostarts(!isDesktop);
93
m_plasmaNetbookAutostart.setStartPhase(KAutostart::BaseDesktop);
94
m_plasmaNetbookAutostart.setCommand("plasma-netbook");
95
m_plasmaNetbookAutostart.setAllowedEnvironments(QStringList()<<"KDE");
97
m_krunnerAutostart.setAutostarts(isDesktop);
98
m_krunnerAutostart.setStartPhase(KAutostart::BaseDesktop);
99
m_krunnerAutostart.setCommand("krunner");
100
m_krunnerAutostart.setAllowedEnvironments(QStringList()<<"KDE");
102
KConfigGroup winCg(m_kwinConfig, "Windows");
104
winCg.writeEntry("BorderlessMaximizedWindows", !isDesktop);
106
winCg.writeEntry("Placement", "Maximizing");
108
winCg.writeEntry("Placement", "Smart");
112
KConfigGroup ownButtonsCg(m_ownConfig, "TitleBarButtons");
113
KConfigGroup ownPresentWindowsCg(m_ownConfig, "Effect-PresentWindows");
114
KConfigGroup kwinStyleCg(m_kwinConfig, "Style");
115
KConfigGroup kwinPresentWindowsCg(m_kwinConfig, "Effect-PresentWindows");
118
QString desktopTitleBarButtonsLeft = ownButtonsCg.readEntry("DesktopLeft", "MS");
119
QString desktopTitleBarButtonsRight = ownButtonsCg.readEntry("DesktopRight", "HIA__X");
121
QString netbookTitleBarButtonsLeft = ownButtonsCg.readEntry("NetbookLeft", "MS");
122
QString netbookTitleBarButtonsRight = ownButtonsCg.readEntry("NetbookRight", "HA__X");
125
bool desktopPresentWindowsTabbox = false;
126
bool desktopBoxSwitchTabbox = true;
127
bool desktopCoverSwitchTabbox = false;
128
bool desktopFlipSwitchTabbox = false;
130
bool netbookPresentWindowsTabbox = true;
131
bool netbookBoxSwitchTabbox = false;
132
bool netbookCoverSwitchTabbox = false;
133
bool netbookFlipSwitchTabbox = false;
136
int desktopPresentWindowsLayoutMode = 0;
137
int netbookPresentWindowsLayoutMode = 1;
139
if (m_currentlyIsDesktop) {
140
//save the user preferences on titlebar buttons
141
desktopTitleBarButtonsLeft = kwinStyleCg.readEntry("ButtonsOnLeft", "MS");
142
desktopTitleBarButtonsRight = kwinStyleCg.readEntry("ButtonsOnRight", "HIA__X");
143
ownButtonsCg.writeEntry("DesktopLeft", desktopTitleBarButtonsLeft);
144
ownButtonsCg.writeEntry("DesktopRight", desktopTitleBarButtonsRight);
146
//desktop grid effect
147
desktopPresentWindowsLayoutMode = kwinPresentWindowsCg.readEntry("LayoutMode", 0);
148
ownPresentWindowsCg.writeEntry("DesktopLayoutMode", desktopPresentWindowsLayoutMode);
151
desktopPresentWindowsTabbox = kwinPresentWindowsCg.readEntry("TabBox", false);
152
ownPresentWindowsCg.writeEntry("DesktopTabBox", desktopPresentWindowsTabbox);
154
KConfigGroup ownBoxSwitchCg( m_ownConfig, "Effect-BoxSwitch" );
155
KConfigGroup kwinBoxSwitchCg( m_kwinConfig, "Effect-BoxSwitch" );
156
desktopBoxSwitchTabbox = kwinBoxSwitchCg.readEntry("TabBox", desktopBoxSwitchTabbox);
157
ownBoxSwitchCg.writeEntry( "DesktopTabBox", desktopBoxSwitchTabbox );
158
ownBoxSwitchCg.sync();
160
KConfigGroup ownCoverSwitchCg( m_ownConfig, "Effect-CoverSwitch" );
161
KConfigGroup kwinCoverSwitchCg( m_kwinConfig, "Effect-CoverSwitch" );
162
desktopCoverSwitchTabbox = kwinCoverSwitchCg.readEntry("TabBox", desktopCoverSwitchTabbox);
163
ownCoverSwitchCg.writeEntry( "DesktopTabBox", desktopCoverSwitchTabbox );
164
ownCoverSwitchCg.sync();
166
KConfigGroup ownFlipSwitchCg( m_ownConfig, "Effect-FlipSwitch" );
167
KConfigGroup kwinFlipSwitchCg( m_kwinConfig, "Effect-FlipSwitch" );
168
desktopFlipSwitchTabbox = kwinFlipSwitchCg.readEntry("TabBox", desktopFlipSwitchTabbox);
169
ownFlipSwitchCg.writeEntry( "DesktopTabBox", desktopFlipSwitchTabbox );
170
ownFlipSwitchCg.sync();
173
//save the user preferences on titlebar buttons
174
netbookTitleBarButtonsLeft = kwinStyleCg.readEntry("ButtonsOnLeft", "MS");
175
netbookTitleBarButtonsRight = kwinStyleCg.readEntry("ButtonsOnRight", "HA__X");
176
ownButtonsCg.writeEntry("NetbookLeft", netbookTitleBarButtonsLeft);
177
ownButtonsCg.writeEntry("NetbookRight", netbookTitleBarButtonsRight);
179
//desktop grid effect
180
desktopPresentWindowsLayoutMode = kwinPresentWindowsCg.readEntry("LayoutMode", 0);
181
ownPresentWindowsCg.writeEntry("NetbookLayoutMode", desktopPresentWindowsLayoutMode);
185
netbookPresentWindowsTabbox = kwinPresentWindowsCg.readEntry("TabBox", false);
186
ownPresentWindowsCg.writeEntry("NetbookTabBox", netbookPresentWindowsTabbox);
188
KConfigGroup ownBoxSwitchCg( m_ownConfig, "Effect-BoxSwitch" );
189
KConfigGroup kwinBoxSwitchCg( m_kwinConfig, "Effect-BoxSwitch" );
190
netbookBoxSwitchTabbox = kwinBoxSwitchCg.readEntry("TabBox", netbookBoxSwitchTabbox);
191
ownBoxSwitchCg.writeEntry( "NetbookTabBox", netbookBoxSwitchTabbox );
192
ownBoxSwitchCg.sync();
194
KConfigGroup ownCoverSwitchCg( m_ownConfig, "Effect-CoverSwitch" );
195
KConfigGroup kwinCoverSwitchCg( m_kwinConfig, "Effect-CoverSwitch" );
196
netbookCoverSwitchTabbox = kwinCoverSwitchCg.readEntry("TabBox", netbookCoverSwitchTabbox);
197
ownCoverSwitchCg.writeEntry( "NetbookTabBox", netbookCoverSwitchTabbox );
198
ownCoverSwitchCg.sync();
200
KConfigGroup ownFlipSwitchCg( m_ownConfig, "Effect-FlipSwitch" );
201
KConfigGroup kwinFlipSwitchCg( m_kwinConfig, "Effect-FlipSwitch" );
202
netbookFlipSwitchTabbox = kwinFlipSwitchCg.readEntry("TabBox", netbookFlipSwitchTabbox);
203
ownFlipSwitchCg.writeEntry( "NetbookTabBox", netbookFlipSwitchTabbox );
204
ownFlipSwitchCg.sync();
207
ownPresentWindowsCg.sync();
209
kwinStyleCg.writeEntry("CustomButtonPositions", true);
211
//kill/enable the minimize button, unless configured differently
212
kwinStyleCg.writeEntry("ButtonsOnLeft", desktopTitleBarButtonsLeft);
213
kwinStyleCg.writeEntry("ButtonsOnRight", desktopTitleBarButtonsRight);
215
//present windows mode
216
kwinPresentWindowsCg.writeEntry("LayoutMode", desktopPresentWindowsLayoutMode);
218
//what to use as tabbox
219
kwinPresentWindowsCg.writeEntry("TabBox", desktopPresentWindowsTabbox);
221
KConfigGroup kwinBoxSwitchCg( m_kwinConfig, "Effect-BoxSwitch" );
222
kwinBoxSwitchCg.writeEntry( "TabBox", desktopBoxSwitchTabbox );
223
kwinBoxSwitchCg.sync();
225
KConfigGroup kwinCoverSwitchCg( m_kwinConfig, "Effect-CoverSwitch" );
226
kwinCoverSwitchCg.writeEntry( "TabBox", desktopCoverSwitchTabbox );
227
kwinCoverSwitchCg.sync();
229
KConfigGroup kwinFlipSwitchCg( m_kwinConfig, "Effect-FlipSwitch" );
230
kwinFlipSwitchCg.writeEntry( "TabBox", desktopFlipSwitchTabbox );
231
kwinFlipSwitchCg.sync();
233
//kill/enable the minimize button, unless configured differently
234
kwinStyleCg.writeEntry("ButtonsOnLeft", netbookTitleBarButtonsLeft);
235
kwinStyleCg.writeEntry("ButtonsOnRight", netbookTitleBarButtonsRight);
237
//present windows mode
238
kwinPresentWindowsCg.writeEntry("LayoutMode", netbookPresentWindowsLayoutMode);
240
//what to use as tabbox
241
kwinPresentWindowsCg.writeEntry("TabBox", netbookPresentWindowsTabbox);
243
KConfigGroup kwinBoxSwitchCg( m_kwinConfig, "Effect-BoxSwitch" );
244
kwinBoxSwitchCg.writeEntry( "TabBox", netbookBoxSwitchTabbox );
245
kwinBoxSwitchCg.sync();
247
KConfigGroup kwinCoverSwitchCg( m_kwinConfig, "Effect-CoverSwitch" );
248
kwinCoverSwitchCg.writeEntry( "TabBox", netbookCoverSwitchTabbox );
249
kwinCoverSwitchCg.sync();
251
KConfigGroup kwinFlipSwitchCg( m_kwinConfig, "Effect-FlipSwitch" );
252
kwinFlipSwitchCg.writeEntry( "TabBox", netbookFlipSwitchTabbox );
253
kwinFlipSwitchCg.sync();
257
kwinPresentWindowsCg.sync();
260
QDBusMessage message = QDBusMessage::createSignal( "/KWin", "org.kde.KWin", "reloadConfig" );
261
QDBusConnection::sessionBus().send(message);
264
if (isDesktop && !m_currentlyIsDesktop) {
265
if (KRun::run("plasma-desktop", KUrl::List(), 0)) {
266
QDBusInterface interface("org.kde.plasma-netbook", "/MainApplication");
267
interface.call("quit");
268
KRun::run("krunner", KUrl::List(), 0);
270
} else if (!isDesktop && m_currentlyIsDesktop) {
271
if (KRun::run("plasma-netbook", KUrl::List(), 0)) {
272
QDBusInterface interface("org.kde.plasma-desktop", "/MainApplication");
273
interface.call("quit");
274
QDBusInterface krunnerInterface("org.kde.krunner", "/MainApplication");
275
krunnerInterface.call("quit");
278
m_currentlyIsDesktop = isDesktop;
280
QDBusInterface interface("org.kde.plasma-desktop", "/App");
281
interface.call("setFixedDashboard", (m_ui->dashboardMode->currentIndex() == 1));
284
void WorkspaceOptionsModule::load()
286
if (m_plasmaDesktopAutostart.autostarts()) {
287
m_ui->formFactor->setCurrentIndex(0);
289
m_ui->formFactor->setCurrentIndex(1);
292
m_currentlyIsDesktop = m_plasmaDesktopAutostart.autostarts();
294
QDBusInterface interface("org.kde.plasma-desktop", "/App");
295
bool fixedDashboard = false;
297
if (interface.isValid()) {
298
fixedDashboard = interface.call("fixedDashboard").arguments().first().toBool();
301
if (fixedDashboard) {
302
m_ui->dashboardMode->setCurrentIndex(1);
304
m_ui->dashboardMode->setCurrentIndex(0);
307
KConfig config("plasmarc");
308
KConfigGroup cg(&config, "PlasmaToolTips");
309
m_ui->showToolTips->setChecked(cg.readEntry("Delay", 0.7) > 0);
312
void WorkspaceOptionsModule::defaults()
314
m_ui->formFactor->setCurrentIndex(0);
315
m_ui->dashboardMode->setCurrentIndex(0);
318
void WorkspaceOptionsModule::formFactorChanged(int newFormFactorIndex)
320
m_ui->dashboardMode->setEnabled(newFormFactorIndex == 0);
321
m_ui->dashboardLabel->setEnabled(newFormFactorIndex == 0);
324
#include "workspaceoptions.moc"