1
//////////////////////////////////////////////////////////////////////////////
2
// oxygenconfigdialog.cpp
3
// oxygen configuration dialog
6
// Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to
10
// deal in the Software without restriction, including without limitation the
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
// sell copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
//////////////////////////////////////////////////////////////////////////////
26
#include "oxygenconfigdialog.h"
27
#include "../oxygen.h"
28
#include "config-liboxygen.h"
34
#include <QPushButton>
36
#include <QTextStream>
43
#include <KConfigGroup>
44
#include <KLocalizedString>
45
#include <KPluginLoader>
46
#include <KStandardShortcut>
48
#include <QDBusConnection>
49
#include <QDBusMessage>
53
//_______________________________________________________________
54
ConfigDialog::ConfigDialog( QWidget* parent ):
56
_stylePluginObject(0),
57
_decorationPluginObject( 0 ),
58
_styleChanged( false ),
59
_decorationChanged( false )
62
setWindowTitle( i18n( "Oxygen Settings" ) );
69
// install Quit shortcut
70
connect( new QShortcut( KStandardShortcut::quit().primary(), this ), SIGNAL(activated()), SLOT(close()) );
71
connect( new QShortcut( KStandardShortcut::quit().alternate(), this ), SIGNAL(activated()), SLOT(close()) );
73
foreach( const QKeySequence& sequence, KStandardShortcut::quit() )
74
{ connect( new QShortcut( sequence, this ), SIGNAL(activated()), SLOT(close()) ); }
77
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL(clicked()), SLOT(close()) );
80
connect( pageWidget, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateWindowTitle(KPageWidgetItem*)) );
83
KPageWidgetItem *page;
86
page = loadStyleConfig();
87
page->setName( i18n("Widget Style") );
88
page->setHeader( i18n("Modify the appearance of widgets") );
90
page->setIcon( KIcon( "preferences-desktop-theme" ) );
92
page->setIcon( QIcon::fromTheme( QStringLiteral( "preferences-desktop-theme" ) ) );
94
pageWidget->addPage( page );
96
if( _stylePluginObject )
98
connect( _stylePluginObject, SIGNAL(changed(bool)), this, SLOT(updateStyleChanged(bool)) );
99
connect( _stylePluginObject, SIGNAL(changed(bool)), this, SLOT(updateChanged()) );
101
connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()), _stylePluginObject, SLOT(reset()) );
102
connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL(clicked()), _stylePluginObject, SLOT(defaults()) );
103
connect( this, SIGNAL(pluginSave()), _stylePluginObject, SLOT(save()) );
104
connect( this, SIGNAL(pluginToggleExpertMode(bool)), _stylePluginObject, SLOT(toggleExpertMode(bool)) );
109
page = loadDecorationConfig();
110
page->setName( i18n("Window Decorations") );
111
page->setHeader( i18n("Modify the appearance of window decorations") );
113
page->setIcon( KIcon( "preferences-system-windows" ) );
115
page->setIcon( QIcon::fromTheme( QStringLiteral( "preferences-system-windows" ) ) );
117
pageWidget->addPage( page );
119
if( _decorationPluginObject )
121
connect( _decorationPluginObject, SIGNAL(changed(bool)), this, SLOT(updateDecorationChanged(bool)) );
122
connect( _decorationPluginObject, SIGNAL(changed(bool)), this, SLOT(updateChanged()) );
124
connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()), _decorationPluginObject, SLOT(load()) );
125
connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL(clicked()), _decorationPluginObject, SLOT(defaults()) );
127
connect( this, SIGNAL(pluginSave()), _decorationPluginObject, SLOT(save()) );
128
connect( this, SIGNAL(pluginToggleExpertMode(bool)), _decorationPluginObject, SLOT(toggleExpertMode(bool)) );
133
emit pluginToggleExpertMode( true );
135
// button connections
136
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL(clicked()), SLOT(save()) );
137
connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(clicked()), SLOT(save()) );
142
//_______________________________________________________________
143
void ConfigDialog::save( void )
146
// trigger pluggins to save themselves
150
* emit dbus message to kwin instances
151
* this is copied from kwin/kcmkwin/kwindecoration/kwindecoration.cpp
153
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
154
QDBusConnection::sessionBus().send(message);
156
// reset 'changed' flags
157
updateStyleChanged( false );
158
updateDecorationChanged( false );
163
//_______________________________________________________________
164
void ConfigDialog::updateChanged( void )
166
bool modified( changed() );
167
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( modified );
168
buttonBox->button( QDialogButtonBox::Reset )->setEnabled( modified );
169
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( modified );
170
updateWindowTitle( pageWidget->currentPage() );
173
//_______________________________________________________________
174
void ConfigDialog::updateWindowTitle( KPageWidgetItem* item )
177
QTextStream what( &title );
180
what << item->name();
181
if( changed() ) what << " [modified]";
185
what << i18n( "Oxygen Settings" );
186
setWindowTitle( title );
189
//_______________________________________________________________
190
KPageWidgetItem* ConfigDialog::loadStyleConfig( void )
193
// load style from plugin
195
KLibrary library( "kstyle_oxygen_config" );
197
QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "kstyle_oxygen_config" ) ) );
204
KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_kstyle_config");
206
QFunctionPointer alloc_ptr = library.resolve( "allocate_kstyle_config" );
208
if( alloc_ptr != nullptr )
211
// pointer to decoration plugin allocation function
212
QWidget* (*allocator)( QWidget* );
213
allocator = (QWidget* (*)(QWidget* parent))alloc_ptr;
216
QWidget* container = new QWidget();
217
container->setLayout( new QVBoxLayout() );
218
container->setObjectName( QStringLiteral( "oxygen-settings-container" ) );
219
container->layout()->setMargin( 0 );
221
// allocate config object
222
_stylePluginObject = (QObject*)(allocator( container ));
223
container->layout()->addWidget( static_cast<QWidget*>( _stylePluginObject ) );
224
return new KPageWidgetItem( container );
230
// fall back to warning label
231
QLabel* label = new QLabel();
233
label->setAlignment( Qt::AlignCenter );
234
label->setText( i18n( "Unable to find oxygen style configuration plugin" ) );
235
return new KPageWidgetItem( label );
239
//_______________________________________________________________
240
KPageWidgetItem* ConfigDialog::loadDecorationConfig( void )
243
// load style from plugin
245
KLibrary library( "kwin_oxygen_config" );
247
QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "kwin/kdecorations/config/kwin_oxygen_config" ) ) );
254
KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_config");
256
QFunctionPointer alloc_ptr = library.resolve( "allocate_config" );
259
if( alloc_ptr != nullptr )
262
// cast resolved function
263
QObject* (*allocator)( KConfig*, QWidget* );
264
allocator = ( QObject* (*)(KConfig*, QWidget*) )alloc_ptr;
267
QWidget* container = new QWidget();
268
container->setLayout( new QVBoxLayout() );
269
container->layout()->setMargin( 0 );
271
_decorationPluginObject = (QObject*)(allocator( nullptr, container ));
273
if( _decorationPluginObject ) return new KPageWidgetItem( container );
275
} else { QTextStream( stdout ) << "unable to resolve function allocate_config" << endl; }
277
} else { QTextStream( stdout ) << "unable to load plugin kwin_oxygen_config" << endl; }
279
// fall back to warning label
280
QLabel* label = new QLabel();
282
label->setAlignment( Qt::AlignCenter );
283
label->setText( i18n( "Unable to find oxygen decoration configuration plugin" ) );
284
return new KPageWidgetItem( label );