Verified Commit 9fbb3ac3 authored by Filipe Azevedo's avatar Filipe Azevedo Committed by Linus Jahn

Refactor file chooser

Task-Id: #287Signed-off-by: Linus Jahn's avatarLinus Jahn <lnj@kaidan.im>
parent c2a206cc
......@@ -29,12 +29,15 @@
*/
import QtQuick 2.6
import QtQuick.Controls 2.0 as Controls
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.2 as Kirigami
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.0 as Controls
import org.kde.kirigami 2.2 as Kirigami
import im.kaidan.kaidan 1.0
import EmojiModel 0.1
import MediaUtils 0.1
import "elements"
Kirigami.ScrollablePage {
......@@ -101,60 +104,64 @@ Kirigami.ScrollablePage {
FileChooser {
id: fileChooser
title: qsTr("Select a file")
onAccepted: {
sendMediaSheet.jid = kaidan.messageModel.chatPartner
sendMediaSheet.fileUrl = fileUrl
sendMediaSheet.open()
}
onAccepted: sendMediaSheet.sendFile(kaidan.messageModel.chatPartner, fileUrl)
}
function openFileDialog(filterName, filter) {
function openFileDialog(filterName, filter, title) {
fileChooser.filterName = filterName
fileChooser.filter = filter
if (title !== undefined)
fileChooser.title = title
fileChooser.open()
mediaDrawer.close()
}
Kirigami.OverlayDrawer {
id: mediaDrawer
edge: Qt.BottomEdge
height: Kirigami.Units.gridUnit * 8
contentItem: RowLayout {
contentItem: ListView {
id: content
Layout.alignment: Qt.AlignHCenter
orientation: Qt.Horizontal
Layout.fillHeight: true
Layout.fillWidth: true
model: [
Enums.MessageType.MessageFile,
Enums.MessageType.MessageImage,
Enums.MessageType.MessageAudio,
Enums.MessageType.MessageVideo,
Enums.MessageType.MessageDocument
]
delegate: IconButton {
height: ListView.view.height
width: height
buttonText: MediaUtilsInstance.label(model.modelData)
iconSource: MediaUtilsInstance.iconName(model.modelData)
IconButton {
buttonText: qsTr("Image")
iconSource: "image-jpeg"
onClicked: openFileDialog("Images", "*.jpg *.jpeg *.png *.gif")
Layout.alignment: Qt.AlignHCenter
}
IconButton {
buttonText: qsTr("Video")
iconSource: "video-mp4"
onClicked: openFileDialog("Videos", "*.mp4 *.mkv *.avi *.webm")
Layout.alignment: Qt.AlignHCenter
}
IconButton {
buttonText: qsTr("Audio")
iconSource: "audio-mp3"
onClicked: openFileDialog("Audio files", "*.mp3 *.wav *.flac *.ogg *.m4a *.mka")
Layout.alignment: Qt.AlignHCenter
}
IconButton {
buttonText: qsTr("Document")
iconSource: "x-office-document"
onClicked: openFileDialog("Documents", "*.doc *.docx *.odt")
Layout.alignment: Qt.AlignHCenter
}
IconButton {
buttonText: qsTr("Other file")
iconSource: "text-x-plain"
onClicked: openFileDialog("All files", "*")
Layout.alignment: Qt.AlignHCenter
onClicked: {
switch (model.modelData) {
case Enums.MessageType.MessageFile:
case Enums.MessageType.MessageImage:
case Enums.MessageType.MessageAudio:
case Enums.MessageType.MessageVideo:
case Enums.MessageType.MessageDocument:
openFileDialog(MediaUtilsInstance.filterName(model.modelData),
MediaUtilsInstance.filter(model.modelData),
MediaUtilsInstance.label(model.modelData))
break
case Enums.MessageType.MessageText:
case Enums.MessageType.MessageGeoLocation:
case Enums.MessageType.MessageUnknown:
break
}
}
}
}
}
......@@ -238,7 +245,7 @@ Kirigami.ScrollablePage {
if (Kirigami.Settings.isMobile)
mediaDrawer.open()
else
openFileDialog("All files", "(*)")
openFileDialog(qsTr("All files"), "*", MediaUtilsInstance.label(Enums.MessageType.MessageFile))
}
}
......
......@@ -58,12 +58,11 @@ Item {
})
}
else if (!Kirigami.Settings.isMobile) {
var selectedNameFilter = filterName + " (" + filter + ")"
fileChooserLoader.setSource("FileChooserDesktop.qml",
{
"selectedNameFilter": selectedNameFilter,
"selectedNameFilter": Qt.binding(function() { return filterName + " (" + filter + ")" }),
"selectFolder": selectFolder,
"title": title
"title": Qt.binding(function() { return title })
})
}
else {
......
......@@ -31,17 +31,21 @@
import QtQuick 2.6
import QtQuick.Dialogs 1.2
import im.kaidan.kaidan 1.0
import MediaUtils 0.1
FileDialog {
id: fileDialog
folder: shortcuts.home
nameFilters: [
"Images (*.jpg *.jpeg *.png *.gif)",
"Videos (*.mp4 *.mkv *.avi *.webm)",
"Audio files (*.mp3 *.wav *.flac *.ogg *.m4a *.mka)",
"Documents (*.doc *.docx *.odt)",
"All files (*)",
selectedNameFilter
]
nameFilters: {
var filters = []
filters = filters.concat(MediaUtilsInstance.namedFilter(Enums.MessageType.MessageImage).split(";;"))
filters = filters.concat(MediaUtilsInstance.namedFilter(Enums.MessageType.MessageAudio).split(";;"))
filters = filters.concat(MediaUtilsInstance.namedFilter(Enums.MessageType.MessageVideo).split(";;"))
filters = filters.concat(MediaUtilsInstance.namedFilter(Enums.MessageType.MessageDocument).split(";;"))
filters = filters.concat(MediaUtilsInstance.namedFilter(Enums.MessageType.MessageFile).split(";;"))
return filters
}
// TODO: support multiple files
// Currently the problem is that the fileUrls list isn't cleared
}
......@@ -83,7 +83,6 @@ Item {
reserveSpaceForIcon: true
icon: (fileIsDir ? "folder" : "text-x-plain")
iconColor: "transparent"
label: fileName + (fileIsDir ? "/" : "")
onClicked: {
......
......@@ -29,8 +29,8 @@
*/
import QtQuick 2.6
import QtQuick.Controls 2.0 as Controls
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.0 as Controls
import org.kde.kirigami 2.0 as Kirigami
Kirigami.OverlaySheet {
......@@ -105,4 +105,10 @@ Kirigami.OverlaySheet {
}
}
}
function sendFile(jid, url) {
fileUrl = url
root.jid = jid
open()
}
}
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