[kcmkwin/tabbox] Use BuiltInEffects to find CoverSwitch and FlipSwitch

Instead of using the KServiceTypeTrader we use the BuiltInEffects to get
the name of CoverSwitch and FlipSwitch.

Showing the configuration dialog is migrated to KPluginTrader which fixes
the showing of the dialog.
remotes/origin/Plasma/5.0
Martin Gräßlin 12 years ago
parent a20903986a
commit 4da220adef
  1. 6
      kcmkwin/kwintabbox/CMakeLists.txt
  2. 50
      kcmkwin/kwintabbox/main.cpp
  3. 3
      kcmkwin/kwintabbox/main.h

@ -1,4 +1,4 @@
include_directories( ${KWIN_SOURCE_DIR}/tabbox ${KWIN_SOURCE_DIR})
include_directories( ${KWIN_SOURCE_DIR}/effects ${KWIN_SOURCE_DIR}/tabbox ${KWIN_SOURCE_DIR})
########### next target ###############
@ -21,7 +21,9 @@ target_link_libraries(kcm_kwintabbox
KF5::I18n
KF5::Service
KF5::NewStuff
XCB::XCB)
XCB::XCB
kwin4_effect_builtins
)
install(TARGETS kcm_kwintabbox DESTINATION ${PLUGIN_INSTALL_DIR} )

@ -18,6 +18,7 @@ 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 "main.h"
#include <effect_builtins.h>
// Qt
#include <QtDBus/QtDBus>
@ -35,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KPluginFactory>
#include <KPluginInfo>
#include <KPluginLoader>
#include <KPluginTrader>
#include <KTitleWidget>
#include <KServiceTypeTrader>
#include <KShortcutsEditor>
@ -158,18 +160,10 @@ KWinTabBoxConfig::~KWinTabBoxConfig()
void KWinTabBoxConfig::initLayoutLists()
{
// search the effect names
// TODO: way to recognize if a effect is not found
KServiceTypeTrader* trader = KServiceTypeTrader::self();
KService::List services;
QString coverswitch;
QString flipswitch;
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_coverswitch'");
if (!services.isEmpty())
coverswitch = services.first()->name();
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_flipswitch'");
if (!services.isEmpty())
flipswitch = services.first()->name();
QString coverswitch = BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).displayName;
QString flipswitch = BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).displayName;
KServiceTypeTrader* trader = KServiceTypeTrader::self();
KService::List offers = trader->query("KWin/WindowSwitcher");
QStringList layoutNames, layoutPlugins, layoutPaths;
foreach (KService::Ptr service, offers) {
@ -227,9 +221,9 @@ void KWinTabBoxConfig::load()
updateUiFromConfig(ui[i], *(tabBoxConfig[i]));
KConfigGroup effectconfig(m_config, "Plugins");
if (effectEnabled("coverswitch", effectconfig) && KConfigGroup(m_config, "Effect-CoverSwitch").readEntry(group[i], false))
if (effectEnabled(BuiltInEffect::CoverSwitch, effectconfig) && KConfigGroup(m_config, "Effect-CoverSwitch").readEntry(group[i], false))
ui[i]->effectCombo->setCurrentIndex(CoverSwitch);
else if (effectEnabled("flipswitch", effectconfig) && KConfigGroup(m_config, "Effect-FlipSwitch").readEntry(group[i], false))
else if (effectEnabled(BuiltInEffect::FlipSwitch, effectconfig) && KConfigGroup(m_config, "Effect-FlipSwitch").readEntry(group[i], false))
ui[i]->effectCombo->setCurrentIndex(FlipSwitch);
QString action;
@ -391,14 +385,10 @@ void KWinTabBoxConfig::defaults()
emit changed(true);
}
bool KWinTabBoxConfig::effectEnabled(const QString& effect, const KConfigGroup& cfg) const
bool KWinTabBoxConfig::effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const
{
KService::List services = KServiceTypeTrader::self()->query(
"KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_" + effect + '\'');
if (services.isEmpty())
return false;
QVariant v = services.first()->property("X-KDE-PluginInfo-EnabledByDefault");
return cfg.readEntry("kwin4_effect_" + effect + "Enabled", v.toBool());
// HACK: remove kwin4_effect_
return cfg.readEntry("kwin4_effect_" + BuiltInEffects::nameForEffect(effect) + "Enabled", BuiltInEffects::enabledByDefault(effect));
}
void KWinTabBoxConfig::updateUiFromConfig(KWinTabBoxConfigForm* ui, const KWin::TabBox::TabBoxConfig& config)
@ -498,20 +488,30 @@ void KWinTabBoxConfig::configureEffectClicked()
connect(buttonBox, SIGNAL(accepted()), configDialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), configDialog, SLOT(reject()));
KCModuleProxy* proxy = new KCModuleProxy(effect == CoverSwitch ? "coverswitch_config" : "flipswitch_config");
connect(configDialog, SIGNAL(defaultClicked()), proxy, SLOT(defaults()));
// HACK: kwin4_effect_ needs to be removed
const QString name = QStringLiteral("kwin4_effect_") + BuiltInEffects::nameForEffect(effect == CoverSwitch ? BuiltInEffect::CoverSwitch : BuiltInEffect::FlipSwitch);
KCModule *kcm = KPluginTrader::createInstanceFromQuery<KCModule>(QStringLiteral("kf5/kwin/effects/configs/"), QString(),
QStringLiteral("[X-KDE-ParentComponents] == '%1'").arg(name),
configDialog);
if (!kcm) {
delete configDialog;
return;
}
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, kcm, &KCModule::defaults);
QWidget *showWidget = new QWidget(configDialog);
QVBoxLayout *layout = new QVBoxLayout;
showWidget->setLayout(layout);
layout->addWidget(proxy);
layout->addWidget(kcm);
configDialog->layout()->addWidget(showWidget);
configDialog->layout()->addWidget(buttonBox);
if (configDialog->exec() == QDialog::Accepted) {
proxy->save();
kcm->save();
} else {
proxy->load();
kcm->load();
}
delete configDialog;
}

@ -32,6 +32,7 @@ class KActionCollection;
namespace KWin
{
enum class BuiltInEffect;
namespace TabBox
{
@ -87,7 +88,7 @@ private:
TabBox::TabBoxConfig m_tabBoxConfig;
TabBox::TabBoxConfig m_tabBoxAlternativeConfig;
bool effectEnabled(const QString& effect, const KConfigGroup& cfg) const;
bool effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const;
};
} // namespace

Loading…
Cancel
Save