Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwineffects/kcm.cpp
Show All 14 Lines | |||||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "kcm.h" | 18 | #include "kcm.h" | ||
19 | #include "effectmodel.h" | 19 | #include "effectmodel.h" | ||
20 | #include "effectsfilterproxymodel.h" | 20 | #include "effectsfilterproxymodel.h" | ||
21 | 21 | | |||
22 | #include <KAboutData> | 22 | #include <KAboutData> | ||
23 | #include <KCModule> | | |||
24 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
25 | #include <KNS3/DownloadDialog> | 24 | #include <KNS3/DownloadDialog> | ||
26 | #include <KPluginFactory> | | |||
27 | #include <KPluginTrader> | | |||
28 | 25 | | |||
29 | #include <QDialogButtonBox> | | |||
30 | #include <QPushButton> | | |||
31 | #include <QQuickWindow> | 26 | #include <QQuickWindow> | ||
32 | #include <QVBoxLayout> | | |||
33 | #include <QWindow> | 27 | #include <QWindow> | ||
34 | 28 | | |||
35 | K_PLUGIN_FACTORY_WITH_JSON(DesktopEffectsKCMFactory, | 29 | K_PLUGIN_FACTORY_WITH_JSON(DesktopEffectsKCMFactory, | ||
36 | "kcm_kwin_effects.json", | 30 | "kcm_kwin_effects.json", | ||
37 | registerPlugin<KWin::DesktopEffectsKCM>();) | 31 | registerPlugin<KWin::DesktopEffectsKCM>();) | ||
38 | 32 | | |||
39 | namespace KWin | 33 | namespace KWin | ||
40 | { | 34 | { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 94 | if (dialog->exec() == QDialog::Accepted) { | |||
101 | if (!dialog->changedEntries().isEmpty()) { | 95 | if (!dialog->changedEntries().isEmpty()) { | ||
102 | m_model->load(); | 96 | m_model->load(); | ||
103 | } | 97 | } | ||
104 | } | 98 | } | ||
105 | 99 | | |||
106 | delete dialog; | 100 | delete dialog; | ||
107 | } | 101 | } | ||
108 | 102 | | |||
109 | static KCModule *findBinaryConfig(const QString &pluginId, QObject *parent) | | |||
110 | { | | |||
111 | return KPluginTrader::createInstanceFromQuery<KCModule>( | | |||
112 | QStringLiteral("kwin/effects/configs/"), | | |||
113 | QString(), | | |||
114 | QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(pluginId), | | |||
115 | parent | | |||
116 | ); | | |||
117 | } | | |||
118 | | ||||
119 | static KCModule *findScriptedConfig(const QString &pluginId, QObject *parent) | | |||
120 | { | | |||
121 | const auto offers = KPluginTrader::self()->query( | | |||
122 | QStringLiteral("kwin/effects/configs/"), | | |||
123 | QString(), | | |||
124 | QStringLiteral("[X-KDE-Library] == 'kcm_kwin4_genericscripted'") | | |||
125 | ); | | |||
126 | | ||||
127 | if (offers.isEmpty()) { | | |||
128 | return nullptr; | | |||
129 | } | | |||
130 | | ||||
131 | const KPluginInfo &generic = offers.first(); | | |||
132 | KPluginLoader loader(generic.libraryPath()); | | |||
133 | KPluginFactory *factory = loader.factory(); | | |||
134 | if (!factory) { | | |||
135 | return nullptr; | | |||
136 | } | | |||
137 | | ||||
138 | return factory->create<KCModule>(pluginId, parent); | | |||
139 | } | | |||
140 | | ||||
141 | void DesktopEffectsKCM::configure(const QString &pluginId, QQuickItem *context) | 103 | void DesktopEffectsKCM::configure(const QString &pluginId, QQuickItem *context) | ||
142 | { | 104 | { | ||
143 | const QModelIndex idx = m_model->findByPluginId(pluginId); | 105 | const QModelIndex index = m_model->findByPluginId(pluginId); | ||
144 | if (!idx.isValid()) { | | |||
145 | return; | | |||
146 | } | | |||
147 | | ||||
148 | QPointer<QDialog> dialog = new QDialog(); | | |||
149 | | ||||
150 | KCModule *module = idx.data(EffectModel::ScriptedRole).toBool() | | |||
151 | ? findScriptedConfig(pluginId, dialog) | | |||
152 | : findBinaryConfig(pluginId, dialog); | | |||
153 | if (!module) { | | |||
154 | delete dialog; | | |||
155 | return; | | |||
156 | } | | |||
157 | | ||||
158 | dialog->setWindowTitle(idx.data(EffectModel::NameRole).toString()); | | |||
159 | dialog->winId(); | | |||
160 | | ||||
161 | auto buttons = new QDialogButtonBox( | | |||
162 | QDialogButtonBox::Ok | | | |||
163 | QDialogButtonBox::Cancel | | | |||
164 | QDialogButtonBox::RestoreDefaults, | | |||
165 | dialog | | |||
166 | ); | | |||
167 | connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | | |||
168 | connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | | |||
169 | connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, | | |||
170 | module, &KCModule::defaults); | | |||
171 | | ||||
172 | auto layout = new QVBoxLayout(dialog); | | |||
173 | layout->addWidget(module); | | |||
174 | layout->addWidget(buttons); | | |||
175 | 106 | | |||
107 | QWindow *transientParent = nullptr; | ||||
176 | if (context && context->window()) { | 108 | if (context && context->window()) { | ||
177 | dialog->windowHandle()->setTransientParent(context->window()); | 109 | transientParent = context->window(); | ||
178 | } | 110 | } | ||
179 | 111 | | |||
180 | dialog->exec(); | 112 | m_model->requestConfigure(index, transientParent); | ||
181 | | ||||
182 | delete dialog; | | |||
183 | } | 113 | } | ||
184 | 114 | | |||
185 | void DesktopEffectsKCM::updateNeedsSave() | 115 | void DesktopEffectsKCM::updateNeedsSave() | ||
186 | { | 116 | { | ||
187 | setNeedsSave(m_model->needsSave()); | 117 | setNeedsSave(m_model->needsSave()); | ||
188 | } | 118 | } | ||
189 | 119 | | |||
190 | } // namespace KWin | 120 | } // namespace KWin | ||
191 | 121 | | |||
192 | #include "kcm.moc" | 122 | #include "kcm.moc" |