From a86a89708e741c91d383460bcd0edf1940a3b3f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anthony=20L=C3=A9onard?=
 <anthony.leonard@savoirfairelinux.com>
Date: Thu, 15 Dec 2016 10:33:47 -0500
Subject: [PATCH] Display registered name in CallWidget

If the current account is registered on the name service,
we now display the name on the welcome page instead of
the full RingID.

The QRCode still contains the RingID.

Change-Id: Ie44521c83cd2162eacc6ede03f23492b8a1cce12
Tuleap: #1418
---
 callwidget.cpp | 19 ++++++++++++-------
 callwidget.h   |  2 +-
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/callwidget.cpp b/callwidget.cpp
index ee5a94f..5dfe0d8 100644
--- a/callwidget.cpp
+++ b/callwidget.cpp
@@ -332,18 +332,23 @@ CallWidget::findRingAccount(QModelIndex idx1, QModelIndex idx2, QVector<int> vec
         auto idx = AccountModel::instance().index(i, 0);
         auto protocol = idx.data(static_cast<int>(Account::Role::Proto));
         if (static_cast<Account::Protocol>(protocol.toUInt()) == Account::Protocol::RING) {
+            auto account = AccountModel::instance().getAccountByModelIndex(idx);
+            auto registeredName = account->registeredName();
             auto username = idx.data(static_cast<int>(Account::Role::Username));
-            ui->ringIdLabel->setText(username.toString());
-            setupQRCode();
+            if (registeredName.isEmpty()) {
+                ui->ringIdLabel->setText(username.toString());
+            } else
+                ui->ringIdLabel->setText(registeredName);
+            setupQRCode(username.toString());
             return;
         }
     }
     ui->ringIdLabel->setText(tr("NO RING ACCOUNT FOUND"));
 }
 
-void CallWidget::setupQRCode()
+void CallWidget::setupQRCode(QString ringID)
 {
-    auto rcode = QRcode_encodeString(ui->ringIdLabel->text().toStdString().c_str(),
+    auto rcode = QRcode_encodeString(ringID.toStdString().c_str(),
                                      0, //Let the version be decided by libqrencode
                                      QR_ECLEVEL_L, // Lowest level of error correction
                                      QR_MODE_8, // 8-bit data mode
@@ -396,9 +401,9 @@ CallWidget::findRingAccount()
                 dlg.exec();
             }
             if (ui->ringIdLabel->text().isEmpty()) {
-                auto username = account->username();
-                ui->ringIdLabel->setText(username);
-                setupQRCode();
+                auto registeredName = account->registeredName();
+                ui->ringIdLabel->setText((registeredName.isEmpty())?account->username():registeredName);
+                setupQRCode(account->username());
             }
         }
     }
diff --git a/callwidget.h b/callwidget.h
index 274cfd9..2ed1ca0 100644
--- a/callwidget.h
+++ b/callwidget.h
@@ -126,7 +126,7 @@ private:
     void setupSmartListMenu();
     void slidePage(QWidget* widget, bool toRight = false);
     void callStateToView(Call* value);
-    void setupQRCode();
+    void setupQRCode(QString ringID);
     void searchContactLineEditEntry(const URI &uri);
 };
 
-- 
GitLab