diff --git a/src/conversationsview.cpp b/src/conversationsview.cpp index 4e02566173361193cb7f58c2c1e75a0870659cfa..a33df48e2621f04a920d097133cbfac573caf934 100644 --- a/src/conversationsview.cpp +++ b/src/conversationsview.cpp @@ -109,8 +109,6 @@ render_contact_photo(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, { // Get active conversation auto path = gtk_tree_model_get_path(model, iter); - auto row = std::atoi(gtk_tree_path_to_string(path)); - if (row == -1) return; auto priv = CONVERSATIONS_VIEW_GET_PRIVATE(self); if (!priv) return; gchar *uid; @@ -150,7 +148,7 @@ render_contact_photo(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, } catch (const std::exception&) { - g_warning("Can't get conversation at row %i", row); + g_warning("Can't get conversation %s", uid); } g_free(uid); @@ -330,15 +328,15 @@ update_conversation(ConversationsView *self, const std::string& uid) { iterIsCorrect = gtk_tree_model_iter_nth_child (model, &iter, nullptr, idx); if (!iterIsCorrect) break; - gchar *ringId; + gchar *uid; gtk_tree_model_get (model, &iter, - 0 /* col# */, &ringId /* data */, + 0 /* col# */, &uid /* data */, -1); - if(std::string(ringId) == uid) { + if(std::string(uid) == uid) { // Get informations - auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(idx); + auto conversation = (*priv->accountInfo_)->conversationModel->getConversationForUID(uid); if (conversation.participants.empty()) { - g_free(ringId); + g_free(uid); return; } auto contactUri = conversation.participants.front(); @@ -357,10 +355,10 @@ update_conversation(ConversationsView *self, const std::string& uid) { 4 /* col # */ , qUtf8Printable(contactInfo.profileInfo.avatar) /* celldata */, 5 /* col # */ , qUtf8Printable(lastMessage) /* celldata */, -1 /* end */); - g_free(ringId); + g_free(uid); return; } - g_free(ringId); + g_free(uid); idx++; } } @@ -431,16 +429,25 @@ create_and_fill_model(ConversationsView *self) static void call_conversation(GtkTreeView *self, - GtkTreePath *path, + G_GNUC_UNUSED GtkTreePath *path, G_GNUC_UNUSED GtkTreeViewColumn *column, G_GNUC_UNUSED gpointer user_data) { - auto row = std::atoi(gtk_tree_path_to_string(path)); - if (row == -1) return; auto priv = CONVERSATIONS_VIEW_GET_PRIVATE(self); if (!priv) return; - auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(row); - (*priv->accountInfo_)->conversationModel->placeCall(conversation.uid); + GtkTreeIter iter; + GtkTreeModel *model = nullptr; + gchar *uid = nullptr; + + auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self)); + if (!gtk_tree_selection_get_selected(selection, &model, &iter)) return; + + gtk_tree_model_get(model, &iter, + 0, &uid, + -1); + + (*priv->accountInfo_)->conversationModel->placeCall(uid); + g_free(uid); } static void @@ -916,10 +923,10 @@ conversations_view_select_conversation(ConversationsView *self, const std::strin } } -int +std::string conversations_view_get_current_selected(ConversationsView *self) { - g_return_val_if_fail(IS_CONVERSATIONS_VIEW(self), -1); + g_return_val_if_fail(IS_CONVERSATIONS_VIEW(self), ""); /* we always drag the selected row */ auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self)); @@ -927,11 +934,16 @@ conversations_view_get_current_selected(ConversationsView *self) GtkTreeIter iter; if (gtk_tree_selection_get_selected(selection, &model, &iter)) { - auto path = gtk_tree_model_get_path(model, &iter); - auto idx = gtk_tree_path_get_indices(path); - return idx[0]; + gchar* uid; + gtk_tree_model_get(model, &iter, + 0, &uid, + -1); + if (!uid) return {}; + std::string result = uid; + g_free(uid); + return result; } - return -1; + return {}; } void diff --git a/src/conversationsview.h b/src/conversationsview.h index 7a924174ed362b74d2bb9dfaeb25db459bfcb8b3..ca4b324501bc0f78f209efd09660125ba1eab933 100644 --- a/src/conversationsview.h +++ b/src/conversationsview.h @@ -35,10 +35,10 @@ G_BEGIN_DECLS typedef struct _ConversationsView ConversationsView; typedef struct _ConversationsViewClass ConversationsViewClass; -GType conversations_view_get_type (void) G_GNUC_CONST; -GtkWidget *conversations_view_new (AccountInfoPointer const & accountInfo); -void conversations_view_select_conversation (ConversationsView *self, const std::string& uid); -int conversations_view_get_current_selected(ConversationsView *self); -void conversations_view_set_theme(ConversationsView *self, bool darkTheme); +GType conversations_view_get_type (void) G_GNUC_CONST; +GtkWidget *conversations_view_new (AccountInfoPointer const & accountInfo); +void conversations_view_select_conversation (ConversationsView *self, const std::string& uid); +std::string conversations_view_get_current_selected(ConversationsView *self); +void conversations_view_set_theme(ConversationsView *self, bool darkTheme); G_END_DECLS diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4b4be63dffe0d757a4399b1bfbd3f87704a75b81..8e34e6e7c6fcdf617402d4b0bf2ceddca73b96bf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -328,7 +328,7 @@ public: void enterSettingsView(); void leaveSettingsView(); - int getCurrentUid(); + std::string getCurrentUid(); void forCurrentConversation(const std::function<void(const lrc::api::conversation::Info&)>& func); bool showOkCancelDialog(const std::string& title, const std::string& text); @@ -716,7 +716,7 @@ on_search_entry_activated(MainWindow* self) // Select the first conversation of the list auto& conversationModel = priv->cpp->accountInfo_->conversationModel; - auto conversations = conversationModel->allFilteredConversations(); + auto conversations = conversationModel->getAllSearchResults(); const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->search_entry)); @@ -1857,7 +1857,7 @@ CppImpl::leaveSettingsView() } } -int +std::string CppImpl::getCurrentUid() { const auto &treeview = gtk_notebook_get_current_page( @@ -1871,9 +1871,9 @@ void CppImpl::forCurrentConversation(const std::function<void(const lrc::api::conversation::Info&)>& func) { const auto current = getCurrentUid(); - if (current == -1) return; + if (current.empty()) return; try { - auto conversation = accountInfo_->conversationModel->filteredConversation(current); + auto conversation = accountInfo_->conversationModel->getConversationForUID(current.c_str()); if (conversation.participants.empty()) return; func(conversation); } catch (...) { @@ -2732,9 +2732,9 @@ main_window_accept_call(MainWindow *win) // Select the first conversation of the list auto current = priv->cpp->getCurrentUid(); - if (current == -1) return; + if (current.empty()) return; try { - auto conversation = priv->cpp->accountInfo_->conversationModel->filteredConversation(current); + auto conversation = priv->cpp->accountInfo_->conversationModel->getConversationForUID(current.c_str()); if (conversation.participants.empty()) return; auto contactUri = conversation.participants.at(0); auto contact = priv->cpp->accountInfo_->contactModel->getContact(contactUri);