Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include "effectmodel.h" | 22 | #include "effectmodel.h" | ||
23 | 23 | | |||
24 | #include <config-kwin.h> | 24 | #include <config-kwin.h> | ||
25 | #include <effect_builtins.h> | 25 | #include <effect_builtins.h> | ||
26 | #include <kwin_effects_interface.h> | 26 | #include <kwin_effects_interface.h> | ||
27 | 27 | | |||
28 | #include <KAboutData> | 28 | #include <KAboutData> | ||
29 | #include <KCModule> | ||||
29 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
30 | #include <KPackage/PackageLoader> | 31 | #include <KPackage/PackageLoader> | ||
31 | #include <KPluginLoader> | 32 | #include <KPluginLoader> | ||
32 | #include <KPluginMetaData> | 33 | #include <KPluginMetaData> | ||
33 | #include <KPluginTrader> | 34 | #include <KPluginTrader> | ||
34 | 35 | | |||
35 | #include <QDBusConnection> | 36 | #include <QDBusConnection> | ||
36 | #include <QDBusInterface> | 37 | #include <QDBusInterface> | ||
37 | #include <QDBusMessage> | 38 | #include <QDBusMessage> | ||
38 | #include <QDBusPendingCall> | 39 | #include <QDBusPendingCall> | ||
40 | #include <QDialog> | ||||
41 | #include <QDialogButtonBox> | ||||
42 | #include <QPushButton> | ||||
43 | #include <QVBoxLayout> | ||||
39 | 44 | | |||
40 | namespace KWin | 45 | namespace KWin | ||
41 | { | 46 | { | ||
42 | 47 | | |||
43 | static QString translatedCategory(const QString &category) | 48 | static QString translatedCategory(const QString &category) | ||
44 | { | 49 | { | ||
45 | static const QVector<QString> knownCategories = { | 50 | static const QVector<QString> knownCategories = { | ||
46 | QStringLiteral("Accessibility"), | 51 | QStringLiteral("Accessibility"), | ||
▲ Show 20 Lines • Show All 484 Lines • ▼ Show 20 Line(s) | 533 | auto it = std::find_if(m_effectsList.constBegin(), m_effectsList.constEnd(), | |||
531 | } | 536 | } | ||
532 | ); | 537 | ); | ||
533 | if (it == m_effectsList.constEnd()) { | 538 | if (it == m_effectsList.constEnd()) { | ||
534 | return {}; | 539 | return {}; | ||
535 | } | 540 | } | ||
536 | return index(std::distance(m_effectsList.constBegin(), it), 0); | 541 | return index(std::distance(m_effectsList.constBegin(), it), 0); | ||
537 | } | 542 | } | ||
538 | 543 | | |||
544 | static KCModule *findBinaryConfig(const QString &pluginId, QObject *parent) | ||||
545 | { | ||||
546 | return KPluginTrader::createInstanceFromQuery<KCModule>( | ||||
547 | QStringLiteral("kwin/effects/configs/"), | ||||
548 | QString(), | ||||
549 | QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(pluginId), | ||||
550 | parent | ||||
551 | ); | ||||
552 | } | ||||
553 | | ||||
554 | static KCModule *findScriptedConfig(const QString &pluginId, QObject *parent) | ||||
555 | { | ||||
556 | const auto offers = KPluginTrader::self()->query( | ||||
557 | QStringLiteral("kwin/effects/configs/"), | ||||
558 | QString(), | ||||
559 | QStringLiteral("[X-KDE-Library] == 'kcm_kwin4_genericscripted'") | ||||
560 | ); | ||||
561 | | ||||
562 | if (offers.isEmpty()) { | ||||
563 | return nullptr; | ||||
564 | } | ||||
565 | | ||||
566 | const KPluginInfo &generic = offers.first(); | ||||
567 | KPluginLoader loader(generic.libraryPath()); | ||||
568 | KPluginFactory *factory = loader.factory(); | ||||
569 | if (!factory) { | ||||
570 | return nullptr; | ||||
571 | } | ||||
572 | | ||||
573 | return factory->create<KCModule>(pluginId, parent); | ||||
574 | } | ||||
575 | | ||||
576 | void EffectModel::requestConfigure(const QModelIndex &index, QWindow *transientParent) | ||||
577 | { | ||||
578 | if (!index.isValid()) { | ||||
579 | return; | ||||
580 | } | ||||
581 | | ||||
582 | QPointer<QDialog> dialog = new QDialog(); | ||||
583 | | ||||
584 | KCModule *module = index.data(ScriptedRole).toBool() | ||||
585 | ? findScriptedConfig(index.data(ServiceNameRole).toString(), dialog) | ||||
586 | : findBinaryConfig(index.data(ServiceNameRole).toString(), dialog); | ||||
587 | if (!module) { | ||||
588 | delete dialog; | ||||
589 | return; | ||||
590 | } | ||||
591 | | ||||
592 | dialog->setWindowTitle(index.data(NameRole).toString()); | ||||
593 | dialog->winId(); | ||||
594 | dialog->windowHandle()->setTransientParent(transientParent); | ||||
595 | | ||||
596 | auto buttons = new QDialogButtonBox( | ||||
597 | QDialogButtonBox::Ok | | ||||
598 | QDialogButtonBox::Cancel | | ||||
599 | QDialogButtonBox::RestoreDefaults, | ||||
600 | dialog | ||||
601 | ); | ||||
602 | connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | ||||
603 | connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | ||||
604 | connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, | ||||
605 | module, &KCModule::defaults); | ||||
606 | | ||||
607 | auto layout = new QVBoxLayout(dialog); | ||||
608 | layout->addWidget(module); | ||||
609 | layout->addWidget(buttons); | ||||
610 | | ||||
611 | dialog->exec(); | ||||
612 | | ||||
613 | delete dialog; | ||||
614 | } | ||||
615 | | ||||
539 | bool EffectModel::shouldStore(const EffectData &data) const | 616 | bool EffectModel::shouldStore(const EffectData &data) const | ||
540 | { | 617 | { | ||
541 | Q_UNUSED(data) | 618 | Q_UNUSED(data) | ||
542 | return true; | 619 | return true; | ||
543 | } | 620 | } | ||
544 | 621 | | |||
545 | } | 622 | } |