Skip to content
Snippets Groups Projects
Commit 55cbcd38 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk
Browse files

misc: using QRegExp to remove file url prefix

Remove file url prefix regardless of two or three slashs (file:// or file:///)

Gitlab: #113
Change-Id: Ia3600336fcc727a32646ee415243c1833e6c1e41
parent 80c26e96
No related branches found
No related tags found
No related merge requests found
...@@ -78,7 +78,7 @@ ItemDelegate { ...@@ -78,7 +78,7 @@ ItemDelegate {
id: preferenceFilePathDialog id: preferenceFilePathDialog
title: JamiStrings.selectFile title: JamiStrings.selectFile
folder: "file://" + currentPath folder: "file:///" + currentPath
onAccepted: { onAccepted: {
var url = UtilsAdapter.getAbsPath(fileUrl.toString()) var url = UtilsAdapter.getAbsPath(fileUrl.toString())
......
...@@ -262,11 +262,12 @@ MessagesAdapter::sendImage(const QString& message) ...@@ -262,11 +262,12 @@ MessagesAdapter::sendImage(const QString& message)
* Img tag contains file paths. * Img tag contains file paths.
*/ */
// TODO: put all QRegExp strings together
QString msg(message); QString msg(message);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
msg = msg.replace("file://", ""); msg = msg.replace(QRegExp("^file:\\/{2,3}"), "");
#else #else
msg = msg.replace("file://", "/"); msg = msg.replace(QRegExp("^file:\\/{2,3}"), "/");
#endif #endif
QFileInfo fi(msg); QFileInfo fi(msg);
QString fileName = fi.fileName(); QString fileName = fi.fileName();
...@@ -337,7 +338,7 @@ MessagesAdapter::deleteInteraction(const QString& arg) ...@@ -337,7 +338,7 @@ MessagesAdapter::deleteInteraction(const QString& arg)
void void
MessagesAdapter::openFile(const QString& arg) MessagesAdapter::openFile(const QString& arg)
{ {
QUrl fileUrl("file://" + arg); QUrl fileUrl("file:///" + arg);
if (!QDesktopServices::openUrl(fileUrl)) { if (!QDesktopServices::openUrl(fileUrl)) {
qDebug() << "Couldn't open file: " << fileUrl; qDebug() << "Couldn't open file: " << fileUrl;
} }
...@@ -399,9 +400,9 @@ MessagesAdapter::pasteKeyDetected() ...@@ -399,9 +400,9 @@ MessagesAdapter::pasteKeyDetected()
*/ */
for (int i = 0; i < urlList.size(); ++i) { for (int i = 0; i < urlList.size(); ++i) {
/* /*
* Trim file:// from url. * Trim file:// or file:/// from url.
*/ */
QString filePath = urlList.at(i).toString().remove("file://"); QString filePath = urlList.at(i).toString().remove(QRegExp("^file:\\/{2,3}"));
QByteArray imageFormat = QImageReader::imageFormat(filePath); QByteArray imageFormat = QImageReader::imageFormat(filePath);
/* /*
......
...@@ -350,9 +350,9 @@ UtilsAdapter::getAbsPath(QString path) ...@@ -350,9 +350,9 @@ UtilsAdapter::getAbsPath(QString path)
// contain 'file:///' for reasons we don't understand. // contain 'file:///' for reasons we don't understand.
// TODO: this logic can be refactored into the JamiFileDialog component. // TODO: this logic can be refactored into the JamiFileDialog component.
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return path.replace("file:///", "").replace("\n", "").replace("\r", ""); return path.replace(QRegExp("^file:\\/{2,3}"), "").replace("\n", "").replace("\r", "");
#else #else
return path.replace("file:///", "/").replace("\n", "").replace("\r", ""); return path.replace(QRegExp("^file:\\/{2,3}"), "/").replace("\n", "").replace("\r", "");
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment