~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/kcmkwin/kwintabbox/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
#include "main.h"
 
21
 
 
22
// Qt
 
23
#include <QtDBus/QtDBus>
 
24
#include <QVBoxLayout>
 
25
 
 
26
// KDE
 
27
#include <KAboutApplicationDialog>
 
28
#include <KAction>
 
29
#include <KActionCollection>
 
30
#include <KCModuleProxy>
 
31
#include <KPluginFactory>
 
32
#include <KPluginInfo>
 
33
#include <KPluginLoader>
 
34
#include <KTabWidget>
 
35
#include <KTitleWidget>
 
36
#include <KServiceTypeTrader>
 
37
#include <KShortcutsEditor>
 
38
 
 
39
// own
 
40
#include "tabboxconfig.h"
 
41
#include "layoutconfig.h"
 
42
 
 
43
K_PLUGIN_FACTORY(KWinTabBoxConfigFactory, registerPlugin<KWin::KWinTabBoxConfig>();)
 
44
K_EXPORT_PLUGIN(KWinTabBoxConfigFactory("kcm_kwintabbox"))
 
45
 
 
46
namespace KWin
 
47
{
 
48
 
 
49
KWinTabBoxConfigForm::KWinTabBoxConfigForm(QWidget* parent)
 
50
    : QWidget(parent)
 
51
{
 
52
    setupUi(this);
 
53
}
 
54
 
 
55
KWinTabBoxConfig::KWinTabBoxConfig(QWidget* parent, const QVariantList& args)
 
56
    : KCModule(KWinTabBoxConfigFactory::componentData(), parent, args)
 
57
    , m_config(KSharedConfig::openConfig("kwinrc"))
 
58
{
 
59
    KGlobal::locale()->insertCatalog("kwin_effects");
 
60
    KTabWidget* tabWidget = new KTabWidget(this);
 
61
    m_primaryTabBoxUi = new KWinTabBoxConfigForm(tabWidget);
 
62
    m_alternativeTabBoxUi = new KWinTabBoxConfigForm(tabWidget);
 
63
    m_alternativeTabBoxUi->description->setText(
 
64
        i18n("These settings are used by the \"Walk Through Windows Alternative\" actions."));
 
65
    tabWidget->addTab(m_primaryTabBoxUi, i18n("Main"));
 
66
    tabWidget->addTab(m_alternativeTabBoxUi, i18n("Alternative"));
 
67
    QVBoxLayout* layout = new QVBoxLayout(this);
 
68
    KTitleWidget* infoLabel = new KTitleWidget(tabWidget);
 
69
    infoLabel->setText(i18n("Focus policy settings limit the functionality of navigating through windows."),
 
70
                       KTitleWidget::InfoMessage);
 
71
    infoLabel->setPixmap(KTitleWidget::InfoMessage, KTitleWidget::ImageLeft);
 
72
    layout->addWidget(infoLabel);
 
73
    layout->addWidget(tabWidget);
 
74
 
 
75
    m_editor = new KShortcutsEditor(m_primaryTabBoxUi, KShortcutsEditor::GlobalAction);
 
76
    // Shortcut config. The shortcut belongs to the component "kwin"!
 
77
    m_actionCollection = new KActionCollection(this, KComponentData("kwin"));
 
78
    m_actionCollection->setConfigGroup("Navigation");
 
79
    m_actionCollection->setConfigGlobal(true);
 
80
    KAction* a = qobject_cast<KAction*>(m_actionCollection->addAction("Walk Through Windows"));
 
81
    a->setProperty("isConfigurationAction", true);
 
82
    a->setText(i18n("Walk Through Windows"));
 
83
    a->setGlobalShortcut(KShortcut(Qt::ALT + Qt::Key_Tab));
 
84
    a = qobject_cast<KAction*>(m_actionCollection->addAction("Walk Through Windows (Reverse)"));
 
85
    a->setProperty("isConfigurationAction", true);
 
86
    a->setText(i18n("Walk Through Windows (Reverse)"));
 
87
    a->setGlobalShortcut(KShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Backtab));
 
88
    a = qobject_cast<KAction*>(m_actionCollection->addAction("Walk Through Windows Alternative"));
 
89
    a->setProperty("isConfigurationAction", true);
 
90
    a->setText(i18n("Walk Through Windows Alternative"));
 
91
    a->setGlobalShortcut(KShortcut(), KAction::ActiveShortcut);
 
92
    a = qobject_cast<KAction*>(m_actionCollection->addAction("Walk Through Windows Alternative (Reverse)"));
 
93
    a->setProperty("isConfigurationAction", true);
 
94
    a->setText(i18n("Walk Through Windows Alternative (Reverse)"));
 
95
    a->setGlobalShortcut(KShortcut(), KAction::ActiveShortcut);
 
96
    m_editor->addCollection(m_actionCollection, i18n("Navigation"));
 
97
    layout->addWidget(m_editor);
 
98
    setLayout(layout);
 
99
 
 
100
    // search the effect names
 
101
    // TODO: way to recognize if a effect is not found
 
102
    KServiceTypeTrader* trader = KServiceTypeTrader::self();
 
103
    KService::List services;
 
104
    QString boxswitch;
 
105
    QString presentwindows;
 
106
    QString coverswitch;
 
107
    QString flipswitch;
 
108
    services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_boxswitch'");
 
109
    if (!services.isEmpty())
 
110
        boxswitch = services.first()->name();
 
111
    services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_presentwindows'");
 
112
    if (!services.isEmpty())
 
113
        presentwindows = services.first()->name();
 
114
    services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_coverswitch'");
 
115
    if (!services.isEmpty())
 
116
        coverswitch = services.first()->name();
 
117
    services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_flipswitch'");
 
118
    if (!services.isEmpty())
 
119
        flipswitch = services.first()->name();
 
120
 
 
121
    m_primaryTabBoxUi->effectCombo->addItem(i18n("No Effect"));
 
122
    m_primaryTabBoxUi->effectCombo->addItem(boxswitch);
 
123
    m_primaryTabBoxUi->effectCombo->addItem(presentwindows);
 
124
    m_primaryTabBoxUi->effectCombo->addItem(coverswitch);
 
125
    m_primaryTabBoxUi->effectCombo->addItem(flipswitch);
 
126
 
 
127
    m_alternativeTabBoxUi->effectCombo->addItem(i18n("No Effect"));
 
128
    m_alternativeTabBoxUi->effectCombo->addItem(boxswitch);
 
129
    m_alternativeTabBoxUi->effectCombo->addItem(presentwindows);
 
130
    m_alternativeTabBoxUi->effectCombo->addItem(coverswitch);
 
131
    m_alternativeTabBoxUi->effectCombo->addItem(flipswitch);
 
132
 
 
133
    // effect config and info button
 
134
    m_primaryTabBoxUi->effectInfoButton->setIcon(KIcon("dialog-information"));
 
135
    m_primaryTabBoxUi->effectConfigButton->setIcon(KIcon("configure"));
 
136
    m_alternativeTabBoxUi->effectInfoButton->setIcon(KIcon("dialog-information"));
 
137
    m_alternativeTabBoxUi->effectConfigButton->setIcon(KIcon("configure"));
 
138
 
 
139
    // combo boxes
 
140
    connect(m_primaryTabBoxUi->listModeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
141
    connect(m_primaryTabBoxUi->switchingModeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
142
    connect(m_primaryTabBoxUi->effectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
143
    // check boxes
 
144
    connect(m_primaryTabBoxUi->showOutlineCheck, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
145
    connect(m_primaryTabBoxUi->showTabBox, SIGNAL(toggled(bool)), this, SLOT(changed()));
 
146
    connect(m_primaryTabBoxUi->highlightWindowCheck, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
147
    connect(m_primaryTabBoxUi->showDesktopBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
148
    // combo boxes alternative
 
149
    connect(m_alternativeTabBoxUi->listModeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
150
    connect(m_alternativeTabBoxUi->switchingModeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
151
    connect(m_alternativeTabBoxUi->effectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
152
    // check boxes alternative
 
153
    connect(m_alternativeTabBoxUi->showOutlineCheck, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
154
    connect(m_alternativeTabBoxUi->showTabBox, SIGNAL(toggled(bool)), this, SLOT(changed()));
 
155
    connect(m_alternativeTabBoxUi->highlightWindowCheck, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
156
    connect(m_alternativeTabBoxUi->showDesktopBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
157
 
 
158
    // effects
 
159
    connect(m_primaryTabBoxUi->effectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEffectSelectionChanged(int)));
 
160
    connect(m_primaryTabBoxUi->effectInfoButton, SIGNAL(clicked(bool)), this, SLOT(slotAboutEffectClicked()));
 
161
    connect(m_primaryTabBoxUi->effectConfigButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureEffectClicked()));
 
162
 
 
163
    connect(m_primaryTabBoxUi->layoutConfigButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureLayoutClicked()));
 
164
 
 
165
    // effects alternative
 
166
    connect(m_alternativeTabBoxUi->effectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEffectSelectionChangedAlternative(int)));
 
167
    connect(m_alternativeTabBoxUi->effectInfoButton, SIGNAL(clicked(bool)), this, SLOT(slotAboutEffectClickedAlternative()));
 
168
    connect(m_alternativeTabBoxUi->effectConfigButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureEffectClickedAlternative()));
 
169
 
 
170
    connect(m_alternativeTabBoxUi->layoutConfigButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureLayoutClickedAlternative()));
 
171
 
 
172
    // check focus policy - we don't offer configs for unreasonable focus policies
 
173
    KConfigGroup config(m_config, "Windows");
 
174
    QString policy = config.readEntry("FocusPolicy", "ClickToFocus");
 
175
    if ((policy == "FocusUnderMouse") || (policy == "FocusStrictlyUnderMouse")) {
 
176
        tabWidget->setEnabled(false);
 
177
        infoLabel->show();
 
178
    } else
 
179
        infoLabel->hide();
 
180
}
 
181
 
 
182
KWinTabBoxConfig::~KWinTabBoxConfig()
 
183
{
 
184
}
 
185
 
 
186
void KWinTabBoxConfig::load()
 
187
{
 
188
    KCModule::load();
 
189
 
 
190
    KConfigGroup config(m_config, "TabBox");
 
191
    KConfigGroup alternativeConfig(m_config, "TabBoxAlternative");
 
192
    loadConfig(config, m_tabBoxConfig);
 
193
    loadConfig(alternativeConfig, m_tabBoxAlternativeConfig);
 
194
 
 
195
    // sync to ui
 
196
    updateUiFromConfig(m_primaryTabBoxUi, m_tabBoxConfig);
 
197
    updateUiFromConfig(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig);
 
198
 
 
199
    // effects
 
200
    // Set current option to "none" if no plugin is activated.
 
201
    m_primaryTabBoxUi->effectCombo->setCurrentIndex(0);
 
202
    m_alternativeTabBoxUi->effectCombo->setCurrentIndex(0);
 
203
    KConfigGroup effectconfig(m_config, "Plugins");
 
204
    KConfigGroup boxswitchconfig(m_config, "Effect-BoxSwitch");
 
205
    if (effectEnabled("boxswitch", effectconfig)) {
 
206
        if (boxswitchconfig.readEntry("TabBox", true))
 
207
            m_primaryTabBoxUi->effectCombo->setCurrentIndex(1);
 
208
        if (boxswitchconfig.readEntry("TabBoxAlternative", false))
 
209
            m_alternativeTabBoxUi->effectCombo->setCurrentIndex(1);
 
210
    }
 
211
    KConfigGroup presentwindowsconfig(m_config, "Effect-PresentWindows");
 
212
    if (effectEnabled("presentwindows", effectconfig)) {
 
213
        if (presentwindowsconfig.readEntry("TabBox", false))
 
214
            m_primaryTabBoxUi->effectCombo->setCurrentIndex(2);
 
215
        if (presentwindowsconfig.readEntry("TabBoxAlternative", false))
 
216
            m_alternativeTabBoxUi->effectCombo->setCurrentIndex(2);
 
217
    }
 
218
    KConfigGroup coverswitchconfig(m_config, "Effect-CoverSwitch");
 
219
    if (effectEnabled("coverswitch", effectconfig)) {
 
220
        if (coverswitchconfig.readEntry("TabBox", false))
 
221
            m_primaryTabBoxUi->effectCombo->setCurrentIndex(3);
 
222
        if (coverswitchconfig.readEntry("TabBoxAlternative", false))
 
223
            m_alternativeTabBoxUi->effectCombo->setCurrentIndex(3);
 
224
    }
 
225
    KConfigGroup flipswitchconfig(m_config, "Effect-FlipSwitch");
 
226
    if (effectEnabled("flipswitch", effectconfig)) {
 
227
        if (flipswitchconfig.readEntry("TabBox", false))
 
228
            m_primaryTabBoxUi->effectCombo->setCurrentIndex(4);
 
229
        if (flipswitchconfig.readEntry("TabBoxAlternative", false))
 
230
            m_alternativeTabBoxUi->effectCombo->setCurrentIndex(4);
 
231
    }
 
232
    slotEffectSelectionChanged(m_primaryTabBoxUi->effectCombo->currentIndex());
 
233
    slotEffectSelectionChangedAlternative(m_alternativeTabBoxUi->effectCombo->currentIndex());
 
234
 
 
235
    emit changed(false);
 
236
}
 
237
 
 
238
void KWinTabBoxConfig::loadConfig(const KConfigGroup& config, KWin::TabBox::TabBoxConfig& tabBoxConfig)
 
239
{
 
240
    tabBoxConfig.setClientListMode(TabBox::TabBoxConfig::ClientListMode(
 
241
                                       config.readEntry<int>("ListMode", TabBox::TabBoxConfig::defaultListMode())));
 
242
    tabBoxConfig.setClientSwitchingMode(TabBox::TabBoxConfig::ClientSwitchingMode(
 
243
                                            config.readEntry<int>("SwitchingMode", TabBox::TabBoxConfig::defaultSwitchingMode())));
 
244
    tabBoxConfig.setLayout(TabBox::TabBoxConfig::LayoutMode(
 
245
                               config.readEntry<int>("LayoutMode", TabBox::TabBoxConfig::defaultLayoutMode())));
 
246
    tabBoxConfig.setSelectedItemViewPosition(TabBox::TabBoxConfig::SelectedItemViewPosition(
 
247
                config.readEntry<int>("SelectedItem", TabBox::TabBoxConfig::defaultSelectedItemViewPosition())));
 
248
    tabBoxConfig.setShowDesktop(config.readEntry<bool>("ShowDesktop",
 
249
                                TabBox::TabBoxConfig::defaultShowDesktop()));
 
250
 
 
251
    tabBoxConfig.setShowOutline(config.readEntry<bool>("ShowOutline",
 
252
                                TabBox::TabBoxConfig::defaultShowOutline()));
 
253
    tabBoxConfig.setShowTabBox(config.readEntry<bool>("ShowTabBox",
 
254
                               TabBox::TabBoxConfig::defaultShowTabBox()));
 
255
    tabBoxConfig.setHighlightWindows(config.readEntry<bool>("HighlightWindows",
 
256
                                     TabBox::TabBoxConfig::defaultHighlightWindow()));
 
257
 
 
258
    tabBoxConfig.setMinWidth(config.readEntry<int>("MinWidth",
 
259
                             TabBox::TabBoxConfig::defaultMinWidth()));
 
260
    tabBoxConfig.setMinHeight(config.readEntry<int>("MinHeight",
 
261
                              TabBox::TabBoxConfig::defaultMinHeight()));
 
262
 
 
263
    tabBoxConfig.setLayoutName(config.readEntry<QString>("LayoutName", TabBox::TabBoxConfig::defaultLayoutName()));
 
264
    tabBoxConfig.setSelectedItemLayoutName(config.readEntry<QString>("SelectedLayoutName", TabBox::TabBoxConfig::defaultSelectedItemLayoutName()));
 
265
}
 
266
 
 
267
void KWinTabBoxConfig::saveConfig(KConfigGroup& config, const KWin::TabBox::TabBoxConfig& tabBoxConfig)
 
268
{
 
269
    // combo boxes
 
270
    config.writeEntry("ListMode",           int(tabBoxConfig.clientListMode()));
 
271
    config.writeEntry("SwitchingMode",      int(tabBoxConfig.clientSwitchingMode()));
 
272
    config.writeEntry("LayoutMode",         int(tabBoxConfig.layout()));
 
273
    config.writeEntry("SelectedItem",       int(tabBoxConfig.selectedItemViewPosition()));
 
274
    config.writeEntry("LayoutName",         tabBoxConfig.layoutName());
 
275
    config.writeEntry("SelectedLayoutName", tabBoxConfig.selectedItemLayoutName());
 
276
    config.writeEntry("ShowDesktop",        tabBoxConfig.isShowDesktop());
 
277
 
 
278
    // check boxes
 
279
    config.writeEntry("ShowOutline",      tabBoxConfig.isShowOutline());
 
280
    config.writeEntry("ShowTabBox",       tabBoxConfig.isShowTabBox());
 
281
    config.writeEntry("HighlightWindows", tabBoxConfig.isHighlightWindows());
 
282
 
 
283
    // spin boxes
 
284
    config.writeEntry("MinWidth",  tabBoxConfig.minWidth());
 
285
    config.writeEntry("MinHeight", tabBoxConfig.minHeight());
 
286
    config.sync();
 
287
}
 
288
 
 
289
void KWinTabBoxConfig::save()
 
290
{
 
291
    KCModule::save();
 
292
    KConfigGroup config(m_config, "TabBox");
 
293
 
 
294
    // sync ui to config
 
295
    updateConfigFromUi(m_primaryTabBoxUi, m_tabBoxConfig);
 
296
    updateConfigFromUi(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig);
 
297
    saveConfig(config, m_tabBoxConfig);
 
298
    config = KConfigGroup(m_config, "TabBoxAlternative");
 
299
    saveConfig(config, m_tabBoxAlternativeConfig);
 
300
 
 
301
    // effects
 
302
    bool boxSwitch              = false;
 
303
    bool presentWindowSwitching = false;
 
304
    bool coverSwitch            = false;
 
305
    bool flipSwitch             = false;
 
306
    bool boxSwitchAlternative               = false;
 
307
    bool presentWindowSwitchingAlternative  = false;
 
308
    bool coverSwitchAlternative             = false;
 
309
    bool flipSwitchAlternative              = false;
 
310
    switch(m_primaryTabBoxUi->effectCombo->currentIndex()) {
 
311
    case 1:
 
312
        boxSwitch = true;
 
313
        break;
 
314
    case 2:
 
315
        presentWindowSwitching = true;
 
316
        break;
 
317
    case 3:
 
318
        coverSwitch = true;
 
319
        break;
 
320
    case 4:
 
321
        flipSwitch = true;
 
322
        break;
 
323
    default:
 
324
        break; // nothing
 
325
    }
 
326
    switch(m_alternativeTabBoxUi->effectCombo->currentIndex()) {
 
327
    case 1:
 
328
        boxSwitchAlternative = true;
 
329
        break;
 
330
    case 2:
 
331
        presentWindowSwitchingAlternative = true;
 
332
        break;
 
333
    case 3:
 
334
        coverSwitchAlternative = true;
 
335
        break;
 
336
    case 4:
 
337
        flipSwitchAlternative = true;
 
338
        break;
 
339
    default:
 
340
        break; // nothing
 
341
    }
 
342
    // activate effects if not active
 
343
    KConfigGroup effectconfig(m_config, "Plugins");
 
344
    if (boxSwitch || boxSwitchAlternative)
 
345
        effectconfig.writeEntry("kwin4_effect_boxswitchEnabled", true);
 
346
    if (presentWindowSwitching || presentWindowSwitchingAlternative)
 
347
        effectconfig.writeEntry("kwin4_effect_presentwindowsEnabled", true);
 
348
    if (coverSwitch || coverSwitchAlternative)
 
349
        effectconfig.writeEntry("kwin4_effect_coverswitchEnabled", true);
 
350
    if (flipSwitch || flipSwitchAlternative)
 
351
        effectconfig.writeEntry("kwin4_effect_flipswitchEnabled", true);
 
352
    effectconfig.sync();
 
353
    KConfigGroup boxswitchconfig(m_config, "Effect-BoxSwitch");
 
354
    boxswitchconfig.writeEntry("TabBox", boxSwitch);
 
355
    boxswitchconfig.writeEntry("TabBoxAlternative", boxSwitchAlternative);
 
356
    boxswitchconfig.sync();
 
357
    KConfigGroup presentwindowsconfig(m_config, "Effect-PresentWindows");
 
358
    presentwindowsconfig.writeEntry("TabBox", presentWindowSwitching);
 
359
    presentwindowsconfig.writeEntry("TabBoxAlternative", presentWindowSwitchingAlternative);
 
360
    presentwindowsconfig.sync();
 
361
    KConfigGroup coverswitchconfig(m_config, "Effect-CoverSwitch");
 
362
    coverswitchconfig.writeEntry("TabBox", coverSwitch);
 
363
    coverswitchconfig.writeEntry("TabBoxAlternative", coverSwitchAlternative);
 
364
    coverswitchconfig.sync();
 
365
    KConfigGroup flipswitchconfig(m_config, "Effect-FlipSwitch");
 
366
    flipswitchconfig.writeEntry("TabBox", flipSwitch);
 
367
    flipswitchconfig.writeEntry("TabBoxAlternative", flipSwitchAlternative);
 
368
    flipswitchconfig.sync();
 
369
 
 
370
    m_editor->save();
 
371
 
 
372
    // Reload KWin.
 
373
    QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
 
374
    QDBusConnection::sessionBus().send(message);
 
375
 
 
376
    emit changed(false);
 
377
}
 
378
 
 
379
void KWinTabBoxConfig::defaults()
 
380
{
 
381
    // combo boxes
 
382
    m_primaryTabBoxUi->listModeCombo->setCurrentIndex(TabBox::TabBoxConfig::defaultListMode());
 
383
    m_primaryTabBoxUi->switchingModeCombo->setCurrentIndex(TabBox::TabBoxConfig::defaultSwitchingMode());
 
384
 
 
385
    // checkboxes
 
386
    m_primaryTabBoxUi->showOutlineCheck->setChecked(TabBox::TabBoxConfig::defaultShowOutline());
 
387
    m_primaryTabBoxUi->showTabBox->setChecked(TabBox::TabBoxConfig::defaultShowTabBox());
 
388
    m_primaryTabBoxUi->highlightWindowCheck->setChecked(TabBox::TabBoxConfig::defaultHighlightWindow());
 
389
    m_primaryTabBoxUi->showDesktopBox->setChecked(TabBox::TabBoxConfig::defaultShowDesktop());
 
390
 
 
391
    // effects
 
392
    m_primaryTabBoxUi->effectCombo->setCurrentIndex(1);
 
393
 
 
394
    // alternative
 
395
    // combo boxes
 
396
    m_alternativeTabBoxUi->listModeCombo->setCurrentIndex(TabBox::TabBoxConfig::defaultListMode());
 
397
    m_alternativeTabBoxUi->switchingModeCombo->setCurrentIndex(TabBox::TabBoxConfig::defaultSwitchingMode());
 
398
 
 
399
    // checkboxes
 
400
    m_alternativeTabBoxUi->showOutlineCheck->setChecked(TabBox::TabBoxConfig::defaultShowOutline());
 
401
    m_alternativeTabBoxUi->showTabBox->setChecked(TabBox::TabBoxConfig::defaultShowTabBox());
 
402
    m_alternativeTabBoxUi->highlightWindowCheck->setChecked(TabBox::TabBoxConfig::defaultHighlightWindow());
 
403
    m_alternativeTabBoxUi->showDesktopBox->setChecked(TabBox::TabBoxConfig::defaultShowDesktop());
 
404
 
 
405
    // effects
 
406
    m_alternativeTabBoxUi->effectCombo->setCurrentIndex(0);
 
407
 
 
408
    m_editor->allDefault();
 
409
 
 
410
    emit changed(true);
 
411
}
 
412
 
 
413
bool KWinTabBoxConfig::effectEnabled(const QString& effect, const KConfigGroup& cfg) const
 
414
{
 
415
    KService::List services = KServiceTypeTrader::self()->query(
 
416
                                  "KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_" + effect + '\'');
 
417
    if (services.isEmpty())
 
418
        return false;
 
419
    QVariant v = services.first()->property("X-KDE-PluginInfo-EnabledByDefault");
 
420
    return cfg.readEntry("kwin4_effect_" + effect + "Enabled", v.toBool());
 
421
}
 
422
 
 
423
void KWinTabBoxConfig::updateUiFromConfig(KWinTabBoxConfigForm* ui, const KWin::TabBox::TabBoxConfig& config)
 
424
{
 
425
    // combo boxes
 
426
    ui->listModeCombo->setCurrentIndex(config.clientListMode());
 
427
    ui->switchingModeCombo->setCurrentIndex(config.clientSwitchingMode());
 
428
 
 
429
    // check boxes
 
430
    ui->showOutlineCheck->setChecked(config.isShowOutline());
 
431
    ui->showTabBox->setChecked(config.isShowTabBox());
 
432
    ui->highlightWindowCheck->setChecked(config.isHighlightWindows());
 
433
    ui->showDesktopBox->setChecked(config.isShowDesktop());
 
434
}
 
435
 
 
436
void KWinTabBoxConfig::updateConfigFromUi(const KWin::KWinTabBoxConfigForm* ui, TabBox::TabBoxConfig& config)
 
437
{
 
438
    config.setClientListMode(TabBox::TabBoxConfig::ClientListMode(ui->listModeCombo->currentIndex()));
 
439
    config.setClientSwitchingMode(TabBox::TabBoxConfig::ClientSwitchingMode(ui->switchingModeCombo->currentIndex()));
 
440
 
 
441
    config.setShowOutline(ui->showOutlineCheck->isChecked());
 
442
    config.setShowTabBox(ui->showTabBox->isChecked());
 
443
    config.setHighlightWindows(ui->highlightWindowCheck->isChecked());
 
444
    config.setShowDesktop(ui->showDesktopBox->isChecked());
 
445
}
 
446
 
 
447
void KWinTabBoxConfig::slotEffectSelectionChanged(int index)
 
448
{
 
449
    effectSelectionChanged(m_primaryTabBoxUi, index);
 
450
}
 
451
 
 
452
void KWinTabBoxConfig::slotEffectSelectionChangedAlternative(int index)
 
453
{
 
454
    effectSelectionChanged(m_alternativeTabBoxUi, index);
 
455
}
 
456
 
 
457
void KWinTabBoxConfig::effectSelectionChanged(KWinTabBoxConfigForm* ui, int index)
 
458
{
 
459
    bool enabled = false;
 
460
    if (index > 0)
 
461
        enabled = true;
 
462
    ui->effectInfoButton->setEnabled(enabled);
 
463
    ui->effectConfigButton->setEnabled(enabled);
 
464
}
 
465
 
 
466
void KWinTabBoxConfig::slotAboutEffectClicked()
 
467
{
 
468
    aboutEffectClicked(m_primaryTabBoxUi);
 
469
}
 
470
 
 
471
void KWinTabBoxConfig::slotAboutEffectClickedAlternative()
 
472
{
 
473
    aboutEffectClicked(m_alternativeTabBoxUi);
 
474
}
 
475
 
 
476
void KWinTabBoxConfig::aboutEffectClicked(KWinTabBoxConfigForm* ui)
 
477
{
 
478
    KServiceTypeTrader* trader = KServiceTypeTrader::self();
 
479
    KService::List services;
 
480
    QString effect;
 
481
    switch(ui->effectCombo->currentIndex()) {
 
482
    case 1:
 
483
        effect = "boxswitch";
 
484
        break;
 
485
    case 2:
 
486
        effect = "presentwindows";
 
487
        break;
 
488
    case 3:
 
489
        effect = "coverswitch";
 
490
        break;
 
491
    case 4:
 
492
        effect = "flipswitch";
 
493
        break;
 
494
    default:
 
495
        return;
 
496
    }
 
497
    services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_" + effect + '\'');
 
498
    if (services.isEmpty())
 
499
        return;
 
500
    KPluginInfo pluginInfo(services.first());
 
501
 
 
502
    const QString name    = pluginInfo.name();
 
503
    const QString comment = pluginInfo.comment();
 
504
    const QString author  = pluginInfo.author();
 
505
    const QString email   = pluginInfo.email();
 
506
    const QString website = pluginInfo.website();
 
507
    const QString version = pluginInfo.version();
 
508
    const QString license = pluginInfo.license();
 
509
    const QString icon    = pluginInfo.icon();
 
510
 
 
511
    KAboutData aboutData(name.toUtf8(), name.toUtf8(), ki18n(name.toUtf8()), version.toUtf8(), ki18n(comment.toUtf8()), KAboutLicense::byKeyword(license).key(), ki18n(QByteArray()), ki18n(QByteArray()), website.toLatin1());
 
512
    aboutData.setProgramIconName(icon);
 
513
    const QStringList authors = author.split(',');
 
514
    const QStringList emails = email.split(',');
 
515
    int i = 0;
 
516
    if (authors.count() == emails.count()) {
 
517
        foreach (const QString & author, authors) {
 
518
            if (!author.isEmpty()) {
 
519
                aboutData.addAuthor(ki18n(author.toUtf8()), ki18n(QByteArray()), emails[i].toUtf8(), 0);
 
520
            }
 
521
            i++;
 
522
        }
 
523
    }
 
524
    QPointer< KAboutApplicationDialog > aboutPlugin = new KAboutApplicationDialog(&aboutData, this);
 
525
    aboutPlugin->exec();
 
526
    delete aboutPlugin;
 
527
}
 
528
 
 
529
void KWinTabBoxConfig::slotConfigureEffectClicked()
 
530
{
 
531
    configureEffectClicked(m_primaryTabBoxUi);
 
532
}
 
533
 
 
534
void KWinTabBoxConfig::slotConfigureEffectClickedAlternative()
 
535
{
 
536
    configureEffectClicked(m_alternativeTabBoxUi);
 
537
}
 
538
 
 
539
void KWinTabBoxConfig::configureEffectClicked(KWinTabBoxConfigForm* ui)
 
540
{
 
541
    QString effect;
 
542
    switch(ui->effectCombo->currentIndex()) {
 
543
    case 1:
 
544
        effect = "boxswitch_config";
 
545
        break;
 
546
    case 2:
 
547
        effect = "presentwindows_config";
 
548
        break;
 
549
    case 3:
 
550
        effect = "coverswitch_config";
 
551
        break;
 
552
    case 4:
 
553
        effect = "flipswitch_config";
 
554
        break;
 
555
    default:
 
556
        return;
 
557
    }
 
558
    KCModuleProxy* proxy = new KCModuleProxy(effect);
 
559
    QPointer< KDialog > configDialog = new KDialog(this);
 
560
    configDialog->setWindowTitle(ui->effectCombo->currentText());
 
561
    configDialog->setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default);
 
562
    connect(configDialog, SIGNAL(defaultClicked()), proxy, SLOT(defaults()));
 
563
 
 
564
    QWidget *showWidget = new QWidget(configDialog);
 
565
    QVBoxLayout *layout = new QVBoxLayout;
 
566
    showWidget->setLayout(layout);
 
567
    layout->addWidget(proxy);
 
568
    layout->insertSpacing(-1, KDialog::marginHint());
 
569
    configDialog->setMainWidget(showWidget);
 
570
 
 
571
    if (configDialog->exec() == QDialog::Accepted) {
 
572
        proxy->save();
 
573
    } else {
 
574
        proxy->load();
 
575
    }
 
576
    delete configDialog;
 
577
}
 
578
 
 
579
void KWinTabBoxConfig::slotConfigureLayoutClicked()
 
580
{
 
581
    QPointer<KDialog> dialog = new KDialog(this);
 
582
    dialog->setCaption(i18n("Configure Layout"));
 
583
    dialog->setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default);
 
584
    connect(dialog, SIGNAL(okClicked()), this, SLOT(slotLayoutChanged()));
 
585
 
 
586
    m_configForm = new TabBox::LayoutConfig(dialog);
 
587
    m_configForm->setConfig(m_tabBoxConfig);
 
588
    dialog->setMainWidget(m_configForm);
 
589
 
 
590
    dialog->exec();
 
591
    delete dialog;
 
592
}
 
593
 
 
594
void KWinTabBoxConfig::slotLayoutChanged()
 
595
{
 
596
    m_tabBoxConfig = m_configForm->config();
 
597
    emit changed(true);
 
598
}
 
599
 
 
600
void KWinTabBoxConfig::slotConfigureLayoutClickedAlternative()
 
601
{
 
602
    QPointer<KDialog> dialog = new KDialog(this);
 
603
    dialog->setCaption(i18n("Configure Layout"));
 
604
    dialog->setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default);
 
605
    connect(dialog, SIGNAL(okClicked()), this, SLOT(slotLayoutChangedAlternative()));
 
606
 
 
607
    m_configForm = new TabBox::LayoutConfig(dialog);
 
608
    m_configForm->setConfig(m_tabBoxAlternativeConfig);
 
609
    dialog->setMainWidget(m_configForm);
 
610
 
 
611
    dialog->exec();
 
612
    delete dialog;
 
613
}
 
614
 
 
615
void KWinTabBoxConfig::slotLayoutChangedAlternative()
 
616
{
 
617
    m_tabBoxAlternativeConfig = m_configForm->config();
 
618
    emit changed(true);
 
619
}
 
620
 
 
621
} // namespace