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
This commit is contained in:
Ming Rui Zhang
2020-09-30 13:39:21 -04:00
committed by Andreas Traczyk
parent 80c26e9696
commit 55cbcd38d2
3 changed files with 9 additions and 8 deletions

View File

@@ -262,11 +262,12 @@ MessagesAdapter::sendImage(const QString& message)
* Img tag contains file paths.
*/
// TODO: put all QRegExp strings together
QString msg(message);
#ifdef Q_OS_WIN
msg = msg.replace("file://", "");
msg = msg.replace(QRegExp("^file:\\/{2,3}"), "");
#else
msg = msg.replace("file://", "/");
msg = msg.replace(QRegExp("^file:\\/{2,3}"), "/");
#endif
QFileInfo fi(msg);
QString fileName = fi.fileName();
@@ -337,7 +338,7 @@ MessagesAdapter::deleteInteraction(const QString& arg)
void
MessagesAdapter::openFile(const QString& arg)
{
QUrl fileUrl("file://" + arg);
QUrl fileUrl("file:///" + arg);
if (!QDesktopServices::openUrl(fileUrl)) {
qDebug() << "Couldn't open file: " << fileUrl;
}
@@ -399,9 +400,9 @@ MessagesAdapter::pasteKeyDetected()
*/
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);
/*