From e059e36d873a2b420e3c23c76cfdff2b53edf66b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 7 Jun 2017 09:26:26 +0200 Subject: [PATCH] feat(ui/scripts/Utils/utils): provide a `getUriFromSystemPath` function --- .../Common/Form/Buttons/FileChooserButton.qml | 7 ++----- .../ui/modules/Common/Form/DroppableTextArea.qml | 2 +- .../NotificationReceivedFileMessage.qml | 2 +- linphone-desktop/ui/scripts/Utils/utils.js | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/linphone-desktop/ui/modules/Common/Form/Buttons/FileChooserButton.qml b/linphone-desktop/ui/modules/Common/Form/Buttons/FileChooserButton.qml index c44c282cd..2e20a817c 100644 --- a/linphone-desktop/ui/modules/Common/Form/Buttons/FileChooserButton.qml +++ b/linphone-desktop/ui/modules/Common/Form/Buttons/FileChooserButton.qml @@ -75,14 +75,11 @@ TextField { return '' } - var folder = Utils.dirname(textField.selectedFile) - return !Utils.startsWith(folder, 'file:') - ? 'file:' + folder - : folder + return Utils.getUriFromSystemPath(Utils.dirname(textField.selectedFile)) } onAccepted: { - textField.selectedFile = Utils.getPathFromUri(fileUrl) + textField.selectedFile = Utils.getSystemPathFromUri(fileUrl) textField.accepted(textField.selectedFile) } diff --git a/linphone-desktop/ui/modules/Common/Form/DroppableTextArea.qml b/linphone-desktop/ui/modules/Common/Form/DroppableTextArea.qml index 8cec6a1f0..5dec7703e 100644 --- a/linphone-desktop/ui/modules/Common/Form/DroppableTextArea.qml +++ b/linphone-desktop/ui/modules/Common/Form/DroppableTextArea.qml @@ -29,7 +29,7 @@ Item { // Filtering files, other urls are forbidden. files = files.reduce(function (files, file) { if (file.startsWith('file:')) { - files.push(Utils.getPathFromUri(file)) + files.push(Utils.getSystemPathFromUri(file)) } return files diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml index 54a9b7cf4..d29eb9ec3 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml @@ -71,7 +71,7 @@ Notification { hoverEnabled: true onClicked: notification._close(function () { - Qt.openUrlExternally('file://' + Utils.dirname(notification._fileUri)) + Qt.openUrlExternally(Utils.getUriFromSystemPath(Utils.dirname(notification._fileUri))) }) } } diff --git a/linphone-desktop/ui/scripts/Utils/utils.js b/linphone-desktop/ui/scripts/Utils/utils.js index fbb48b85b..9de8e6607 100644 --- a/linphone-desktop/ui/scripts/Utils/utils.js +++ b/linphone-desktop/ui/scripts/Utils/utils.js @@ -155,7 +155,7 @@ function openWindow (window, parent, options) { // ----------------------------------------------------------------------------- -function getPathFromUri (uri) { +function getSystemPathFromUri (uri) { var str = uri.toString() if (startsWith(str, 'file://')) { str = str.substring(7) @@ -172,6 +172,19 @@ function getPathFromUri (uri) { return str } +function getUriFromSystemPath (path) { + if (path.startsWith('file://')) { + return path + } + + var os = Qt.platform.os + if (os === 'windows' || os === 'winrt') { + return 'file://' + (/^[^:]+:/.exec(path) ? '' : '/') + } + + return 'file://' + path +} + // ----------------------------------------------------------------------------- // Test if a point is in a item.