Commit bd03827d authored by Marco Martin's avatar Marco Martin

encapsulate module pages in pages

kcm pages are in their own detached qqmlcontext so can't really access
the applicationwindow
they may eventually go out of process as well.
use a layer more of pages to put them in the main pagerow.
also support push and pop by multi-level kcms (can be seen in the
notification kcm)
parent 064cb709
......@@ -21,7 +21,7 @@
import QtQuick 2.2
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.2 as Controls
import org.kde.kirigami 2.2 as Kirigami
import org.kde.kirigami 2.8 as Kirigami
import org.kde.active.settings 2.0 as ActiveSettings
import org.kde.plasma.settings 0.1
......@@ -84,11 +84,52 @@ Kirigami.ScrollablePage {
onClicked: {
print("Clicked ndex: " + index + " current: " + listView.currentIndex + " " + name + " curr: " + rootItem.currentModule);
pageStack.push(mainUi, {})
// Only the first main page has a kcm property
var container = kcmContainer.createObject(pageStack, {"kcm": model.kcm, "internalPage": model.kcm.mainUi});
print(container.internalPage)
pageStack.push(container);
}
}
}
// This is pretty much a placeholder of what will be the sandboxing mechanism: this element will be a wayland compositor that will contain off-process kcm pages
Component {
id: kcmContainer
Kirigami.Page {
id: container
title: internalPage.title
property QtObject kcm
property Item internalPage
topPadding: 0
leftPadding: 0
rightPadding: 0
bottomPadding: 0
flickable: internalPage.flickable
onInternalPageChanged: {
internalPage.parent = contentItem;
internalPage.anchors.fill = contentItem;
}
data: [
Connections {
target: kcm
onPagePushed: {
pageStack.push(kcmContainer.createObject(pageStack, {"internalPage": page}));
}
onPageRemoved: pageStack.pop();
},
Connections {
target: pageStack
onPageRemoved: {
if (page == container) {
page.destroy();
}
}
}
]
}
}
ListView {
id: listView
model: ModulesModel{}
......
......@@ -34,7 +34,9 @@ QVariant ModulesModel::data(const QModelIndex& index, int role) const
return QVariant();
}
Data d = m_plugins[index.row()];
// NOTE: as the kcm is lazy loading, this needs to not be const
// a cleaner alternative, would be a ConfigModule *loadKcm(pluginId) method, which also wouldn't risk erroneous kcm instantiation when it shouldn't
Data &d = const_cast<ModulesModel *>(this)->m_plugins[index.row()];
switch (role) {
case NameRole:
......@@ -43,13 +45,13 @@ QVariant ModulesModel::data(const QModelIndex& index, int role) const
return d.plugin.description();
case IconNameRole:
return d.plugin.iconName();
case MainUiRole: {
case KcmRole: {
if(!d.kcm) {
d.kcm = instantiateKcm(d.plugin.pluginId());
}
return QVariant::fromValue(d.kcm->mainUi());
return QVariant::fromValue(d.kcm.data());
}
default:
return QVariant();
......@@ -67,7 +69,7 @@ QHash<int, QByteArray> ModulesModel::roleNames() const
names.insert(NameRole, "name");
names.insert(DescriptionRole, "description");
names.insert(IconNameRole, "iconName");
names.insert(MainUiRole, "mainUi");
names.insert(KcmRole, "kcm");
return names;
}
......
......@@ -9,7 +9,7 @@
struct Data {
KPluginMetaData plugin;
KQuickAddons::ConfigModule* kcm = nullptr;
QPointer<KQuickAddons::ConfigModule> kcm;
};
class ModulesModel : public QAbstractListModel
......@@ -22,7 +22,7 @@ public:
NameRole = Qt::DisplayRole,
IconNameRole = Qt::DecorationRole,
DescriptionRole = Qt::UserRole + 1,
MainUiRole
KcmRole
};
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment