2009-08-24 16:15:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// config.cpp
|
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-24 16:15:14 +00:00
|
|
|
// Copyright (C) 2008 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
//
|
|
|
|
// Based on the Quartz configuration module,
|
|
|
|
// Copyright (c) 2001 Karol Szwed <gallium@kde.org>
|
|
|
|
//
|
|
|
|
// 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
|
2009-09-09 00:55:55 +00:00
|
|
|
// IN THE SOFTWARE.
|
2009-08-24 16:15:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-01 23:44:27 +00:00
|
|
|
#include "oxygenconfig.h"
|
|
|
|
#include "oxygenconfig.moc"
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2011-07-18 07:49:15 +00:00
|
|
|
#include "oxygenanimationconfigwidget.h"
|
2012-11-23 09:09:39 +00:00
|
|
|
#include "oxygenconfiguration.h"
|
|
|
|
#include "oxygenutil.h"
|
|
|
|
#include "../oxygenexceptionlist.h"
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2011-07-18 07:49:15 +00:00
|
|
|
#include <QtCore/QTextStream>
|
2011-01-29 18:33:01 +00:00
|
|
|
#include <QtDBus/QDBusConnection>
|
|
|
|
#include <QtDBus/QDBusMessage>
|
|
|
|
|
2009-09-16 06:09:31 +00:00
|
|
|
#include <KAboutData>
|
|
|
|
#include <KAboutApplicationDialog>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KGlobal>
|
|
|
|
#include <KLocale>
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_______________________________________________________________________
|
|
|
|
extern "C"
|
|
|
|
{
|
2010-10-03 02:22:56 +00:00
|
|
|
KDE_EXPORT QObject* allocate_config( KConfig* conf, QWidget* parent )
|
|
|
|
{ return ( new Oxygen::Config( conf, parent ) ); }
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
namespace Oxygen
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2010-11-11 16:37:52 +00:00
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
//_______________________________________________________________________
|
|
|
|
Config::Config( KConfig*, QWidget* parent ):
|
|
|
|
QObject( parent )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
KGlobal::locale()->insertCatalog("kwin_clients");
|
|
|
|
|
2011-02-24 16:47:38 +00:00
|
|
|
_configuration = new KConfig( "oxygenrc" );
|
|
|
|
KConfigGroup configurationGroup( _configuration, "Windeco");
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2011-02-24 16:47:38 +00:00
|
|
|
ui = new ConfigurationUi( parent );
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
load( configurationGroup );
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( ui, SIGNAL(changed()), SLOT(updateChanged()) );
|
2011-02-24 16:47:38 +00:00
|
|
|
ui->show();
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
//_______________________________________________________________________
|
|
|
|
Config::~Config()
|
|
|
|
{
|
2011-02-24 16:47:38 +00:00
|
|
|
delete ui;
|
|
|
|
delete _configuration;
|
2010-10-03 02:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
void Config::toggleExpertMode( bool value )
|
2011-02-24 16:47:38 +00:00
|
|
|
{ ui->toggleExpertMode( value ); }
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
void Config::load( const KConfigGroup& )
|
|
|
|
{
|
|
|
|
|
|
|
|
// load standard configuration
|
2012-11-23 09:09:39 +00:00
|
|
|
ConfigurationPtr configuration( new Configuration() );
|
|
|
|
configuration->readConfig();
|
|
|
|
loadConfiguration( configuration );
|
|
|
|
|
|
|
|
// load shadows
|
|
|
|
foreach( ShadowConfigurationUi* ui, ui->shadowConfigurations )
|
|
|
|
{ ui->readConfig( _configuration ); }
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// load exceptions
|
|
|
|
ExceptionList exceptions;
|
2012-11-23 09:09:39 +00:00
|
|
|
exceptions.readConfig( *_configuration );
|
|
|
|
ui->ui.exceptions->setExceptions( exceptions.get() );
|
2010-10-03 02:22:56 +00:00
|
|
|
updateChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
void Config::updateChanged( void )
|
|
|
|
{
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
ConfigurationPtr configuration( new Configuration() );
|
|
|
|
configuration->readConfig();
|
2010-10-03 02:22:56 +00:00
|
|
|
bool modified( false );
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
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;
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// shadow configurations
|
2012-11-23 09:09:39 +00:00
|
|
|
else if( ui->shadowConfigurations[0]->isModified() ) modified = true;
|
|
|
|
else if( ui->shadowConfigurations[1]->isModified() ) modified = true;
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// exceptions
|
|
|
|
else if( exceptionListChanged() ) modified = true;
|
|
|
|
|
2011-07-18 07:49:15 +00:00
|
|
|
// animations
|
2012-11-23 09:09:39 +00:00
|
|
|
else if( !ui->expertMode() && ui->ui.animationsEnabled->isChecked() != configuration->animationsEnabled() ) modified = true;
|
2011-07-18 08:06:13 +00:00
|
|
|
else if( ui->expertMode() && ui->animationConfigWidget()->isChanged() ) modified = true;
|
2011-07-18 07:49:15 +00:00
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
// emit relevant signals
|
|
|
|
if( modified ) emit changed();
|
|
|
|
emit changed( modified );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
void Config::save( KConfigGroup& )
|
|
|
|
{
|
|
|
|
|
2012-11-16 10:59:58 +00:00
|
|
|
// create configuration from group
|
2012-11-23 09:09:39 +00:00
|
|
|
ConfigurationPtr configuration( new Configuration() );
|
|
|
|
configuration->readConfig();
|
2012-11-16 10:59:58 +00:00
|
|
|
|
|
|
|
// apply modifications from ui
|
2012-11-23 09:09:39 +00:00
|
|
|
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() );
|
2010-12-22 22:08:15 +00:00
|
|
|
|
2011-07-18 08:09:22 +00:00
|
|
|
if( ui->expertMode() )
|
|
|
|
{
|
2011-07-18 07:49:15 +00:00
|
|
|
|
2011-07-18 08:09:22 +00:00
|
|
|
ui->animationConfigWidget()->setConfiguration( configuration );
|
|
|
|
ui->animationConfigWidget()->save();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
configuration->setAnimationsEnabled( ui->ui.animationsEnabled->isChecked() );
|
2011-07-18 08:09:22 +00:00
|
|
|
|
|
|
|
}
|
2011-07-18 08:21:17 +00:00
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
// save standard configuration
|
2012-11-23 09:09:39 +00:00
|
|
|
Util::writeConfig( configuration.data(), _configuration );
|
2010-10-03 02:22:56 +00:00
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
// get list of exceptions and write
|
|
|
|
ConfigurationList exceptions( ui->ui.exceptions->exceptions() );
|
|
|
|
ExceptionList( exceptions ).writeConfig( *_configuration );
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// write shadow configuration
|
2012-11-23 09:09:39 +00:00
|
|
|
foreach( ShadowConfigurationUi* ui, ui->shadowConfigurations )
|
|
|
|
{ ui->writeConfig( _configuration ); }
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// sync configuration
|
2011-02-24 16:47:38 +00:00
|
|
|
_configuration->sync();
|
2010-10-03 02:22:56 +00:00
|
|
|
|
2011-01-29 18:33:01 +00:00
|
|
|
QDBusMessage message( QDBusMessage::createSignal("/OxygenWindeco", "org.kde.Oxygen.Style", "reparseConfiguration") );
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
void Config::defaults()
|
|
|
|
{
|
|
|
|
|
|
|
|
// install default configuration
|
2012-11-23 09:09:39 +00:00
|
|
|
ConfigurationPtr configuration( new Configuration() );
|
|
|
|
configuration->setDefaults();
|
|
|
|
loadConfiguration( configuration );
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// load shadows
|
2012-11-23 09:09:39 +00:00
|
|
|
foreach( ShadowConfigurationUi* ui, ui->shadowConfigurations )
|
|
|
|
{ ui->readDefaults( _configuration ); }
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
// install default exceptions
|
2012-11-23 09:09:39 +00:00
|
|
|
// ui->ui.exceptions->setExceptions( ExceptionList::defaultList() );
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
updateChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
2012-11-23 09:09:39 +00:00
|
|
|
void Config::loadConfiguration( ConfigurationPtr configuration )
|
2010-10-03 02:22:56 +00:00
|
|
|
{
|
|
|
|
|
2012-11-23 09:09:39 +00:00
|
|
|
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() );
|
2011-07-18 07:49:15 +00:00
|
|
|
|
|
|
|
ui->animationConfigWidget()->setConfiguration( configuration );
|
|
|
|
ui->animationConfigWidget()->load();
|
|
|
|
|
2010-10-03 02:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
bool Config::exceptionListChanged( void ) const
|
|
|
|
{
|
2012-11-23 09:09:39 +00:00
|
|
|
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();
|
2010-10-03 02:22:56 +00:00
|
|
|
|
|
|
|
}
|
2009-08-30 17:42:04 +00:00
|
|
|
|
2009-09-09 00:55:55 +00:00
|
|
|
}
|