From a8f9115221f742ccbacebed1c94b5e99c88253dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Tue, 3 Apr 2018 14:13:01 -0400 Subject: [PATCH] conversationsview: link to new signal conversationUpdated Change-Id: I487d10566086710351e9e349ed895dd0b9365f07 Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> --- src/conversationsview.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/conversationsview.cpp b/src/conversationsview.cpp index a25f3394..879a8664 100644 --- a/src/conversationsview.cpp +++ b/src/conversationsview.cpp @@ -62,6 +62,7 @@ struct _ConversationsViewPrivate QMetaObject::Connection selection_updated; QMetaObject::Connection layout_changed; QMetaObject::Connection modelSortedConnection_; + QMetaObject::Connection conversationUpdatedConnection_; QMetaObject::Connection filterChangedConnection_; }; @@ -222,6 +223,50 @@ render_time(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, g_object_set(G_OBJECT(cell), "markup", text, NULL); } +void +update_conversation(ConversationsView *self, const std::string& uid) { + auto priv = CONVERSATIONS_VIEW_GET_PRIVATE(self); + auto model = gtk_tree_view_get_model (GTK_TREE_VIEW(self)); + + auto idx = 0; + auto iterIsCorrect = true; + GtkTreeIter iter; + + while(iterIsCorrect) { + iterIsCorrect = gtk_tree_model_iter_nth_child (model, &iter, nullptr, idx); + if (!iterIsCorrect) + break; + gchar *ringId; + gtk_tree_model_get (model, &iter, + 0 /* col# */, &ringId /* data */, + -1); + if(std::string(ringId) == uid) { + // Get informations + auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(idx); + auto contactUri = conversation.participants.front(); + auto contactInfo = priv->accountContainer_->info.contactModel->getContact(contactUri); + auto lastMessage = conversation.interactions.empty() ? "" : + conversation.interactions.at(conversation.lastMessageUid).body; + std::replace(lastMessage.begin(), lastMessage.end(), '\n', ' '); + auto alias = contactInfo.profileInfo.alias; + alias.erase(std::remove(alias.begin(), alias.end(), '\r'), alias.end()); + // Update iter + gtk_list_store_set (GTK_LIST_STORE(model), &iter, + 0 /* col # */ , conversation.uid.c_str() /* celldata */, + 1 /* col # */ , alias.c_str() /* celldata */, + 2 /* col # */ , contactInfo.profileInfo.uri.c_str() /* celldata */, + 3 /* col # */ , contactInfo.registeredName.c_str() /* celldata */, + 4 /* col # */ , contactInfo.profileInfo.avatar.c_str() /* celldata */, + 5 /* col # */ , lastMessage.c_str() /* celldata */, + -1 /* end */); + g_free(ringId); + return; + } + g_free(ringId); + idx++; + } +} + static GtkTreeModel* create_and_fill_model(ConversationsView *self) { @@ -529,6 +574,12 @@ build_conversations_view(ConversationsView *self) gtk_tree_view_set_model(GTK_TREE_VIEW(self), GTK_TREE_MODEL(model)); }); + priv->conversationUpdatedConnection_ = QObject::connect( + &*priv->accountContainer_->info.conversationModel, + &lrc::api::ConversationModel::conversationUpdated, + [self] (const std::string& uid) { + update_conversation(self, uid); + }); priv->filterChangedConnection_ = QObject::connect( &*priv->accountContainer_->info.conversationModel, @@ -578,6 +629,7 @@ conversations_view_dispose(GObject *object) QObject::disconnect(priv->selection_updated); QObject::disconnect(priv->layout_changed); QObject::disconnect(priv->modelSortedConnection_); + QObject::disconnect(priv->conversationUpdatedConnection_); QObject::disconnect(priv->filterChangedConnection_); gtk_widget_destroy(priv->popupMenu_); -- GitLab