Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 7fd1a8c3 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳 Committed by Linus Jahn

media-sharing: Abstract file chooser, add mobile version

parent 8bab2fdb
......@@ -15,6 +15,9 @@
<file alias="qml/elements/ChatMessage.qml">src/qml/elements/ChatMessage.qml</file>
<file alias="qml/elements/RoundImage.qml">src/qml/elements/RoundImage.qml</file>
<file alias="qml/elements/IconButton.qml">src/qml/elements/IconButton.qml</file>
<file alias="qml/elements/FileChooser.qml">src/qml/elements/FileChooser.qml</file>
<file alias="qml/elements/FileChooserDesktop.qml">src/qml/elements/FileChooserDesktop.qml</file>
<file alias="qml/elements/FileChooserMobile.qml">src/qml/elements/FileChooserMobile.qml</file>
<file alias="qtquickcontrols2.conf">misc/qtquickcontrols2.conf</file>
</qresource>
......
......@@ -224,6 +224,7 @@ void Kaidan::sendFile(QString jid, QString filePath, QString message)
if (client->isConnected()) {
// convert file-URLs to file paths
filePath.replace("file://", "");
filePath.replace("qrc:", "");
emit client->sendFileRequested(jid, filePath, message);
} else {
emit passiveNotificationRequested(tr("Could not send file, as a result of not being connected."));
......
......@@ -30,7 +30,6 @@
import QtQuick 2.6
import QtQuick.Controls 2.0 as Controls
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.2 as Kirigami
import QtGraphicalEffects 1.0
......@@ -45,23 +44,22 @@ Kirigami.ScrollablePage {
title: chatName
keyboardNavigationEnabled: true
FileDialog {
id: fileDialog
title: qsTr("Please choose a file to upload")
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 (*)"
]
// TODO: support multiple files
// Currently the problem is that the fileUrls list isn't cleared
FileChooser {
id: fileChooser
title: qsTr("Select a file")
onAccepted: {
// TODO: Add sheet for entering description, maybe later also image cropping
kaidan.sendFile(recipientJid, fileUrl, "")
}
}
function openFileDialog(filterName, filter) {
fileChooser.filterName = filterName
fileChooser.filter = filter
fileChooser.open()
mediaDrawer.close()
}
Kirigami.OverlayDrawer {
......@@ -75,31 +73,31 @@ Kirigami.ScrollablePage {
IconButton {
buttonText: qsTr("Image")
iconSource: "image-jpeg"
onClicked: openFileDialog("Images (*.jpg *.jpeg *.png *.gif)")
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)")
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)")
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)")
onClicked: openFileDialog("Documents", "*.doc *.docx *.odt")
Layout.alignment: Qt.AlignHCenter
}
IconButton {
buttonText: qsTr("Other file")
iconSource: "text-x-plain"
onClicked: openFileDialog("All files (*)")
onClicked: openFileDialog("All files", "*")
Layout.alignment: Qt.AlignHCenter
}
......@@ -174,7 +172,7 @@ Kirigami.ScrollablePage {
if (Kirigami.Settings.isMobile)
mediaDrawer.open()
else
openFileDialog("All files (*)")
openFileDialog("All files", "(*)")
}
}
......@@ -234,10 +232,4 @@ Kirigami.ScrollablePage {
}
}
}
function openFileDialog(filter) {
fileDialog.selectedNameFilter = filter
fileDialog.open()
mediaDrawer.close()
}
}
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2016-2018 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import org.kde.kirigami 2.0 as Kirigami
Item {
id: root
property string filter: "*"
property string filterName: "All files"
property string fileUrl
property bool selectFolder: false
property string title: qsTr("Select a file")
signal accepted
Loader {
id: fileChooserLoader
}
function open() {
fileChooserLoader.item.open()
}
Component.onCompleted: {
if (Kirigami.Settings.isMobile) {
fileChooserLoader.setSource("FileChooserMobile.qml",
{
"nameFilter": filter,
"title": title
})
}
else if (!Kirigami.Settings.isMobile) {
var selectedNameFilter = filterName + " (" + filter + ")"
fileChooserLoader.setSource("FileChooserDesktop.qml",
{
"selectedNameFilter": selectedNameFilter,
"selectFolder": selectFolder,
"title": title
})
}
else {
fileChooserLoader.setSource("FileChooserDesktop.qml")
}
}
Connections {
target: fileChooserLoader.item
onAccepted: {
fileUrl = fileChooserLoader.item.fileUrl
root.accepted()
console.log("Child file dialog accepted. URL: " + fileUrl)
}
}
}
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2016-2018 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import QtQuick.Dialogs 1.2
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
]
// TODO: support multiple files
// Currently the problem is that the fileUrls list isn't cleared
}
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2016-2018 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import QtQuick.Layouts 1.1
import org.kde.kirigami 2.0 as Kirigami
import Qt.labs.folderlistmodel 2.1
Item {
id: root
property url fileUrl
property string title
signal accepted
property string nameFilter
Component {
id: fileChooserPage
Kirigami.ScrollablePage {
title: root.title
actions {
main: Kirigami.Action {
id: parentFolderButton
tooltip: qsTr("go to parent folder")
iconName: "go-parent-folder"
onTriggered: fileModel.folder = fileModel.parentFolder
enabled: true
}
right: Kirigami.Action {
tooltip: qsTr("Close")
iconName: "dialog-close"
onTriggered: pageStack.pop()
enabled: true
}
}
FolderListModel {
id: fileModel
nameFilters: root.nameFilter
showDirsFirst: true
showDotAndDotDot: false // replaced by the main action Button
showOnlyReadable: true
}
ListView {
id: view
model: fileModel
anchors.fill: parent
delegate: Kirigami.BasicListItem {
width: parent.width
reserveSpaceForIcon: true
icon: (fileIsDir ? "folder" : "text-x-plain")
label: fileName + (fileIsDir ? "/" : "")
onClicked: {
if (fileIsDir) {
if (fileName === "..")
fileModel.folder = fileModel.parentFolder
else if (fileName === ".")
return
else
fileModel.folder = "file://" + filePath
} else {
root.fileUrl = filePath
root.accepted()
pageStack.pop()
}
}
}
}
}
}
function open() {
pageStack.push(fileChooserPage)
}
}
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