From e87e0d97e0ce4f420c52f07dfed8504d0160f2d4 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Tue, 17 Aug 2021 15:26:08 -0400
Subject: [PATCH] qrcode: fix account qr code generation

The current account id is passed to the qr image provider but is
interpreted as a model index.

Change-Id: I5e2a94d5d02d07daa4826315a5d76925e80f033e
Gitlab: #490
---
 src/qrimageprovider.h | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/qrimageprovider.h b/src/qrimageprovider.h
index 96c99ffca..318b98bd7 100644
--- a/src/qrimageprovider.h
+++ b/src/qrimageprovider.h
@@ -78,15 +78,14 @@ public:
         } else {
             if (indexPair.second.isEmpty())
                 return QImage();
-
-            auto accountList = lrcInstance_->accountModel().getAccountList();
-            auto accountIndex = indexPair.second.toInt();
-            if (accountList.size() <= accountIndex)
+            auto accountId = indexPair.second;
+            try {
+                auto& accountInfo = lrcInstance_->getAccountInfo(accountId);
+                uri = accountInfo.profileInfo.uri;
+            } catch (const std::out_of_range&) {
+                qWarning() << "Couldn't get account info for id:" << accountId;
                 return QImage();
-
-            auto& accountInfo = lrcInstance_->accountModel().getAccountInfo(
-                accountList.at(accountIndex));
-            uri = accountInfo.profileInfo.uri;
+            }
         }
 
         if (!requestedSize.isEmpty())
-- 
GitLab