diff --git a/linphone-app/src/components/contact/VcardModel.cpp b/linphone-app/src/components/contact/VcardModel.cpp index 38a8d49cf..a81e67a26 100644 --- a/linphone-app/src/components/contact/VcardModel.cpp +++ b/linphone-app/src/components/contact/VcardModel.cpp @@ -263,7 +263,7 @@ void VcardModel::setCountry (const QString &country) { // ----------------------------------------------------------------------------- -QVariantList VcardModel::getSipAddresses () const { +QVariantList VcardModel::getSipAddresses () const { QVariantList list; if(mVcard->getVcard()){ shared_ptr core = CoreManager::getInstance()->getCore(); @@ -282,6 +282,25 @@ QVariantList VcardModel::getSipAddresses () const { return list; } +QVariantList VcardModel::getSipUsernames () const { + QVariantList list; + if(mVcard->getVcard()){ + shared_ptr core = CoreManager::getInstance()->getCore(); + for (const auto &address : mVcard->getVcard()->getImpp()) { + string value = address->getValue(); + shared_ptr linphoneAddress = core->createAddress(value); + + if (linphoneAddress) + list << Utils::coreStringToAppString(linphoneAddress->getUsername()); + else + qWarning() << QStringLiteral("Unable to parse sip address: `%1`") + .arg(QString::fromStdString(value)); + } + + } + return list; +} + QList> VcardModel::getLinphoneSipAddresses () const { QList> list; if(mVcard->getVcard()){ diff --git a/linphone-app/src/components/contact/VcardModel.hpp b/linphone-app/src/components/contact/VcardModel.hpp index f96cdcb5e..1b7f18998 100644 --- a/linphone-app/src/components/contact/VcardModel.hpp +++ b/linphone-app/src/components/contact/VcardModel.hpp @@ -43,6 +43,7 @@ class VcardModel : public QObject { Q_PROPERTY(QVariantMap address READ getAddress NOTIFY vcardUpdated); //Q_PROPERTY(QString sipAddress Q_PROPERTY(QVariantList sipAddresses READ getSipAddresses NOTIFY vcardUpdated); + Q_PROPERTY(QVariantList sipUsernames READ getSipUsernames NOTIFY vcardUpdated); Q_PROPERTY(QVariantList companies READ getCompanies NOTIFY vcardUpdated); Q_PROPERTY(QVariantList emails READ getEmails NOTIFY vcardUpdated); Q_PROPERTY(QVariantList urls READ getUrls NOTIFY vcardUpdated); @@ -71,6 +72,7 @@ public: // --------------------------------------------------------------------------- QVariantList getSipAddresses () const; + QVariantList getSipUsernames () const; QList> getLinphoneSipAddresses () const; QVariantMap getAddress () const; QVariantList getEmails () const; diff --git a/linphone-app/src/components/participant/ParticipantListModel.cpp b/linphone-app/src/components/participant/ParticipantListModel.cpp index c06bb26f3..0be6f5219 100644 --- a/linphone-app/src/components/participant/ParticipantListModel.cpp +++ b/linphone-app/src/components/participant/ParticipantListModel.cpp @@ -93,7 +93,7 @@ QString ParticipantListModel::addressesToString()const{ for(auto item : mList){ auto participant = item.objectCast(); if( participant->getParticipant())// is Participant. We test it because this participant is not accepted by chat room yet. - txt << Utils::coreStringToAppString(participant->getParticipant()->getAddress()->asStringUriOnly()); + txt << Utils::toDisplayString(Utils::coreStringToAppString(participant->getParticipant()->getAddress()->asStringUriOnly())); } txt.removeFirst();// Remove me return txt.join(", "); diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp index 86c99afed..dc41266ea 100644 --- a/linphone-app/src/utils/Utils.cpp +++ b/linphone-app/src/utils/Utils.cpp @@ -133,6 +133,20 @@ QString Utils::toDateString(QDateTime date, const QString& format){ return QLocale().toString(getOffsettedUTC(date), (!format.isEmpty() ? format : QLocale().dateFormat()) ); } +// Return custom address to be displayed on UI. +// In order to return only the username and to remove all domains from the GUI, you may just change the default mode. +QString Utils::toDisplayString(const QString& str, SipDisplayMode displayMode){ + if(displayMode == SIP_DISPLAY_ALL) return str; + std::shared_ptr addr = linphone::Factory::get()->createAddress(str.toStdString()); + QString displayString; + if( addr && ( (displayMode & SIP_DISPLAY_USERNAME) == SIP_DISPLAY_USERNAME)) + displayString = Utils::coreStringToAppString(addr->getUsername()); + if(displayString.isEmpty()) + return str; + else + return displayString; +} + QString Utils::getDisplayName(const QString& address){ return getDisplayName(interpretUrl(address)); } diff --git a/linphone-app/src/utils/Utils.hpp b/linphone-app/src/utils/Utils.hpp index 1242a37ac..926cabb1f 100644 --- a/linphone-app/src/utils/Utils.hpp +++ b/linphone-app/src/utils/Utils.hpp @@ -55,6 +55,13 @@ class Utils : public QObject{ Q_OBJECT public: Utils(QObject * parent = nullptr) : QObject(parent){} + + typedef enum{ + SIP_DISPLAY_USERNAME = 0, + SIP_DISPLAY_ALL = -1 + }SipDisplayMode; + Q_ENUM(SipDisplayMode) + // Qt interfaces Q_INVOKABLE static bool hasCapability(const QString& address, const LinphoneEnums::FriendCapability& capability); Q_INVOKABLE static QDateTime addMinutes(QDateTime date, const int& min); @@ -62,6 +69,7 @@ public: Q_INVOKABLE static QString toDateTimeString(QDateTime date); Q_INVOKABLE static QString toTimeString(QDateTime date, const QString& format = "hh:mm:ss"); Q_INVOKABLE static QString toDateString(QDateTime date, const QString& format = ""); + Q_INVOKABLE static QString toDisplayString(const QString& str, SipDisplayMode displayMode = SIP_DISPLAY_ALL); static void cleanDisplayNameCache(const QString& address = "");// if "", clean all cache Q_INVOKABLE static QString getDisplayName(const QString& address); Q_INVOKABLE static QString getInitials(const QString& username); // Support UTF32 diff --git a/linphone-app/ui/modules/Common/Form/CommonItemDelegate.qml b/linphone-app/ui/modules/Common/Form/CommonItemDelegate.qml index 8442caae7..8f5469e24 100644 --- a/linphone-app/ui/modules/Common/Form/CommonItemDelegate.qml +++ b/linphone-app/ui/modules/Common/Form/CommonItemDelegate.qml @@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3 import Common 1.0 import Common.Styles 1.0 +import UtilsCpp 1.0 // ============================================================================= Controls.ItemDelegate { @@ -64,7 +65,7 @@ Controls.ItemDelegate { pointSize: CommonItemDelegateStyle.contentItem.text.pointSize } - text: item.flattenedModel[container.textRole] || modelData + text: UtilsCpp.toDisplayString(item.flattenedModel[container.textRole] || modelData) } Item { diff --git a/linphone-app/ui/modules/Linphone/Account/AccountStatus.qml b/linphone-app/ui/modules/Linphone/Account/AccountStatus.qml index 12c107cfc..8a60bff1d 100644 --- a/linphone-app/ui/modules/Linphone/Account/AccountStatus.qml +++ b/linphone-app/ui/modules/Linphone/Account/AccountStatus.qml @@ -39,7 +39,7 @@ Item { spacing: AccountStatusStyle.horizontalSpacing Item { - Layout.alignment: Qt.AlignBottom | Qt.AlignLeft + Layout.alignment: !subtitle.visible ? Qt.AlignVCenter | Qt.AlignLeft: Qt.AlignBottom | Qt.AlignLeft Layout.bottomMargin: AccountStatusStyle.presenceLevel.bottomMargin Layout.preferredHeight: AccountStatusStyle.presenceLevel.size Layout.preferredWidth: AccountStatusStyle.presenceLevel.size @@ -70,7 +70,7 @@ Item { Text { id:username Layout.fillWidth: true - Layout.alignment: accountStatus.noAccountConfigured ? Qt.AlignVCenter | Qt.AlignLeft: Qt.AlignBottom | Qt.AlignLeft + Layout.alignment: !subtitle.visible ? Qt.AlignVCenter | Qt.AlignLeft: Qt.AlignBottom | Qt.AlignLeft color: AccountStatusStyle.username.colorModel.color elide: Text.ElideRight font.bold: true @@ -104,13 +104,14 @@ Item { }//RowLayout Text { + id: subtitle Layout.preferredHeight:parent.height / 2 Layout.preferredWidth:parent.width - visible: !accountStatus.noAccountConfigured + visible: !accountStatus.noAccountConfigured && text != username.text color: AccountStatusStyle.sipAddress.colorModel.color elide: Text.ElideRight font.pointSize: AccountStatusStyle.sipAddress.pointSize - text: AccountSettingsModel.sipAddress + text: UtilsCpp.toDisplayString(AccountSettingsModel.sipAddress) verticalAlignment: Text.AlignTop } }//ColumnLayout diff --git a/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml b/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml index d99cbf7aa..0b1c9b860 100644 --- a/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml +++ b/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml @@ -45,13 +45,16 @@ RowLayout { // The avatar is only visible for the first message of a incoming messages sequence. visible: index <= 0 ? true // 1. First message, so visible. : $chatEntry && !$chatEntry.isOutgoing && !mainRow.isTopGrouped || false + TooltipArea{ delay:0 text:avatar.username+'\n'+$chatEntry.fromSipAddress maxWidth: mainRow.width isClickable: true onClicked: { - window.mainSearchBar.text = $chatEntry.fromSipAddress + window.mainSearchBar.text = UtilsCpp.toDisplayString($chatEntry.fromSipAddress) + } + } } } } diff --git a/linphone-app/ui/modules/Linphone/Contact/Contact.qml b/linphone-app/ui/modules/Linphone/Contact/Contact.qml index c397f7f9f..5ca8f3d88 100644 --- a/linphone-app/ui/modules/Linphone/Contact/Contact.qml +++ b/linphone-app/ui/modules/Linphone/Contact/Contact.qml @@ -123,7 +123,8 @@ Rectangle { ? item.subject : item.username subtitleText: entry && item.showSubtitle - ? item.subtitle + ? UtilsCpp.toDisplayString( + item.subtitle ? item.subtitle : (entry.isOneToOne == undefined || entry.isOneToOne) && (entry.haveEncryption == undefined || !entry.haveEncryption) ? item.organizer @@ -132,6 +133,7 @@ Rectangle { : entry.participants ? entry.participants.addressesToString : '' + ) : '' } diff --git a/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml b/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml index bd944a223..b2b12b25b 100644 --- a/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml +++ b/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml @@ -95,7 +95,7 @@ Column { anchors.left: parent.left anchors.right: parent.right height: (parent.height-parent.topPadding-parent.bottomPadding)/parent.visibleChildren.length - visible: subtitle.fullText != '' + visible: subtitle.fullText != '' && subtitle.fullText != title.fullText TextEdit { id:subtitle property string fullText diff --git a/linphone-app/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml b/linphone-app/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml index 3d1079c05..d52aa8fd6 100644 --- a/linphone-app/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml +++ b/linphone-app/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml @@ -44,7 +44,7 @@ Notification { property ChatRoomModel chatRoomModel : notification.timelineModel.getChatRoomModel() property var sipObserver: SipAddressesModel.getSipAddressObserver(notification.fullPeerAddress, notification.fullLocalAddress) subtitle: chatRoomModel.isOneToOne - ? SipAddressesModel.cleanSipAddress(notification.fullPeerAddress) + ? UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(notification.fullPeerAddress)) : UtilsCpp.getDisplayName(notification.fullPeerAddress) entry: chatRoomModel ? chatRoomModel : sipObserver Component.onDestruction: sipObserver=null// Need to set it to null because of not calling destructor if not. diff --git a/linphone-app/ui/views/App/Calls/AbstractStartingCall.qml b/linphone-app/ui/views/App/Calls/AbstractStartingCall.qml index 4e3a446eb..e70cb6e6c 100644 --- a/linphone-app/ui/views/App/Calls/AbstractStartingCall.qml +++ b/linphone-app/ui/views/App/Calls/AbstractStartingCall.qml @@ -43,7 +43,7 @@ Rectangle { anchors.horizontalCenter: parent.horizontalCenter height: CallStyle.header.contactDescription.height horizontalTextAlignment: Text.AlignHCenter - subtitleText: SipAddressesModel.cleanSipAddress(call.peerAddress) + subtitleText: UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(call.peerAddress)) titleText: _sipAddressObserver ? UtilsCpp.getDisplayName(_sipAddressObserver.peerAddress) : '' width: contentWidth } diff --git a/linphone-app/ui/views/App/Calls/Conference.qml b/linphone-app/ui/views/App/Calls/Conference.qml index e6653659d..0c6826726 100644 --- a/linphone-app/ui/views/App/Calls/Conference.qml +++ b/linphone-app/ui/views/App/Calls/Conference.qml @@ -137,7 +137,7 @@ Rectangle { width: parent.width horizontalTextAlignment: Text.AlignHCenter - subtitleText: SipAddressesModel.cleanSipAddress(parent.sipAddress) + subtitleText: UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(parent.sipAddress)) titleText: parent._sipAddressObserver ? UtilsCpp.getDisplayName(parent._sipAddressObserver.peerAddress) : '' } IncallAvatar { diff --git a/linphone-app/ui/views/App/Calls/Incall.qml b/linphone-app/ui/views/App/Calls/Incall.qml index c22c5e9f0..caed1cc9f 100644 --- a/linphone-app/ui/views/App/Calls/Incall.qml +++ b/linphone-app/ui/views/App/Calls/Incall.qml @@ -231,9 +231,9 @@ Rectangle { id: address Layout.fillWidth: true horizontalAlignment: Qt.AlignHCenter - visible: !conferenceModel && callModel && !callModel.isConference + visible: !conferenceModel && callModel && !callModel.isConference && text != title.text text: !conferenceModel && callModel - ? SipAddressesModel.cleanSipAddress(callModel.peerAddress) + ? UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(callModel.peerAddress)) : '' color: IncallStyle.title.colorModel.color font.pointSize: IncallStyle.title.addressPointSize diff --git a/linphone-app/ui/views/App/Calls/WaitingRoom.qml b/linphone-app/ui/views/App/Calls/WaitingRoom.qml index ef14a0369..ebcffca50 100644 --- a/linphone-app/ui/views/App/Calls/WaitingRoom.qml +++ b/linphone-app/ui/views/App/Calls/WaitingRoom.qml @@ -208,6 +208,7 @@ Rectangle { visible: !mainItem.conferenceInfoModel spacing: 10 Text{ + id: displayName Layout.alignment: Qt.AlignCenter text: mainItem._sipAddressObserver ? UtilsCpp.getDisplayName(mainItem._sipAddressObserver.peerAddress) : '' color: WaitingRoomStyle.callee.colorModel.color @@ -218,12 +219,12 @@ Rectangle { } Text{ Layout.fillWidth: true - text: mainItem.callModel && SipAddressesModel.cleanSipAddress(mainItem.callModel.peerAddress) + text: mainItem.callModel && UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(mainItem.callModel.peerAddress)) color: WaitingRoomStyle.callee.colorModel.color font.pointSize: WaitingRoomStyle.callee.addressPointSize horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter - visible: mainItem.callModel && !mainItem.conferenceInfoModel + visible: mainItem.callModel && !mainItem.conferenceInfoModel && text != displayName.text } } // ------------------------------------------------------------------------- diff --git a/linphone-app/ui/views/App/Main/Conversation.qml b/linphone-app/ui/views/App/Main/Conversation.qml index c537c83d5..47cd97b65 100644 --- a/linphone-app/ui/views/App/Main/Conversation.qml +++ b/linphone-app/ui/views/App/Main/Conversation.qml @@ -154,7 +154,7 @@ ColumnLayout { }else if(chatRoomModel.isSecure()) return chatRoomModel.participants.addressesToString; else - return SipAddressesModel.cleanSipAddress(chatRoomModel.sipAddress) + return UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(chatRoomModel.sipAddress)) }else return '' diff --git a/linphone-app/ui/views/App/Main/HistoryView.qml b/linphone-app/ui/views/App/Main/HistoryView.qml index fd6947fdd..595e2c470 100644 --- a/linphone-app/ui/views/App/Main/HistoryView.qml +++ b/linphone-app/ui/views/App/Main/HistoryView.qml @@ -57,9 +57,7 @@ ColumnLayout { presenceLevel: historyView._sipAddressObserver?Presence.getPresenceLevel( historyView._sipAddressObserver.presenceStatus ):null - presenceTimestamp: historyView._sipAddressObserver?Presence.getPresenceTimestamp( - historyView._sipAddressObserver.presenceStatus - ):null + presenceTimestamp: historyView._sipAddressObserver && historyView._sipAddressObserver.contact ? historyView._sipAddressObserver.contact.presenceTimestamp :null username: historyView.entry && historyView.entry.wasConference ? historyView.entry.title @@ -76,10 +74,10 @@ ColumnLayout { subtitleText: historyView.entry && historyView.entry.wasConference ? '' - : SipAddressesModel.cleanSipAddress(historyView.peerAddress) - subtitleColor: HistoryViewStyle.bar.description.subtitleColor + : UtilsCpp.toDisplayString(SipAddressesModel.cleanSipAddress(historyView.peerAddress)) + subtitleColor: HistoryViewStyle.bar.description.subtitleColor.color titleText: avatar.username - titleColor: HistoryViewStyle.bar.description.titleColor + titleColor: HistoryViewStyle.bar.description.titleColor.color visible:peerAddress } diff --git a/linphone-app/ui/views/App/Main/MainWindow.qml b/linphone-app/ui/views/App/Main/MainWindow.qml index 9775b017f..243945835 100644 --- a/linphone-app/ui/views/App/Main/MainWindow.qml +++ b/linphone-app/ui/views/App/Main/MainWindow.qml @@ -9,6 +9,7 @@ import Utils 1.0 import App.Styles 1.0 import ColorsList 1.0 +import UtilsCpp 1.0 import 'MainWindow.js' as Logic import 'qrc:/ui/scripts/Utils/utils.js' as Utils @@ -139,7 +140,7 @@ ApplicationWindow { Layout.fillWidth: false TooltipArea { - text: AccountSettingsModel.sipAddress + text: UtilsCpp.toDisplayString(AccountSettingsModel.sipAddress) hoveringCursor: Qt.PointingHandCursor }