Skip to content
Snippets Groups Projects
Commit 946491a5 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

conversationsadapter: replace signal reconnect with unique connect

Change-Id: I34b1dca62ad5b28b49ddf319c4ea9724efd66b21
parent 8152db58
No related branches found
No related tags found
No related merge requests found
......@@ -155,7 +155,6 @@ ConversationsAdapter::deselectConversation()
void
ConversationsAdapter::onCurrentAccountIdChanged()
{
disconnectConversationModel();
connectConversationModel();
setProperty("currentTypeFilter",
......@@ -265,8 +264,11 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
// Signal connections
auto currentConversationModel = lrcInstance_->getCurrentConversationModel();
modelSortedConnection_ = QObject::connect(
currentConversationModel, &lrc::api::ConversationModel::modelChanged, [this]() {
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::modelChanged,
this,
[this]() {
conversationSmartListModel_->fillConversationsList();
updateConversationsFilterWidget();
......@@ -284,76 +286,94 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
return;
}
Q_EMIT modelSorted(QVariant::fromValue(convInfo.uid));
});
contactProfileUpdatedConnection_
= QObject::connect(lrcInstance_->getCurrentAccountInfo().contactModel.get(),
&lrc::api::ContactModel::profileUpdated,
[this](const QString& contactUri) {
conversationSmartListModel_->updateContactAvatarUid(contactUri);
Q_EMIT updateListViewRequested();
});
modelUpdatedConnection_ = QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::conversationUpdated,
[this](const QString&) {
updateConversationsFilterWidget();
Q_EMIT updateListViewRequested();
});
filterChangedConnection_
= QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::filterChanged,
[this]() {
conversationSmartListModel_->fillConversationsList();
updateConversationsFilterWidget();
if (!lrcInstance_->get_selectedConvUid().isEmpty())
Q_EMIT indexRepositionRequested();
Q_EMIT updateListViewRequested();
});
newConversationConnection_ = QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::newConversation,
[this](const QString& convUid) {
conversationSmartListModel_
->fillConversationsList();
updateConversationForNewContact(convUid);
});
conversationRemovedConnection_
= QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::conversationRemoved,
[this]() { backToWelcomePage(); });
conversationClearedConnection
= QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::conversationCleared,
[this](const QString& convUid) {
// If currently selected, switch to welcome screen (deselecting
// current smartlist item).
if (convUid != lrcInstance_->get_selectedConvUid()) {
return;
}
backToWelcomePage();
});
searchStatusChangedConnection_
= QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::searchStatusChanged,
[this](const QString& status) { Q_EMIT showSearchStatus(status); });
},
Qt::UniqueConnection);
QObject::connect(
lrcInstance_->getCurrentAccountInfo().contactModel.get(),
&lrc::api::ContactModel::profileUpdated,
this,
[this](const QString& contactUri) {
conversationSmartListModel_->updateContactAvatarUid(contactUri);
Q_EMIT updateListViewRequested();
},
Qt::UniqueConnection);
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::conversationUpdated,
this,
[this](const QString&) {
updateConversationsFilterWidget();
Q_EMIT updateListViewRequested();
},
Qt::UniqueConnection);
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::filterChanged,
this,
[this]() {
conversationSmartListModel_->fillConversationsList();
updateConversationsFilterWidget();
if (!lrcInstance_->get_selectedConvUid().isEmpty())
Q_EMIT indexRepositionRequested();
Q_EMIT updateListViewRequested();
},
Qt::UniqueConnection);
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::newConversation,
this,
[this](const QString& convUid) {
conversationSmartListModel_->fillConversationsList();
updateConversationForNewContact(convUid);
},
Qt::UniqueConnection);
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::conversationRemoved,
this,
[this]() { backToWelcomePage(); },
Qt::UniqueConnection);
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::conversationCleared,
this,
[this](const QString& convUid) {
// If currently selected, switch to welcome screen (deselecting
// current smartlist item).
if (convUid != lrcInstance_->get_selectedConvUid()) {
return;
}
backToWelcomePage();
},
Qt::UniqueConnection);
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::searchStatusChanged,
this,
[this](const QString& status) { Q_EMIT showSearchStatus(status); },
Qt::UniqueConnection);
// This connection is ideal when separated search results list.
// This signal is guaranteed to fire just after filterChanged during a search if results are
// changed, and once before filterChanged when calling setFilter.
// NOTE: Currently, when searching, the entire conversation list will be copied 2-3 times each
// keystroke :/.
searchResultUpdatedConnection_
= QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::searchResultUpdated,
[this]() {
conversationSmartListModel_->fillConversationsList();
Q_EMIT updateListViewRequested();
});
QObject::connect(
currentConversationModel,
&lrc::api::ConversationModel::searchResultUpdated,
this,
[this]() {
conversationSmartListModel_->fillConversationsList();
Q_EMIT updateListViewRequested();
},
Qt::UniqueConnection);
if (updateFilter) {
currentTypeFilter_ = lrc::api::profile::Type::INVALID;
......@@ -361,23 +381,6 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
return true;
}
void
ConversationsAdapter::disconnectConversationModel()
{
QObject::disconnect(modelSortedConnection_);
QObject::disconnect(modelUpdatedConnection_);
QObject::disconnect(filterChangedConnection_);
QObject::disconnect(newConversationConnection_);
QObject::disconnect(conversationRemovedConnection_);
QObject::disconnect(conversationClearedConnection);
QObject::disconnect(selectedCallChanged_);
QObject::disconnect(smartlistSelectionConnection_);
QObject::disconnect(interactionRemovedConnection_);
QObject::disconnect(searchStatusChangedConnection_);
QObject::disconnect(searchResultUpdatedConnection_);
QObject::disconnect(contactProfileUpdatedConnection_);
}
void
ConversationsAdapter::updateConversationForNewContact(const QString& convUid)
{
......
......@@ -44,7 +44,6 @@ protected:
public:
Q_INVOKABLE bool connectConversationModel(bool updateFilter = true);
Q_INVOKABLE void disconnectConversationModel();
Q_INVOKABLE void selectConversation(const QString& accountId, const QString& uid);
Q_INVOKABLE void deselectConversation();
Q_INVOKABLE void refill();
......@@ -82,19 +81,5 @@ private:
lrc::api::profile::Type currentTypeFilter_ {};
// Connections.
QMetaObject::Connection modelSortedConnection_;
QMetaObject::Connection modelUpdatedConnection_;
QMetaObject::Connection filterChangedConnection_;
QMetaObject::Connection newConversationConnection_;
QMetaObject::Connection conversationRemovedConnection_;
QMetaObject::Connection conversationClearedConnection;
QMetaObject::Connection contactProfileUpdatedConnection_;
QMetaObject::Connection selectedCallChanged_;
QMetaObject::Connection smartlistSelectionConnection_;
QMetaObject::Connection interactionRemovedConnection_;
QMetaObject::Connection searchStatusChangedConnection_;
QMetaObject::Connection searchResultUpdatedConnection_;
SystemTray* systemTray_;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment