> parse(const QString& text, const QRegularExpression regex);
+
+ QRegularExpression mIriRegularExpression;//https://tools.ietf.org/html/rfc3987
+ QRegularExpression mUriRegularExpression;//https://tools.ietf.org/html/rfc3986
+};
+
+
+
+#endif
\ No newline at end of file
diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp
index 1ff0e0351..5b8cf8025 100644
--- a/linphone-app/src/utils/Utils.cpp
+++ b/linphone-app/src/utils/Utils.cpp
@@ -31,6 +31,7 @@
#include "config.h"
#include "Utils.hpp"
+#include "UriTools.hpp"
#include "components/core/CoreManager.hpp"
#include "components/contacts/ContactsListModel.hpp"
#include "components/contact/ContactModel.hpp"
@@ -604,4 +605,46 @@ QString Utils::getFileChecksum(const QString& filePath){
}
}
return QString();
+}
+
+QString Utils::encodeTextToQmlRichFormat(const QString& text, const QVariantMap& options){
+
+ QString images;
+ QStringList formattedText;
+ QStringList imageFormat;
+ for(auto format : QImageReader::supportedImageFormats())
+ imageFormat.append(QString::fromLatin1(format).toUpper());
+ auto iriParsed = UriTools::parseIri(text);
+ for(int i = 0 ; i < iriParsed.size() ; ++i){
+ QString iri = iriParsed[i].second.replace('&', "&")
+ .replace('<', "\u2063<")
+ .replace('>', "\u2063>")
+ .replace('"', """)
+ .replace('\'', "'");
+ if(!iriParsed[i].first)
+ formattedText.append(iri);
+ else{
+ QString uri = iriParsed[i].second.left(3) == "www" ? "http://"+iriParsed[i].second : iriParsed[i].second ;
+ int extIndex = iriParsed[i].second.lastIndexOf('.');
+ QString ext;
+ if( extIndex >= 0)
+ ext = iriParsed[i].second.mid(extIndex+1).toUpper();
+ if(imageFormat.contains(ext.toLatin1())){// imagesHeight is not used because of bugs on display (blank image if set without width)
+ images += "
";
+ }else
+ formattedText.append( "" + iri + "");
+ }
+ }
+ if(images != "")
+ images = "" + images +"
";
+
+ return images + "" + formattedText.join("") + "
";
}
\ No newline at end of file
diff --git a/linphone-app/src/utils/Utils.hpp b/linphone-app/src/utils/Utils.hpp
index 3a435a297..8c8fcc8b5 100644
--- a/linphone-app/src/utils/Utils.hpp
+++ b/linphone-app/src/utils/Utils.hpp
@@ -66,6 +66,7 @@ public:
Q_INVOKABLE QSize getImageSize(const QString& url);
Q_INVOKABLE static QPoint getCursorPosition();
Q_INVOKABLE static QString getFileChecksum(const QString& filePath);
+ Q_INVOKABLE static QString encodeTextToQmlRichFormat(const QString& text, const QVariantMap& options);
//----------------------------------------------------------------------------------
diff --git a/linphone-app/ui/modules/Linphone/Chat/ChatTextMessage.qml b/linphone-app/ui/modules/Linphone/Chat/ChatTextMessage.qml
index a3cc6428a..794e63cab 100644
--- a/linphone-app/ui/modules/Linphone/Chat/ChatTextMessage.qml
+++ b/linphone-app/ui/modules/Linphone/Chat/ChatTextMessage.qml
@@ -42,7 +42,7 @@ TextEdit {
font.family: customFont.family
font.pointSize: Units.dp * customFont.pointSize
- text: visible ? Utils.encodeTextToQmlRichFormat(contentModel.text, {
+ text: visible ? UtilsCpp.encodeTextToQmlRichFormat(contentModel.text, {
imagesHeight: ChatStyle.entry.message.images.height,
imagesWidth: ChatStyle.entry.message.images.width
})
diff --git a/linphone-app/ui/modules/Linphone/Styles/Chat/ChatStyle.qml b/linphone-app/ui/modules/Linphone/Styles/Chat/ChatStyle.qml
index 5027e8946..07bda7f80 100644
--- a/linphone-app/ui/modules/Linphone/Styles/Chat/ChatStyle.qml
+++ b/linphone-app/ui/modules/Linphone/Styles/Chat/ChatStyle.qml
@@ -243,7 +243,8 @@ QtObject {
}
property QtObject images: QtObject {
- property int height: 48
+ property int height: 240
+ property int width: 240
}
property QtObject incoming: QtObject {
diff --git a/linphone-app/ui/scripts/Utils/uri-tools.js b/linphone-app/ui/scripts/Utils/uri-tools.js
deleted file mode 100644
index b32941cd4..000000000
--- a/linphone-app/ui/scripts/Utils/uri-tools.js
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2010-2020 Belledonne Communications SARL.
- *
- * This file is part of linphone-desktop
- * (see https://www.linphone.org).
- *
- * This program 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.
- *
- * This program 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 this program. If not, see .
- */
-// =============================================================================
-// Library to deal with URI.
-// See: https://tools.ietf.org/html/rfc3986#section-1.3
-// =============================================================================
-
-.pragma library
-
-// Options.
-
-// If true, strings starting with `www.` can be detected.
-// Not standard but helpful.
-var SUPPORTS_URL = true
-
-// Level 0. --------------------------------------------------------------------
-
-var URI_DEC_OCTET = '(?:' +
- '25[0-5]' +
- '|' + '2[0-4]\\d' +
- '|' + '1\\d{2}' +
- '|' + '[1-9]\\d' +
- '|' + '\\d' +
-')'
-
-var URI_H16 = '[0-9A-Fa-f]{1,4}'
-var URI_PCT_ENCODED = '%[A-Fa-f\\d]{2}'
-var URI_PORT = '\\d*'
-var URI_SCHEME = '[a-zA-Z][\\w+\-\.]*'
-var URI_SUB_DELIMS = '[!$&\'()*+,;=]'
-var URI_UNRESERVED = '[\\w\-\._~]'
-
-// Level 1. --------------------------------------------------------------------
-
-var URI_IPV_FUTURE = 'v[0-9A-Fa-f]+\\.' + '(?:' +
- URI_UNRESERVED +
- URI_SUB_DELIMS +
- ':' +
-')'
-
-var URI_IPV4_ADDRESS = URI_DEC_OCTET + '\\.' + URI_DEC_OCTET + '\\.' +
- URI_DEC_OCTET + '\\.' + URI_DEC_OCTET
-
-var URI_PCHAR = '(?:' +
- URI_UNRESERVED +
- '|' + URI_PCT_ENCODED +
- '|' + URI_SUB_DELIMS +
- '|' + '[:@]' +
-')'
-
-var URI_REG_NAME = '(?:' +
- URI_UNRESERVED +
- '|' + URI_PCT_ENCODED +
- '|' + URI_SUB_DELIMS +
-')*'
-
-var URI_USERINFO = '(?:' +
- URI_UNRESERVED +
- '|' + URI_PCT_ENCODED +
- '|' + URI_SUB_DELIMS +
- '|' + ':' +
-')*'
-
-// Level 2. --------------------------------------------------------------------
-
-var URI_FRAGMENT = '(?:' +
- URI_PCHAR +
- '|' + '[/?]' +
-')*'
-
-var URI_LS32 = '(?:' +
- URI_H16 + ':' + URI_H16 +
- '|' + URI_IPV4_ADDRESS +
-')'
-
-var URI_QUERY = '(?:' +
- URI_PCHAR +
- '|' + '[/?]' +
-')*'
-
-var URI_SEGMENT = URI_PCHAR + '*'
-var URI_SEGMENT_NZ = URI_PCHAR + '+'
-
-// Level 3. --------------------------------------------------------------------
-
-var URI_IPV6_ADDRESS = '(?:' +
- '(?:' + URI_H16 + ':){6}' + URI_LS32 +
- '|' + '::(?:' + URI_H16 + ':){5}' + URI_LS32 +
- '|' + '\\[' + URI_H16 + '\\]::(?:' + URI_H16 + ':){4}' + URI_LS32 +
- '|' + '\\[' + '(?:' + URI_H16 + ':)?' + URI_H16 + '\\]::(?:' + URI_H16 + ':){3}' + URI_LS32 +
- '|' + '\\[' + '(?:' + URI_H16 + ':){0,2}' + URI_H16 + '\\]::(?:' + URI_H16 + ':){2}' + URI_LS32 +
- '|' + '\\[' + '(?:' + URI_H16 + ':){0,3}' + URI_H16 + '\\]::' + URI_H16 + ':' + URI_LS32 +
- '|' + '\\[' + '(?:' + URI_H16 + ':){0,4}' + URI_H16 + '\\]::' + URI_LS32 +
- '|' + '\\[' + '(?:' + URI_H16 + ':){0,5}' + URI_H16 + '\\]::' + URI_H16 +
- '|' + '\\[' + '(?:' + URI_H16 + ':){0,6}' + URI_H16 + '\\]::' +
-')'
-
-var URI_PATH_ABEMPTY = '(?:' + '/' + URI_SEGMENT + ')*'
-
-var URI_PATH_ABSOLUTE = '/' +
- '(?:' + URI_SEGMENT_NZ + '(?:' + '/' + URI_SEGMENT + ')*' + ')?'
-
-var URI_PATH_ROOTLESS =
- URI_SEGMENT_NZ + '(?:' + '/' + URI_SEGMENT + ')*'
-
-// Level 4. --------------------------------------------------------------------
-
-var URI_IP_LITERAL = '\\[' +
- '(?:' +
- URI_IPV6_ADDRESS +
- '|' + URI_IPV_FUTURE +
- ')' +
-'\\]'
-
-// Level 5. --------------------------------------------------------------------
-
-var URI_HOST = '(?:' +
- URI_REG_NAME +
- '|' + URI_IPV4_ADDRESS +
- '|' + URI_IP_LITERAL +
-')'
-
-// Level 6. --------------------------------------------------------------------
-
-var URI_AUTHORITY = '(?:' + URI_USERINFO + '@' + ')?' +
- URI_HOST +
- '(?:' + ':' + URI_PORT + ')?'
-
-// Level 7. --------------------------------------------------------------------
-
-// `path-empty` not used.
-var URI_HIER_PART = '(?:' +
- '//' + URI_AUTHORITY + URI_PATH_ABEMPTY +
- '|' + URI_PATH_ABSOLUTE +
- '|' + URI_PATH_ROOTLESS +
-')'
-
-// Level 8. --------------------------------------------------------------------
-
-// Regex to match URI. It respects the RFC 3986.
-var URI = (SUPPORTS_URL
- ? '(?:' + URI_SCHEME + ':' + '|' + 'www\\.' + ')'
- : URI_SCHEME + ':'
-) + URI_HIER_PART + '(?:' + '\\?' + URI_QUERY + ')?' +
- '(?:' + '#' + URI_FRAGMENT + ')?'
-
-var URI_REGEX = new RegExp('(' + URI + ')', 'g')
diff --git a/linphone-app/ui/scripts/Utils/utils.js b/linphone-app/ui/scripts/Utils/utils.js
index 3b8c80bc8..d4a0e1132 100644
--- a/linphone-app/ui/scripts/Utils/utils.js
+++ b/linphone-app/ui/scripts/Utils/utils.js
@@ -27,7 +27,6 @@
.import Linphone 1.0 as Linphone
.import 'port-tools.js' as PortTools
-.import 'uri-tools.js' as UriTools
// =============================================================================
// Constants.
@@ -97,51 +96,6 @@ function createObject (source, parent, options) {
// -----------------------------------------------------------------------------
-function encodeTextToQmlRichFormat (text, options) {
- var images = ''
-
- if (!options) {
- options = {}
- }
-
- var formattedText = execAll(UriTools.URI_REGEX, text, function (str, valid) {
- if (!valid) {
- return unscapeHtml(str)
- }
-
- var uri = startsWith(str, 'www.') ? 'http://' + str : str
-
- var ext = getExtension(str)
- if (includes([ 'jpg', 'jpeg', 'gif', 'png', 'svg' ], ext)) {
- images += '
'
- }
-
- return '' + unscapeHtml(str) + ''
- }).join('')
- if (images.length > 0) {
- images = '' + images + '
'
- }
-
- return images.concat('' + formattedText + '
')
-}
-
-function extractFirstUri (str) {
- var res = str.match(UriTools.URI_REGEX)
- return res == null || startsWith(res[0], 'www')
- ? undefined
- : res[0]
-}
-
-// -----------------------------------------------------------------------------
-
function getSystemPathFromUri (uri) {
var str = uri.toString()
if (startsWith(str, 'file://')) {
@@ -385,40 +339,6 @@ function dirname (str) {
// -----------------------------------------------------------------------------
-function execAll (regex, text, cb) {
- var index = 0
- var arr = []
- var match
-
- if (!cb) {
- cb = function (text) {
- return text
- }
- }
-
- while ((match = regex.exec(text))) {
- var curIndex = match.index
- var matchStr = match[0]
-
- if (curIndex > index) {
- arr.push(cb(text.substring(index, curIndex), false))
- }
-
- arr.push(cb(matchStr, true))
-
- index = curIndex + matchStr.length
- }
-
- var length = text.length
- if (index < length) {
- arr.push(cb(text.substring(index, length)))
- }
-
- return arr
-}
-
-// -----------------------------------------------------------------------------
-
function extractProperties (obj, pattern) {
if (!pattern) {
return {}