diff --git a/kstyle/config/CMakeLists.txt b/kstyle/config/CMakeLists.txt index 2db754c4..3ba7e405 100644 --- a/kstyle/config/CMakeLists.txt +++ b/kstyle/config/CMakeLists.txt @@ -28,3 +28,25 @@ else() endif() +########### next target ############### +if(KF5Service_FOUND AND NOT BREEZE_USE_KDE4) + + set(breeze_settings_SOURCES + breezeconfigdialog.cpp + main.cpp) + + set(breeze_settings_FORMS ui/breezeconfigdialog.ui) + + ki18n_wrap_ui(breeze_settings_FORMS_HEADERS ${breeze_settings_FORMS}) + + add_executable(breeze-settings5 + ${breeze_settings_SOURCES} + ${breeze_settings_FORMS_HEADERS} + ) + + target_link_libraries(breeze-settings5 Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus) + target_link_libraries(breeze-settings5 KF5::I18n KF5::WidgetsAddons KF5::ConfigCore KF5::ConfigGui KF5::Service) + + install(TARGETS breeze-settings5 ${INSTALL_TARGETS_DEFAULT_ARGS}) + +endif() diff --git a/kstyle/config/breezeconfigdialog.cpp b/kstyle/config/breezeconfigdialog.cpp new file mode 100644 index 00000000..ab5bc065 --- /dev/null +++ b/kstyle/config/breezeconfigdialog.cpp @@ -0,0 +1,285 @@ +////////////////////////////////////////////////////////////////////////////// +// breezeconfigdialog.cpp +// breeze configuration dialog +// ------------------- +// +// Copyright (c) 2010 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// +#include "breezeconfigdialog.h" +#include "breezeconfigdialog.moc" +#include "../breeze.h" +#include "../config-breeze.h" + +#include +#include +#include +#include +#include +#include +#include + +#if BREEZE_USE_KDE4 +#include +#include +#endif + +#include +#include +#include +#include + +#include +#include + +namespace Breeze +{ + //_______________________________________________________________ + ConfigDialog::ConfigDialog( QWidget* parent ): + QDialog( parent ), + _stylePluginObject(0), + _decorationPluginObject( 0 ), + _styleChanged( false ), + _decorationChanged( false ) + { + + setWindowTitle( i18n( "Breeze Settings" ) ); + updateWindowTitle(); + + // ui + setupUi(this); + + #if BREEZE_USE_KDE4 + // install Quit shortcut + connect( new QShortcut( KStandardShortcut::quit().primary(), this ), SIGNAL(activated()), SLOT(close()) ); + connect( new QShortcut( KStandardShortcut::quit().alternate(), this ), SIGNAL(activated()), SLOT(close()) ); + #else + foreach( const QKeySequence& sequence, KStandardShortcut::quit() ) + { connect( new QShortcut( sequence, this ), SIGNAL(activated()), SLOT(close()) ); } + #endif + + connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL(clicked()), SLOT(close()) ); + + // connections + connect( pageWidget, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateWindowTitle(KPageWidgetItem*)) ); + + // generic page + KPageWidgetItem *page; + + // style + page = loadStyleConfig(); + page->setName( i18n("Widget Style") ); + page->setHeader( i18n("Modify the appearance of widgets") ); + #if BREEZE_USE_KDE4 + page->setIcon( KIcon( "preferences-desktop-theme" ) ); + #else + page->setIcon( QIcon::fromTheme( QStringLiteral( "preferences-desktop-theme" ) ) ); + #endif + pageWidget->addPage( page ); + + if( _stylePluginObject ) + { + connect( _stylePluginObject, SIGNAL(changed(bool)), this, SLOT(updateStyleChanged(bool)) ); + connect( _stylePluginObject, SIGNAL(changed(bool)), this, SLOT(updateChanged()) ); + + connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()), _stylePluginObject, SLOT(reset()) ); + connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL(clicked()), _stylePluginObject, SLOT(defaults()) ); + connect( this, SIGNAL(pluginSave()), _stylePluginObject, SLOT(save()) ); + + } + + // decoration + page = loadDecorationConfig(); + page->setName( i18n("Window Decorations") ); + page->setHeader( i18n("Modify the appearance of window decorations") ); + #if BREEZE_USE_KDE4 + page->setIcon( KIcon( "preferences-system-windows" ) ); + #else + page->setIcon( QIcon::fromTheme( QStringLiteral( "preferences-system-windows" ) ) ); + #endif + pageWidget->addPage( page ); + + if( _decorationPluginObject ) + { + connect( _decorationPluginObject, SIGNAL(changed(bool)), this, SLOT(updateDecorationChanged(bool)) ); + connect( _decorationPluginObject, SIGNAL(changed(bool)), this, SLOT(updateChanged()) ); + + connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()), _decorationPluginObject, SLOT(load()) ); + connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL(clicked()), _decorationPluginObject, SLOT(defaults()) ); + + connect( this, SIGNAL(pluginSave()), _decorationPluginObject, SLOT(save()) ); + + } + + // button connections + connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL(clicked()), SLOT(save()) ); + connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(clicked()), SLOT(save()) ); + updateChanged(); + + } + + //_______________________________________________________________ + void ConfigDialog::save( void ) + { + + // trigger pluggins to save themselves + emit pluginSave(); + + /* + * emit dbus message to kwin instances + * this is copied from kwin/kcmkwin/kwindecoration/kwindecoration.cpp + */ + QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); + QDBusConnection::sessionBus().send(message); + + // reset 'changed' flags + updateStyleChanged( false ); + updateDecorationChanged( false ); + updateChanged(); + + } + + //_______________________________________________________________ + void ConfigDialog::updateChanged( void ) + { + bool modified( changed() ); + buttonBox->button( QDialogButtonBox::Apply )->setEnabled( modified ); + buttonBox->button( QDialogButtonBox::Reset )->setEnabled( modified ); + buttonBox->button( QDialogButtonBox::Ok )->setEnabled( modified ); + updateWindowTitle( pageWidget->currentPage() ); + } + + //_______________________________________________________________ + void ConfigDialog::updateWindowTitle( KPageWidgetItem* item ) + { + QString title; + QTextStream what( &title ); + if( item ) + { + what << item->name(); + if( changed() ) what << " [modified]"; + what << " - "; + } + + what << i18n( "Breeze Settings" ); + setWindowTitle( title ); + } + + //_______________________________________________________________ + KPageWidgetItem* ConfigDialog::loadStyleConfig( void ) + { + + // load style from plugin + #if BREEZE_USE_KDE4 + KLibrary library( "kstyle_breeze_config" ); + #else + QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "kstyle_breeze_config" ) ) ); + #endif + + if( library.load() ) + { + + #if BREEZE_USE_KDE4 + KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_kstyle_config"); + #else + QFunctionPointer alloc_ptr = library.resolve( "allocate_kstyle_config" ); + #endif + if( alloc_ptr != nullptr ) + { + + // pointer to decoration plugin allocation function + QWidget* (*allocator)( QWidget* ); + allocator = (QWidget* (*)(QWidget* parent))alloc_ptr; + + // create container + QWidget* container = new QWidget(); + container->setLayout( new QVBoxLayout() ); + container->setObjectName( QStringLiteral( "breeze-settings-container" ) ); + container->layout()->setMargin( 0 ); + + // allocate config object + _stylePluginObject = (QObject*)(allocator( container )); + container->layout()->addWidget( static_cast( _stylePluginObject ) ); + return new KPageWidgetItem( container ); + + } + + } + + // fall back to warning label + QLabel* label = new QLabel(); + label->setMargin(5); + label->setAlignment( Qt::AlignCenter ); + label->setText( i18n( "Unable to find breeze style configuration plugin" ) ); + return new KPageWidgetItem( label ); + + } + + //_______________________________________________________________ + KPageWidgetItem* ConfigDialog::loadDecorationConfig( void ) + { + + // load style from plugin + #if BREEZE_USE_KDE4 + KLibrary library( "kwin_breeze_config" ); + #else + // QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "kwin/kdecorations/config/kwin_breeze_config" ) ) ); + QLibrary library( KPluginLoader::findPlugin( QStringLiteral( "org.kde.kdecoration2/breezedecoration_config.so" ) ) ); + #endif + + if( library.load() ) + { + + #if BREEZE_USE_KDE4 + KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_config"); + #else + QFunctionPointer alloc_ptr = library.resolve( "allocate_config" ); + #endif + + if( alloc_ptr != nullptr ) + { + + // cast resolved function + QObject* (*allocator)( KConfig*, QWidget* ); + allocator = ( QObject* (*)(KConfig*, QWidget*) )alloc_ptr; + + // create container + QWidget* container = new QWidget(); + container->setLayout( new QVBoxLayout() ); + container->layout()->setMargin( 0 ); + + _decorationPluginObject = (QObject*)(allocator( nullptr, container )); + + if( _decorationPluginObject ) return new KPageWidgetItem( container ); + + } else { QTextStream( stdout ) << "unable to resolve function allocate_config" << endl; } + + } else { QTextStream( stdout ) << "unable to load plugin kwin_breeze_config" << endl; } + + // fall back to warning label + QLabel* label = new QLabel(); + label->setMargin(5); + label->setAlignment( Qt::AlignCenter ); + label->setText( i18n( "Unable to find breeze decoration configuration plugin" ) ); + return new KPageWidgetItem( label ); + + } + +} diff --git a/kstyle/config/breezeconfigdialog.h b/kstyle/config/breezeconfigdialog.h new file mode 100644 index 00000000..bc5c6686 --- /dev/null +++ b/kstyle/config/breezeconfigdialog.h @@ -0,0 +1,99 @@ +#ifndef breezeconfigdialog_h +#define breezeconfigdialog_h + +////////////////////////////////////////////////////////////////////////////// +// breezeconfigdialog.h +// breeze configuration dialog +// ------------------- +// +// Copyright (c) 2010 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "ui_breezeconfigdialog.h" + +namespace Breeze +{ + + class ConfigDialog: public QDialog, Ui::BreezeConfigDialog + { + Q_OBJECT + + public: + + //! constructor + explicit ConfigDialog( QWidget* parent = 0 ); + + //! destructor + virtual ~ConfigDialog( void ) + {} + + Q_SIGNALS: + + //! save local changes + void pluginSave( void ); + + public Q_SLOTS: + + //! save local changes + virtual void save( void ); + + protected Q_SLOTS: + + // update decoration changed state + void updateStyleChanged( bool state = true ) + { _styleChanged = state; } + + // update decoration changed state + void updateDecorationChanged( bool state = true ) + { _decorationChanged = state; } + + // handle configuration modifications + virtual void updateChanged( void ); + + // update window title based on selected page + virtual void updateWindowTitle( KPageWidgetItem* = 0 ); + + private: + + //! true if configuration changed + bool changed( void ) const + { return _styleChanged || _decorationChanged; } + + //! load style config widget from plugin + KPageWidgetItem* loadStyleConfig( void ); + + //! load decoration config widget from plugin + KPageWidgetItem* loadDecorationConfig( void ); + + //! style plugin widget + QObject *_stylePluginObject; + + //! decoration plugin widget + QObject *_decorationPluginObject; + + bool _styleChanged; + bool _decorationChanged; + + }; + +} + +#endif diff --git a/kstyle/config/main.cpp b/kstyle/config/main.cpp new file mode 100644 index 00000000..ece2ba62 --- /dev/null +++ b/kstyle/config/main.cpp @@ -0,0 +1,60 @@ +////////////////////////////////////////////////////////////////////////////// +// breezeanimationconfigitem.h +// animation configuration item +// ------------------- +// +// Copyright (c) 2010 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezeconfigdialog.h" +#include "../breeze.h" +#include "../config-breeze.h" + +#include +#include + +#include + +namespace Breeze +{ + + int run(int argc, char *argv[]) + { + QApplication app( argc, argv ); + app.setApplicationName( i18n( "Breeze Settings" ) ); + app.setWindowIcon( QIcon::fromTheme( QStringLiteral( "breeze" ) ) ); + Breeze::ConfigDialog dialog; + dialog.show(); + bool result = app.exec(); + return result; + } + +} + +//__________________________________________ +int main(int argc, char *argv[]) +{ + #if !BREEZE_USE_KDE4 + KLocalizedString::setApplicationDomain("breeze_style_config"); + #endif + + return Breeze::run( argc, argv ); +} diff --git a/kstyle/config/ui/breezeconfigdialog.ui b/kstyle/config/ui/breezeconfigdialog.ui new file mode 100644 index 00000000..5fee26a5 --- /dev/null +++ b/kstyle/config/ui/breezeconfigdialog.ui @@ -0,0 +1,79 @@ + + + BreezeConfigDialog + + + + 0 + 0 + 447 + 300 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults + + + + + + + + KPageView + QWidget +
kpageview.h
+
+ + KPageWidget + KPageView +
kpagewidget.h
+
+
+ + + + buttonBox + accepted() + BreezeConfigDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + BreezeConfigDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +