diff --git a/Linphone/core/friend/FriendCore.cpp b/Linphone/core/friend/FriendCore.cpp index 5249d41d4..79488843d 100644 --- a/Linphone/core/friend/FriendCore.cpp +++ b/Linphone/core/friend/FriendCore.cpp @@ -349,9 +349,12 @@ QVariant FriendCore::getAddressAt(int index) const { return mAddressList[index]; } -void FriendCore::setAddressAt(int index, const QString &label, const QString &address) { +void FriendCore::setAddressAt(int index, const QString &label, QString address) { if (index < 0 || index >= mAddressList.count()) return; auto map = mAddressList[index].toMap(); + if (Utils::isUsername(address)) { + address = Utils::interpretUrl(address); + } auto oldLabel = map["label"].toString(); if (/*oldLabel != label || */ map["address"] != address) { mAddressList.replace(index, createFriendAddressVariant(label.isEmpty() ? oldLabel : label, address)); diff --git a/Linphone/core/friend/FriendCore.hpp b/Linphone/core/friend/FriendCore.hpp index 6b5ed8aa9..bd175dc0c 100644 --- a/Linphone/core/friend/FriendCore.hpp +++ b/Linphone/core/friend/FriendCore.hpp @@ -107,7 +107,7 @@ public: QVariant getAddressAt(int index) const; Q_INVOKABLE void appendAddress(const QString &addr); Q_INVOKABLE void removeAddress(int index); - Q_INVOKABLE void setAddressAt(int index, const QString &label, const QString &address); + Q_INVOKABLE void setAddressAt(int index, const QString &label, QString address); void setDefaultAddress(const QString &address); QString getDefaultAddress() const; diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index ce2fff99d..a9626c39c 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -283,15 +283,18 @@ QString Utils::formatDateElapsedTime(const QDateTime &date) { return QString::number(s) + " s"; } -QString Utils::generateLinphoneSipAddress(const QString &uri) { - QString ret = uri; - if (!ret.startsWith("sip:")) { - ret.prepend("sip:"); +QString Utils::interpretUrl(const QString &uri) { + QString address = uri; + + if (!address.contains('@')) { + App::postModelBlock([address, uri]() mutable { + auto addr = ToolModel::interpretUrl(uri); + if (addr) address = Utils::coreStringToAppString(addr->asStringUriOnly()); + }); + } else if (!address.startsWith("sip:")) { + address.prepend("sip:"); } - if (!ret.endsWith("@sip.linphone.org")) { - ret.append("@sip.linphone.org"); - } - return ret; + return address; } QString Utils::findAvatarByAddress(const QString &address) { diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 6280e9727..582d309ca 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -106,7 +106,7 @@ public: Q_INVOKABLE static int secsTo(const QString &start, const QString &end); Q_INVOKABLE static QDateTime addSecs(QDateTime date, int secs); Q_INVOKABLE static QDateTime addYears(QDateTime date, int years); - Q_INVOKABLE static QString generateLinphoneSipAddress(const QString &uri); + Q_INVOKABLE static QString interpretUrl(const QString &uri); Q_INVOKABLE static QString findAvatarByAddress(const QString &address); Q_INVOKABLE static VariantObject *findFriendByAddress(const QString &address); static QString generateSavedFilename(const QString &from, const QString &to); diff --git a/Linphone/view/Item/Contact/Avatar.qml b/Linphone/view/Item/Contact/Avatar.qml index bb96a7b3a..6c3366262 100644 --- a/Linphone/view/Item/Contact/Avatar.qml +++ b/Linphone/view/Item/Contact/Avatar.qml @@ -5,6 +5,7 @@ import QtQuick.Effects import Linphone import UtilsCpp +import SettingsCpp // Fill contact, account or call // Initials will be displayed if there isn't any avatar. @@ -15,13 +16,14 @@ StackView { property AccountGui account: null property FriendGui contact: null property CallGui call: null - property string address: account + property string _address: account ? account.core.identityAddress : call ? call.core.peerAddress : contact ? contact.core.defaultAddress : '' + property string address: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(_address) : _address property var displayNameObj: UtilsCpp.getDisplayName(address) property string displayNameVal: displayNameObj ? displayNameObj.value : "" property bool haveAvatar: (account && account.core.pictureUri ) diff --git a/Linphone/view/Item/Contact/ContactDescription.qml b/Linphone/view/Item/Contact/ContactDescription.qml index b341e9644..15c8d108b 100644 --- a/Linphone/view/Item/Contact/ContactDescription.qml +++ b/Linphone/view/Item/Contact/ContactDescription.qml @@ -4,13 +4,14 @@ import QtQuick.Controls import Linphone import UtilsCpp +import SettingsCpp ColumnLayout{ id: mainItem property AccountGui account: null property var displayName: account ? UtilsCpp.getDisplayName(account.core.identityAddress) : "" property string topText: displayName ? displayName.value : "" - property string bottomText: account ? account.core.identityAddress : "" + property string bottomText: account ? SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(account.core.identityAddress) : account.core.identityAddress : "" spacing: 0 width: topTextItem.implicitWidth Text { diff --git a/Linphone/view/Item/Contact/ContactEdition.qml b/Linphone/view/Item/Contact/ContactEdition.qml index 76cf7d24d..75b6f8531 100644 --- a/Linphone/view/Item/Contact/ContactEdition.qml +++ b/Linphone/view/Item/Contact/ContactEdition.qml @@ -1,11 +1,12 @@ import QtCore -import QtQuick 2.15 +import QtQuick import QtQuick.Controls as Control import QtQuick.Dialogs import QtQuick.Effects import QtQuick.Layouts import Linphone -import UtilsCpp 1.0 +import UtilsCpp +import SettingsCpp RightPanelLayout { id: mainItem @@ -167,9 +168,10 @@ RightPanelLayout { contentItem: RowLayout { TextField { onEditingFinished: { - if (text.length != 0) mainItem.contact.core.setAddressAt(index, qsTr("Address SIP"), text) + if (text.length != 0) mainItem.contact.core.setAddressAt(index, qsTr("Adresse SIP"), text) } - initialText: modelData.address + property string _initialText: modelData.address + initialText: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(_initialText) : _initialText backgroundColor: DefaultStyle.grey_0 Layout.preferredWidth: width Layout.preferredHeight: height @@ -285,4 +287,4 @@ RightPanelLayout { } } } -} \ No newline at end of file +} diff --git a/Linphone/view/Item/Contact/Sticker.qml b/Linphone/view/Item/Contact/Sticker.qml index d39683430..6f26cb813 100644 --- a/Linphone/view/Item/Contact/Sticker.qml +++ b/Linphone/view/Item/Contact/Sticker.qml @@ -3,7 +3,8 @@ import QtQuick.Effects import QtQuick.Layouts import QtQuick.Controls as Control import Linphone -import UtilsCpp 1.0 +import UtilsCpp +import SettingsCpp // Display a sticker from a call or from an account. // The Avatar is shown while the camera become available. @@ -180,7 +181,8 @@ Item { Text { Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter - text: mainItem.call && mainItem.call.core.peerAddress + property string _text: mainItem.call && mainItem.call.core.peerAddress + text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(_text) : _text color: DefaultStyle.grey_0 font { pixelSize: 14 * DefaultStyle.dp @@ -245,11 +247,12 @@ Item { anchors.leftMargin: 10 * DefaultStyle.dp anchors.bottomMargin: 10 * DefaultStyle.dp width: implicitWidth - text: mainItem.peerAddress != '' + property string _text: mainItem.peerAddress != '' ? mainItem.peerAddress : mainItem.account && mainItem.identityAddress ? mainItem.identityAddress.value : "" + text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(_text) : _text color: DefaultStyle.grey_0 font { pixelSize: 14 * DefaultStyle.dp diff --git a/Linphone/view/Layout/Meeting/AddParticipantsLayout.qml b/Linphone/view/Layout/Meeting/AddParticipantsLayout.qml index 033b3bc01..4d8a71354 100644 --- a/Linphone/view/Layout/Meeting/AddParticipantsLayout.qml +++ b/Linphone/view/Layout/Meeting/AddParticipantsLayout.qml @@ -1,9 +1,10 @@ -import QtQuick 2.15 +import QtQuick import QtQuick.Effects import QtQuick.Layouts import QtQuick.Controls as Control import Linphone -import UtilsCpp 1.0 +import UtilsCpp +import SettingsCpp ColumnLayout { id: mainItem @@ -148,7 +149,8 @@ ColumnLayout { spacing: 0 Text { id: sipAddr - text: UtilsCpp.generateLinphoneSipAddress(searchbar.text) + property string _text: UtilsCpp.interpretUrl(searchbar.text) + text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(_text) : _text font.pixelSize: 14 * DefaultStyle.dp } } diff --git a/Linphone/view/Page/Main/ContactPage.qml b/Linphone/view/Page/Main/ContactPage.qml index a3d114c9a..92d42dbb7 100644 --- a/Linphone/view/Page/Main/ContactPage.qml +++ b/Linphone/view/Page/Main/ContactPage.qml @@ -1,11 +1,11 @@ -import QtQuick 2.15 +import QtQuick import QtQuick.Effects import QtQuick.Layouts import QtQuick.Controls as Control import Linphone -import UtilsCpp 1.0 -import EnumsToStringCpp 1.0 -import SettingsCpp 1.0 +import UtilsCpp +import EnumsToStringCpp +import SettingsCpp AbstractMainPage { id: mainItem @@ -427,7 +427,8 @@ AbstractMainPage { } Text { Layout.fillWidth: true - text: modelData.address + property string _text: modelData.address + text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(_text) : _text font { pixelSize: 14 * DefaultStyle.dp weight: 400 * DefaultStyle.dp diff --git a/Linphone/view/Page/Main/MeetingPage.qml b/Linphone/view/Page/Main/MeetingPage.qml index c8cd78902..1970f65e1 100644 --- a/Linphone/view/Page/Main/MeetingPage.qml +++ b/Linphone/view/Page/Main/MeetingPage.qml @@ -3,7 +3,7 @@ import QtQuick.Effects import QtQuick.Layouts import QtQuick.Controls as Control import Linphone -import UtilsCpp 1.0 +import UtilsCpp // TODO : spacing AbstractMainPage {