2002-01-16 12:26:03 +00:00
|
|
|
/*
|
|
|
|
This is the new kwindecoration kcontrol module
|
|
|
|
|
|
|
|
Copyright (c) 2001
|
|
|
|
Karol Szwed <gallium@kde.org>
|
|
|
|
http://gallium.n3.net/
|
|
|
|
|
|
|
|
Supports new kwin configuration plugins, and titlebar button position
|
|
|
|
modification via dnd interface.
|
|
|
|
|
2003-06-30 08:14:54 +00:00
|
|
|
Based on original "kwintheme" (Window Borders)
|
2002-01-16 12:26:03 +00:00
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
2003-09-19 11:14:41 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2004-05-15 00:38:42 +00:00
|
|
|
|
2003-09-19 11:14:41 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2004-05-15 00:38:42 +00:00
|
|
|
|
2003-09-19 11:14:41 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-12-21 06:45:09 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-09-19 11:14:41 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-24 12:41:56 +00:00
|
|
|
#include <assert.h>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QDir>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QFileInfo>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QLayout>
|
2005-07-28 14:59:42 +00:00
|
|
|
|
|
|
|
#include <q3groupbox.h>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QCheckBox>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QTabWidget>
|
2005-09-18 14:52:14 +00:00
|
|
|
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QFile>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QSlider>
|
2005-07-28 14:59:42 +00:00
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2006-07-02 18:31:00 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2006-06-08 13:43:23 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
#include <kapplication.h>
|
2003-06-30 08:14:54 +00:00
|
|
|
#include <kcombobox.h>
|
2002-01-16 12:26:03 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kdialog.h>
|
|
|
|
#include <kgenericfactory.h>
|
|
|
|
#include <kaboutdata.h>
|
|
|
|
|
|
|
|
#include "kwindecoration.h"
|
2003-09-16 19:34:03 +00:00
|
|
|
#include "preview.h"
|
|
|
|
#include <kdecoration_plugins_p.h>
|
2003-09-24 12:41:56 +00:00
|
|
|
#include <kdecorationfactory.h>
|
2005-09-18 14:52:14 +00:00
|
|
|
#include <kvbox.h>
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// KCModule plugin interface
|
|
|
|
// =========================
|
|
|
|
typedef KGenericFactory<KWinDecorationModule, QWidget> KWinDecoFactory;
|
2003-07-26 10:41:28 +00:00
|
|
|
K_EXPORT_COMPONENT_FACTORY( kcm_kwindecoration, KWinDecoFactory("kcmkwindecoration") )
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2006-05-08 08:28:37 +00:00
|
|
|
KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QStringList &)
|
2007-01-29 17:14:20 +00:00
|
|
|
: KCModule(KWinDecoFactory::componentData(), parent),
|
|
|
|
kwinConfig(KSharedConfig::openConfig("kwinrc")),
|
|
|
|
pluginObject(0)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfigGroup style( kwinConfig, "Style");
|
2007-01-29 17:14:20 +00:00
|
|
|
plugins = new KDecorationPreviewPlugins(kwinConfig);
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2006-04-12 15:13:31 +00:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(KDialog::spacingHint());
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Save this for later...
|
|
|
|
// cbUseMiniWindows = new QCheckBox( i18n( "Render mini &titlebars for all windows"), checkGroup );
|
2006-05-18 14:17:47 +00:00
|
|
|
// QWhatsThis::add( cbUseMiniWindows, i18n( "Note that this option is not available on all styles yet" ) );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-11-20 23:43:16 +00:00
|
|
|
tabWidget = new QTabWidget( this );
|
|
|
|
layout->addWidget( tabWidget );
|
|
|
|
|
|
|
|
// Page 1 (General Options)
|
|
|
|
QWidget *pluginPage = new QWidget( tabWidget );
|
|
|
|
|
2006-04-12 15:13:31 +00:00
|
|
|
QVBoxLayout* pluginLayout = new QVBoxLayout(pluginPage);
|
2006-04-12 15:34:39 +00:00
|
|
|
pluginLayout->setMargin(KDialog::marginHint());
|
|
|
|
pluginLayout->setSpacing(KDialog::spacingHint());
|
2003-10-23 14:56:44 +00:00
|
|
|
|
2004-12-02 23:02:03 +00:00
|
|
|
// decoration chooser
|
|
|
|
decorationList = new KComboBox( pluginPage );
|
|
|
|
QString whatsThis = i18n("Select the window decoration. This is the look and feel of both "
|
|
|
|
"the window borders and the window handle.");
|
2005-07-28 14:59:42 +00:00
|
|
|
decorationList->setWhatsThis( whatsThis);
|
2004-12-02 23:02:03 +00:00
|
|
|
pluginLayout->addWidget(decorationList);
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3GroupBox *pluginSettingsGrp = new Q3GroupBox( i18n("Decoration Options"), pluginPage );
|
|
|
|
pluginSettingsGrp->setColumnLayout( 0, Qt::Vertical );
|
2004-12-02 23:02:03 +00:00
|
|
|
pluginSettingsGrp->setFlat( true );
|
|
|
|
pluginSettingsGrp->layout()->setMargin( 0 );
|
|
|
|
pluginSettingsGrp->layout()->setSpacing( KDialog::spacingHint() );
|
|
|
|
pluginLayout->addWidget( pluginSettingsGrp );
|
2003-10-23 14:56:44 +00:00
|
|
|
|
2004-11-20 23:53:54 +00:00
|
|
|
pluginLayout->addStretch();
|
2003-09-16 19:34:03 +00:00
|
|
|
|
2004-12-02 23:02:03 +00:00
|
|
|
// Border size chooser
|
2004-12-03 19:32:35 +00:00
|
|
|
lBorder = new QLabel (i18n("B&order size:"), pluginSettingsGrp);
|
|
|
|
cBorder = new QComboBox(pluginSettingsGrp);
|
|
|
|
lBorder->setBuddy(cBorder);
|
2005-07-28 14:59:42 +00:00
|
|
|
cBorder->setWhatsThis( i18n( "Use this combobox to change the border size of the decoration." ));
|
2004-12-02 23:02:03 +00:00
|
|
|
lBorder->hide();
|
2004-12-03 19:32:35 +00:00
|
|
|
cBorder->hide();
|
2006-04-12 15:13:31 +00:00
|
|
|
QHBoxLayout *borderSizeLayout = new QHBoxLayout();
|
|
|
|
pluginSettingsGrp->layout()->addItem( borderSizeLayout );
|
2004-12-03 19:32:35 +00:00
|
|
|
borderSizeLayout->addWidget(lBorder);
|
|
|
|
borderSizeLayout->addWidget(cBorder);
|
|
|
|
borderSizeLayout->addStretch();
|
2004-12-02 23:02:03 +00:00
|
|
|
|
2005-09-18 14:52:14 +00:00
|
|
|
pluginConfigWidget = new KVBox(pluginSettingsGrp);
|
2006-04-12 15:13:31 +00:00
|
|
|
pluginSettingsGrp->layout()->addWidget( pluginConfigWidget );
|
2004-12-02 23:02:03 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
// Page 2 (Button Selector)
|
2004-12-02 23:02:03 +00:00
|
|
|
QWidget* buttonPage = new QWidget( tabWidget );
|
2006-04-12 15:13:31 +00:00
|
|
|
QVBoxLayout* buttonLayout = new QVBoxLayout(buttonPage);
|
2006-04-12 15:34:39 +00:00
|
|
|
buttonLayout->setMargin(KDialog::marginHint());
|
|
|
|
buttonLayout->setSpacing(KDialog::spacingHint());
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2003-05-31 17:40:57 +00:00
|
|
|
cbShowToolTips = new QCheckBox(
|
|
|
|
i18n("&Show window button tooltips"), buttonPage );
|
2005-07-28 14:59:42 +00:00
|
|
|
cbShowToolTips->setWhatsThis(
|
2003-05-31 17:40:57 +00:00
|
|
|
i18n( "Enabling this checkbox will show window button tooltips. "
|
|
|
|
"If this checkbox is off, no window button tooltips will be shown."));
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2003-05-31 17:40:57 +00:00
|
|
|
cbUseCustomButtonPositions = new QCheckBox(
|
|
|
|
i18n("Use custom titlebar button &positions"), buttonPage );
|
2005-07-28 14:59:42 +00:00
|
|
|
cbUseCustomButtonPositions->setWhatsThis(
|
2004-05-19 13:27:23 +00:00
|
|
|
i18n( "The appropriate settings can be found in the \"Buttons\" Tab; "
|
|
|
|
"please note that this option is not available on all styles yet." ) );
|
2003-05-31 17:40:57 +00:00
|
|
|
|
2004-12-02 23:02:03 +00:00
|
|
|
buttonLayout->addWidget( cbShowToolTips );
|
|
|
|
buttonLayout->addWidget( cbUseCustomButtonPositions );
|
2003-05-31 17:40:57 +00:00
|
|
|
|
|
|
|
// Add nifty dnd button modification widgets
|
2004-12-03 22:23:20 +00:00
|
|
|
buttonPositionWidget = new ButtonPositionWidget(buttonPage, "button_position_widget");
|
2004-12-10 18:28:28 +00:00
|
|
|
buttonPositionWidget->setDecorationFactory(plugins->factory() );
|
2006-04-12 15:13:31 +00:00
|
|
|
QHBoxLayout* buttonControlLayout = new QHBoxLayout();
|
|
|
|
buttonLayout->addLayout( buttonControlLayout );
|
2004-12-02 23:02:03 +00:00
|
|
|
buttonControlLayout->addSpacing(20);
|
2004-12-03 22:23:20 +00:00
|
|
|
buttonControlLayout->addWidget(buttonPositionWidget);
|
2004-12-02 23:02:03 +00:00
|
|
|
// buttonLayout->addStretch();
|
|
|
|
|
|
|
|
// preview
|
2006-04-12 15:13:31 +00:00
|
|
|
QVBoxLayout* previewLayout = new QVBoxLayout();
|
|
|
|
previewLayout->setSpacing( KDialog::spacingHint() );
|
|
|
|
layout->addLayout( previewLayout );
|
2004-12-03 18:49:35 +00:00
|
|
|
previewLayout->setMargin( KDialog::marginHint() );
|
2004-12-02 23:02:03 +00:00
|
|
|
|
2004-12-03 18:49:35 +00:00
|
|
|
preview = new KDecorationPreview( this );
|
|
|
|
previewLayout->addWidget(preview);
|
2004-12-02 23:02:03 +00:00
|
|
|
|
2004-12-03 18:49:35 +00:00
|
|
|
preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2004-12-02 23:02:03 +00:00
|
|
|
tabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
2004-11-09 19:34:18 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
// Load all installed decorations into memory
|
|
|
|
// Set up the decoration lists and other UI settings
|
|
|
|
findDecorations();
|
|
|
|
createDecorationList();
|
2007-02-20 07:00:30 +00:00
|
|
|
readConfig( style );
|
|
|
|
|
|
|
|
resetPlugin( style );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2006-04-12 15:13:31 +00:00
|
|
|
tabWidget->addTab( pluginPage, i18n("&Window Decoration") );
|
|
|
|
tabWidget->addTab( buttonPage, i18n("&Buttons") );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-03 22:23:20 +00:00
|
|
|
connect( buttonPositionWidget, SIGNAL(changed()), this, SLOT(slotButtonsChanged()) ); // update preview etc.
|
|
|
|
connect( buttonPositionWidget, SIGNAL(changed()), this, SLOT(slotSelectionChanged()) ); // emit changed()...
|
2003-06-30 08:14:54 +00:00
|
|
|
connect( decorationList, SIGNAL(activated(const QString&)), SLOT(slotSelectionChanged()) );
|
|
|
|
connect( decorationList, SIGNAL(activated(const QString&)),
|
|
|
|
SLOT(slotChangeDecoration(const QString&)) );
|
2002-01-16 12:26:03 +00:00
|
|
|
connect( cbUseCustomButtonPositions, SIGNAL(clicked()), SLOT(slotSelectionChanged()) );
|
2004-12-03 22:23:20 +00:00
|
|
|
connect(cbUseCustomButtonPositions, SIGNAL(toggled(bool)), buttonPositionWidget, SLOT(setEnabled(bool)));
|
2004-11-20 23:43:16 +00:00
|
|
|
connect(cbUseCustomButtonPositions, SIGNAL(toggled(bool)), this, SLOT(slotButtonsChanged()) );
|
2002-01-16 12:26:03 +00:00
|
|
|
connect( cbShowToolTips, SIGNAL(clicked()), SLOT(slotSelectionChanged()) );
|
2004-12-03 19:32:35 +00:00
|
|
|
connect( cBorder, SIGNAL( activated( int )), SLOT( slotBorderChanged( int )));
|
2002-01-16 12:26:03 +00:00
|
|
|
// connect( cbUseMiniWindows, SIGNAL(clicked()), SLOT(slotSelectionChanged()) );
|
|
|
|
|
2004-07-18 23:40:42 +00:00
|
|
|
KAboutData *about =
|
|
|
|
new KAboutData(I18N_NOOP("kcmkwindecoration"),
|
|
|
|
I18N_NOOP("Window Decoration Control Module"),
|
|
|
|
0, 0, KAboutData::License_GPL,
|
|
|
|
I18N_NOOP("(c) 2001 Karol Szwed"));
|
|
|
|
about->addAuthor("Karol Szwed", 0, "gallium@kde.org");
|
|
|
|
setAboutData(about);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KWinDecorationModule::~KWinDecorationModule()
|
|
|
|
{
|
2003-09-16 19:34:03 +00:00
|
|
|
delete preview; // needs to be destroyed before plugins
|
|
|
|
delete plugins;
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Find all theme desktop files in all 'data' dirs owned by kwin.
|
|
|
|
// And insert these into a DecorationInfo structure
|
|
|
|
void KWinDecorationModule::findDecorations()
|
|
|
|
{
|
|
|
|
QStringList dirList = KGlobal::dirs()->findDirs("data", "kwin");
|
|
|
|
QStringList::ConstIterator it;
|
|
|
|
|
|
|
|
for (it = dirList.begin(); it != dirList.end(); it++)
|
|
|
|
{
|
|
|
|
QDir d(*it);
|
|
|
|
if (d.exists())
|
2005-07-28 14:59:42 +00:00
|
|
|
foreach (const QFileInfo& fi, d.entryInfoList())
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2005-11-08 10:20:07 +00:00
|
|
|
QString filename(fi.absoluteFilePath());
|
2002-01-16 12:26:03 +00:00
|
|
|
if (KDesktopFile::isDesktopFile(filename))
|
|
|
|
{
|
|
|
|
KDesktopFile desktopFile(filename);
|
2007-02-20 07:00:30 +00:00
|
|
|
QString libName = desktopFile.desktopGroup().readEntry("X-KDE-Library");
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2003-09-16 19:34:03 +00:00
|
|
|
if (!libName.isEmpty() && libName.startsWith( "kwin3_" ))
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
|
|
|
DecorationInfo di;
|
|
|
|
di.name = desktopFile.readName();
|
|
|
|
di.libraryName = libName;
|
|
|
|
decorations.append( di );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-30 08:14:54 +00:00
|
|
|
// Fills the decorationList with a list of available kwin decorations
|
2002-01-16 12:26:03 +00:00
|
|
|
void KWinDecorationModule::createDecorationList()
|
|
|
|
{
|
2005-09-17 20:02:02 +00:00
|
|
|
QList<DecorationInfo>::ConstIterator it;
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Sync with kwin hardcoded KDE2 style which has no desktop item
|
2003-06-30 08:14:54 +00:00
|
|
|
QStringList decorationNames;
|
|
|
|
decorationNames.append( i18n("KDE 2") );
|
2002-01-16 12:26:03 +00:00
|
|
|
for (it = decorations.begin(); it != decorations.end(); ++it)
|
|
|
|
{
|
2003-06-30 08:14:54 +00:00
|
|
|
decorationNames.append((*it).name);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
2003-06-30 08:14:54 +00:00
|
|
|
decorationNames.sort();
|
2006-04-12 15:13:31 +00:00
|
|
|
decorationList->addItems(decorationNames);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reset the decoration plugin to what the user just selected
|
2003-06-30 08:14:54 +00:00
|
|
|
void KWinDecorationModule::slotChangeDecoration( const QString & text)
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig _kwinConfig( "kwinrc" );
|
|
|
|
KConfigGroup kwinConfig(&_kwinConfig, "Style");
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Let the user see config options for the currently selected decoration
|
2007-02-20 07:00:30 +00:00
|
|
|
resetPlugin( kwinConfig, text );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is the selection handler setting
|
|
|
|
void KWinDecorationModule::slotSelectionChanged()
|
|
|
|
{
|
2003-11-08 23:43:53 +00:00
|
|
|
emit KCModule::changed(true);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2003-09-24 12:41:56 +00:00
|
|
|
static const char* const border_names[ KDecorationDefines::BordersCount ] =
|
|
|
|
{
|
2004-12-03 19:32:35 +00:00
|
|
|
I18N_NOOP( "Tiny" ),
|
|
|
|
I18N_NOOP( "Normal" ),
|
|
|
|
I18N_NOOP( "Large" ),
|
|
|
|
I18N_NOOP( "Very Large" ),
|
|
|
|
I18N_NOOP( "Huge" ),
|
|
|
|
I18N_NOOP( "Very Huge" ),
|
|
|
|
I18N_NOOP( "Oversized" )
|
2003-09-24 12:41:56 +00:00
|
|
|
};
|
|
|
|
|
2005-09-17 20:02:02 +00:00
|
|
|
int KWinDecorationModule::borderSizeToIndex( BorderSize size, QList< BorderSize > sizes )
|
2003-09-24 12:41:56 +00:00
|
|
|
{
|
|
|
|
int pos = 0;
|
2005-09-17 20:02:02 +00:00
|
|
|
for( QList< BorderSize >::ConstIterator it = sizes.begin();
|
2003-09-24 12:41:56 +00:00
|
|
|
it != sizes.end();
|
|
|
|
++it, ++pos )
|
|
|
|
if( size <= *it )
|
|
|
|
break;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecorationDefines::BorderSize KWinDecorationModule::indexToBorderSize( int index,
|
2005-09-17 20:02:02 +00:00
|
|
|
QList< BorderSize > sizes )
|
2003-09-24 12:41:56 +00:00
|
|
|
{
|
2005-09-17 20:02:02 +00:00
|
|
|
QList< BorderSize >::ConstIterator it = sizes.begin();
|
2003-09-24 12:41:56 +00:00
|
|
|
for(;
|
|
|
|
it != sizes.end();
|
|
|
|
++it, --index )
|
|
|
|
if( index == 0 )
|
|
|
|
break;
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::slotBorderChanged( int size )
|
|
|
|
{
|
|
|
|
if( lBorder->isHidden())
|
|
|
|
return;
|
2003-11-08 23:43:53 +00:00
|
|
|
emit KCModule::changed( true );
|
2005-09-17 20:02:02 +00:00
|
|
|
QList< BorderSize > sizes;
|
2003-09-24 12:41:56 +00:00
|
|
|
if( plugins->factory() != NULL )
|
|
|
|
sizes = plugins->factory()->borderSizes();
|
|
|
|
assert( sizes.count() >= 2 );
|
|
|
|
border_size = indexToBorderSize( size, sizes );
|
2004-11-20 23:43:16 +00:00
|
|
|
|
|
|
|
// update preview
|
|
|
|
preview->setTempBorderSize(plugins, border_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::slotButtonsChanged()
|
|
|
|
{
|
|
|
|
// update preview
|
2004-12-03 22:23:20 +00:00
|
|
|
preview->setTempButtons(plugins, cbUseCustomButtonPositions->isChecked(), buttonPositionWidget->buttonsLeft(), buttonPositionWidget->buttonsRight() );
|
2003-09-24 12:41:56 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
QString KWinDecorationModule::decorationName( QString& libName )
|
|
|
|
{
|
|
|
|
QString decoName;
|
|
|
|
|
2005-09-17 20:02:02 +00:00
|
|
|
QList<DecorationInfo>::Iterator it;
|
2002-01-16 12:26:03 +00:00
|
|
|
for( it = decorations.begin(); it != decorations.end(); ++it )
|
|
|
|
if ( (*it).libraryName == libName )
|
|
|
|
{
|
|
|
|
decoName = (*it).name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return decoName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString KWinDecorationModule::decorationLibName( const QString& name )
|
|
|
|
{
|
|
|
|
QString libName;
|
|
|
|
|
|
|
|
// Find the corresponding library name to that of
|
|
|
|
// the current plugin name
|
2005-09-17 20:02:02 +00:00
|
|
|
QList<DecorationInfo>::Iterator it;
|
2002-01-16 12:26:03 +00:00
|
|
|
for( it = decorations.begin(); it != decorations.end(); ++it )
|
|
|
|
if ( (*it).name == name )
|
|
|
|
{
|
|
|
|
libName = (*it).libraryName;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (libName.isEmpty())
|
2003-06-30 08:14:54 +00:00
|
|
|
libName = "kwin_default"; // KDE 2
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
return libName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Loads/unloads and inserts the decoration config plugin into the
|
2003-06-30 08:14:54 +00:00
|
|
|
// pluginConfigWidget, allowing for dynamic configuration of decorations
|
2007-02-20 07:00:30 +00:00
|
|
|
void KWinDecorationModule::resetPlugin( KConfigGroup& conf, const QString& currentDecoName )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2002-02-19 16:56:16 +00:00
|
|
|
// Config names are "kwin_icewm_config"
|
2003-09-16 19:34:03 +00:00
|
|
|
// for "kwin3_icewm" kwin client
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2003-09-16 19:34:03 +00:00
|
|
|
QString oldName = styleToConfigLib( oldLibraryName );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
QString currentName;
|
2003-06-30 08:14:54 +00:00
|
|
|
if (!currentDecoName.isEmpty())
|
|
|
|
currentName = decorationLibName( currentDecoName ); // Use what the user selected
|
2002-01-16 12:26:03 +00:00
|
|
|
else
|
|
|
|
currentName = currentLibraryName; // Use what was read from readConfig()
|
|
|
|
|
2003-09-16 19:34:03 +00:00
|
|
|
if( plugins->loadPlugin( currentName )
|
|
|
|
&& preview->recreateDecoration( plugins ))
|
|
|
|
preview->enablePreview();
|
|
|
|
else
|
|
|
|
preview->disablePreview();
|
|
|
|
plugins->destroyPreviousPlugin();
|
2003-09-24 12:41:56 +00:00
|
|
|
|
|
|
|
checkSupportedBorderSizes();
|
|
|
|
|
2004-12-10 18:28:28 +00:00
|
|
|
// inform buttonPositionWidget about the new factory...
|
|
|
|
buttonPositionWidget->setDecorationFactory(plugins->factory() );
|
|
|
|
|
2003-09-16 19:34:03 +00:00
|
|
|
currentName = styleToConfigLib( currentName );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Delete old plugin widget if it exists
|
2003-07-14 23:39:12 +00:00
|
|
|
delete pluginObject;
|
2003-07-28 19:08:15 +00:00
|
|
|
pluginObject = 0;
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Use klibloader for library manipulation
|
|
|
|
KLibLoader* loader = KLibLoader::self();
|
|
|
|
|
|
|
|
// Free the old library if possible
|
|
|
|
if (!oldLibraryName.isNull())
|
|
|
|
loader->unloadLibrary( QFile::encodeName(oldName) );
|
|
|
|
|
|
|
|
KLibrary* library = loader->library( QFile::encodeName(currentName) );
|
|
|
|
if (library != NULL)
|
2003-06-30 08:14:54 +00:00
|
|
|
{
|
2002-01-16 12:26:03 +00:00
|
|
|
void* alloc_ptr = library->symbol("allocate_config");
|
|
|
|
|
|
|
|
if (alloc_ptr != NULL)
|
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
allocatePlugin = (QObject* (*)(KConfigGroup& conf, QWidget* parent))alloc_ptr;
|
2003-07-29 13:12:39 +00:00
|
|
|
pluginObject = (QObject*)(allocatePlugin( conf, pluginConfigWidget ));
|
2003-06-30 08:14:54 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
// connect required signals and slots together...
|
2003-06-30 08:14:54 +00:00
|
|
|
connect( pluginObject, SIGNAL(changed()), this, SLOT(slotSelectionChanged()) );
|
2002-01-16 12:26:03 +00:00
|
|
|
connect( this, SIGNAL(pluginLoad(KConfig*)), pluginObject, SLOT(load(KConfig*)) );
|
|
|
|
connect( this, SIGNAL(pluginSave(KConfig*)), pluginObject, SLOT(save(KConfig*)) );
|
|
|
|
connect( this, SIGNAL(pluginDefaults()), pluginObject, SLOT(defaults()) );
|
2004-11-20 23:53:54 +00:00
|
|
|
pluginConfigWidget->show();
|
2002-01-16 12:26:03 +00:00
|
|
|
return;
|
2003-06-30 08:14:54 +00:00
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2004-11-20 23:53:54 +00:00
|
|
|
pluginConfigWidget->hide();
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reads the kwin config settings, and sets all UI controls to those settings
|
|
|
|
// Updating the config plugin if required
|
2007-02-20 07:00:30 +00:00
|
|
|
void KWinDecorationModule::readConfig( const KConfigGroup & conf )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
|
|
|
// General tab
|
|
|
|
// ============
|
2007-02-20 07:00:30 +00:00
|
|
|
cbShowToolTips->setChecked( conf.readEntry("ShowToolTips", true));
|
|
|
|
// cbUseMiniWindows->setChecked( conf.readEntry("MiniWindowBorders", false));
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Find the corresponding decoration name to that of
|
|
|
|
// the current plugin library name
|
|
|
|
|
|
|
|
oldLibraryName = currentLibraryName;
|
2007-02-20 07:00:30 +00:00
|
|
|
currentLibraryName = conf.readEntry("PluginLib",
|
2004-09-17 21:09:28 +00:00
|
|
|
((QPixmap::defaultDepth() > 8) ? "kwin_plastik" : "kwin_quartz"));
|
2002-01-16 12:26:03 +00:00
|
|
|
QString decoName = decorationName( currentLibraryName );
|
|
|
|
|
|
|
|
// If we are using the "default" kde client, use the "default" entry.
|
|
|
|
if (decoName.isEmpty())
|
2003-06-30 08:14:54 +00:00
|
|
|
decoName = i18n("KDE 2");
|
|
|
|
|
|
|
|
int numDecos = decorationList->count();
|
|
|
|
for (int i = 0; i < numDecos; ++i)
|
|
|
|
{
|
2006-02-22 11:02:57 +00:00
|
|
|
if (decorationList->itemText(i) == decoName)
|
2003-06-30 08:14:54 +00:00
|
|
|
{
|
2006-02-22 10:12:16 +00:00
|
|
|
decorationList->setCurrentIndex(i);
|
2003-06-30 08:14:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Buttons tab
|
|
|
|
// ============
|
2007-02-20 08:18:28 +00:00
|
|
|
bool customPositions = conf.readEntry("CustomButtonPositions", false);
|
2003-05-31 17:40:57 +00:00
|
|
|
cbUseCustomButtonPositions->setChecked( customPositions );
|
2004-12-03 22:23:20 +00:00
|
|
|
buttonPositionWidget->setEnabled( customPositions );
|
2003-09-16 19:34:03 +00:00
|
|
|
// Menu and onAllDesktops buttons are default on LHS
|
2007-02-20 07:00:30 +00:00
|
|
|
buttonPositionWidget->setButtonsLeft( conf.readEntry("ButtonsOnLeft", "MS") );
|
2002-01-16 12:26:03 +00:00
|
|
|
// Help, Minimize, Maximize and Close are default on RHS
|
2007-02-20 07:00:30 +00:00
|
|
|
buttonPositionWidget->setButtonsRight( conf.readEntry("ButtonsOnRight", "HIAX") );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
int bsize = conf.readEntry( "BorderSize", (int)BorderNormal );
|
2003-09-24 12:41:56 +00:00
|
|
|
if( bsize >= BorderTiny && bsize < BordersCount )
|
|
|
|
border_size = static_cast< BorderSize >( bsize );
|
|
|
|
else
|
|
|
|
border_size = BorderNormal;
|
|
|
|
checkSupportedBorderSizes();
|
|
|
|
|
2003-11-08 23:43:53 +00:00
|
|
|
emit KCModule::changed(false);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Writes the selected user configuration to the kwin config file
|
2007-02-20 07:00:30 +00:00
|
|
|
void KWinDecorationModule::writeConfig( KConfigGroup & conf )
|
2002-01-16 12:26:03 +00:00
|
|
|
{
|
2003-06-30 08:14:54 +00:00
|
|
|
QString name = decorationList->currentText();
|
2002-01-16 12:26:03 +00:00
|
|
|
QString libName = decorationLibName( name );
|
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig _kwinConfig( "kwinrc" );
|
|
|
|
KConfigGroup kwinConfig(&_kwinConfig, "Style");
|
2003-06-30 08:14:54 +00:00
|
|
|
|
2002-01-16 12:26:03 +00:00
|
|
|
// General settings
|
2007-02-20 07:00:30 +00:00
|
|
|
conf.writeEntry("PluginLib", libName);
|
|
|
|
conf.writeEntry("CustomButtonPositions", cbUseCustomButtonPositions->isChecked());
|
|
|
|
conf.writeEntry("ShowToolTips", cbShowToolTips->isChecked());
|
|
|
|
// conf.writeEntry("MiniWindowBorders", cbUseMiniWindows->isChecked());
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Button settings
|
2007-02-20 07:00:30 +00:00
|
|
|
conf.writeEntry("ButtonsOnLeft", buttonPositionWidget->buttonsLeft() );
|
|
|
|
conf.writeEntry("ButtonsOnRight", buttonPositionWidget->buttonsRight() );
|
|
|
|
conf.writeEntry("BorderSize", static_cast<int>( border_size ) );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
oldLibraryName = currentLibraryName;
|
|
|
|
currentLibraryName = libName;
|
|
|
|
|
|
|
|
// We saved, so tell kcmodule that there have been no new user changes made.
|
2003-11-08 23:43:53 +00:00
|
|
|
emit KCModule::changed(false);
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Virutal functions required by KCModule
|
|
|
|
void KWinDecorationModule::load()
|
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig _kwinConfig( "kwinrc" );
|
|
|
|
KConfigGroup kwinConfig(&_kwinConfig, "Style");
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2003-06-30 08:14:54 +00:00
|
|
|
// Reset by re-reading the config
|
2007-02-20 07:00:30 +00:00
|
|
|
readConfig( kwinConfig );
|
|
|
|
resetPlugin( kwinConfig );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinDecorationModule::save()
|
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig _kwinConfig( "kwinrc" );
|
|
|
|
KConfigGroup kwinConfig(&_kwinConfig, "Style");
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2007-02-20 07:00:30 +00:00
|
|
|
writeConfig( kwinConfig );
|
|
|
|
emit pluginSave( kwinConfig );
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
kwinConfig.sync();
|
2007-02-20 22:31:26 +00:00
|
|
|
QDBusInterface kwin( "org.kde.kwin", "/KWin", "org.kde.KWin" );
|
|
|
|
kwin.call( "reconfigure" );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinDecorationModule::defaults()
|
|
|
|
{
|
|
|
|
// Set the KDE defaults
|
|
|
|
cbUseCustomButtonPositions->setChecked( false );
|
2004-12-03 22:23:20 +00:00
|
|
|
buttonPositionWidget->setEnabled( false );
|
2002-01-16 12:26:03 +00:00
|
|
|
cbShowToolTips->setChecked( true );
|
|
|
|
// cbUseMiniWindows->setChecked( false);
|
|
|
|
// Don't set default for now
|
2003-06-30 08:14:54 +00:00
|
|
|
// decorationList->setSelected(
|
|
|
|
// decorationList->findItem( i18n("KDE 2") ), true ); // KDE classic client
|
2002-01-16 12:26:03 +00:00
|
|
|
|
2004-12-03 22:23:20 +00:00
|
|
|
buttonPositionWidget->setButtonsLeft("MS");
|
|
|
|
buttonPositionWidget->setButtonsRight("HIAX");
|
|
|
|
|
2003-09-24 12:41:56 +00:00
|
|
|
border_size = BorderNormal;
|
|
|
|
checkSupportedBorderSizes();
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
// Set plugin defaults
|
|
|
|
emit pluginDefaults();
|
|
|
|
}
|
|
|
|
|
2003-09-24 12:41:56 +00:00
|
|
|
void KWinDecorationModule::checkSupportedBorderSizes()
|
|
|
|
{
|
2005-09-17 20:02:02 +00:00
|
|
|
QList< BorderSize > sizes;
|
2003-09-24 12:41:56 +00:00
|
|
|
if( plugins->factory() != NULL )
|
|
|
|
sizes = plugins->factory()->borderSizes();
|
2004-12-03 19:32:35 +00:00
|
|
|
if( sizes.count() < 2 ) {
|
|
|
|
lBorder->hide();
|
|
|
|
cBorder->hide();
|
|
|
|
} else {
|
|
|
|
cBorder->clear();
|
2005-09-17 20:02:02 +00:00
|
|
|
for (QList<BorderSize>::const_iterator it = sizes.begin(); it != sizes.end(); ++it) {
|
2004-12-03 19:32:35 +00:00
|
|
|
BorderSize size = *it;
|
2006-04-12 15:13:31 +00:00
|
|
|
cBorder->addItem(i18n(border_names[size]), borderSizeToIndex(size,sizes) );
|
2004-12-03 19:32:35 +00:00
|
|
|
}
|
|
|
|
int pos = borderSizeToIndex( border_size, sizes );
|
|
|
|
lBorder->show();
|
|
|
|
cBorder->show();
|
2006-02-22 10:12:16 +00:00
|
|
|
cBorder->setCurrentIndex(pos);
|
2004-12-03 19:32:35 +00:00
|
|
|
slotBorderChanged( pos );
|
|
|
|
}
|
2003-09-24 12:41:56 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 19:34:03 +00:00
|
|
|
QString KWinDecorationModule::styleToConfigLib( QString& styleLib )
|
|
|
|
{
|
|
|
|
if( styleLib.startsWith( "kwin3_" ))
|
|
|
|
return "kwin_" + styleLib.mid( 6 ) + "_config";
|
|
|
|
else
|
|
|
|
return styleLib + "_config";
|
|
|
|
}
|
2002-01-16 12:26:03 +00:00
|
|
|
|
|
|
|
QString KWinDecorationModule::quickHelp() const
|
|
|
|
{
|
2003-09-16 19:34:03 +00:00
|
|
|
return i18n( "<h1>Window Manager Decoration</h1>"
|
|
|
|
"<p>This module allows you to choose the window border decorations, "
|
|
|
|
"as well as titlebar button positions and custom decoration options.</p>"
|
2003-05-10 09:13:36 +00:00
|
|
|
"To choose a theme for your window decoration click on its name and apply your choice by clicking the \"Apply\" button below."
|
2004-09-06 15:39:21 +00:00
|
|
|
" If you do not want to apply your choice you can click the \"Reset\" button to discard your changes."
|
2003-05-10 09:13:36 +00:00
|
|
|
"<p>You can configure each theme in the \"Configure [...]\" tab. There are different options specific for each theme.</p>"
|
|
|
|
"<p>In \"General Options (if available)\" you can activate the \"Buttons\" tab by checking the \"Use custom titlebar button positions\" box."
|
|
|
|
" In the \"Buttons\" tab you can change the positions of the buttons to your liking.</p>" );
|
2002-01-16 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "kwindecoration.moc"
|
|
|
|
// vim: ts=4
|
2004-11-09 19:34:18 +00:00
|
|
|
// kate: space-indent off; tab-width 4;
|
2002-01-16 12:26:03 +00:00
|
|
|
|