fix empty display name

This commit is contained in:
Gaelle Braud 2024-11-18 17:21:51 +01:00
parent 932b83774c
commit 24f51fbf69
11 changed files with 39 additions and 28 deletions

View file

@ -66,7 +66,7 @@ CallHistoryCore::CallHistoryCore(const std::shared_ptr<linphone::CallLog> &callL
auto inFriend = Utils::findFriendByAddress(mRemoteAddress);
if (inFriend) {
auto friendGui = inFriend->getValue().value<FriendGui *>();
if (friendGui) mDisplayName = friendGui->getCore()->getDisplayName();
if (friendGui) mDisplayName = friendGui->getCore()->getFullName();
}
}
}
@ -89,7 +89,7 @@ void CallHistoryCore::setSelf(QSharedPointer<CallHistoryCore> me) {
QString displayName;
if (inFriend) {
auto friendGui = inFriend->getValue().value<FriendGui *>();
if (friendGui) displayName = friendGui->getCore()->getDisplayName();
if (friendGui) displayName = friendGui->getCore()->getFullName();
}
if (!displayName.isEmpty()) {
mCoreModelConnection->invokeToCore([this, displayName]() {

View file

@ -70,9 +70,9 @@ FriendCore::FriendCore(const std::shared_ptr<linphone::Friend> &contact, bool is
mFullName = Utils::coreStringToAppString(vcard->getFullName());
mVCardString = Utils::coreStringToAppString(vcard->asVcard4String());
}
if (defaultAddress) {
if (mGivenName.isEmpty()) mGivenName = Utils::coreStringToAppString(defaultAddress->getUsername());
}
if (mFullName.isEmpty()) mFullName = Utils::coreStringToAppString(contact->getName());
if (mFullName.isEmpty()) mFullName = Utils::coreStringToAppString(contact->getOrganization());
auto addresses = contact->getAddresses();
for (auto &address : addresses) {
mAddressList.append(
@ -108,8 +108,12 @@ FriendCore::FriendCore(const std::shared_ptr<linphone::Friend> &contact, bool is
mIsLdap = ToolModel::friendIsInFriendList(ToolModel::getLdapFriendList(), contact);
connect(this, &FriendCore::addressChanged, &FriendCore::allAddressesChanged);
connect(this, &FriendCore::phoneNumberChanged, &FriendCore::allAddressesChanged);
connect(this, &FriendCore::givenNameChanged, &FriendCore::displayNameChanged);
connect(this, &FriendCore::familyNameChanged, &FriendCore::displayNameChanged);
auto updateFullName = [this] {
auto name = (mGivenName.isEmpty() ? "" : mGivenName) + (mFamilyName.isEmpty() ? "" : mFamilyName);
if (!name.isEmpty()) setFullName(name);
};
connect(this, &FriendCore::givenNameChanged, updateFullName);
connect(this, &FriendCore::familyNameChanged, updateFullName);
}
FriendCore::FriendCore(const FriendCore &friendCore) {
@ -248,11 +252,18 @@ void FriendCore::reset(const FriendCore &contact) {
setIsSaved(mFriendModel != nullptr);
}
QString FriendCore::getDisplayName() const {
QString FriendCore::getFullName() const {
if (mFullName.isEmpty()) return mGivenName + " " + mFamilyName;
else return mFullName;
}
void FriendCore::setFullName(const QString &name) {
if (mFullName != name) {
mFullName = name;
emit fullNameChanged(name);
}
}
QString FriendCore::getGivenName() const {
return mGivenName;
}
@ -527,9 +538,8 @@ void FriendCore::writeIntoModel(std::shared_ptr<FriendModel> model) const {
mustBeInLinphoneThread(QString("[") + gClassName + "] " + Q_FUNC_INFO);
model->getFriend()->edit();
// needed to create the vcard if not created yet
model->setName(mFullName.isEmpty()
? mGivenName + (mFamilyName.isEmpty() || mGivenName.isEmpty() ? "" : " ") + mFamilyName
: mFullName);
auto name = mGivenName + (mFamilyName.isEmpty() || mGivenName.isEmpty() ? "" : " ") + mFamilyName;
model->setName(name.isEmpty() ? (mFullName.isEmpty() ? mOrganization : mFullName) : name);
auto core = CoreModel::getInstance()->getCore();
std::list<std::shared_ptr<linphone::Address>> addresses;

View file

@ -57,7 +57,7 @@ class FriendCore : public QObject, public AbstractObject {
Q_PROPERTY(int verifiedDeviceCount MEMBER mVerifiedDeviceCount NOTIFY verifiedDevicesChanged)
Q_PROPERTY(QString givenName READ getGivenName WRITE setGivenName NOTIFY givenNameChanged)
Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName NOTIFY familyNameChanged)
Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(QString fullName READ getFullName NOTIFY fullNameChanged)
Q_PROPERTY(QString organization READ getOrganization WRITE setOrganization NOTIFY organizationChanged)
Q_PROPERTY(QString job READ getJob WRITE setJob NOTIFY jobChanged)
Q_PROPERTY(QString defaultAddress READ getDefaultAddress WRITE setDefaultAddress NOTIFY defaultAddressChanged)
@ -81,7 +81,8 @@ public:
void setSelf(SafeSharedPointer<FriendCore> me);
void reset(const FriendCore &contact);
QString getDisplayName() const;
QString getFullName() const;
void setFullName(const QString &name);
QString getFamilyName() const;
void setFamilyName(const QString &name);
@ -154,8 +155,9 @@ protected:
signals:
void contactUpdated();
void displayNameChanged();
void givenNameChanged(const QString &name);
void familyNameChanged(const QString &name);
void givenNameChanged(QString name);
void familyNameChanged(QString name);
void fullNameChanged(QString name);
void starredChanged();
void phoneNumberChanged();
void addressChanged();

View file

@ -215,8 +215,8 @@ bool MagicSearchProxy::SortFilterList::lessThan(const QModelIndex &sourceLeft, c
bool rIsStored = r->getIsStored();
if (lIsStored && !rIsStored) return true;
else if (!lIsStored && rIsStored) return false;
auto lName = l->getDisplayName().toLower();
auto rName = r->getDisplayName().toLower();
auto lName = l->getFullName().toLower();
auto rName = r->getFullName().toLower();
return lName < rName;
}
return true;

View file

@ -83,7 +83,6 @@ QString ToolModel::getDisplayName(const std::shared_ptr<const linphone::Address>
if (address) {
auto linFriend = CoreModel::getInstance()->getCore()->findFriend(address);
if (linFriend) {
if (auto vcard = linFriend->getVcard()) displayName = Utils::coreStringToAppString(vcard->getFullName());
if (displayName.isEmpty()) displayName = Utils::coreStringToAppString(linFriend->getName());
}
if (displayName.isEmpty()) {

View file

@ -17,7 +17,7 @@ ColumnLayout {
property var computedContactNameObj: UtilsCpp.getDisplayName(contactAddress)
property string computedContactName: computedContactNameObj ? computedContactNameObj.value: ""
property string contactName: contact
? contact.core.displayName
? contact.core.fullName
: conferenceInfo
? conferenceInfo.core.subject
: computedContactName

View file

@ -26,8 +26,8 @@ Loader{
property var displayNameObj: UtilsCpp.getDisplayName(_address)
property string displayNameVal: account && account.core.displayName
? account.core.displayName
: contact && contact.core.displayName
? contact.core.displayName
: contact && contact.core.fullName
? contact.core.fullName
: displayNameObj
? displayNameObj.value
: ""

View file

@ -28,7 +28,7 @@ FocusScope {
property var previousInitial // Use directly previous initial
property int itemsRightMargin: 39 * DefaultStyle.dp
property var displayName: searchResultItem.core.displayName
property var displayName: searchResultItem.core.fullName
property string initial: displayName ? displayName[0].toLocaleLowerCase(ConstantsCpp.DefaultLocale) : ''
signal clicked(var mouse)

View file

@ -57,11 +57,11 @@ AbstractMainPage {
if (!contact) return
var mainWin = UtilsCpp.getMainWindow()
mainWin.showConfirmationLambdaPopup("",
qsTr("%1 sera supprimé des contacts. Voulez-vous continuer ?").arg(contact.core.displayName),
qsTr("%1 sera supprimé des contacts. Voulez-vous continuer ?").arg(contact.core.fullName),
"",
function (confirmed) {
if (confirmed) {
var name = contact.core.displayName
var name = contact.core.fullName
contact.core.remove()
UtilsCpp.showInformationPopup(qsTr("Supprimé"), qsTr("%1 a été supprimé").arg(name)) }
}
@ -339,7 +339,7 @@ AbstractMainPage {
property var computedContactNameObj: UtilsCpp.getDisplayName(contactAddress)
property string computedContactName: computedContactNameObj ? computedContactNameObj.value : ""
property string contactName: contact
? contact.core.displayName
? contact.core.fullName
: computedContactName
component LabelButton: ColumnLayout {
id: labelButton

View file

@ -149,7 +149,7 @@ ApplicationWindow {
if (parentItem == undefined) parentItem = mainWindow.contentItem
startCallPopup.parent = parentItem
if (contact) {
console.log("START CALL WITH", contact.core.displayName, "addresses count", contact.core.allAddresses.length)
console.log("START CALL WITH", contact.core.fullName, "addresses count", contact.core.allAddresses.length)
if (contact.core.allAddresses.length > 1) {
startCallPopup.contact = contact
startCallPopup.videoEnabled = videoEnabled
@ -171,7 +171,7 @@ ApplicationWindow {
if (parentItem == undefined) parentItem = mainWindow.contentItem
startCallPopup.parent = parentItem
if (contact) {
console.log("[AbstractWindow] Transfer call to", contact.core.displayName, "addresses count", contact.core.allAddresses.length, call)
console.log("[AbstractWindow] Transfer call to", contact.core.fullName, "addresses count", contact.core.allAddresses.length, call)
if (contact.core.allAddresses.length > 1) {
startCallPopup.contact = contact
startCallPopup.currentCall = call

View file

@ -572,7 +572,7 @@ AbstractWindow {
var callsWin = UtilsCpp.getCallsWindow()
if (contact) callsWin.showConfirmationLambdaPopup(
qsTr("Confirmer le transfert ?"),
qsTr("Vous allez transférer %1 à %2.").arg(mainWindow.call.core.remoteName).arg(contact.core.displayName),
qsTr("Vous allez transférer %1 à %2.").arg(mainWindow.call.core.remoteName).arg(contact.core.fullName),
"",
function (confirmed) {
if (confirmed) {