Commit de2f318a authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

katesession: Make basic showing/launching of entries work without Dataengine

parent 6d7762f9
......@@ -16,6 +16,7 @@ import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.private.profiles 1.0
PlasmaComponents.ListItem {
id: menuItem
......@@ -33,8 +34,8 @@ PlasmaComponents.ListItem {
hoverEnabled: true
onClicked: {
if (TypeRole!=1)
menuItem.itemSelected(UuidRole);
if (type == ProfilesModel.Default)
menuItem.itemSelected(profileIdentifier);
else {
showInput=true;
}
......@@ -61,7 +62,7 @@ PlasmaComponents.ListItem {
verticalCenter: parent.verticalCenter
}
maximumLineCount: 1
text: DisplayRole.trim()
text: name.trim()
visible: !showInput // TypeRole: 0: Text, 1: Image, 2: Url
elide: Text.ElideRight
wrapMode: Text.Wrap
......@@ -72,7 +73,7 @@ PlasmaComponents.ListItem {
width: PlasmaCore.Units.iconSizes.small
height: width
anchors.verticalCenter: parent.verticalCenter
source: DecorationRole
source: iconName
}
}
......@@ -132,7 +133,7 @@ PlasmaComponents.ListItem {
}
Component.onCompleted: {
toolButtonsLayout.visible = Qt.binding(function () { return (TypeRole==2) && (menuListView.currentIndex == index); });
toolButtonsLayout.visible = Qt.binding(function () { return (type == ProfilesModel.NewSession) && (menuListView.currentIndex == index); });
}
}
}
......
......@@ -17,6 +17,8 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.private.profiles 1.0
Item {
id: main
width: (Plasmoid.formFactor==PlasmaCore.Types.Planar)? PlasmaCore.Units.gridUnit * 14 : undefined
......@@ -33,24 +35,6 @@ Item {
plasmoid.removeAction("configure");
}
PlasmaCore.DataSource {
id: sessionsSource
property bool editing: false;
engine: "org.kde.plasma.katesessions"
connectedSources: "katesessions"
function serviceAction(uuid, op) {
const service = sessionsSource.serviceForSource(uuid);
var operation = service.operationDescription(op);
return service.startOperationCall(operation);
}
function newSession(sessionName) {
const service = sessionsSource.serviceForSource("");
var operation = service.operationDescription("newSession");
operation.sessionName = sessionName;
return service.startOperationCall(operation);
}
}
property var searchHeader: PlasmaExtras.PlasmoidHeading {
PlasmaComponents3.TextField {
id: filter
......@@ -136,15 +120,18 @@ Item {
Menu {
id: sessionsMenu
model: PlasmaCore.SortFilterModel {
sourceModel: sessionsSource.models.katesessions
filterRole: "DisplayRole"
sourceModel: ProfilesModel {
id: model
appName: "kate"
}
filterRole: "name"
filterRegExp: filter.text
}
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: PlasmaCore.Units.smallSpacing
onItemSelected: {
sessionsSource.serviceAction(uuid, "invoke")
onItemSelected: function (profileIdentifier) {
model.openProfile(profileIdentifier)
plasmoid.expanded = false;
}
onRemove: sessionsSource.serviceAction(uuid, "remove")
......
......@@ -50,16 +50,18 @@ void ProfilesModel::loadProfiles()
for (const auto &profilePath : std::as_const(profilesPaths)) {
QFileInfo info(profilePath);
const QString profileIdentifier = info.baseName();
QString niceName = profileIdentifier;
QString iconName = QStringLiteral("utilities-terminal");
QString name = profileIdentifier;
QString iconName;
if (m_appName == QLatin1String("konsole")) {
KConfig cfg(profilePath, KConfig::SimpleConfig);
KConfigGroup grp(&cfg, "General");
iconName = grp.readEntry("Icon", iconName);
niceName = grp.readEntry("Name", niceName);
name = grp.readEntry("Name", name);
} else {
iconName = m_appName;
}
m_data.append(ProfileData{niceName, profileIdentifier, iconName});
m_data.append(ProfileData{name, profileIdentifier, iconName, ProfilesModel::Type::Default});
}
endResetModel();
}
......@@ -70,6 +72,7 @@ QHash<int, QByteArray> ProfilesModel::roleNames() const
{NameRole, "name"},
{ProfileIdentifierRole, "profileIdentifier"},
{IconNameRole, "iconName"},
{TypeRole, "type"},
};
}
......@@ -83,6 +86,8 @@ QVariant ProfilesModel::data(const QModelIndex &index, int role) const
return data.profileIdentifier;
case IconNameRole:
return data.iconName;
case TypeRole:
return data.type;
default:
return QVariant();
}
......
......@@ -6,6 +6,7 @@
#pragma once
#include <QAbstractListModel>
#include <qnamespace.h>
class KDirWatch;
......@@ -13,6 +14,7 @@ struct ProfileData {
QString name;
QString profileIdentifier;
QString iconName;
int type;
};
class ProfilesModel : public QAbstractListModel
......@@ -26,8 +28,16 @@ public:
enum Roles {
NameRole = Qt::DisplayRole,
ProfileIdentifierRole = Qt::UserRole,
IconNameRole,
IconNameRole = Qt::DecorationRole,
TypeRole,
};
enum Type {
Default,
NewSession,
};
Q_ENUM(Type)
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
Q_INVOKABLE void openProfile(const QString profileIdentifier);
......
Supports Markdown
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