Commit 24d4502a authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud

chatview: fix crash when destroying while a signal is executed

Change-Id: I0fd34b2777bbf7c1ebd26e96ea4fcbb86ac55ad5
parent 246c6ae1
...@@ -79,6 +79,8 @@ G_DEFINE_TYPE_WITH_PRIVATE(ChatView, chat_view, GTK_TYPE_BOX); ...@@ -79,6 +79,8 @@ G_DEFINE_TYPE_WITH_PRIVATE(ChatView, chat_view, GTK_TYPE_BOX);
enum { enum {
NEW_MESSAGES_DISPLAYED, NEW_MESSAGES_DISPLAYED,
HIDE_VIEW_CLICKED, HIDE_VIEW_CLICKED,
PLACE_CALL_CLICKED,
PLACE_AUDIO_CALL_CLICKED,
LAST_SIGNAL LAST_SIGNAL
}; };
...@@ -142,18 +144,15 @@ placecall_clicked(ChatView *self) ...@@ -142,18 +144,15 @@ placecall_clicked(ChatView *self)
{ {
auto priv = CHAT_VIEW_GET_PRIVATE(self); auto priv = CHAT_VIEW_GET_PRIVATE(self);
if (!priv->conversation_) return; if (!priv->conversation_) return;
(*priv->accountInfo_)->conversationModel->placeCall(priv->conversation_->uid); g_signal_emit(G_OBJECT(self), chat_view_signals[PLACE_CALL_CLICKED], 0, priv->conversation_->uid.c_str());
} }
static void static void
place_audio_call_clicked(ChatView *self) place_audio_call_clicked(ChatView *self)
{ {
auto priv = CHAT_VIEW_GET_PRIVATE(self); auto priv = CHAT_VIEW_GET_PRIVATE(self);
if (!priv->conversation_) return;
if (!priv->conversation_) g_signal_emit(G_OBJECT(self), chat_view_signals[PLACE_AUDIO_CALL_CLICKED], 0, priv->conversation_->uid.c_str());
return;
(*priv->accountInfo_)->conversationModel->placeAudioOnlyCall(priv->conversation_->uid);
} }
static void static void
...@@ -342,6 +341,26 @@ chat_view_class_init(ChatViewClass *klass) ...@@ -342,6 +341,26 @@ chat_view_class_init(ChatViewClass *klass)
nullptr, nullptr,
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
chat_view_signals[PLACE_CALL_CLICKED] = g_signal_new (
"place-call-clicked",
G_TYPE_FROM_CLASS(klass),
(GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED),
0,
nullptr,
nullptr,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
chat_view_signals[PLACE_AUDIO_CALL_CLICKED] = g_signal_new (
"place-audio-call-clicked",
G_TYPE_FROM_CLASS(klass),
(GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
0,
nullptr,
nullptr,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
} }
static void static void
......
...@@ -367,6 +367,7 @@ public: ...@@ -367,6 +367,7 @@ public:
QMetaObject::Connection accountStatusChangedConnection_; QMetaObject::Connection accountStatusChangedConnection_;
QMetaObject::Connection profileUpdatedConnection_; QMetaObject::Connection profileUpdatedConnection_;
std::string eventUid_;
private: private:
CppImpl() = delete; CppImpl() = delete;
CppImpl(const CppImpl&) = delete; CppImpl(const CppImpl&) = delete;
...@@ -421,6 +422,50 @@ on_hide_view_clicked(RingMainWindow* self) ...@@ -421,6 +422,50 @@ on_hide_view_clicked(RingMainWindow* self)
priv->cpp->resetToWelcome(); priv->cpp->resetToWelcome();
} }
static gboolean
place_call_event(RingMainWindow* self)
{
g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), G_SOURCE_REMOVE);
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
if (!priv->cpp->eventUid_.empty())
priv->cpp->accountInfo_->conversationModel->placeCall(priv->cpp->eventUid_);
return G_SOURCE_REMOVE;
}
static void
on_place_call_clicked(G_GNUC_UNUSED GtkWidget*, gchar *uid, RingMainWindow* self)
{
g_return_if_fail(IS_RING_MAIN_WINDOW(self) && uid);
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
priv->cpp->eventUid_ = uid;
g_idle_add((GSourceFunc)place_call_event, self);
}
static gboolean
place_audio_call_event(RingMainWindow* self)
{
g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), G_SOURCE_REMOVE);
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
if (!priv->cpp->eventUid_.empty())
priv->cpp->accountInfo_->conversationModel->placeAudioOnlyCall(priv->cpp->eventUid_);
return G_SOURCE_REMOVE;
}
static void
on_place_audio_call_clicked(G_GNUC_UNUSED GtkWidget*, gchar *uid, RingMainWindow* self)
{
g_return_if_fail(IS_RING_MAIN_WINDOW(self) && uid);
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
priv->cpp->eventUid_ = uid;
g_idle_add((GSourceFunc)place_audio_call_event, self);
}
static void static void
on_account_creation_completed(RingMainWindow* self) on_account_creation_completed(RingMainWindow* self)
{ {
...@@ -1335,6 +1380,8 @@ CppImpl::displayChatView(lrc::api::conversation::Info conversation, bool redraw_ ...@@ -1335,6 +1380,8 @@ CppImpl::displayChatView(lrc::api::conversation::Info conversation, bool redraw_
chatViewConversation_.reset(new lrc::api::conversation::Info(conversation)); chatViewConversation_.reset(new lrc::api::conversation::Info(conversation));
auto* new_view = chat_view_new(webkitChatContainer(redraw_webview), accountInfo_, chatViewConversation_.get()); auto* new_view = chat_view_new(webkitChatContainer(redraw_webview), accountInfo_, chatViewConversation_.get());
g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self); g_signal_connect_swapped(new_view, "hide-view-clicked", G_CALLBACK(on_hide_view_clicked), self);
g_signal_connect(new_view, "place-call-clicked", G_CALLBACK(on_place_call_clicked), self);
g_signal_connect(new_view, "place-audio-call-clicked", G_CALLBACK(on_place_audio_call_clicked), self);
try { try {
auto contactUri = chatViewConversation_->participants.front(); auto contactUri = chatViewConversation_->participants.front();
auto contactInfo = accountInfo_->contactModel->getContact(contactUri); auto contactInfo = accountInfo_->contactModel->getContact(contactUri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment