8#include "Plasma/Applet"
9#include "Plasma/Containment"
10#include "appletcontext_p.h"
11#include "appletquickitem.h"
12#include "configcategory_p.h"
13#include "configmodel.h"
17#include <QQmlComponent>
20#include <QQmlFileSelector>
24#include <KLocalizedContext>
25#include <KLocalizedString>
26#include <KPackage/Package>
28#include <Plasma/Corona>
29#include <Plasma/PluginLoader>
30#include <qqmlengine.h>
33#define DIALOGSIZE_MAX ((1 << 24) - 1)
39class ConfigViewPrivate
43 ~ConfigViewPrivate() =
default;
47 void updateMinimumWidth();
48 void updateMinimumHeight();
49 void updateMaximumWidth();
50 void updateMaximumHeight();
52 void mainItemLoaded();
56 ConfigModel *configModel;
57 ConfigModel *kcmConfigModel;
59 AppletContext *rootContext;
67ConfigViewPrivate::ConfigViewPrivate(
Plasma::Applet *appl, ConfigView *view)
75void ConfigViewPrivate::init()
78 qWarning() <<
"Null applet passed to constructor";
81 if (!applet.data()->pluginMetaData().isValid()) {
82 qWarning() <<
"Invalid applet passed to constructor";
83 if (applet->containment()) {
84 corona = applet->containment()->corona();
89 rootContext =
new AppletContext(q->engine(), applet,
nullptr);
90 rootContext->setParent(q->engine());
92 applet.data()->setUserConfiguring(
true);
95 localizedContextObject->setTranslationDomain(applet->translationDomain());
96 rootContext->setContextObject(localizedContextObject);
103 if (!applet.data()->containment()->corona()) {
104 Plasma::Applet *a = qobject_cast<Plasma::Applet *>(applet.data()->containment()->parent());
109 if (!applet.data()->containment()->corona()->kPackage().isValid()) {
110 qWarning() <<
"Invalid home screen package";
112 corona = applet.data()->containment()->corona();
115 qWarning() <<
"Cannot find a Corona, this should never happen!";
119 const auto pkg = corona->kPackage();
124 if (!qEnvironmentVariableIntValue(
"PLASMA_NO_CONTEXTPROPERTIES")) {
130 QQmlComponent component(q->engine(), applet.data()->configModel());
131 QObject *
object = component.create(rootContext);
132 configModel = qobject_cast<ConfigModel *>(
object);
135 configModel->setApplet(applet.data());
136 configModel->setParent(q);
149 return !KAuthorized::authorizeControlModule(kcm + QLatin1String(
".desktop"));
155 configModel =
new ConfigModel(q);
158 for (
const QString &kcm : std::as_const(kcms)) {
164 qWarning() <<
"Could not find" << kcm
165 <<
"requested by X-Plasma-ConfigPlugins. Ensure that it exists, is a QML KCM, and lives in the 'kcms/' subdirectory.";
174void ConfigViewPrivate::updateMinimumWidth()
176 if (mainItemLayout) {
177 q->setMinimumWidth(mainItemLayout.data()->property(
"minimumWidth").toInt());
180 q->setWidth(qMax(q->width(), q->minimumWidth()));
182 q->setMinimumWidth(-1);
186void ConfigViewPrivate::updateMinimumHeight()
188 if (mainItemLayout) {
189 q->setMinimumHeight(mainItemLayout.data()->property(
"minimumHeight").toInt());
192 q->setHeight(qMax(q->height(), q->minimumHeight()));
194 q->setMinimumHeight(-1);
198void ConfigViewPrivate::updateMaximumWidth()
200 if (mainItemLayout) {
201 const int hint = mainItemLayout.
data()->property(
"maximumWidth").
toInt();
204 q->setMaximumWidth(hint);
206 q->setMaximumWidth(DIALOGSIZE_MAX);
209 q->setMaximumWidth(DIALOGSIZE_MAX);
213void ConfigViewPrivate::updateMaximumHeight()
215 if (mainItemLayout) {
216 const int hint = mainItemLayout.
data()->property(
"maximumHeight").
toInt();
219 q->setMaximumHeight(hint);
221 q->setMaximumHeight(DIALOGSIZE_MAX);
224 q->setMaximumHeight(DIALOGSIZE_MAX);
228void ConfigViewPrivate::updateTitle()
232 :
i18n(
"%1 Settings", applet.data()->title()));
235void ConfigViewPrivate::mainItemLoaded()
240 q->resize(cg.
readEntry(
"DialogWidth", q->width()), cg.
readEntry(
"DialogHeight", q->height()));
242 if (rootItem->property(
"title").isValid()) {
253 const auto children = rootItem->
children();
254 for (
QObject *child : children) {
256 if (child->property(
"minimumWidth").isValid() && child->property(
"minimumHeight").isValid() && child->property(
"preferredWidth").isValid()
257 && child->property(
"preferredHeight").isValid() && child->property(
"maximumWidth").isValid() && child->property(
"maximumHeight").isValid()
258 && child->property(
"fillWidth").isValid() && child->property(
"fillHeight").isValid()) {
263 mainItemLayout = layout;
266 QObject::connect(layout, SIGNAL(minimumWidthChanged()), q, SLOT(updateMinimumWidth()));
267 QObject::connect(layout, SIGNAL(minimumHeightChanged()), q, SLOT(updateMinimumHeight()));
268 QObject::connect(layout, SIGNAL(maximumWidthChanged()), q, SLOT(updateMaximumWidth()));
269 QObject::connect(layout, SIGNAL(maximumHeightChanged()), q, SLOT(updateMaximumHeight()));
271 updateMinimumWidth();
272 updateMinimumHeight();
273 updateMaximumWidth();
274 updateMaximumHeight();
280 , d(new ConfigViewPrivate(applet, this))
284 [[maybe_unused]]
static int configModelRegisterResult = qmlRegisterType<ConfigModel>(
"org.kde.plasma.configuration", 2, 0,
"ConfigModel");
285 [[maybe_unused]]
static int configCategoryRegisterResult = qmlRegisterType<ConfigCategory>(
"org.kde.plasma.configuration", 2, 0,
"ConfigCategory");
290ConfigView::~ConfigView()
293 d->applet.data()->setUserConfiguring(
false);
294 if (d->applet.data()->containment() && d->applet.data()->containment()->corona()) {
295 d->applet.data()->containment()->corona()->requestConfigSync();
308 return d->rootContext;
311void ConfigView::setSource(
const QUrl &src)
314 if (uiComponent.isError()) {
315 for (
const auto &error : uiComponent.errors()) {
320 std::unique_ptr<QObject> object(uiComponent.createWithInitialProperties({{QStringLiteral(
"parent"), QVariant::fromValue(contentItem())}}, d->rootContext));
321 d->rootItem = qobject_cast<QQuickItem *>(
object.
get());
325 Q_UNUSED(
object.release());
328 if (d->rootItem->implicitHeight() > 0 || d->rootItem->implicitWidth() > 0) {
329 resize(
QSize(d->rootItem->implicitWidth(), d->rootItem->implicitHeight()));
331 d->rootItem->setSize(
QSizeF(width(), height()));
334 setWidth(d->rootItem->implicitWidth());
337 setWidth(d->rootItem->implicitHeight());
346void ConfigView::init()
348 setSource(d->corona->kPackage().fileUrl(
"appletconfigurationui"));
353 return d->applet.data();
356ConfigModel *ConfigView::configModel()
const
358 return d->configModel;
361QString ConfigView::appletGlobalShortcut()
const
367 return d->applet.
data()->globalShortcut().toString();
370void ConfigView::setAppletGlobalShortcut(
const QString &shortcut)
372 if (!d->applet || d->applet.data()->globalShortcut().toString().toLower() ==
shortcut.toLower()) {
376 d->applet.data()->setGlobalShortcut(shortcut);
377 Q_EMIT appletGlobalShortcutChanged();
393 d->rootItem->setSize(re->
size());
407#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