8#include <KLocalizedQmlContext>
10#include "Plasma/Applet"
11#include "Plasma/Containment"
12#include "appletcontext_p.h"
13#include "appletquickitem.h"
14#include "configcategory_p.h"
15#include "configmodel.h"
19#include <QQmlComponent>
22#include <QQmlFileSelector>
26#include <KLocalizedContext>
27#include <KLocalizedString>
28#include <KPackage/Package>
30#include <Plasma/Corona>
31#include <Plasma/PluginLoader>
32#include <qqmlengine.h>
35#define DIALOGSIZE_MAX ((1 << 24) - 1)
41class ConfigViewPrivate
45 ~ConfigViewPrivate() =
default;
49 void updateMinimumWidth();
50 void updateMinimumHeight();
51 void updateMaximumWidth();
52 void updateMaximumHeight();
54 void mainItemLoaded();
58 ConfigModel *configModel;
59 ConfigModel *kcmConfigModel;
61 AppletContext *rootContext;
69ConfigViewPrivate::ConfigViewPrivate(
Plasma::Applet *appl, ConfigView *view)
77void ConfigViewPrivate::init()
80 qWarning() <<
"Null applet passed to constructor";
83 if (!applet.data()->pluginMetaData().isValid()) {
84 qWarning() <<
"Invalid applet passed to constructor";
85 if (applet->containment()) {
86 corona = applet->containment()->corona();
91 rootContext =
new AppletContext(q->engine(), applet,
nullptr);
92 rootContext->setParent(q->engine());
94 applet.data()->setUserConfiguring(
true);
97 localizedContextObject->setTranslationDomain(applet->translationDomain());
98 rootContext->setContextObject(localizedContextObject);
105 if (!applet.data()->containment()->corona()) {
106 Plasma::Applet *a = qobject_cast<Plasma::Applet *>(applet.data()->containment()->parent());
111 if (!applet.data()->containment()->corona()->kPackage().isValid()) {
112 qWarning() <<
"Invalid home screen package";
114 corona = applet.data()->containment()->corona();
117 qWarning() <<
"Cannot find a Corona, this should never happen!";
121 const auto pkg = corona->kPackage();
126 if (!qEnvironmentVariableIntValue(
"PLASMA_NO_CONTEXTPROPERTIES")) {
132 QQmlComponent component(q->engine(), applet.data()->configModel());
133 QObject *
object = component.create(rootContext);
134 configModel = qobject_cast<ConfigModel *>(
object);
137 configModel->setApplet(applet.data());
138 configModel->setParent(q);
151 return !KAuthorized::authorizeControlModule(kcm + QLatin1String(
".desktop"));
157 configModel =
new ConfigModel(q);
160 for (
const QString &kcm : std::as_const(kcms)) {
166 qWarning() <<
"Could not find" << kcm
167 <<
"requested by X-Plasma-ConfigPlugins. Ensure that it exists, is a QML KCM, and lives in the 'kcms/' subdirectory.";
176void ConfigViewPrivate::updateMinimumWidth()
178 if (mainItemLayout) {
179 q->setMinimumWidth(mainItemLayout.data()->property(
"minimumWidth").toInt());
182 q->setWidth(qMax(q->width(), q->minimumWidth()));
184 q->setMinimumWidth(-1);
188void ConfigViewPrivate::updateMinimumHeight()
190 if (mainItemLayout) {
191 q->setMinimumHeight(mainItemLayout.data()->property(
"minimumHeight").toInt());
194 q->setHeight(qMax(q->height(), q->minimumHeight()));
196 q->setMinimumHeight(-1);
200void ConfigViewPrivate::updateMaximumWidth()
202 if (mainItemLayout) {
203 const int hint = mainItemLayout.
data()->property(
"maximumWidth").
toInt();
206 q->setMaximumWidth(hint);
208 q->setMaximumWidth(DIALOGSIZE_MAX);
211 q->setMaximumWidth(DIALOGSIZE_MAX);
215void ConfigViewPrivate::updateMaximumHeight()
217 if (mainItemLayout) {
218 const int hint = mainItemLayout.
data()->property(
"maximumHeight").
toInt();
221 q->setMaximumHeight(hint);
223 q->setMaximumHeight(DIALOGSIZE_MAX);
226 q->setMaximumHeight(DIALOGSIZE_MAX);
230void ConfigViewPrivate::updateTitle()
234 :
i18n(
"%1 Settings", applet.data()->title()));
237void ConfigViewPrivate::mainItemLoaded()
242 q->resize(cg.
readEntry(
"DialogWidth", q->width()), cg.
readEntry(
"DialogHeight", q->height()));
244 if (rootItem->property(
"title").isValid()) {
255 const auto children = rootItem->
children();
256 for (
QObject *child : children) {
258 if (child->property(
"minimumWidth").isValid() && child->property(
"minimumHeight").isValid() && child->property(
"preferredWidth").isValid()
259 && child->property(
"preferredHeight").isValid() && child->property(
"maximumWidth").isValid() && child->property(
"maximumHeight").isValid()
260 && child->property(
"fillWidth").isValid() && child->property(
"fillHeight").isValid()) {
265 mainItemLayout = layout;
268 QObject::connect(layout, SIGNAL(minimumWidthChanged()), q, SLOT(updateMinimumWidth()));
269 QObject::connect(layout, SIGNAL(minimumHeightChanged()), q, SLOT(updateMinimumHeight()));
270 QObject::connect(layout, SIGNAL(maximumWidthChanged()), q, SLOT(updateMaximumWidth()));
271 QObject::connect(layout, SIGNAL(maximumHeightChanged()), q, SLOT(updateMaximumHeight()));
273 updateMinimumWidth();
274 updateMinimumHeight();
275 updateMaximumWidth();
276 updateMaximumHeight();
282 , d(new ConfigViewPrivate(applet, this))
286 [[maybe_unused]]
static int configModelRegisterResult = qmlRegisterType<ConfigModel>(
"org.kde.plasma.configuration", 2, 0,
"ConfigModel");
287 [[maybe_unused]]
static int configCategoryRegisterResult = qmlRegisterType<ConfigCategory>(
"org.kde.plasma.configuration", 2, 0,
"ConfigCategory");
292ConfigView::~ConfigView()
295 d->applet.data()->setUserConfiguring(
false);
296 if (d->applet.data()->containment() && d->applet.data()->containment()->corona()) {
297 d->applet.data()->containment()->corona()->requestConfigSync();
310 return d->rootContext;
313void ConfigView::setSource(
const QUrl &src)
316 if (uiComponent.isError()) {
317 for (
const auto &error : uiComponent.errors()) {
322 std::unique_ptr<QObject> object(uiComponent.createWithInitialProperties({{QStringLiteral(
"parent"), QVariant::fromValue(contentItem())}}, d->rootContext));
323 d->rootItem = qobject_cast<QQuickItem *>(
object.
get());
327 Q_UNUSED(
object.release());
330 if (d->rootItem->implicitHeight() > 0 || d->rootItem->implicitWidth() > 0) {
331 resize(
QSize(d->rootItem->implicitWidth(), d->rootItem->implicitHeight()));
333 d->rootItem->setSize(
QSizeF(width(), height()));
336 setWidth(d->rootItem->implicitWidth());
339 setWidth(d->rootItem->implicitHeight());
348void ConfigView::init()
350 setSource(d->corona->kPackage().fileUrl(
"appletconfigurationui"));
355 return d->applet.data();
358ConfigModel *ConfigView::configModel()
const
360 return d->configModel;
363QString ConfigView::appletGlobalShortcut()
const
369 return d->applet.
data()->globalShortcut().toString();
372void ConfigView::setAppletGlobalShortcut(
const QString &shortcut)
374 if (!d->applet || d->applet.data()->globalShortcut().toString().toLower() ==
shortcut.toLower()) {
378 d->applet.data()->setGlobalShortcut(shortcut);
379 Q_EMIT appletGlobalShortcutChanged();
395 d->rootItem->setSize(re->
size());
409#include "moc_configview.cpp"
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
Plasma::Containment * containment
The Containment managing this applet.
Plasma::Corona * corona
The corona for this contaiment.
A bookkeeping Scene for Plasma::Applets.
QString i18n(const char *text, const TYPE &arg...)
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
const QList< QKeySequence > & shortcut(StandardShortcut id)
The EdgeEventForwarder class This class forwards edge events to be replayed within the given margin T...
QVariant data() const const
QIcon fromTheme(const QString &name)
iterator erase(const_iterator begin, const_iterator end)
bool isEmpty() const const
const QObjectList & children() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
void implicitHeightChanged()
void implicitWidthChanged()
virtual void hideEvent(QHideEvent *) override
virtual void resizeEvent(QResizeEvent *ev) override
const QSize & size() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool canConvert() const const
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
QString toString() const const