aerothemeplasma/plasma/plasmoids/org.kde.desktopcontainment/contents/ui/ConfigLocation.qml

202 lines
5.1 KiB
QML
Raw Normal View History

/*
SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
2024-08-09 01:20:25 +00:00
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import org.kde.plasma.plasmoid 2.0
2024-08-09 01:20:25 +00:00
import org.kde.kirigami 2.20 as Kirigami
import org.kde.private.desktopcontainment.folder 0.1 as Folder
Item {
id: configLocation
property string cfg_url
property alias cfg_labelMode: labelMode.currentIndex
property alias cfg_labelText: labelText.text
property bool titleVisible: !("containmentType" in plasmoid)
onCfg_urlChanged: applyConfig()
function applyConfig(force) {
2024-08-09 01:20:25 +00:00
if (!force && locationGroup.checkedButton !== null) {
return;
}
2024-08-09 01:20:25 +00:00
if (cfg_url === "desktop:/") {
locationDesktop.checked = true;
locationCustomValue.text = "";
2024-08-09 01:20:25 +00:00
} else if (cfg_url === "activities:/current/") {
locationCurrentActivity.checked = true;
locationCustomValue.text = "";
} else {
var placeForUrl = placesModel.indexForUrl(cfg_url);
if (placeForUrl !== -1) {
locationPlace.checked = true;
locationPlaceValue.currentIndex = placeForUrl;
locationCustomValue.text = "";
} else {
locationCustom.checked = true;
locationCustomValue.text = cfg_url;
}
}
locationPlaceValue.enabled = locationPlace.checked;
}
Folder.PlacesModel {
id: placesModel
showDesktopEntry: false
onPlacesChanged: applyConfig(true)
}
ButtonGroup {
id: locationGroup
2024-08-09 01:20:25 +00:00
buttons: [locationDesktop, locationCurrentActivity, locationPlace, locationCustom]
onCheckedButtonChanged: {
2024-08-09 01:20:25 +00:00
if (checkedButton === locationDesktop) {
cfg_url = "desktop:/";
2024-08-09 01:20:25 +00:00
} else if (checkedButton === locationCurrentActivity) {
cfg_url = "activities:/current/";
}
}
}
Kirigami.FormLayout {
anchors.horizontalCenter: parent.horizontalCenter
RadioButton {
id: locationDesktop
Kirigami.FormData.label: i18n("Show:")
text: i18n("Desktop folder")
}
RadioButton {
id: locationCurrentActivity
visible: placesModel.activityLinkingEnabled
text: i18n("Files linked to the current activity")
}
RowLayout {
RadioButton {
id: locationPlace
text: i18n("Places panel item:")
onCheckedChanged: {
locationPlaceValue.enabled = checked;
}
}
ComboBox {
id: locationPlaceValue
Layout.fillWidth: true
model: placesModel
textRole: "display"
enabled: true
onEnabledChanged: {
2024-08-09 01:20:25 +00:00
if (enabled && currentIndex !== -1) {
cfg_url = placesModel.urlForIndex(currentIndex);
}
}
onActivated: {
cfg_url = placesModel.urlForIndex(index);
}
}
}
RowLayout {
RadioButton {
id: locationCustom
text: i18n("Custom location:")
}
TextField {
id: locationCustomValue
enabled: locationCustom.checked
Layout.fillWidth: true
placeholderText: i18n("Type path or URL…")
inputMethodHints: Qt.ImhNoPredictiveText
onEnabledChanged: {
2024-08-09 01:20:25 +00:00
if (enabled && text !== "") {
cfg_url = text;
}
}
onTextChanged: {
if (enabled) {
cfg_url = text;
}
}
}
Button {
icon.name: "document-open"
enabled: locationCustom.checked
onClicked: {
directoryPicker.open();
}
}
Folder.DirectoryPicker {
id: directoryPicker
onUrlChanged: {
locationCustomValue.text = url;
}
}
}
Item {
visible: titleVisible
Kirigami.FormData.isSection: true
}
ComboBox {
id: labelMode
visible: titleVisible
Kirigami.FormData.label: i18n("Title:")
model: [i18n("None"), i18n("Default"), i18n("Full path"), i18n("Custom title")]
}
RowLayout {
visible: titleVisible
Item {
2024-08-09 01:20:25 +00:00
width: Kirigami.Units.iconSizes.small
}
TextField {
id: labelText
Layout.fillWidth: true
2024-08-09 01:20:25 +00:00
enabled: (labelMode.currentIndex === 3)
placeholderText: i18n("Enter custom title…")
}
}
}
}