2010-01-19 13:44:22 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
|
|
|
|
|
|
|
|
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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "configdialog.h"
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
|
2010-11-04 22:45:33 +00:00
|
|
|
#include <KLibrary>
|
2010-01-19 13:44:22 +00:00
|
|
|
#include <KVBox>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const char* const border_names[ KDecorationDefines::BordersCount ] = {
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Tiny"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Normal"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Large"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Very Large"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Huge"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Very Huge"),
|
2013-01-04 13:02:44 +00:00
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "Oversized"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "No Side Border"),
|
|
|
|
I18N_NOOP2("@item:inlistbox Border size:", "No Border"),
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
KWinAuroraeConfigForm::KWinAuroraeConfigForm(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2013-01-04 13:02:44 +00:00
|
|
|
void KWinAuroraeConfigForm::enableNoSideBorderSupport(bool enable)
|
|
|
|
{
|
|
|
|
if (!enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
borderSizesCombo->addItem(i18nc("@item:inlistbox Border size:", border_names[KDecorationDefines::BorderBottom]));
|
|
|
|
borderSizesCombo->addItem(i18nc("@item:inlistbox Border size:", border_names[KDecorationDefines::BorderNone]));
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWinDecorationConfigForm::KWinDecorationConfigForm(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
KWinDecorationConfigDialog::KWinDecorationConfigDialog(QString deco, const QList<QVariant>& borderSizes,
|
|
|
|
KDecorationDefines::BorderSize size,
|
|
|
|
QWidget* parent, Qt::WFlags flags)
|
|
|
|
: KDialog(parent, flags)
|
|
|
|
, m_borderSizes(borderSizes)
|
|
|
|
, m_kwinConfig(KSharedConfig::openConfig("kwinrc"))
|
|
|
|
, m_pluginObject(0)
|
|
|
|
, m_pluginConfigWidget(0)
|
|
|
|
{
|
|
|
|
m_ui = new KWinDecorationConfigForm(this);
|
|
|
|
setWindowTitle(i18n("Decoration Options"));
|
|
|
|
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default | KDialog::Reset);
|
|
|
|
enableButton(KDialog::Reset, false);
|
2010-01-19 13:44:22 +00:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout;
|
2011-01-30 14:34:42 +00:00
|
|
|
layout->addWidget(m_ui);
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KLibrary library(styleToConfigLib(deco));
|
|
|
|
if (library.load()) {
|
2010-11-04 22:45:33 +00:00
|
|
|
KLibrary::void_function_ptr alloc_ptr = library.resolveFunction("allocate_config");
|
2011-01-30 14:34:42 +00:00
|
|
|
if (alloc_ptr != NULL) {
|
|
|
|
allocatePlugin = (QObject * (*)(KConfigGroup & conf, QWidget * parent))alloc_ptr;
|
|
|
|
KConfigGroup config(m_kwinConfig, "Style");
|
|
|
|
m_pluginConfigWidget = new KVBox(this);
|
|
|
|
m_pluginObject = (QObject*)(allocatePlugin(config, m_pluginConfigWidget));
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
// connect required signals and slots together...
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
|
|
|
|
connect(m_pluginObject, SIGNAL(changed()), this, SLOT(slotSelectionChanged()));
|
2011-08-17 21:51:55 +00:00
|
|
|
connect(this, SIGNAL(pluginSave(KConfigGroup&)), m_pluginObject, SLOT(save(KConfigGroup&)));
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(this, SIGNAL(defaultClicked()), m_pluginObject, SLOT(defaults()));
|
|
|
|
connect(this, SIGNAL(defaultClicked()), SLOT(slotDefault()));
|
2010-01-19 13:44:22 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_pluginConfigWidget) {
|
|
|
|
layout->addWidget(m_pluginConfigWidget);
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (borderSizes.count() >= 2) {
|
|
|
|
foreach (const QVariant & borderSize, borderSizes) {
|
2010-01-19 13:44:22 +00:00
|
|
|
KDecorationDefines::BorderSize currentSize =
|
2011-01-30 14:34:42 +00:00
|
|
|
static_cast<KDecorationDefines::BorderSize>(borderSize.toInt());
|
|
|
|
m_ui->bordersCombo->addItem(i18nc("@item:inlistbox Border size:", border_names[currentSize]), borderSizeToIndex(currentSize, borderSizes));
|
2010-01-19 13:44:22 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->bordersCombo->setCurrentIndex(borderSizeToIndex(size, borderSizes));
|
|
|
|
} else {
|
2010-01-19 13:44:22 +00:00
|
|
|
m_ui->bordersCombo->hide();
|
|
|
|
m_ui->borderLabel->hide();
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QWidget* main = new QWidget(this);
|
|
|
|
main->setLayout(layout);
|
|
|
|
setMainWidget(main);
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
KWinDecorationConfigDialog::~KWinDecorationConfigDialog()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
delete m_pluginObject;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
KDecorationDefines::BorderSize KWinDecorationConfigDialog::borderSize() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_borderSizes.count() >= 2)
|
|
|
|
return (KDecorationDefines::BorderSize)m_borderSizes.at(m_ui->bordersCombo->currentIndex()).toInt();
|
2010-01-19 13:44:22 +00:00
|
|
|
return KDecorationDefines::BorderNormal;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int KWinDecorationConfigDialog::borderSizeToIndex(KDecorationDefines::BorderSize size, const QList< QVariant >& sizes)
|
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
int pos = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (QList< QVariant >::ConstIterator it = sizes.constBegin();
|
2010-01-19 13:44:22 +00:00
|
|
|
it != sizes.constEnd();
|
2011-01-30 14:34:42 +00:00
|
|
|
++it, ++pos)
|
|
|
|
if (size <= (*it).toInt())
|
2010-01-19 13:44:22 +00:00
|
|
|
break;
|
|
|
|
return pos;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
void KWinDecorationConfigDialog::slotAccepted()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
KConfigGroup config(m_kwinConfig, "Style");
|
|
|
|
emit pluginSave(config);
|
2010-01-19 13:44:22 +00:00
|
|
|
config.sync();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
void KWinDecorationConfigDialog::slotSelectionChanged()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
enableButton(KDialog::Reset, true);
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QString KWinDecorationConfigDialog::styleToConfigLib(const QString& styleLib) const
|
|
|
|
{
|
|
|
|
if (styleLib.startsWith(QLatin1String("kwin3_")))
|
|
|
|
return "kwin_" + styleLib.mid(6) + "_config";
|
2010-01-19 13:44:22 +00:00
|
|
|
else
|
|
|
|
return styleLib + "_config";
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
void KWinDecorationConfigDialog::slotDefault()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_borderSizes.count() >= 2)
|
|
|
|
m_ui->bordersCombo->setCurrentIndex(borderSizeToIndex(BorderNormal, m_borderSizes));
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#include "configdialog.moc"
|