2007-04-29 17:35:43 +00:00
|
|
|
/*
|
2010-01-19 13:56:57 +00:00
|
|
|
This is the new kwindecoration kcontrol module
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
Copyright (c) 2001
|
|
|
|
Karol Szwed <gallium@kde.org>
|
|
|
|
http://gallium.n3.net/
|
|
|
|
Copyright 2009, 2010 Martin Gräßlin <kde@martin-graesslin.com>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
Supports new kwin configuration plugins, and titlebar button position
|
|
|
|
modification via dnd interface.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
Based on original "kwintheme" (Window Borders)
|
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
2007-04-29 17:35:43 +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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
2010-01-19 13:44:22 +00:00
|
|
|
// own
|
2009-12-27 14:59:39 +00:00
|
|
|
#include "kwindecoration.h"
|
2010-01-19 13:44:22 +00:00
|
|
|
#include "buttonsconfigdialog.h"
|
2010-04-23 19:44:50 +00:00
|
|
|
#include "configdialog.h"
|
2010-01-19 13:44:22 +00:00
|
|
|
#include "decorationdelegate.h"
|
|
|
|
#include "decorationmodel.h"
|
|
|
|
// Qt
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2010-01-19 13:44:22 +00:00
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
|
|
|
// KDE
|
|
|
|
#include <KAboutData>
|
|
|
|
#include <KDialog>
|
|
|
|
#include <KLocale>
|
|
|
|
#include <KNS3/DownloadDialog>
|
2007-08-28 12:42:05 +00:00
|
|
|
#include <KPluginFactory>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// KCModule plugin interface
|
|
|
|
// =========================
|
2007-08-28 12:42:05 +00:00
|
|
|
K_PLUGIN_FACTORY(KWinDecoFactory,
|
2010-01-19 13:44:22 +00:00
|
|
|
registerPlugin<KWin::KWinDecorationModule>();
|
2007-08-28 12:42:05 +00:00
|
|
|
)
|
|
|
|
K_EXPORT_PLUGIN(KWinDecoFactory("kcmkwindecoration"))
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWinDecorationForm::KWinDecorationForm( QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
{
|
|
|
|
setupUi( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-28 12:42:05 +00:00
|
|
|
KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &)
|
2010-01-19 13:44:22 +00:00
|
|
|
: KCModule(KWinDecoFactory::componentData(), parent)
|
|
|
|
, kwinConfig(KSharedConfig::openConfig("kwinrc"))
|
|
|
|
, m_showTooltips( false )
|
|
|
|
, m_customPositions( false )
|
|
|
|
, m_leftButtons( QString() )
|
|
|
|
, m_rightButtons( QString() )
|
|
|
|
, m_configLoaded( false )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
m_ui = new KWinDecorationForm( this );
|
2010-04-23 19:44:50 +00:00
|
|
|
DecorationDelegate* delegate = new DecorationDelegate( this );
|
2010-01-19 13:44:22 +00:00
|
|
|
m_ui->decorationList->setItemDelegate( delegate );
|
2010-04-23 19:44:50 +00:00
|
|
|
m_ui->configureDecorationButton->setIcon( KIcon( "configure" ) );
|
2010-01-19 13:44:22 +00:00
|
|
|
m_ui->configureButtonsButton->setIcon( KIcon( "configure" ) );
|
|
|
|
m_ui->ghnsButton->setIcon( KIcon( "get-hot-new-stuff" ) );
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout( this );
|
|
|
|
layout->addWidget( m_ui );
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
KConfigGroup style( kwinConfig, "Style");
|
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
// Set up the decoration lists and other UI settings
|
|
|
|
m_model = new DecorationModel( kwinConfig, this );
|
|
|
|
m_proxyModel = new QSortFilterProxyModel( this );
|
|
|
|
m_proxyModel->setSourceModel( m_model );
|
|
|
|
m_proxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
|
|
|
|
m_ui->decorationList->setModel( m_proxyModel );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
readConfig( style );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-27 21:09:04 +00:00
|
|
|
connect( m_ui->decorationList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), SLOT(slotSelectionChanged()) );
|
2010-01-19 13:44:22 +00:00
|
|
|
connect( m_ui->configureButtonsButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureButtons()));
|
|
|
|
connect( m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked()) );
|
|
|
|
connect( m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
|
|
|
|
connect( delegate, SIGNAL(regeneratePreview(QModelIndex,QSize)),
|
|
|
|
m_model, SLOT(regeneratePreview(QModelIndex,QSize)));
|
2010-04-23 19:44:50 +00:00
|
|
|
connect( m_ui->configureDecorationButton, SIGNAL(clicked(bool)), SLOT(slotConfigureDecoration()));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
KAboutData *about =
|
|
|
|
new KAboutData(I18N_NOOP("kcmkwindecoration"), 0,
|
|
|
|
ki18n("Window Decoration Control Module"),
|
|
|
|
0, KLocalizedString(), KAboutData::License_GPL,
|
|
|
|
ki18n("(c) 2001 Karol Szwed"));
|
|
|
|
about->addAuthor(ki18n("Karol Szwed"), KLocalizedString(), "gallium@kde.org");
|
|
|
|
setAboutData(about);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KWinDecorationModule::~KWinDecorationModule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the selection handler setting
|
|
|
|
void KWinDecorationModule::slotSelectionChanged()
|
|
|
|
{
|
2010-01-19 13:56:57 +00:00
|
|
|
emit KCModule::changed(true);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reads the kwin config settings, and sets all UI controls to those settings
|
|
|
|
// Updating the config plugin if required
|
|
|
|
void KWinDecorationModule::readConfig( const KConfigGroup & conf )
|
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
m_showTooltips = conf.readEntry("ShowToolTips", true);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// Find the corresponding decoration name to that of
|
|
|
|
// the current plugin library name
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
QString libraryName = conf.readEntry("PluginLib",
|
|
|
|
((QPixmap::defaultDepth() > 8) ? "kwin3_oxygen" : "kwin3_plastik"));
|
|
|
|
|
|
|
|
if( libraryName.isEmpty() )
|
|
|
|
{ // Selected decoration doesn't exist, use the default
|
|
|
|
libraryName = ( ( QPixmap::defaultDepth() > 8 ) ? "kwin3_oxygen" : "kwin3_plastik" );
|
|
|
|
}
|
|
|
|
|
|
|
|
const int bsize = conf.readEntry( "BorderSize", (int)BorderNormal );
|
|
|
|
BorderSize borderSize = BorderNormal;
|
|
|
|
if( bsize >= BorderTiny && bsize < BordersCount )
|
|
|
|
borderSize = static_cast< BorderSize >( bsize );
|
|
|
|
if( libraryName == "kwin3_aurorae" )
|
|
|
|
{
|
|
|
|
KConfig auroraeConfig( "auroraerc" );
|
|
|
|
KConfigGroup group( &auroraeConfig, "Engine");
|
|
|
|
const QString themeName = group.readEntry( "ThemeName", "example-deco" );
|
|
|
|
const QModelIndex index = m_proxyModel->mapFromSource( m_model->indexOfAuroraeName( themeName ) );
|
|
|
|
if( index.isValid() )
|
|
|
|
{
|
|
|
|
m_ui->decorationList->setCurrentIndex( index );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QModelIndex index = m_proxyModel->mapFromSource( m_model->indexOfLibrary( libraryName ) );
|
|
|
|
if( index.isValid() )
|
|
|
|
{
|
|
|
|
m_model->setBorderSize( index, borderSize );
|
|
|
|
m_ui->decorationList->setCurrentIndex( index );
|
|
|
|
}
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// Buttons tab
|
|
|
|
// ============
|
2010-01-19 13:44:22 +00:00
|
|
|
m_customPositions = conf.readEntry("CustomButtonPositions", false);
|
2010-01-19 13:56:57 +00:00
|
|
|
// Menu and onAllDesktops buttons are default on LHS
|
2010-01-19 13:44:22 +00:00
|
|
|
m_leftButtons = conf.readEntry("ButtonsOnLeft", KDecorationOptions::defaultTitleButtonsLeft());
|
2010-01-19 13:56:57 +00:00
|
|
|
// Help, Minimize, Maximize and Close are default on RHS
|
|
|
|
m_rightButtons = conf.readEntry("ButtonsOnRight", KDecorationOptions::defaultTitleButtonsRight());
|
2010-01-19 13:44:22 +00:00
|
|
|
if( m_configLoaded )
|
|
|
|
m_model->changeButtons( m_customPositions, m_leftButtons, m_rightButtons );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_configLoaded = true;
|
|
|
|
m_model->setButtons( m_customPositions, m_leftButtons, m_rightButtons );
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
emit KCModule::changed(false);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Writes the selected user configuration to the kwin config file
|
|
|
|
void KWinDecorationModule::writeConfig( KConfigGroup & conf )
|
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
const QModelIndex index = m_proxyModel->mapToSource( m_ui->decorationList->currentIndex() );
|
|
|
|
const QString libName = m_model->data( index, DecorationModel::LibraryNameRole ).toString();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// General settings
|
|
|
|
conf.writeEntry("PluginLib", libName);
|
2010-01-19 13:44:22 +00:00
|
|
|
conf.writeEntry("CustomButtonPositions", m_customPositions );
|
|
|
|
conf.writeEntry("ShowToolTips", m_showTooltips );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// Button settings
|
2010-01-19 13:44:22 +00:00
|
|
|
conf.writeEntry("ButtonsOnLeft", m_leftButtons );
|
|
|
|
conf.writeEntry("ButtonsOnRight", m_rightButtons );
|
|
|
|
conf.writeEntry( "BorderSize",
|
|
|
|
static_cast<int>( m_model->data( index, DecorationModel::BorderSizeRole ).toInt()));
|
|
|
|
|
|
|
|
if( m_model->data( index, DecorationModel::TypeRole ).toInt() == DecorationModelData::AuroraeDecoration )
|
|
|
|
{
|
|
|
|
KConfig auroraeConfig( "auroraerc" );
|
|
|
|
KConfigGroup group( &auroraeConfig, "Engine");
|
|
|
|
group.writeEntry( "ThemeName", m_model->data( index, DecorationModel::AuroraeNameRole ).toString() );
|
|
|
|
group.sync();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// We saved, so tell kcmodule that there have been no new user changes made.
|
|
|
|
emit KCModule::changed(false);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Virutal functions required by KCModule
|
|
|
|
void KWinDecorationModule::load()
|
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
const KConfigGroup config( kwinConfig, "Style" );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
// Reset by re-reading the config
|
|
|
|
readConfig( config );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinDecorationModule::save()
|
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
KConfigGroup config( kwinConfig, "Style" );
|
|
|
|
writeConfig( config );
|
|
|
|
config.sync();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-04-30 11:32:47 +00:00
|
|
|
// Send signal to all kwin instances
|
|
|
|
QDBusMessage message =
|
2008-01-30 16:08:23 +00:00
|
|
|
QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
|
2007-04-30 11:32:47 +00:00
|
|
|
QDBusConnection::sessionBus().send(message);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinDecorationModule::defaults()
|
|
|
|
{
|
2010-01-19 13:56:57 +00:00
|
|
|
// Set the KDE defaults
|
2010-01-19 13:44:22 +00:00
|
|
|
m_customPositions = false;
|
|
|
|
m_showTooltips = true;
|
|
|
|
const QModelIndex index = m_proxyModel->mapFromSource( m_model->indexOfName( i18n("Oxygen") ) );
|
|
|
|
if( index.isValid() )
|
|
|
|
m_ui->decorationList->setCurrentIndex( index );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
m_leftButtons = KDecorationOptions::defaultTitleButtonsLeft();
|
|
|
|
m_rightButtons = KDecorationOptions::defaultTitleButtonsRight();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
m_model->changeButtons( m_customPositions, m_leftButtons, m_rightButtons );
|
|
|
|
|
|
|
|
emit changed( true );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KWinDecorationModule::quickHelp() const
|
|
|
|
{
|
2010-01-19 13:56:57 +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>"
|
|
|
|
"To choose a theme for your window decoration click on its name and apply your choice by clicking the \"Apply\" button below."
|
|
|
|
" If you do not want to apply your choice you can click the \"Reset\" button to discard your changes."
|
|
|
|
"<p>You can configure each theme. There are different options specific for each theme.</p>"
|
|
|
|
"<p>On the \"Buttons\" tab check the \"Use custom titlebar button positions\" box "
|
|
|
|
"and you can change the positions of the buttons to your liking.</p>" );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
void KWinDecorationModule::slotConfigureButtons()
|
|
|
|
{
|
|
|
|
QPointer< KWinDecorationButtonsConfigDialog > configDialog = new KWinDecorationButtonsConfigDialog( m_customPositions, m_showTooltips, m_leftButtons, m_rightButtons, this );
|
|
|
|
if( configDialog->exec() == KDialog::Accepted )
|
|
|
|
{
|
|
|
|
m_customPositions = configDialog->customPositions();
|
|
|
|
m_showTooltips = configDialog->showTooltips();
|
|
|
|
m_leftButtons = configDialog->buttonsLeft();
|
|
|
|
m_rightButtons = configDialog->buttonsRight();
|
|
|
|
m_model->changeButtons( m_customPositions, m_leftButtons, m_rightButtons );
|
|
|
|
emit changed( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete configDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::slotGHNSClicked()
|
|
|
|
{
|
|
|
|
QPointer<KNS3::DownloadDialog> downloadDialog = new KNS3::DownloadDialog( "aurorae.knsrc", this );
|
|
|
|
if( downloadDialog->exec() == KDialog::Accepted )
|
|
|
|
{
|
|
|
|
if( !downloadDialog->changedEntries().isEmpty() )
|
|
|
|
{
|
|
|
|
const QModelIndex index = m_proxyModel->mapToSource( m_ui->decorationList->currentIndex() );
|
|
|
|
const QString libraryName = m_model->data( index, DecorationModel::LibraryNameRole ).toString();
|
|
|
|
bool aurorae = m_model->data( index, DecorationModel::TypeRole ).toInt() == DecorationModelData::AuroraeDecoration;
|
|
|
|
const QString auroraeName = m_model->data( index, DecorationModel::AuroraeNameRole ).toString();
|
|
|
|
m_model->reload();
|
|
|
|
if( aurorae )
|
|
|
|
{
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource( m_model->indexOfAuroraeName( auroraeName ) );
|
|
|
|
if( proxyIndex.isValid() )
|
|
|
|
m_ui->decorationList->setCurrentIndex( proxyIndex );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource( m_model->indexOfLibrary( libraryName ) );
|
|
|
|
if( proxyIndex.isValid() )
|
|
|
|
m_ui->decorationList->setCurrentIndex( proxyIndex );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete downloadDialog;
|
|
|
|
}
|
|
|
|
|
2010-04-23 19:44:50 +00:00
|
|
|
void KWinDecorationModule::slotConfigureDecoration()
|
|
|
|
{
|
|
|
|
const QModelIndex index = m_proxyModel->mapToSource( m_ui->decorationList->currentIndex() );
|
|
|
|
bool reload = false;
|
|
|
|
if( index.data( DecorationModel::TypeRole ).toInt() == DecorationModelData::AuroraeDecoration )
|
|
|
|
{
|
|
|
|
QPointer< KDialog > dlg = new KDialog( this );
|
|
|
|
dlg->setCaption( i18n( "Decoration Options" ) );
|
|
|
|
dlg->setButtons( KDialog::Ok | KDialog::Cancel );
|
|
|
|
KWinAuroraeConfigForm *form = new KWinAuroraeConfigForm( dlg );
|
|
|
|
dlg->setMainWidget( form );
|
|
|
|
form->borderSizesCombo->setCurrentIndex( index.data( DecorationModel::BorderSizeRole ).toInt() );
|
|
|
|
form->buttonSizesCombo->setCurrentIndex( index.data( DecorationModel::ButtonSizeRole ).toInt() );
|
|
|
|
if( dlg->exec() == KDialog::Accepted )
|
|
|
|
{
|
|
|
|
m_model->setData( index, form->borderSizesCombo->currentIndex(), DecorationModel::BorderSizeRole );
|
|
|
|
m_model->setData( index, form->buttonSizesCombo->currentIndex(), DecorationModel::ButtonSizeRole );
|
|
|
|
reload = true;
|
|
|
|
}
|
|
|
|
delete dlg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString name = index.data( DecorationModel::LibraryNameRole ).toString();
|
|
|
|
QList< QVariant > borderSizes = index.data( DecorationModel::BorderSizesRole ).toList();
|
|
|
|
const KDecorationDefines::BorderSize size =
|
|
|
|
static_cast<KDecorationDefines::BorderSize>( index.data( DecorationModel::BorderSizeRole ).toInt() );
|
|
|
|
QPointer< KWinDecorationConfigDialog > configDialog =
|
|
|
|
new KWinDecorationConfigDialog( name, borderSizes, size, this );
|
|
|
|
if( configDialog->exec() == KDialog::Accepted )
|
|
|
|
{
|
|
|
|
m_model->setData( index, configDialog->borderSize(), DecorationModel::BorderSizeRole );
|
|
|
|
reload = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete configDialog;
|
|
|
|
}
|
|
|
|
if( reload )
|
|
|
|
{
|
|
|
|
// Send signal to all kwin instances
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
} // namespace KWin
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "kwindecoration.moc"
|