////////////////////////////////////////////////////////////////////////////// // config.cpp // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // Copyright (C) 2008 Lubos Lunak // // Based on the Quartz configuration module, // Copyright (c) 2001 Karol Szwed // // 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 "oxygenconfig.h" #include "oxygenconfig.moc" #include "oxygenanimationconfigwidget.h" #include "oxygenconfiguration.h" #include "oxygenutil.h" #include "../oxygenexceptionlist.h" #include #include #include #include #include #include #include #include //_______________________________________________________________________ extern "C" { KDE_EXPORT QObject* allocate_config( KConfig* conf, QWidget* parent ) { return ( new Oxygen::Config( conf, parent ) ); } } namespace Oxygen { //_______________________________________________________________________ Config::Config( KConfig*, QWidget* parent ): QObject( parent ) { KGlobal::locale()->insertCatalog("kwin_clients"); _configuration = new KConfig( "oxygenrc" ); KConfigGroup configurationGroup( _configuration, "Windeco"); ui = new ConfigurationUi( parent ); load( configurationGroup ); connect( ui, SIGNAL(changed()), SLOT(updateChanged()) ); ui->show(); } //_______________________________________________________________________ Config::~Config() { delete ui; delete _configuration; } //_______________________________________________________________________ void Config::toggleExpertMode( bool value ) { ui->toggleExpertMode( value ); } //_______________________________________________________________________ void Config::load( const KConfigGroup& ) { // load standard configuration ConfigurationPtr configuration( new Configuration() ); configuration->readConfig(); loadConfiguration( configuration ); // load shadows foreach( ShadowConfigurationUi* ui, ui->shadowConfigurations ) { ui->readConfig( _configuration ); } // load exceptions ExceptionList exceptions; exceptions.readConfig( *_configuration ); ui->ui.exceptions->setExceptions( exceptions.get() ); updateChanged(); } //_______________________________________________________________________ void Config::updateChanged( void ) { ConfigurationPtr configuration( new Configuration() ); configuration->readConfig(); bool modified( false ); if( ui->ui.titleAlignment->currentIndex() != configuration->titleAlignment() ) modified = true; else if( ui->ui.buttonSize->currentIndex() != configuration->buttonSize() ) modified = true; else if( ui->ui.blendColor->currentIndex() != configuration->blendStyle() ) modified = true; else if( ui->ui.frameBorder->currentIndex() != configuration->frameBorder() ) modified = true; else if( ui->ui.separatorMode->currentIndex() != configuration->separatorMode() ) modified = true; else if( ui->ui.drawSizeGrip->isChecked() != configuration->drawSizeGrip() ) modified = true; else if( ui->ui.titleOutline->isChecked() != configuration->drawTitleOutline() ) modified = true; else if( ui->ui.narrowButtonSpacing->isChecked() != configuration->useNarrowButtonSpacing() ) modified = true; // shadow configurations else if( ui->shadowConfigurations[0]->isModified() ) modified = true; else if( ui->shadowConfigurations[1]->isModified() ) modified = true; // exceptions else if( exceptionListChanged() ) modified = true; // animations else if( !ui->expertMode() && ui->ui.animationsEnabled->isChecked() != configuration->animationsEnabled() ) modified = true; else if( ui->expertMode() && ui->animationConfigWidget()->isChanged() ) modified = true; // emit relevant signals if( modified ) emit changed(); emit changed( modified ); } //_______________________________________________________________________ void Config::save( KConfigGroup& ) { // create configuration from group ConfigurationPtr configuration( new Configuration() ); configuration->readConfig(); // apply modifications from ui configuration->setTitleAlignment( ui->ui.titleAlignment->currentIndex() ); configuration->setButtonSize( ui->ui.buttonSize->currentIndex() ); configuration->setBlendStyle( ui->ui.blendColor->currentIndex() ); configuration->setFrameBorder( ui->ui.frameBorder->currentIndex() ); configuration->setSeparatorMode( ui->ui.separatorMode->currentIndex() ); configuration->setDrawSizeGrip( ui->ui.drawSizeGrip->isChecked() ); configuration->setDrawTitleOutline( ui->ui.titleOutline->isChecked() ); configuration->setUseNarrowButtonSpacing( ui->ui.narrowButtonSpacing->isChecked() ); configuration->setCloseWindowFromMenuButton( ui->ui.closeFromMenuButton->isChecked() ); if( ui->expertMode() ) { ui->animationConfigWidget()->setConfiguration( configuration ); ui->animationConfigWidget()->save(); } else { configuration->setAnimationsEnabled( ui->ui.animationsEnabled->isChecked() ); } // save standard configuration Util::writeConfig( configuration.data(), _configuration ); // get list of exceptions and write ConfigurationList exceptions( ui->ui.exceptions->exceptions() ); ExceptionList( exceptions ).writeConfig( *_configuration ); // write shadow configuration foreach( ShadowConfigurationUi* ui, ui->shadowConfigurations ) { ui->writeConfig( _configuration ); } // sync configuration _configuration->sync(); QDBusMessage message( QDBusMessage::createSignal("/OxygenWindeco", "org.kde.Oxygen.Style", "reparseConfiguration") ); QDBusConnection::sessionBus().send(message); } //_______________________________________________________________________ void Config::defaults() { // install default configuration ConfigurationPtr configuration( new Configuration() ); configuration->setDefaults(); loadConfiguration( configuration ); // load shadows foreach( ShadowConfigurationUi* ui, ui->shadowConfigurations ) { ui->readDefaults( _configuration ); } // install default exceptions // ui->ui.exceptions->setExceptions( ExceptionList::defaultList() ); updateChanged(); } //_______________________________________________________________________ void Config::loadConfiguration( ConfigurationPtr configuration ) { ui->ui.titleAlignment->setCurrentIndex( configuration->titleAlignment() ); ui->ui.buttonSize->setCurrentIndex( configuration->buttonSize() ); ui->ui.blendColor->setCurrentIndex( configuration->blendStyle() ); ui->ui.frameBorder->setCurrentIndex( configuration->frameBorder() ); ui->ui.separatorMode->setCurrentIndex( configuration->separatorMode() ); ui->ui.drawSizeGrip->setChecked( configuration->drawSizeGrip() ); ui->ui.titleOutline->setChecked( configuration->drawTitleOutline() ); ui->ui.animationsEnabled->setChecked( configuration->animationsEnabled() ); ui->ui.narrowButtonSpacing->setChecked( configuration->useNarrowButtonSpacing() ); ui->ui.closeFromMenuButton->setChecked( configuration->closeWindowFromMenuButton() ); ui->animationConfigWidget()->setConfiguration( configuration ); ui->animationConfigWidget()->load(); } //_______________________________________________________________________ bool Config::exceptionListChanged( void ) const { return true; // // get saved list // ExceptionList exceptions; // exceptions.read( *_configuration ); // if( exceptions.empty() ) // { exceptions = ExceptionList::defaultList(); } // // // compare to current // return exceptions != ui->ui.exceptions->exceptions(); } }