2009-08-24 16:12:50 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nitrogenconfiguration.cpp
|
|
|
|
// -------------------
|
|
|
|
//
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-24 16:12:50 +00:00
|
|
|
//
|
|
|
|
// 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 <KLocale>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <kdeversion.h>
|
|
|
|
|
|
|
|
#include "nitrogenconfiguration.h"
|
|
|
|
|
|
|
|
namespace Nitrogen
|
|
|
|
{
|
|
|
|
|
|
|
|
//__________________________________________________
|
|
|
|
NitrogenConfiguration::NitrogenConfiguration( void ):
|
|
|
|
titleAlignment_( Qt::AlignLeft ),
|
|
|
|
buttonSize_( ButtonDefault ),
|
|
|
|
frameBorder_( BorderDefault ),
|
|
|
|
blendColor_( RadialBlending ),
|
2009-09-02 02:15:53 +00:00
|
|
|
sizeGripMode_( SizeGripWhenNeeded ),
|
2009-08-29 04:53:13 +00:00
|
|
|
showStripes_( true ),
|
|
|
|
drawSeparator_( true ),
|
2009-09-04 19:02:20 +00:00
|
|
|
drawTitleOutline_( false ),
|
2009-08-22 08:24:06 +00:00
|
|
|
useOxygenShadows_( true )
|
|
|
|
{}
|
|
|
|
|
|
|
|
//__________________________________________________
|
|
|
|
NitrogenConfiguration::NitrogenConfiguration( KConfigGroup group )
|
|
|
|
{
|
|
|
|
|
|
|
|
// used to set default values when entries are not found in kconfig
|
|
|
|
NitrogenConfiguration defaultConfiguration;
|
|
|
|
|
|
|
|
// title alignment
|
|
|
|
setTitleAlignment( titleAlignment(
|
|
|
|
group.readEntry( NitrogenConfig::TITLE_ALIGNMENT,
|
2009-08-24 16:12:50 +00:00
|
|
|
defaultConfiguration.titleAlignmentName( false ) ), false ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// button size
|
|
|
|
setButtonSize( buttonSize(
|
|
|
|
group.readEntry( NitrogenConfig::BUTTON_SIZE,
|
2009-08-24 16:12:50 +00:00
|
|
|
defaultConfiguration.buttonSizeName( false ) ), false ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// frame border
|
|
|
|
setFrameBorder( frameBorder(
|
|
|
|
group.readEntry( NitrogenConfig::FRAME_BORDER,
|
2009-08-24 16:12:50 +00:00
|
|
|
defaultConfiguration.frameBorderName( false ) ), false ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// blend color
|
|
|
|
setBlendColor( blendColor(
|
|
|
|
group.readEntry( NitrogenConfig::BLEND_COLOR,
|
2009-08-24 16:12:50 +00:00
|
|
|
defaultConfiguration.blendColorName( false ) ), false ) );
|
2009-09-02 02:15:53 +00:00
|
|
|
|
|
|
|
// size grip
|
|
|
|
setSizeGripMode( sizeGripMode(
|
|
|
|
group.readEntry( NitrogenConfig::SIZE_GRIP_MODE,
|
|
|
|
defaultConfiguration.sizeGripModeName( false ) ), false ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// show stripes
|
|
|
|
setShowStripes( group.readEntry(
|
|
|
|
NitrogenConfig::SHOW_STRIPES,
|
|
|
|
defaultConfiguration.showStripes() ) );
|
|
|
|
|
|
|
|
// draw separator
|
|
|
|
setDrawSeparator( group.readEntry(
|
|
|
|
NitrogenConfig::DRAW_SEPARATOR,
|
|
|
|
defaultConfiguration.drawSeparator() ) );
|
|
|
|
|
2009-09-04 19:02:20 +00:00
|
|
|
// title outline
|
|
|
|
setDrawTitleOutline( group.readEntry(
|
|
|
|
NitrogenConfig::DRAW_TITLE_OUTLINE,
|
|
|
|
defaultConfiguration.drawTitleOutline() ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// oxygen shadows
|
|
|
|
setUseOxygenShadows( group.readEntry(
|
|
|
|
NitrogenConfig::USE_OXYGEN_SHADOWS,
|
|
|
|
defaultConfiguration.useOxygenShadows() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
|
|
|
void NitrogenConfiguration::write( KConfigGroup& group ) const
|
|
|
|
{
|
|
|
|
|
2009-08-24 16:12:50 +00:00
|
|
|
group.writeEntry( NitrogenConfig::TITLE_ALIGNMENT, titleAlignmentName( false ) );
|
|
|
|
group.writeEntry( NitrogenConfig::BUTTON_SIZE, buttonSizeName( false ) );
|
|
|
|
group.writeEntry( NitrogenConfig::BLEND_COLOR, blendColorName( false ) );
|
|
|
|
group.writeEntry( NitrogenConfig::FRAME_BORDER, frameBorderName( false ) );
|
2009-09-02 02:15:53 +00:00
|
|
|
group.writeEntry( NitrogenConfig::SIZE_GRIP_MODE, sizeGripModeName( false ) );
|
2009-08-24 16:12:50 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
group.writeEntry( NitrogenConfig::SHOW_STRIPES, showStripes() );
|
|
|
|
group.writeEntry( NitrogenConfig::DRAW_SEPARATOR, drawSeparator() );
|
2009-09-04 19:02:20 +00:00
|
|
|
group.writeEntry( NitrogenConfig::DRAW_TITLE_OUTLINE, drawTitleOutline() );
|
2009-08-22 08:24:06 +00:00
|
|
|
group.writeEntry( NitrogenConfig::USE_OXYGEN_SHADOWS, useOxygenShadows() );
|
2009-08-24 16:12:50 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
QString NitrogenConfiguration::titleAlignmentName( Qt::Alignment value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
const char* out;
|
2009-08-22 08:24:06 +00:00
|
|
|
switch( value )
|
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
case Qt::AlignLeft: out = "Left"; break;
|
|
|
|
case Qt::AlignHCenter: out = "Center"; break;
|
|
|
|
case Qt::AlignRight: out = "Right"; break;
|
|
|
|
default: return NitrogenConfiguration().titleAlignmentName( translated );
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 04:35:25 +00:00
|
|
|
return translated ? i18n(out):out;
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
Qt::Alignment NitrogenConfiguration::titleAlignment( QString value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
if (value == titleAlignmentName( Qt::AlignLeft, translated ) ) return Qt::AlignLeft;
|
2009-08-25 05:00:41 +00:00
|
|
|
else if (value == titleAlignmentName( Qt::AlignHCenter, translated ) ) return Qt::AlignHCenter;
|
|
|
|
else if (value == titleAlignmentName( Qt::AlignRight, translated ) ) return Qt::AlignRight;
|
2009-08-22 08:24:06 +00:00
|
|
|
else return NitrogenConfiguration().titleAlignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
QString NitrogenConfiguration::buttonSizeName( ButtonSize value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
const char* out;
|
2009-08-22 08:24:06 +00:00
|
|
|
switch( value )
|
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
case ButtonSmall: out = "Small"; break;
|
2009-09-04 03:02:26 +00:00
|
|
|
case ButtonDefault: out = "Normal"; break;
|
2009-08-24 16:12:50 +00:00
|
|
|
case ButtonLarge: out = "Large"; break;
|
|
|
|
case ButtonHuge: out = "Huge"; break;
|
|
|
|
default: return NitrogenConfiguration().buttonSizeName( translated );
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 04:35:25 +00:00
|
|
|
return translated ? i18n(out):out;
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
NitrogenConfiguration::ButtonSize NitrogenConfiguration::buttonSize( QString value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
if( value == buttonSizeName( ButtonSmall, translated ) ) return ButtonSmall;
|
|
|
|
else if( value == buttonSizeName( ButtonDefault, translated ) ) return ButtonDefault;
|
|
|
|
else if( value == buttonSizeName( ButtonLarge, translated ) ) return ButtonLarge;
|
|
|
|
else if( value == buttonSizeName( ButtonHuge, translated ) ) return ButtonHuge;
|
2009-08-22 08:24:06 +00:00
|
|
|
else return NitrogenConfiguration().buttonSize();
|
|
|
|
}
|
|
|
|
|
2009-08-29 05:38:58 +00:00
|
|
|
//__________________________________________________
|
|
|
|
int NitrogenConfiguration::iconScale( ButtonSize value )
|
|
|
|
{
|
|
|
|
switch( value )
|
|
|
|
{
|
|
|
|
case ButtonSmall: return 13;
|
|
|
|
case ButtonDefault: return 16;
|
|
|
|
case ButtonLarge: return 24;
|
|
|
|
case ButtonHuge: return 35;
|
|
|
|
default: return NitrogenConfiguration().iconScale();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
QString NitrogenConfiguration::frameBorderName( FrameBorder value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
const char* out;
|
2009-08-22 08:24:06 +00:00
|
|
|
switch( value )
|
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
case BorderNone: out = "No Border"; break;
|
|
|
|
case BorderTiny: out = "Tiny"; break;
|
2009-08-25 04:51:08 +00:00
|
|
|
case BorderDefault: out = "Normal"; break;
|
2009-08-24 16:12:50 +00:00
|
|
|
case BorderLarge: out = "Large"; break;
|
2009-08-25 04:51:08 +00:00
|
|
|
case BorderVeryLarge: out = "Very Large"; break;
|
|
|
|
case BorderHuge: out = "Huge"; break;
|
|
|
|
case BorderVeryHuge: out = "Very Huge"; break;
|
|
|
|
case BorderOversized: out = "Oversized"; break;
|
2009-08-24 16:12:50 +00:00
|
|
|
default: return NitrogenConfiguration().frameBorderName( translated );
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 04:35:25 +00:00
|
|
|
return translated ? i18n(out):out;
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
NitrogenConfiguration::FrameBorder NitrogenConfiguration::frameBorder( QString value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
if( value == frameBorderName( BorderNone, translated ) ) return BorderNone;
|
|
|
|
else if( value == frameBorderName( BorderTiny, translated ) ) return BorderTiny;
|
|
|
|
else if( value == frameBorderName( BorderDefault, translated ) ) return BorderDefault;
|
|
|
|
else if( value == frameBorderName( BorderLarge, translated ) ) return BorderLarge;
|
2009-08-25 04:51:08 +00:00
|
|
|
else if( value == frameBorderName( BorderVeryLarge, translated ) ) return BorderVeryLarge;
|
|
|
|
else if( value == frameBorderName( BorderHuge, translated ) ) return BorderHuge;
|
|
|
|
else if( value == frameBorderName( BorderVeryHuge, translated ) ) return BorderVeryHuge;
|
|
|
|
else if( value == frameBorderName( BorderOversized, translated ) ) return BorderOversized;
|
2009-08-22 08:24:06 +00:00
|
|
|
else return NitrogenConfiguration().frameBorder();
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
QString NitrogenConfiguration::blendColorName( BlendColorType value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
const char* out;
|
2009-08-22 08:24:06 +00:00
|
|
|
switch( value )
|
|
|
|
{
|
2009-08-29 06:03:09 +00:00
|
|
|
case NoBlending: out = "Solid Color"; break;
|
|
|
|
case RadialBlending: out = "Radial Gradient"; break;
|
2009-08-24 16:12:50 +00:00
|
|
|
default: return NitrogenConfiguration().blendColorName( translated );
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-25 04:35:25 +00:00
|
|
|
return translated ? i18n(out):out;
|
2009-08-24 16:12:50 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
2009-08-24 16:12:50 +00:00
|
|
|
NitrogenConfiguration::BlendColorType NitrogenConfiguration::blendColor( QString value, bool translated )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-08-24 16:12:50 +00:00
|
|
|
if( value == blendColorName( NoBlending, translated ) ) return NoBlending;
|
|
|
|
else if( value == blendColorName( RadialBlending, translated ) ) return RadialBlending;
|
2009-08-22 08:24:06 +00:00
|
|
|
else return NitrogenConfiguration().blendColor();
|
|
|
|
}
|
|
|
|
|
2009-09-02 02:15:53 +00:00
|
|
|
//__________________________________________________
|
|
|
|
QString NitrogenConfiguration::sizeGripModeName( SizeGripMode value, bool translated )
|
|
|
|
{
|
|
|
|
const char* out;
|
|
|
|
switch( value )
|
|
|
|
{
|
|
|
|
case SizeGripAlways: out = "Always Show Extra Size Grip"; break;
|
|
|
|
case SizeGripNever: out = "Always Hide Extra Size Grip"; break;
|
|
|
|
case SizeGripWhenNeeded: out = "Show Extra Size Grip When Needed"; break;
|
|
|
|
default: return NitrogenConfiguration().sizeGripModeName( translated );
|
|
|
|
}
|
|
|
|
|
|
|
|
return translated ? i18n(out):out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________
|
|
|
|
NitrogenConfiguration::SizeGripMode NitrogenConfiguration::sizeGripMode( QString value, bool translated )
|
|
|
|
{
|
|
|
|
if( value == sizeGripModeName( SizeGripAlways, translated ) ) return SizeGripAlways;
|
|
|
|
else if( value == sizeGripModeName( SizeGripNever, translated ) ) return SizeGripNever;
|
|
|
|
else if( value == sizeGripModeName( SizeGripWhenNeeded, translated ) ) return SizeGripWhenNeeded;
|
|
|
|
else return NitrogenConfiguration().sizeGripMode();
|
|
|
|
}
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
//________________________________________________________
|
|
|
|
bool NitrogenConfiguration::operator == (const NitrogenConfiguration& other ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
return
|
|
|
|
titleAlignment() == other.titleAlignment() &&
|
|
|
|
buttonSize() == other.buttonSize() &&
|
|
|
|
frameBorder() == other.frameBorder() &&
|
|
|
|
blendColor() == other.blendColor() &&
|
2009-09-02 02:15:53 +00:00
|
|
|
sizeGripMode() == other.sizeGripMode() &&
|
2009-08-22 08:24:06 +00:00
|
|
|
showStripes() == other.showStripes() &&
|
|
|
|
drawSeparator() == other.drawSeparator() &&
|
2009-09-04 19:02:20 +00:00
|
|
|
drawTitleOutline() == other.drawTitleOutline() &&
|
2009-08-22 08:24:06 +00:00
|
|
|
useOxygenShadows() == other.useOxygenShadows();
|
|
|
|
}
|
|
|
|
|
2009-08-24 06:27:49 +00:00
|
|
|
}
|