mainview: fix account selection
- avoid duplicate call of LRC's setTopAccount()
- welcome view displays always the first account on the list, so passing the index is not necessary
- conversationsadapter and messagesadapter no longer listen to currentAccountChanged signal since there is a specific function for the setup
Gitlab: #12
Change-Id: Iac932d2596bf59c7528d83be799342ccefeea6b0
diff --git a/src/accountadapter.cpp b/src/accountadapter.cpp
index adb1389..9038999 100644
--- a/src/accountadapter.cpp
+++ b/src/accountadapter.cpp
@@ -42,7 +42,7 @@
void
AccountAdapter::initQmlObject()
{
- connectAccount(LRCInstance::getCurrAccId());
+ setSelectedAccount(LRCInstance::getCurrAccId());
}
void
@@ -50,7 +50,7 @@
{
auto accountList = LRCInstance::accountModel().getAccountList();
if (accountList.size() > index)
- setSelectedAccount(accountList.at(index), index);
+ setSelectedAccount(accountList.at(index));
}
void
@@ -331,22 +331,21 @@
}
void
-AccountAdapter::setSelectedAccount(const QString &accountId, int index)
+AccountAdapter::setSelectedAccount(const QString &accountId)
{
LRCInstance::setSelectedAccountId(accountId);
- backToWelcomePage(index);
+ backToWelcomePage();
- QMetaObject::invokeMethod(qmlObj_, "updateSmartList", Q_ARG(QVariant, accountId));
connectAccount(accountId);
emit accountSignalsReconnect(accountId);
}
void
-AccountAdapter::backToWelcomePage(int index)
+AccountAdapter::backToWelcomePage()
{
deselectConversation();
- QMetaObject::invokeMethod(qmlObj_, "backToWelcomePage", Q_ARG(QVariant, index));
+ QMetaObject::invokeMethod(qmlObj_, "backToWelcomePage");
}
void
diff --git a/src/accountadapter.h b/src/accountadapter.h
index 2344895..9671aed 100644
--- a/src/accountadapter.h
+++ b/src/accountadapter.h
@@ -98,8 +98,8 @@
private:
void initQmlObject() override final;
- void setSelectedAccount(const QString &accountId, int index);
- void backToWelcomePage(int index);
+ void setSelectedAccount(const QString &accountId);
+ void backToWelcomePage();
void deselectConversation();
/*
diff --git a/src/conversationsadapter.cpp b/src/conversationsadapter.cpp
index 04abc04..e077108 100644
--- a/src/conversationsadapter.cpp
+++ b/src/conversationsadapter.cpp
@@ -44,18 +44,6 @@
[this](const QString &accountId, lrc::api::conversation::Info convInfo) {
emit showChatView(accountId, convInfo.uid);
});
- connect(&LRCInstance::instance(),
- &LRCInstance::currentAccountChanged,
- this,
- &ConversationsAdapter::slotAccountChanged);
-
- connectConversationModel();
-}
-
-void
-ConversationsAdapter::slotAccountChanged()
-{
- connectConversationModel();
}
void
@@ -139,7 +127,6 @@
auto &accountInfo = LRCInstance::accountModel().getAccountInfo(accountId);
currentTypeFilter_ = accountInfo.profileInfo.type;
LRCInstance::getCurrentConversationModel()->setFilter(accountInfo.profileInfo.type);
- updateConversationsFilterWidget();
connectConversationModel();
}
diff --git a/src/conversationsadapter.h b/src/conversationsadapter.h
index e4c2aa6..85960cd 100644
--- a/src/conversationsadapter.h
+++ b/src/conversationsadapter.h
@@ -48,9 +48,6 @@
void showConversationTabs(bool visible);
void showSearchStatus(const QString &status);
-public slots:
- void slotAccountChanged();
-
private:
void initQmlObject() override;
void setConversationFilter(lrc::api::profile::Type filter);
diff --git a/src/mainview/MainView.qml b/src/mainview/MainView.qml
index c9511ce..d7a0a89 100644
--- a/src/mainview/MainView.qml
+++ b/src/mainview/MainView.qml
@@ -301,8 +301,8 @@
function onAccountSignalsReconnect(accountId) {
CallAdapter.connectCallModel(accountId)
- ConversationsAdapter.accountChangedSetUp(accountId)
mainViewWindowSidePanel.accountSignalsReconnect(accountId)
+ ConversationsAdapter.accountChangedSetUp(accountId)
}
function onUpdateConversationForAddedContact() {
@@ -319,8 +319,7 @@
}
onAccountChanged: {
- ClientWrapper.accountAdaptor.accountChanged(index)
- mainViewWindowSidePanel.refreshAccountComboBox(0)
+ mainViewWindowSidePanel.refreshAccountComboBox(index)
settingsView.slotAccountListChanged()
settingsView.setSelected(settingsView.selectedMenu, true)
@@ -341,7 +340,7 @@
onNeedToBackToWelcomePage: {
if (!inSettingsView)
- mainViewWindowSidePanel.accountComboBoxNeedToShowWelcomePage(index)
+ mainViewWindowSidePanel.accountComboBoxNeedToShowWelcomePage()
}
onNewAccountButtonClicked: {
@@ -515,15 +514,15 @@
*/
if (!inSettingsView) {
mainViewStack.pop(welcomePage)
- welcomePage.currentAccountIndex = index
- qrDialog.currentAccountIndex = index
+ welcomePage.updateWelcomePage()
+ qrDialog.updateQrDialog()
}
}
onConversationSmartListViewNeedToShowWelcomePage: {
mainViewStack.pop(welcomePage)
- welcomePage.currentAccountIndex = 0
- qrDialog.currentAccountIndex = 0
+ welcomePage.updateWelcomePage()
+ qrDialog.updateQrDialog()
}
onAccountSignalsReconnect: {
diff --git a/src/mainview/components/AccountComboBox.qml b/src/mainview/components/AccountComboBox.qml
index 5c58708..dce72c8 100644
--- a/src/mainview/components/AccountComboBox.qml
+++ b/src/mainview/components/AccountComboBox.qml
@@ -27,35 +27,29 @@
id: accountComboBox
signal accountChanged(int index)
- signal needToBackToWelcomePage(int index)
+ signal needToBackToWelcomePage()
signal needToUpdateSmartList(string accountId)
signal newAccountButtonClicked
signal settingBtnClicked
currentIndex: 0
- function backToWelcomePage(index) {
- accountComboBox.needToBackToWelcomePage(index)
+ function backToWelcomePage() {
+ needToBackToWelcomePage()
}
function updateSmartList(accountId) {
- accountComboBox.needToUpdateSmartList(accountId)
+ needToUpdateSmartList(accountId)
}
-
- /*
- * Refresh every item in accountListModel.
- */
+ // Refresh every item in accountListModel.
function updateAccountListModel() {
accountListModel.dataChanged(accountListModel.index(0, 0),
accountListModel.index(
accountListModel.rowCount() - 1, 0))
}
-
- /*
- * Reset accountListModel.
- */
+ // Reset accountListModel.
function resetAccountListModel() {
accountListModel.reset()
}
@@ -72,10 +66,7 @@
fillMode: Image.PreserveAspectFit
-
- /*
- * Base 64 format
- */
+ // Base 64 format
source: {
if (currentIndex !== -1)
return "data:image/png;base64," + accountListModel.data(
@@ -97,10 +88,7 @@
width: 12
height: 12
-
- /*
- * Visible when account is registered, enum REGISTERED == 5.
- */
+ // Visible when account is registered, enum REGISTERED == 5.
visible: {
if (currentIndex !== -1)
return accountListModel.data(
@@ -153,7 +141,6 @@
source: "qrc:/images/icons/round-arrow_drop_down-24px.svg"
}
-
Text {
id: textUsernameRoot
@@ -174,10 +161,7 @@
elideWidth: accountComboBox.width - userImageRoot.width - settingsButton.width
- arrowDropDown.width - qrCodeGenerateButton.width - 55
-
- /*
- * Role::Alias
- */
+ // Role::Alias
text: {
if (currentIndex !== -1)
return accountListModel.data(accountListModel.index(
@@ -197,9 +181,8 @@
- qrCodeGenerateButton.width - 55
- /*
- * Role::Username
- */
+
+ // Role::Username
text: {
if (currentIndex !== -1)
return accountListModel.data(accountListModel.index(
@@ -210,8 +193,6 @@
}
}
-
-
HoverableButton {
id: qrCodeGenerateButton
@@ -308,9 +289,8 @@
rootItemBackground.color = JamiTheme.backgroundColor
}
onMouseXChanged: {
- /*
- * Manually making button hover.
- */
+
+ // Manually making button hover.
qrCodeGenerateButton.backgroundColor = (isMouseOnButton(mouse, qrCodeGenerateButton)) ?
JamiTheme.hoverColor : "white"
@@ -334,10 +314,7 @@
indicator: null
-
- /*
- * Overwrite the combo box pop up to add footer (for add accounts).
- */
+ // Overwrite the combo box pop up to add footer (for add accounts).
popup: AccountComboBoxPopup {
id: comboBoxPopup
diff --git a/src/mainview/components/SidePanel.qml b/src/mainview/components/SidePanel.qml
index c37bcb3..736fecb 100644
--- a/src/mainview/components/SidePanel.qml
+++ b/src/mainview/components/SidePanel.qml
@@ -32,7 +32,7 @@
property int totalUnreadMessagesCount: 0
signal conversationSmartListNeedToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, string callStateStr)
- signal accountComboBoxNeedToShowWelcomePage(int index)
+ signal accountComboBoxNeedToShowWelcomePage()
signal conversationSmartListViewNeedToShowWelcomePage
signal accountSignalsReconnect(string accountId)
signal needToUpdateConversationForAddedContact
@@ -87,8 +87,6 @@
}
function refreshAccountComboBox(index = -1) {
- accountComboBox.resetAccountListModel()
-
/*
* To make sure that the ui is refreshed for accountComboBox.
@@ -105,6 +103,7 @@
accountComboBox.currentIndex = currentIndex
accountComboBox.update()
accountChangedUIReset()
+ accountComboBox.resetAccountListModel()
}
function deselectConversationSmartList() {
diff --git a/src/mainview/components/WelcomePage.qml b/src/mainview/components/WelcomePage.qml
index 3563eea..ad48871 100644
--- a/src/mainview/components/WelcomePage.qml
+++ b/src/mainview/components/WelcomePage.qml
@@ -25,11 +25,15 @@
Rectangle {
id: welcomeRect
-
- property int currentAccountIndex: 0
property int buttonPreferredSize: 30
anchors.fill: parent
+ function updateWelcomePage(){
+ jamiShareWithFriendText.visible = accountListModel.data(accountListModel.index(0, 0), 260) === 1
+ jamiRegisteredNameRect.visible = accountListModel.data(accountListModel.index(0, 0), 260) === 1
+ textMetricsjamiRegisteredNameText.text = accountListModel.data(accountListModel.index(0, 0), 258)
+ }
+
Rectangle {
id: welcomeRectComponentsGroup
@@ -86,8 +90,9 @@
verticalAlignment: Text.AlignVCenter
visible: accountListModel.data(accountListModel.index(
- currentAccountIndex, 0),
+ 0, 0),
260) === 1
+
text: qsTr("This is your ID.\nCopy and share it with your friends")
color: JamiTheme.faddedFontColor
}
@@ -101,9 +106,8 @@
Layout.bottomMargin: 5
visible: accountListModel.data(accountListModel.index(
- currentAccountIndex, 0),
+ 0, 0),
260) === 1
-
ColumnLayout {
id: jamiRegisteredNameRectColumnLayout
@@ -163,4 +167,8 @@
bBorderwidth: 0
borderColor: JamiTheme.tabbarBorderColor
}
+
+ Component.onCompleted: {
+ updateWelcomePage()
+ }
}
diff --git a/src/mainview/components/WelcomePageQrDialog.qml b/src/mainview/components/WelcomePageQrDialog.qml
index 45c8ff2..ccadf0f 100644
--- a/src/mainview/components/WelcomePageQrDialog.qml
+++ b/src/mainview/components/WelcomePageQrDialog.qml
@@ -21,22 +21,21 @@
import QtQuick.Layouts 1.14
import net.jami.Models 1.0
+
Dialog {
id: userQrImageDialog
- property int currentAccountIndex: 0
+ property string accountIdStr: ClientWrapper.utilsAdaptor.getCurrAccId()
+ function updateQrDialog() {
+ accountIdStr = ClientWrapper.utilsAdaptor.getCurrAccId()
+ }
- /*
- * When dialog is opened, trigger mainViewWindow overlay which is defined in overlay.model.
- * (model : true is necessary)
- */
+ // When dialog is opened, trigger mainViewWindow overlay which is defined in overlay.model.
+ // (model : true is necessary)
modal: true
-
- /*
- * Content height + margin.
- */
+ //Content height + margin.
contentHeight: userQrImage.height + 30
Image {
@@ -48,7 +47,7 @@
height: 250
fillMode: Image.PreserveAspectFit
- source: "image://qrImage/account_" + currentAccountIndex
+ source: "image://qrImage/account_" + accountIdStr
sourceSize.width: 260
sourceSize.height: 260
mipmap: true
diff --git a/src/messagesadapter.cpp b/src/messagesadapter.cpp
index 056286e..5214d0b 100644
--- a/src/messagesadapter.cpp
+++ b/src/messagesadapter.cpp
@@ -39,20 +39,7 @@
MessagesAdapter::~MessagesAdapter() {}
void
-MessagesAdapter::initQmlObject()
-{
- connect(&LRCInstance::instance(),
- &LRCInstance::currentAccountChanged,
- this,
- &MessagesAdapter::slotAccountChanged);
- connectConversationModel();
-}
-
-void
-MessagesAdapter::slotAccountChanged()
-{
- connectConversationModel();
-}
+MessagesAdapter::initQmlObject() {}
void
MessagesAdapter::setupChatView(const QString &uid)
diff --git a/src/messagesadapter.h b/src/messagesadapter.h
index ed5601a..6b520d2 100644
--- a/src/messagesadapter.h
+++ b/src/messagesadapter.h
@@ -91,7 +91,6 @@
void slotUpdateDraft(const QString &content);
void slotMessagesCleared();
void slotMessagesLoaded();
- void slotAccountChanged();
private:
void initQmlObject() override final;
diff --git a/src/smartlistmodel.cpp b/src/smartlistmodel.cpp
index d10d8ce..d778398 100644
--- a/src/smartlistmodel.cpp
+++ b/src/smartlistmodel.cpp
@@ -65,8 +65,7 @@
}
return rowCount;
}
- return accInfo.conversationModel->allFilteredConversations().size()
- + accInfo.conversationModel->getAllSearchResults().size();
+ return conversations_.size();
}
return 0;
}