Commit ed7e5488 authored by Mohammed Sadiq's avatar Mohammed Sadiq
Browse files

chat: Add 'buddy-typing' property and use it

So that we can update chat-view widgets based on the property
instead of letting other classes do it.
parent e5e1cfa3
......@@ -471,6 +471,22 @@ chat_encrypt_changed_cb (ChattyChatView *self)
gtk_image_set_from_icon_name (GTK_IMAGE (self->encrypt_icon), icon_name, 1);
}
static void
chat_buddy_typing_changed_cb (ChattyChatView *self)
{
g_assert (CHATTY_IS_CHAT_VIEW (self));
if (chatty_chat_get_buddy_typing (self->chat)) {
gtk_revealer_set_reveal_child (GTK_REVEALER (self->typing_revealer), TRUE);
self->refresh_typing_id = g_timeout_add (300,
(GSourceFunc)chat_view_indicator_refresh_cb,
self);
} else {
gtk_revealer_set_reveal_child (GTK_REVEALER (self->typing_revealer), FALSE);
g_clear_handle_id (&self->refresh_typing_id, g_source_remove);
}
}
static gboolean
chat_view_input_focus_in_cb (ChattyChatView *self)
{
......@@ -992,8 +1008,13 @@ chatty_chat_view_set_chat (ChattyChatView *self,
G_CALLBACK (chat_encrypt_changed_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (self->chat, "notify::buddy-typing",
G_CALLBACK (chat_buddy_typing_changed_cb),
self,
G_CONNECT_SWAPPED);
chat_encrypt_changed_cb (self);
chat_buddy_typing_changed_cb (self);
chatty_chat_view_update (self);
}
......@@ -1015,24 +1036,3 @@ chatty_chat_view_remove_footer (ChattyChatView *self)
chat_view_hash_table_match_item,
self);
}
void
chatty_chat_view_show_typing_indicator (ChattyChatView *self)
{
g_return_if_fail (CHATTY_IS_CHAT_VIEW (self));
gtk_revealer_set_reveal_child (GTK_REVEALER (self->typing_revealer), TRUE);
self->refresh_typing_id = g_timeout_add (300,
(GSourceFunc)chat_view_indicator_refresh_cb,
self);
}
void
chatty_chat_view_hide_typing_indicator (ChattyChatView *self)
{
g_return_if_fail (CHATTY_IS_CHAT_VIEW (self));
gtk_revealer_set_reveal_child (GTK_REVEALER (self->typing_revealer), FALSE);
g_clear_handle_id (&self->refresh_typing_id, g_source_remove);
}
......@@ -46,7 +46,5 @@ ChattyChat *chatty_chat_view_get_chat (ChattyChatView *self);
void chatty_chat_view_load (ChattyChatView *self,
guint limit);
void chatty_chat_view_remove_footer (ChattyChatView *self);
void chatty_chat_view_show_typing_indicator (ChattyChatView *self);
void chatty_chat_view_hide_typing_indicator (ChattyChatView *self);
G_END_DECLS
......@@ -65,6 +65,7 @@ struct _ChattyChat
e_msg_dir last_msg_direction;
ChattyEncryption encrypt;
gboolean is_im;
gboolean buddy_typing;
};
G_DEFINE_TYPE (ChattyChat, chatty_chat, CHATTY_TYPE_ITEM)
......@@ -72,6 +73,7 @@ G_DEFINE_TYPE (ChattyChat, chatty_chat, CHATTY_TYPE_ITEM)
enum {
PROP_0,
PROP_ENCRYPT,
PROP_BUDDY_TYPING,
PROP_PURPLE_CHAT,
N_PROPS
};
......@@ -329,6 +331,10 @@ chatty_chat_get_property (GObject *object,
g_value_set_boolean (value, self->encrypt == CHATTY_ENCRYPTION_ENABLED);
break;
case PROP_BUDDY_TYPING:
g_value_set_boolean (value, self->buddy_typing);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -396,6 +402,13 @@ chatty_chat_class_init (ChattyChatClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_BUDDY_TYPING] =
g_param_spec_boolean ("buddy-typing",
"Buddy typing",
"Whether the buddy in chat is typing",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_PURPLE_CHAT] =
g_param_spec_pointer ("purple-chat",
"Purple Chat",
......@@ -1091,3 +1104,37 @@ chatty_chat_get_auto_join (ChattyChat *self)
return purple_blist_node_get_bool (node, "chatty-autojoin");
}
/**
* chatty_chat_get_buddy_typing:
* @self: A #ChattyChat
*
* Get if the associated buddy is typing or
* not. This is accurate only for IM chat.
* For multi user chat, this function always
* returns %FALSE
*
* Returns: %TRUE if the chat buddy is typing.
* %FALSE otherwise.
*/
gboolean
chatty_chat_get_buddy_typing (ChattyChat *self)
{
g_return_val_if_fail (CHATTY_IS_CHAT (self), FALSE);
return self->buddy_typing;
}
void
chatty_chat_set_buddy_typing (ChattyChat *self,
gboolean is_typing)
{
g_return_if_fail (CHATTY_IS_CHAT (self));
if (self->buddy_typing == !!is_typing)
return;
self->buddy_typing = !!is_typing;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BUDDY_TYPING]);
}
......@@ -82,5 +82,8 @@ void chatty_chat_set_encryption (ChattyChat *self,
void chatty_chat_set_show_notifications (ChattyChat *self,
gboolean show);
gboolean chatty_chat_get_auto_join (ChattyChat *self);
gboolean chatty_chat_get_buddy_typing (ChattyChat *self);
void chatty_chat_set_buddy_typing (ChattyChat *self,
gboolean is_typing);
G_END_DECLS
......@@ -22,50 +22,6 @@
// *** callbacks
static void
cb_buddy_typing (PurpleAccount *account,
const char *name)
{
PurpleConversation *conv;
ChattyConversation *chatty_conv;
conv = purple_find_conversation_with_account (PURPLE_CONV_TYPE_IM,
name,
account);
if (!conv) {
return;
}
chatty_conv = CHATTY_CONVERSATION(conv);
if (chatty_conv && chatty_conv->conv == conv) {
chatty_chat_view_show_typing_indicator (CHATTY_CHAT_VIEW (chatty_conv->chat_view));
}
}
static void
cb_buddy_typed (PurpleAccount *account,
const char *name)
{
PurpleConversation *conv;
ChattyConversation *chatty_conv;
conv = purple_find_conversation_with_account (PURPLE_CONV_TYPE_IM,
name,
account);
if (!conv) {
return;
}
chatty_conv = CHATTY_CONVERSATION(conv);
if (chatty_conv && chatty_conv->conv == conv) {
chatty_chat_view_hide_typing_indicator (CHATTY_CHAT_VIEW (chatty_conv->chat_view));
}
}
static void
cb_update_buddy_icon (PurpleBuddy *buddy)
{
......@@ -277,18 +233,6 @@ chatty_conversations_init (void)
purple_signal_connect (blist_handle, "buddy-icon-changed",
handle, PURPLE_CALLBACK (cb_update_buddy_icon), NULL);
purple_signal_connect (purple_conversations_get_handle (),
"buddy-typing", &handle,
PURPLE_CALLBACK (cb_buddy_typing), NULL);
purple_signal_connect (purple_conversations_get_handle (),
"buddy-typed", &handle,
PURPLE_CALLBACK (cb_buddy_typed), NULL);
purple_signal_connect (purple_conversations_get_handle (),
"buddy-typing-stopped", &handle,
PURPLE_CALLBACK (cb_buddy_typed), NULL);
chatty_chat_view_purple_init ();
}
......
......@@ -1365,6 +1365,44 @@ manager_deleting_conversation_cb (PurpleConversation *conv,
chatty_manager_delete_conversation (self, conv);
}
static void
manager_buddy_set_typing (PurpleAccount *account,
const char *name,
ChattyManager *self,
gboolean is_typing)
{
PurpleConversation *conv;
ChattyChat *chat;
g_assert (CHATTY_IS_MANAGER (self));
conv = purple_find_conversation_with_account (PURPLE_CONV_TYPE_IM,
name,
account);
if (!conv)
return;
chat = chatty_manager_find_purple_conv (self, conv);
g_return_if_fail (chat);
chatty_chat_set_buddy_typing (chat, is_typing);
}
static void
manager_buddy_typing_cb (PurpleAccount *account,
const char *name,
ChattyManager *self)
{
manager_buddy_set_typing (account, name, self, TRUE);
}
static void
manager_buddy_typing_stopped_cb (PurpleAccount *account,
const char *name,
ChattyManager *self)
{
manager_buddy_set_typing (account, name, self, FALSE);
}
static gboolean
manager_conversation_buddy_leaving_cb (PurpleConversation *conv,
......@@ -1779,6 +1817,16 @@ chatty_manager_initialize_libpurple (ChattyManager *self)
"deleting-conversation", self,
PURPLE_CALLBACK (manager_deleting_conversation_cb), self);
purple_signal_connect (purple_conversations_get_handle (),
"buddy-typing", self,
PURPLE_CALLBACK (manager_buddy_typing_cb), self);
purple_signal_connect (purple_conversations_get_handle (),
"buddy-typed", self,
PURPLE_CALLBACK (manager_buddy_typing_stopped_cb), self);
purple_signal_connect (purple_conversations_get_handle (),
"buddy-typing-stopped", self,
PURPLE_CALLBACK (manager_buddy_typing_stopped_cb), self);
/**
* This is default fallback history handler which is called last,
* other plugins may intercept and suppress it if they handle history
......
......@@ -276,29 +276,6 @@ window_get_active_purple_conv (GtkNotebook *notebook)
return chatty_conv ? chatty_conv->conv : NULL;
}
static void
window_notebook_before_switch_cb (GtkNotebook *notebook,
GtkWidget *page,
gint page_num,
ChattyWindow *self)
{
ChattyConversation *chatty_conv;
PurpleConversation *conv;
g_assert (GTK_IS_NOTEBOOK (notebook));
g_assert (CHATTY_IS_WINDOW (self));
conv = window_get_active_purple_conv (GTK_NOTEBOOK (self->convs_notebook));
g_return_if_fail (conv != NULL);
chatty_conv = CHATTY_CONVERSATION (conv);
chatty_chat_view_hide_typing_indicator (CHATTY_CHAT_VIEW (chatty_conv->chat_view));
}
static void
window_notebook_after_switch_cb (GtkNotebook *notebook,
GtkWidget *page,
......@@ -1160,10 +1137,6 @@ chatty_window_init (ChattyWindow *self)
G_CALLBACK (window_active_protocols_changed_cb), self,
G_CONNECT_SWAPPED);
g_signal_connect (G_OBJECT (self->convs_notebook),
"switch-page",
G_CALLBACK (window_notebook_before_switch_cb), self);
g_signal_connect_after (G_OBJECT (self->convs_notebook),
"switch-page",
G_CALLBACK (window_notebook_after_switch_cb), self);
......
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