From 12daccb51f21f28658b5089849040a5a6803de9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 6 Apr 2021 15:37:34 -0400
Subject: [PATCH] accountadapter: do not set incorrect ringtone on creation

On GNU/Linux, the ringtone is managed by the deamon. No need to
manage it (incorrectly) in the client

Change-Id: I38fe783d6bd0778f702ee6da333468c54d59d678
GitLab: #351
---
 src/accountadapter.cpp | 53 +++++++++++++++++++++++++-----------------
 src/utils.cpp          |  2 +-
 2 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/src/accountadapter.cpp b/src/accountadapter.cpp
index de7b6758d..7be029e71 100644
--- a/src/accountadapter.cpp
+++ b/src/accountadapter.cpp
@@ -99,7 +99,9 @@ AccountAdapter::createJamiAccount(QString registeredName,
         &lrc::api::NewAccountModel::accountAdded,
         [this, registeredName, settings, isCreating](const QString& accountId) {
             auto confProps = lrcInstance_->accountModel().getAccountConfig(accountId);
+#ifdef Q_OS_WIN
             confProps.Ringtone.ringtonePath = Utils::GetRingtonePath();
+#endif
             confProps.isRendezVous = settings["isRendezVous"].toBool();
             lrcInstance_->accountModel().setAccountConfig(accountId, confProps);
 
@@ -108,19 +110,21 @@ AccountAdapter::createJamiAccount(QString registeredName,
                                       .toBool();
             if (!registeredName.isEmpty()) {
                 QObject::disconnect(registeredNameSavedConnection_);
-                registeredNameSavedConnection_ = connect(
-                    &lrcInstance_->accountModel(),
-                    &lrc::api::NewAccountModel::profileUpdated,
-                    [this, showBackup, addedAccountId = accountId](const QString& accountId) {
-                        if (addedAccountId == accountId) {
-                            Q_EMIT lrcInstance_->accountListChanged();
-                            Q_EMIT accountAdded(accountId,
-                                              showBackup,
-                                              lrcInstance_->accountModel().getAccountList().indexOf(
-                                                  accountId));
-                            QObject::disconnect(registeredNameSavedConnection_);
-                        }
-                    });
+                registeredNameSavedConnection_
+                    = connect(&lrcInstance_->accountModel(),
+                              &lrc::api::NewAccountModel::profileUpdated,
+                              [this, showBackup, addedAccountId = accountId](
+                                  const QString& accountId) {
+                                  if (addedAccountId == accountId) {
+                                      Q_EMIT lrcInstance_->accountListChanged();
+                                      Q_EMIT accountAdded(accountId,
+                                                          showBackup,
+                                                          lrcInstance_->accountModel()
+                                                              .getAccountList()
+                                                              .indexOf(accountId));
+                                      QObject::disconnect(registeredNameSavedConnection_);
+                                  }
+                              });
 
                 lrcInstance_->accountModel().registerName(accountId,
                                                           settings["password"].toString(),
@@ -128,8 +132,9 @@ AccountAdapter::createJamiAccount(QString registeredName,
             } else {
                 Q_EMIT lrcInstance_->accountListChanged();
                 Q_EMIT accountAdded(accountId,
-                                  showBackup,
-                                  lrcInstance_->accountModel().getAccountList().indexOf(accountId));
+                                    showBackup,
+                                    lrcInstance_->accountModel().getAccountList().indexOf(
+                                        accountId));
             }
         });
 
@@ -158,14 +163,17 @@ AccountAdapter::createSIPAccount(const QVariantMap& settings)
                               confProps.username = settings["username"].toString();
                               confProps.password = settings["password"].toString();
                               confProps.routeset = settings["proxy"].toString();
+#ifdef Q_OS_WIN
                               confProps.Ringtone.ringtonePath = Utils::GetRingtonePath();
+#endif
                               lrcInstance_->accountModel().setAccountConfig(accountId, confProps);
 
                               Q_EMIT lrcInstance_->accountListChanged();
                               Q_EMIT accountAdded(accountId,
-                                                false,
-                                                lrcInstance_->accountModel().getAccountList().indexOf(
-                                                    accountId));
+                                                  false,
+                                                  lrcInstance_->accountModel()
+                                                      .getAccountList()
+                                                      .indexOf(accountId));
                           });
 
     connectFailure();
@@ -192,13 +200,16 @@ AccountAdapter::createJAMSAccount(const QVariantMap& settings)
 
                               auto confProps = lrcInstance_->accountModel().getAccountConfig(
                                   accountId);
+#ifdef Q_OS_WIN
                               confProps.Ringtone.ringtonePath = Utils::GetRingtonePath();
+#endif
                               lrcInstance_->accountModel().setAccountConfig(accountId, confProps);
 
                               Q_EMIT accountAdded(accountId,
-                                                false,
-                                                lrcInstance_->accountModel().getAccountList().indexOf(
-                                                    accountId));
+                                                  false,
+                                                  lrcInstance_->accountModel()
+                                                      .getAccountList()
+                                                      .indexOf(accountId));
                               Q_EMIT lrcInstance_->accountListChanged();
                           });
 
diff --git a/src/utils.cpp b/src/utils.cpp
index 46081a1c7..60947c1ca 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -280,7 +280,7 @@ Utils::GetRingtonePath()
 #ifdef Q_OS_WIN
     return QCoreApplication::applicationDirPath() + "\\ringtones\\default.opus";
 #else
-    return QString("/usr/local");
+    return QString("/usr/share/ring/ringtones/default.opus");
 #endif
 }
 
-- 
GitLab