~ubuntu-branches/ubuntu/wily/oxygen/wily

« back to all changes in this revision

Viewing changes to kstyle/config/oxygenconfigdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Scarlett Clark, Jonathan Riddell
  • Date: 2015-08-10 23:18:51 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20150810231851-wtw33zvkigya4f7t
Tags: 4:5.3.95-0ubuntu1
[ Scarlett Clark ]
* Vivid backport. 

[ Jonathan Riddell ]
* new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
// oxygenconfigdialog.cpp
3
 
// oxygen configuration dialog
4
 
// -------------------
5
 
//
6
 
// Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
7
 
//
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:
14
 
//
15
 
// The above copyright notice and this permission notice shall be included in
16
 
// all copies or substantial portions of the Software.
17
 
//
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
24
 
// IN THE SOFTWARE.
25
 
//////////////////////////////////////////////////////////////////////////////
26
 
#include "oxygenconfigdialog.h"
27
 
#include "../oxygen.h"
28
 
#include "config-liboxygen.h"
29
 
 
30
 
#include <QIcon>
31
 
#include <QLabel>
32
 
#include <QLayout>
33
 
#include <QLibrary>
34
 
#include <QPushButton>
35
 
#include <QShortcut>
36
 
#include <QTextStream>
37
 
 
38
 
#if OXYGEN_USE_KDE4
39
 
#include <KIcon>
40
 
#include <KLibrary>
41
 
#endif
42
 
 
43
 
#include <KConfigGroup>
44
 
#include <KLocalizedString>
45
 
#include <KPluginLoader>
46
 
#include <KStandardShortcut>
47
 
 
48
 
#include <QDBusConnection>
49
 
#include <QDBusMessage>
50
 
 
51
 
namespace Oxygen
52
 
{
53
 
    //_______________________________________________________________
54
 
    ConfigDialog::ConfigDialog( QWidget* parent ):
55
 
        QDialog( parent ),
56
 
        _stylePluginObject(0),
57
 
        _decorationPluginObject( 0 ),
58
 
        _styleChanged( false ),
59
 
        _decorationChanged( false )
60
 
   {
61
 
 
62
 
        setWindowTitle( i18n( "Oxygen Settings" ) );
63
 
        updateWindowTitle();
64
 
 
65
 
        // ui
66
 
        setupUi(this);
67
 
 
68
 
        #if OXYGEN_USE_KDE4
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()) );
72
 
        #else
73
 
        foreach( const QKeySequence& sequence, KStandardShortcut::quit() )
74
 
        { connect( new QShortcut( sequence, this ), SIGNAL(activated()), SLOT(close()) ); }
75
 
        #endif
76
 
 
77
 
        connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL(clicked()), SLOT(close()) );
78
 
 
79
 
        // connections
80
 
        connect( pageWidget, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateWindowTitle(KPageWidgetItem*)) );
81
 
 
82
 
        // generic page
83
 
        KPageWidgetItem *page;
84
 
 
85
 
        // style
86
 
        page = loadStyleConfig();
87
 
        page->setName( i18n("Widget Style") );
88
 
        page->setHeader( i18n("Modify the appearance of widgets") );
89
 
        #if OXYGEN_USE_KDE4
90
 
        page->setIcon( KIcon( "preferences-desktop-theme" ) );
91
 
        #else
92
 
        page->setIcon( QIcon::fromTheme( QStringLiteral( "preferences-desktop-theme" ) ) );
93
 
        #endif
94
 
        pageWidget->addPage( page );
95
 
 
96
 
        if( _stylePluginObject )
97
 
        {
98
 
            connect( _stylePluginObject, SIGNAL(changed(bool)), this, SLOT(updateStyleChanged(bool)) );
99
 
            connect( _stylePluginObject, SIGNAL(changed(bool)), this, SLOT(updateChanged()) );
100
 
 
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)) );
105
 
 
106
 
        }
107
 
 
108
 
        // decoration
109
 
        page = loadDecorationConfig();
110
 
        page->setName( i18n("Window Decorations") );
111
 
        page->setHeader( i18n("Modify the appearance of window decorations") );
112
 
        #if OXYGEN_USE_KDE4
113
 
        page->setIcon( KIcon( "preferences-system-windows" ) );
114
 
        #else
115
 
        page->setIcon( QIcon::fromTheme( QStringLiteral( "preferences-system-windows" ) ) );
116
 
        #endif
117
 
        pageWidget->addPage( page );
118
 
 
119
 
        if( _decorationPluginObject )
120
 
        {
121
 
            connect( _decorationPluginObject, SIGNAL(changed(bool)), this, SLOT(updateDecorationChanged(bool)) );
122
 
            connect( _decorationPluginObject, SIGNAL(changed(bool)), this, SLOT(updateChanged()) );
123
 
 
124
 
            connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()), _decorationPluginObject, SLOT(load()) );
125
 
            connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL(clicked()), _decorationPluginObject, SLOT(defaults()) );
126
 
 
127
 
            connect( this, SIGNAL(pluginSave()), _decorationPluginObject, SLOT(save()) );
128
 
            connect( this, SIGNAL(pluginToggleExpertMode(bool)), _decorationPluginObject, SLOT(toggleExpertMode(bool)) );
129
 
 
130
 
        }
131
 
 
132
 
        // expert mode
133
 
        emit pluginToggleExpertMode( true );
134
 
 
135
 
        // button connections
136
 
        connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL(clicked()), SLOT(save()) );
137
 
        connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(clicked()), SLOT(save()) );
138
 
        updateChanged();
139
 
 
140
 
    }
141
 
 
142
 
    //_______________________________________________________________
143
 
    void ConfigDialog::save( void )
144
 
    {
145
 
 
146
 
        // trigger pluggins to save themselves
147
 
        emit pluginSave();
148
 
 
149
 
        /*
150
 
         * emit dbus message to kwin instances
151
 
         * this is copied from kwin/kcmkwin/kwindecoration/kwindecoration.cpp
152
 
         */
153
 
        QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
154
 
        QDBusConnection::sessionBus().send(message);
155
 
 
156
 
        // reset 'changed' flags
157
 
        updateStyleChanged( false );
158
 
        updateDecorationChanged( false );
159
 
        updateChanged();
160
 
 
161
 
    }
162
 
 
163
 
    //_______________________________________________________________
164
 
    void ConfigDialog::updateChanged( void )
165
 
    {
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() );
171
 
    }
172
 
 
173
 
    //_______________________________________________________________
174
 
    void ConfigDialog::updateWindowTitle( KPageWidgetItem* item )
175
 
    {
176
 
        QString title;
177
 
        QTextStream what( &title );
178
 
        if( item )
179
 
        {
180
 
            what << item->name();
181
 
            if( changed() ) what << " [modified]";
182
 
            what << " - ";
183
 
        }
184
 
 
185
 
        what << i18n( "Oxygen Settings" );
186
 
        setWindowTitle( title );
187
 
    }
188
 
 
189
 
    //_______________________________________________________________
190
 
    KPageWidgetItem* ConfigDialog::loadStyleConfig( void )
191
 
    {
192
 
 
193
 
        // load style from plugin
194
 
        #if OXYGEN_USE_KDE4
195
 
        KLibrary library( "kstyle_oxygen_config" );
196
 
        #else
197
 
        QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "kstyle_oxygen_config" ) ) );
198
 
        #endif
199
 
 
200
 
        if( library.load() )
201
 
        {
202
 
 
203
 
            #if OXYGEN_USE_KDE4
204
 
            KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_kstyle_config");
205
 
            #else
206
 
            QFunctionPointer alloc_ptr = library.resolve( "allocate_kstyle_config" );
207
 
            #endif
208
 
            if( alloc_ptr != nullptr )
209
 
            {
210
 
 
211
 
                // pointer to decoration plugin allocation function
212
 
                QWidget* (*allocator)( QWidget* );
213
 
                allocator = (QWidget* (*)(QWidget* parent))alloc_ptr;
214
 
 
215
 
                // create container
216
 
                QWidget* container = new QWidget();
217
 
                container->setLayout( new QVBoxLayout() );
218
 
                container->setObjectName( QStringLiteral( "oxygen-settings-container" ) );
219
 
                container->layout()->setMargin( 0 );
220
 
 
221
 
                // allocate config object
222
 
                _stylePluginObject = (QObject*)(allocator( container ));
223
 
                container->layout()->addWidget( static_cast<QWidget*>( _stylePluginObject ) );
224
 
                return new KPageWidgetItem( container );
225
 
 
226
 
            }
227
 
 
228
 
        }
229
 
 
230
 
        // fall back to warning label
231
 
        QLabel* label = new QLabel();
232
 
        label->setMargin(5);
233
 
        label->setAlignment( Qt::AlignCenter );
234
 
        label->setText( i18n( "Unable to find oxygen style configuration plugin" ) );
235
 
        return new KPageWidgetItem( label );
236
 
 
237
 
    }
238
 
 
239
 
    //_______________________________________________________________
240
 
    KPageWidgetItem* ConfigDialog::loadDecorationConfig( void )
241
 
    {
242
 
 
243
 
        // load style from plugin
244
 
        #if OXYGEN_USE_KDE4
245
 
        KLibrary library( "kwin_oxygen_config" );
246
 
        #else
247
 
        QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "kwin/kdecorations/config/kwin_oxygen_config" ) ) );
248
 
        #endif
249
 
 
250
 
        if( library.load() )
251
 
        {
252
 
 
253
 
            #if OXYGEN_USE_KDE4
254
 
            KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_config");
255
 
            #else
256
 
            QFunctionPointer alloc_ptr = library.resolve( "allocate_config" );
257
 
            #endif
258
 
 
259
 
            if( alloc_ptr != nullptr )
260
 
            {
261
 
 
262
 
                // cast resolved function
263
 
                QObject* (*allocator)( KConfig*, QWidget* );
264
 
                allocator = ( QObject* (*)(KConfig*, QWidget*) )alloc_ptr;
265
 
 
266
 
                // create container
267
 
                QWidget* container = new QWidget();
268
 
                container->setLayout( new QVBoxLayout() );
269
 
                container->layout()->setMargin( 0 );
270
 
 
271
 
                _decorationPluginObject = (QObject*)(allocator( nullptr, container ));
272
 
 
273
 
                if( _decorationPluginObject ) return new KPageWidgetItem( container );
274
 
 
275
 
            } else { QTextStream( stdout ) << "unable to resolve function allocate_config" << endl; }
276
 
 
277
 
        } else { QTextStream( stdout ) << "unable to load plugin kwin_oxygen_config" << endl; }
278
 
 
279
 
        // fall back to warning label
280
 
        QLabel* label = new QLabel();
281
 
        label->setMargin(5);
282
 
        label->setAlignment( Qt::AlignCenter );
283
 
        label->setText( i18n( "Unable to find oxygen decoration configuration plugin" ) );
284
 
        return new KPageWidgetItem( label );
285
 
 
286
 
    }
287
 
 
288
 
}