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