Refactoring of the accountContainer logic
Before:
- RingMainWindow has an unique_ptr to an AccountContainer
accountContainer_.
- each view / secondary class has its own *copy* of the account
container pointer (given by ringmainwindow using
accountContainer_.get()).
- each time the reference to the struct Info is updated,
accountContainer_ has to be reset()-ed and and the account
container re-created by the RingMainWindow. This makes *all*
copies of the account container pointer invalid (hence all
view / secondary classes trying to access the account container
before getting updated perform use-after-free / NULL pointer
dereference).
- These copies have to be manually updated ! (well, currently they
are not updated at all)
After:
- RingMainWindow has a pointer to a struct Info from LRC.
- Each view / secondary class has a pointer pointing to
the struct Info pointer of RingMainWindow
- Each time the reference to the struct Info is updated, the
RingMainWindow updates its pointer. Since secondary classes and
views hold a pointer to this pointer, they are automatically
updated and there is no dangling pointer anymore.
This requires no lrc side changes.
Change-Id: I1329721920a3d42ad623f9fd7202b43700713eed
Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com>
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
diff --git a/src/conversationpopupmenu.cpp b/src/conversationpopupmenu.cpp
index ea404ac..5434748 100644
--- a/src/conversationpopupmenu.cpp
+++ b/src/conversationpopupmenu.cpp
@@ -27,6 +27,8 @@
#include <api/contactmodel.h>
#include <api/contact.h>
+#include "accountinfopointer.h"
+
struct _ConversationPopupMenu
{
GtkMenu parent;
@@ -43,7 +45,7 @@
{
GtkTreeView *treeview;
- AccountContainer* accountContainer_;
+ AccountInfoPointer const *accountInfo_;
int row_;
};
@@ -56,9 +58,9 @@
{
try
{
- auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_);
+ auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_);
if (conversation.participants.empty()) return;
- auto& contact = priv->accountContainer_->info.contactModel->getContact(conversation.participants.front());
+ auto& contact = (*priv->accountInfo_)->contactModel->getContact(conversation.participants.front());
auto bestName = contact.registeredName.empty() ? contact.profileInfo.uri : contact.registeredName;
auto text = (gchar *)bestName.c_str();
GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
@@ -77,8 +79,8 @@
{
try
{
- auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_);
- priv->accountContainer_->info.conversationModel->clearHistory(conversation.uid);
+ auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_);
+ (*priv->accountInfo_)->conversationModel->clearHistory(conversation.uid);
}
catch (...)
{
@@ -91,8 +93,8 @@
{
try
{
- auto conversationUid = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_).uid;
- priv->accountContainer_->info.conversationModel->removeConversation(conversationUid);
+ auto conversationUid = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_).uid;
+ (*priv->accountInfo_)->conversationModel->removeConversation(conversationUid);
}
catch (...)
{
@@ -105,8 +107,8 @@
{
try
{
- auto conversationUid = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_).uid;
- priv->accountContainer_->info.conversationModel->removeConversation(conversationUid, true);
+ auto conversationUid = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_).uid;
+ (*priv->accountInfo_)->conversationModel->removeConversation(conversationUid, true);
}
catch (...)
{
@@ -119,8 +121,8 @@
{
try
{
- auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_);
- priv->accountContainer_->info.conversationModel->makePermanent(conversation.uid);
+ auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_);
+ (*priv->accountInfo_)->conversationModel->makePermanent(conversation.uid);
}
catch (...)
{
@@ -133,8 +135,8 @@
{
try
{
- auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_);
- priv->accountContainer_->info.conversationModel->placeCall(conversation.uid);
+ auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_);
+ (*priv->accountInfo_)->conversationModel->placeCall(conversation.uid);
} catch (...) {
g_warning("Can't get conversation at row %i", priv->row_);
}
@@ -145,8 +147,8 @@
{
try
{
- auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(priv->row_);
- priv->accountContainer_->info.conversationModel->placeAudioOnlyCall(conversation.uid);
+ auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(priv->row_);
+ (*priv->accountInfo_)->conversationModel->placeAudioOnlyCall(conversation.uid);
} catch (...) {
g_warning("Can't get conversation at row %i", priv->row_);
}
@@ -168,10 +170,10 @@
if (!gtk_tree_selection_get_selected(selection, &model, &iter)) return;
auto path = gtk_tree_model_get_path(model, &iter);
auto idx = gtk_tree_path_get_indices(path);
- auto conversation = priv->accountContainer_->info.conversationModel->filteredConversation(idx[0]);
+ auto conversation = (*priv->accountInfo_)->conversationModel->filteredConversation(idx[0]);
priv->row_ = idx[0];
try {
- auto contactInfo = priv->accountContainer_->info.contactModel->getContact(conversation.participants.front());
+ auto contactInfo = (*priv->accountInfo_)->contactModel->getContact(conversation.participants.front());
if (contactInfo.profileInfo.uri.empty()) return;
// we always build a menu, however in some cases some or all of the conversations will be deactivated
@@ -248,11 +250,11 @@
}
GtkWidget *
-conversation_popup_menu_new (GtkTreeView *treeview, AccountContainer* accountContainer)
+conversation_popup_menu_new (GtkTreeView *treeview, AccountInfoPointer const & accountInfo)
{
gpointer self = g_object_new(CONVERSATION_POPUP_MENU_TYPE, NULL);
ConversationPopupMenuPrivate *priv = CONVERSATION_POPUP_MENU_GET_PRIVATE(self);
- priv->accountContainer_ = accountContainer;
+ priv->accountInfo_ = &accountInfo;
priv->treeview = treeview;
GtkTreeSelection *selection = gtk_tree_view_get_selection(priv->treeview);