Skip to content

Commit c84397f

Browse files
committed
feat: drag and drop to add files
1 parent 23270e4 commit c84397f

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

package/contents/ui/config.qml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ColumnLayout {
7070
property var isLockScreenSettings: null
7171
property alias cfg_MuteMode: muteModeCombo.currentValue
7272
property int editingIndex: -1
73+
property var validDropExtensions: [".mp4", ".mpg", ".ogg", ".mov", ".webm", ".flv", ".mkv", ".avi", ".wmv", ".gif"]
7374

7475
property var muteModeModel: {
7576
// options for desktop and lock screen
@@ -686,7 +687,51 @@ ColumnLayout {
686687
visible: root.currentTab === 0
687688
}
688689

689-
Item {
690+
Component {
691+
id: inlineMessageComponent
692+
Kirigami.InlineMessage {
693+
visible: true
694+
width: dropArea.width
695+
type: Kirigami.MessageType.Information
696+
showCloseButton: true
697+
Timer {
698+
running: true
699+
interval: 5000
700+
onTriggered: parent.destroy()
701+
}
702+
}
703+
}
704+
705+
DropArea {
706+
id: dropArea
707+
onEntered: drag => {
708+
if (drag.hasUrls) {
709+
drag.accept();
710+
}
711+
}
712+
onDropped: drop => {
713+
const validUrls = drop.urls.filter(url => {
714+
url = url.toString();
715+
const isValid = validDropExtensions.some(ext => url.endsWith(ext));
716+
if (!isValid) {
717+
inlineMessageComponent.createObject(messagesList, {
718+
text: `${url.toString()} invalid extension`,
719+
type: Kirigami.MessageType.Warning
720+
});
721+
}
722+
return isValid;
723+
});
724+
validUrls.forEach(function (url) {
725+
url = url.toString();
726+
if (videosModel.fileExists(url)) {
727+
inlineMessageComponent.createObject(messagesList, {
728+
text: `${url.toString()} already exists`
729+
});
730+
} else {
731+
videosModel.addItem(url);
732+
}
733+
});
734+
}
690735
Layout.fillWidth: true
691736
Layout.fillHeight: true
692737
visible: root.currentTab === 0
@@ -696,6 +741,19 @@ ColumnLayout {
696741
Kirigami.Theme.colorSet: Kirigami.Theme.View
697742
color: Kirigami.Theme.backgroundColor
698743
}
744+
Kirigami.PlaceholderMessage {
745+
visible: videosModel.model.count === 0
746+
anchors.centerIn: parent
747+
width: parent.width - Kirigami.Units.gridUnit * 2
748+
icon.name: "edit-none"
749+
text: i18n("No items found \n add or drop some files")
750+
}
751+
ColumnLayout {
752+
id: messagesList
753+
anchors.horizontalCenter: parent.horizontalCenter
754+
anchors.bottom: parent.bottom
755+
z: 2
756+
}
699757
ScrollView {
700758
anchors.fill: parent
701759
ListView {

0 commit comments

Comments
 (0)