diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2007-07-01 05:12:20 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2007-07-01 05:12:20 +0800 |
commit | 63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2 (patch) | |
tree | 569b475dff544ef4e2b6f75ac86dc196f600167a /libempathy-gtk | |
parent | 7746736afa656f880933e3f5a9effaba490be65a (diff) | |
download | gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.tar gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.tar.gz gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.tar.bz2 gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.tar.lz gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.tar.xz gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.tar.zst gsoc2013-empathy-63bc73ed30d97c8ecfb1be4bc19c3e30e9aaddf2.zip |
Fix a leaked ref.
2007-06-30 Xavier Claessens <xclaesse@gmail.com>
* libempathy-gtk/empathy-account-widget-generic.c: Fix a leaked ref.
* src/empathy.c: If we get a chatroom we have to create an
EmpathyTpChatroom object.
* src/Makefile.am: Fix build system, programs links to libempathy-gtk
and libempathy.
* configure.ac: libempathy does not depends on libgnome-vfs.
* libempathy-gtk/empathy-status-icon.c:
* libempathy-gtk/empathy-chat.c:
* libempathy/empathy-tp-chat.c:
* libempathy/empathy-tp-chat.h:
* libempathy/empathy-filter.c:
* libempathy/empathy-filter.h:
* libempathy/empathy-filter.xml:
* libempathy/Makefile.am: Filter incoming text channels and make
status icon flash when there we receive a new message. Dispatch the
channel only when we get a message and the user click on the icon.
svn path=/trunk/; revision=175
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-account-widget-generic.c | 2 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 16 | ||||
-rw-r--r-- | libempathy-gtk/empathy-group-chat.c | 37 | ||||
-rw-r--r-- | libempathy-gtk/empathy-private-chat.c | 19 | ||||
-rw-r--r-- | libempathy-gtk/empathy-status-icon.c | 99 |
5 files changed, 126 insertions, 47 deletions
diff --git a/libempathy-gtk/empathy-account-widget-generic.c b/libempathy-gtk/empathy-account-widget-generic.c index 4f9ea03b0..73b579a55 100644 --- a/libempathy-gtk/empathy-account-widget-generic.c +++ b/libempathy-gtk/empathy-account-widget-generic.c @@ -258,6 +258,8 @@ accounts_widget_generic_setup (EmpathyAccountWidgetGeneric *settings) settings); g_slist_free (params); + g_object_unref (profile); + g_object_unref (protocol); } static void diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 0000e5d5a..8f6ca3705 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -392,7 +392,7 @@ chat_input_text_view_send (EmpathyChat *chat) } static void -chat_message_received_cb (EmpathyTpChat *tp_chat, +chat_message_received_cb (EmpathyTpChat *tp_chat, EmpathyMessage *message, EmpathyChat *chat) { @@ -1288,10 +1288,11 @@ empathy_chat_load_geometry (EmpathyChat *chat, } void -empathy_chat_set_tp_chat (EmpathyChat *chat, - EmpathyTpChat *tp_chat) +empathy_chat_set_tp_chat (EmpathyChat *chat, + EmpathyTpChat *tp_chat) { EmpathyChatPriv *priv; + GList *messages, *l; g_return_if_fail (EMPATHY_IS_CHAT (chat)); g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat)); @@ -1332,7 +1333,14 @@ empathy_chat_set_tp_chat (EmpathyChat *chat, G_CALLBACK (chat_destroy_cb), chat); - empathy_tp_chat_request_pending (tp_chat); + /* Get pending messages */ + empathy_tp_chat_set_acknowledge (tp_chat, TRUE); + messages = empathy_tp_chat_get_pendings (tp_chat); + for (l = messages; l; l = l->next) { + chat_message_received_cb (tp_chat, l->data, chat); + g_object_unref (l->data); + } + g_list_free (messages); if (!priv->sensitive) { gtk_widget_set_sensitive (chat->input_text_view, TRUE); diff --git a/libempathy-gtk/empathy-group-chat.c b/libempathy-gtk/empathy-group-chat.c index 623547d9b..6861dd5cd 100644 --- a/libempathy-gtk/empathy-group-chat.c +++ b/libempathy-gtk/empathy-group-chat.c @@ -75,39 +75,36 @@ struct _EmpathyGroupChatPriv { }; static void group_chat_finalize (GObject *object); -static void group_chat_create_ui (EmpathyGroupChat *chat); +static void group_chat_create_ui (EmpathyGroupChat *chat); static void group_chat_widget_destroy_cb (GtkWidget *widget, - EmpathyGroupChat *chat); + EmpathyGroupChat *chat); static void group_chat_contact_added_cb (EmpathyTpChatroom *tp_chat, - EmpathyContact *contact, - EmpathyGroupChat *chat); + EmpathyContact *contact, + EmpathyGroupChat *chat); static void group_chat_contact_removed_cb (EmpathyTpChatroom *tp_chat, - EmpathyContact *contact, - EmpathyGroupChat *chat); -/*static void group_chat_topic_changed_cb (EmpathyTpChatroom *tp_chat, - const gchar *new_topic, - EmpathyGroupChat *chat);*/ + EmpathyContact *contact, + EmpathyGroupChat *chat); static void group_chat_topic_entry_activate_cb (GtkWidget *entry, GtkDialog *dialog); static void group_chat_topic_response_cb (GtkWidget *dialog, gint response, - EmpathyGroupChat *chat); -static const gchar * group_chat_get_name (EmpathyChat *chat); -static gchar * group_chat_get_tooltip (EmpathyChat *chat); -static const gchar * group_chat_get_status_icon_name (EmpathyChat *chat); -static GtkWidget * group_chat_get_widget (EmpathyChat *chat); -static gboolean group_chat_is_group_chat (EmpathyChat *chat); -static void group_chat_set_tp_chat (EmpathyChat *chat, + EmpathyGroupChat *chat); +static const gchar * group_chat_get_name (EmpathyChat *chat); +static gchar * group_chat_get_tooltip (EmpathyChat *chat); +static const gchar * group_chat_get_status_icon_name (EmpathyChat *chat); +static GtkWidget * group_chat_get_widget (EmpathyChat *chat); +static gboolean group_chat_is_group_chat (EmpathyChat *chat); +static void group_chat_set_tp_chat (EmpathyChat *chat, EmpathyTpChat *tp_chat); static void group_chat_subject_notify_cb (EmpathyTpChat *tp_chat, GParamSpec *param, - EmpathyGroupChat *chat); + EmpathyGroupChat *chat); static void group_chat_name_notify_cb (EmpathyTpChat *tp_chat, GParamSpec *param, - EmpathyGroupChat *chat); + EmpathyGroupChat *chat); /*static gboolean group_chat_key_press_event (GtkWidget *widget, GdkEventKey *event, - EmpathyGroupChat *chat);*/ + EmpathyGroupChat *chat);*/ static gint group_chat_contacts_completion_func (const gchar *s1, const gchar *s2, gsize n); @@ -173,7 +170,7 @@ group_chat_finalize (GObject *object) EmpathyGroupChat * empathy_group_chat_new (McAccount *account, - TpChan *tp_chan) + TpChan *tp_chan) { EmpathyGroupChat *chat; EmpathyGroupChatPriv *priv; diff --git a/libempathy-gtk/empathy-private-chat.c b/libempathy-gtk/empathy-private-chat.c index ddc0633e4..81f93c021 100644 --- a/libempathy-gtk/empathy-private-chat.c +++ b/libempathy-gtk/empathy-private-chat.c @@ -37,7 +37,6 @@ #include <libempathy/empathy-tp-chat.h> #include <libempathy/empathy-tp-contact-list.h> #include <libempathy/empathy-contact-manager.h> -//#include <libempathy/empathy-log.h> #include "empathy-private-chat.h" #include "empathy-chat-view.h" @@ -53,12 +52,10 @@ struct _EmpathyPrivateChatPriv { EmpathyContact *contact; - gchar *name; - - gboolean is_online; - - GtkWidget *widget; - GtkWidget *text_view_sw; + gchar *name; + gboolean is_online; + GtkWidget *widget; + GtkWidget *text_view_sw; }; static void empathy_private_chat_class_init (EmpathyPrivateChatClass *klass); @@ -328,13 +325,13 @@ private_chat_setup (EmpathyPrivateChat *chat, EmpathyPrivateChat * empathy_private_chat_new (McAccount *account, - TpChan *tp_chan) + TpChan *tp_chan) { - EmpathyPrivateChat *chat; + EmpathyPrivateChat *chat; EmpathyTpChat *tp_chat; EmpathyContactManager *manager; EmpathyTpContactList *list; - EmpathyContact *contact; + EmpathyContact *contact; g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); @@ -359,7 +356,7 @@ EmpathyPrivateChat * empathy_private_chat_new_with_contact (EmpathyContact *contact) { EmpathyPrivateChat *chat; - EmpathyTpChat *tp_chat; + EmpathyTpChat *tp_chat; g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); diff --git a/libempathy-gtk/empathy-status-icon.c b/libempathy-gtk/empathy-status-icon.c index b9c1af790..6ec17ecc0 100644 --- a/libempathy-gtk/empathy-status-icon.c +++ b/libempathy-gtk/empathy-status-icon.c @@ -33,10 +33,12 @@ #include <libempathy/empathy-contact-list.h> #include <libempathy/empathy-contact-manager.h> #include <libempathy/empathy-contact.h> +#include <libempathy/empathy-tp-chat.h> #include <libempathy/empathy-debug.h> #include <libempathy/empathy-utils.h> #include <libempathy/empathy-conf.h> #include <libempathy/empathy-idle.h> +#include <libempathy/empathy-filter.h> #include "empathy-status-icon.h" #include "empathy-contact-dialogs.h" @@ -44,6 +46,7 @@ #include "empathy-preferences.h" #include "empathy-ui-utils.h" #include "empathy-accounts-dialog.h" +#include "empathy-images.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ @@ -59,9 +62,11 @@ typedef struct _StatusIconEvent StatusIconEvent; struct _EmpathyStatusIconPriv { GtkStatusIcon *icon; EmpathyContactManager *manager; + EmpathyFilter *text_filter; EmpathyIdle *idle; + MissionControl *mc; GList *events; - GList *current_event; + gboolean showing_event_icon; StatusIconEvent *flash_state_event; guint blink_timeout; @@ -85,6 +90,10 @@ struct _StatusIconEvent { static void empathy_status_icon_class_init (EmpathyStatusIconClass *klass); static void empathy_status_icon_init (EmpathyStatusIcon *icon); static void status_icon_finalize (GObject *object); +static void status_icon_filter_new_channel (EmpathyFilter *filter, + TpConn *tp_conn, + TpChan *tp_chan, + EmpathyStatusIcon *icon); static void status_icon_idle_notify_cb (EmpathyStatusIcon *icon); static void status_icon_update_tooltip (EmpathyStatusIcon *icon); static void status_icon_set_from_state (EmpathyStatusIcon *icon); @@ -111,6 +120,7 @@ static void status_icon_local_pending_cb (EmpathyContactManager *manag EmpathyStatusIcon *icon); static void status_icon_event_subscribe_cb (StatusIconEvent *event); static void status_icon_event_flash_state_cb (StatusIconEvent *event); +static void status_icon_event_msg_cb (StatusIconEvent *event); static StatusIconEvent * status_icon_event_new (EmpathyStatusIcon *icon, const gchar *icon_name, const gchar *message); @@ -142,10 +152,19 @@ empathy_status_icon_init (EmpathyStatusIcon *icon) priv->icon = gtk_status_icon_new (); priv->idle = empathy_idle_new (); priv->manager = empathy_contact_manager_new (); + priv->mc = empathy_mission_control_new (); + priv->text_filter = empathy_filter_new ("org.gnome.Empathy.Chat", + "/org/freedesktop/Telepathy/Filter", + TP_IFACE_CHANNEL_TYPE_TEXT, + MC_FILTER_PRIORITY_DIALOG, + MC_FILTER_FLAG_INCOMING); status_icon_create_menu (icon); status_icon_idle_notify_cb (icon); + g_signal_connect (priv->text_filter, "new-channel", + G_CALLBACK (status_icon_filter_new_channel), + icon); g_signal_connect_swapped (priv->idle, "notify", G_CALLBACK (status_icon_idle_notify_cb), icon); @@ -190,6 +209,7 @@ status_icon_finalize (GObject *object) g_object_unref (priv->window); g_object_unref (priv->idle); g_object_unref (priv->manager); + g_object_unref (priv->mc); } EmpathyStatusIcon * @@ -224,6 +244,51 @@ empathy_status_icon_new (GtkWindow *window) } static void +status_icon_filter_new_channel (EmpathyFilter *filter, + TpConn *tp_conn, + TpChan *tp_chan, + EmpathyStatusIcon *icon) +{ + EmpathyStatusIconPriv *priv; + McAccount *account; + EmpathyTpChat *tp_chat; + EmpathyContact *sender; + GList *messages; + gchar *msg; + StatusIconEvent *event; + + priv = GET_PRIV (icon); + + empathy_debug (DEBUG_DOMAIN, "New text channel to be filtered"); + + account = mission_control_get_account_for_connection (priv->mc, tp_conn, NULL); + tp_chat = empathy_tp_chat_new (account, tp_chan); + g_object_unref (account); + + messages = empathy_tp_chat_get_pendings (tp_chat); + if (!messages) { + empathy_debug (DEBUG_DOMAIN, "There is no message pending, " + "don't dispatch the channel"); + empathy_filter_process (filter, tp_chan, FALSE); + g_object_unref (tp_chat); + return; + } + + sender = empathy_message_get_sender (messages->data); + msg = g_strdup_printf (_("New message from %s:\n%s"), + empathy_contact_get_name (sender), + empathy_message_get_body (messages->data)); + + g_object_set_data (G_OBJECT (tp_chat), "filter", filter); + event = status_icon_event_new (icon, EMPATHY_IMAGE_NEW_MESSAGE, msg); + event->func = status_icon_event_msg_cb; + event->user_data = tp_chat; + + g_list_foreach (messages, (GFunc) g_object_unref, NULL); + g_list_free (messages); +} + +static void status_icon_idle_notify_cb (EmpathyStatusIcon *icon) { EmpathyStatusIconPriv *priv; @@ -241,7 +306,6 @@ status_icon_idle_notify_cb (EmpathyStatusIcon *icon) priv->flash_state_event = status_icon_event_new (icon, icon_name, NULL); priv->flash_state_event->user_data = icon; priv->flash_state_event->func = status_icon_event_flash_state_cb; - } else { /* We are still flashing but with another state */ g_free (priv->flash_state_event->icon_name); @@ -254,7 +318,7 @@ status_icon_idle_notify_cb (EmpathyStatusIcon *icon) priv->flash_state_event = NULL; } - if (!priv->current_event) { + if (!priv->showing_event_icon) { status_icon_set_from_state (icon); } @@ -498,6 +562,21 @@ status_icon_event_flash_state_cb (StatusIconEvent *event) empathy_idle_set_flash_state (priv->idle, MC_PRESENCE_UNSET); } +static void +status_icon_event_msg_cb (StatusIconEvent *event) +{ + EmpathyFilter *filter; + EmpathyTpChat *tp_chat; + + empathy_debug (DEBUG_DOMAIN, "Dispatching text channel"); + + tp_chat = event->user_data; + filter = g_object_get_data (G_OBJECT (tp_chat), "filter"); + empathy_filter_process (filter, + empathy_tp_chat_get_channel (tp_chat), + TRUE); + g_object_unref (tp_chat); +} static StatusIconEvent * status_icon_event_new (EmpathyStatusIcon *icon, @@ -515,7 +594,7 @@ status_icon_event_new (EmpathyStatusIcon *icon, priv->events = g_list_append (priv->events, event); if (!priv->blink_timeout) { - priv->current_event = NULL; + priv->showing_event_icon = FALSE; priv->blink_timeout = g_timeout_add (BLINK_TIMEOUT, (GSourceFunc) status_icon_event_timeout_cb, icon); @@ -538,7 +617,7 @@ status_icon_event_remove (EmpathyStatusIcon *icon, } priv->events = g_list_remove (priv->events, event); status_icon_event_free (event); - priv->current_event = NULL; + priv->showing_event_icon = FALSE; status_icon_update_tooltip (icon); status_icon_set_from_state (icon); @@ -559,18 +638,14 @@ status_icon_event_timeout_cb (EmpathyStatusIcon *icon) priv = GET_PRIV (icon); - if (priv->current_event) { - priv->current_event = priv->current_event->next; - } else { - priv->current_event = priv->events; - } + priv->showing_event_icon = !priv->showing_event_icon; - if (!priv->current_event) { + if (!priv->showing_event_icon) { status_icon_set_from_state (icon); } else { StatusIconEvent *event; - event = priv->current_event->data; + event = priv->events->data; gtk_status_icon_set_from_icon_name (priv->icon, event->icon_name); } status_icon_update_tooltip (icon); |