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 | |
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')
-rw-r--r-- | libempathy/Makefile.am | 6 | ||||
-rw-r--r-- | libempathy/empathy-filter.c | 232 | ||||
-rw-r--r-- | libempathy/empathy-filter.h | 63 | ||||
-rw-r--r-- | libempathy/empathy-filter.xml | 18 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.c | 272 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.h | 10 |
6 files changed, 498 insertions, 103 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index c30f62fa5..3f73265cf 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -8,6 +8,7 @@ AM_CPPFLAGS = \ BUILT_SOURCES = \ empathy-marshal.h \ empathy-marshal.c \ + empathy-filter-glue.h \ empathy-chandler-glue.h lib_LTLIBRARIES = libempathy.la @@ -30,6 +31,7 @@ libempathy_la_SOURCES = \ empathy-tp-chat.c \ empathy-tp-chatroom.c \ empathy-chandler.c \ + empathy-filter.c \ empathy-idle.c \ empathy-log-manager.c \ empathy-marshal-main.c @@ -56,6 +58,7 @@ libempathy_HEADERS = \ empathy-tp-chat.h \ empathy-tp-chatroom.h \ empathy-chandler.h \ + empathy-filter.h \ empathy-idle.h \ empathy-log-manager.h @@ -69,6 +72,8 @@ libempathy_HEADERS = \ empathy-chandler-glue.h: empathy-chandler.xml $(LIBTOOL) --mode=execute $(DBUS_BINDING_TOOL) --prefix=empathy_chandler --mode=glib-server --output=$@ $< +empathy-filter-glue.h: empathy-filter.xml + $(LIBTOOL) --mode=execute $(DBUS_BINDING_TOOL) --prefix=empathy_filter --mode=glib-server --output=$@ $< dtddir = $(datadir)/empathy dtd_DATA = \ @@ -84,6 +89,7 @@ pkgconfig_DATA = libempathy.pc EXTRA_DIST = \ empathy-marshal.list \ empathy-chandler.xml \ + empathy-filter.xml \ $(stylesheet_DATA) \ $(dtd_DATA) diff --git a/libempathy/empathy-filter.c b/libempathy/empathy-filter.c new file mode 100644 index 000000000..c811991f5 --- /dev/null +++ b/libempathy/empathy-filter.c @@ -0,0 +1,232 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Xavier Claessens <xclaesse@gmail.com> + */ + +#include <config.h> + +#include <dbus/dbus-glib.h> + +#include <libtelepathy/tp-helpers.h> +#include <libtelepathy/tp-conn.h> + +#include "empathy-filter.h" +#include "empathy-debug.h" +#include "empathy-utils.h" +#include "empathy-marshal.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + EMPATHY_TYPE_FILTER, EmpathyFilterPriv)) + +#define DEBUG_DOMAIN "EmpathyFilter" + +struct _EmpathyFilterPriv { + GHashTable *table; +}; + +static void empathy_filter_class_init (EmpathyFilterClass *klass); +static void empathy_filter_init (EmpathyFilter *filter); +static void filter_finalize (GObject *object); +static gboolean empathy_filter_filter_channel (EmpathyFilter *filter, + const gchar *bus_name, + const gchar *connection, + const gchar *channel_type, + const gchar *channel, + guint handle_type, + guint handle, + guint id, + GError **error); + +#include "empathy-filter-glue.h" + +enum { + PROCESS, + NEW_CHANNEL, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (EmpathyFilter, empathy_filter, G_TYPE_OBJECT) + +static void +empathy_filter_class_init (EmpathyFilterClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = filter_finalize; + + signals[NEW_CHANNEL] = + g_signal_new ("new-channel", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + empathy_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, + 2, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE); + + signals[PROCESS] = + g_signal_new ("process", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + empathy_marshal_VOID__UINT_BOOLEAN, + G_TYPE_NONE, + 2, G_TYPE_UINT, G_TYPE_BOOLEAN); + + g_type_class_add_private (object_class, sizeof (EmpathyFilterPriv)); +} + +static void +empathy_filter_init (EmpathyFilter *filter) +{ + EmpathyFilterPriv *priv; + + priv = GET_PRIV (filter); + + priv->table = g_hash_table_new_full (g_direct_hash, g_direct_equal, + (GDestroyNotify) g_object_unref, + NULL); +} + +static void +filter_finalize (GObject *object) +{ + EmpathyFilterPriv *priv; + + priv = GET_PRIV (object); + + g_hash_table_destroy (priv->table); +} + +EmpathyFilter * +empathy_filter_new (const gchar *bus_name, + const gchar *object_path, + const gchar *channel_type, + guint priority, + guint flags) +{ + static gboolean initialized = FALSE; + MissionControl *mc; + EmpathyFilter *filter; + DBusGProxy *proxy; + guint result; + GError *error = NULL; + + if (!initialized) { + dbus_g_object_type_install_info (EMPATHY_TYPE_FILTER, + &dbus_glib_empathy_filter_object_info); + initialized = TRUE; + } + + proxy = dbus_g_proxy_new_for_name (tp_get_bus (), + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + + if (!dbus_g_proxy_call (proxy, "RequestName", &error, + G_TYPE_STRING, bus_name, + G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, + G_TYPE_INVALID, + G_TYPE_UINT, &result, + G_TYPE_INVALID)) { + empathy_debug (DEBUG_DOMAIN, + "Failed to request name: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + + return NULL; + } + g_object_unref (proxy); + + filter = g_object_new (EMPATHY_TYPE_FILTER, NULL); + dbus_g_connection_register_g_object (tp_get_bus (), + object_path, + G_OBJECT (filter)); + + mc = empathy_mission_control_new (); + mission_control_register_filter (mc, + bus_name, + object_path, + channel_type, + priority, + flags, + NULL); + g_object_unref (mc); + + return filter; +} + +void +empathy_filter_process (EmpathyFilter *filter, + TpChan *tp_chan, + gboolean process) +{ + EmpathyFilterPriv *priv; + guint id; + + priv = GET_PRIV (filter); + + id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->table, tp_chan)); + if (id != 0) { + g_signal_emit (filter, signals[PROCESS], 0, id, process); + g_hash_table_remove (priv->table, tp_chan); + } +} + +static gboolean +empathy_filter_filter_channel (EmpathyFilter *filter, + const gchar *bus_name, + const gchar *connection, + const gchar *channel_type, + const gchar *channel, + guint handle_type, + guint handle, + guint id, + GError **error) +{ + EmpathyFilterPriv *priv; + TpChan *tp_chan; + TpConn *tp_conn; + + priv = GET_PRIV (filter); + + tp_conn = tp_conn_new (tp_get_bus (), + bus_name, + connection); + + tp_chan = tp_chan_new (tp_get_bus(), + bus_name, + channel, + channel_type, + handle_type, + handle); + + g_hash_table_insert (priv->table, tp_chan, GUINT_TO_POINTER (id)); + + g_signal_emit (filter, signals[NEW_CHANNEL], 0, tp_conn, tp_chan); + + g_object_unref (tp_conn); + + return TRUE; +} + diff --git a/libempathy/empathy-filter.h b/libempathy/empathy-filter.h new file mode 100644 index 000000000..53c85935a --- /dev/null +++ b/libempathy/empathy-filter.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Xavier Claessens <xclaesse@gmail.com> + */ + +#ifndef __EMPATHY_FILTER_H__ +#define __EMPATHY_FILTER_H__ + +#include <glib.h> + +#include <libtelepathy/tp-chan.h> + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_FILTER (empathy_filter_get_type ()) +#define EMPATHY_FILTER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_FILTER, EmpathyFilter)) +#define EMPATHY_FILTER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_FILTER, EmpathyFilterClass)) +#define EMPATHY_IS_FILTER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_FILTER)) +#define EMPATHY_IS_FILTER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_FILTER)) +#define EMPATHY_FILTER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_FILTER, EmpathyFilterClass)) + +typedef struct _EmpathyFilter EmpathyFilter; +typedef struct _EmpathyFilterClass EmpathyFilterClass; +typedef struct _EmpathyFilterPriv EmpathyFilterPriv; + +struct _EmpathyFilter { + GObject parent; +}; + +struct _EmpathyFilterClass { + GObjectClass parent_class; +}; + +GType empathy_filter_get_type (void) G_GNUC_CONST; +EmpathyFilter *empathy_filter_new (const gchar *bus_name, + const gchar *object_path, + const gchar *channel_type, + guint priority, + guint flags); +void empathy_filter_process (EmpathyFilter *filter, + TpChan *tp_chan, + gboolean process); + +G_END_DECLS + +#endif /* __EMPATHY_FILTER_H__ */ diff --git a/libempathy/empathy-filter.xml b/libempathy/empathy-filter.xml new file mode 100644 index 000000000..0223fefb0 --- /dev/null +++ b/libempathy/empathy-filter.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<node name="/"> + <interface name="org.freedesktop.Telepathy.MissionControl.Filter"> + <method name="FilterChannel"> + <arg direction="in" type="s" name="bus_name" /> + <arg direction="in" type="o" name="connection" /> + <arg direction="in" type="s" name="channel_type" /> + <arg direction="in" type="o" name="channel" /> + <arg direction="in" type="u" name="handle_type" /> + <arg direction="in" type="u" name="handle" /> + <arg direction="in" type="u" name="id" /> + </method> + <signal name="Process"> + <arg type="u" name="id"/> + <arg type="b" name="process"/> + </signal> + </interface> +</node> diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index e97b5d641..e52b4a086 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -49,6 +49,7 @@ struct _EmpathyTpChatPriv { McAccount *account; gchar *id; MissionControl *mc; + gboolean acknowledge; TpChan *tp_chan; DBusGProxy *props_iface; @@ -56,56 +57,57 @@ struct _EmpathyTpChatPriv { DBusGProxy *chat_state_iface; }; -static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass); -static void empathy_tp_chat_init (EmpathyTpChat *chat); -static void tp_chat_finalize (GObject *object); -static GObject * tp_chat_constructor (GType type, - guint n_props, - GObjectConstructParam *props); -static void tp_chat_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void tp_chat_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void tp_chat_destroy_cb (TpChan *text_chan, - EmpathyTpChat *chat); -static void tp_chat_closed_cb (TpChan *text_chan, - EmpathyTpChat *chat); -static void tp_chat_received_cb (DBusGProxy *text_iface, - guint message_id, - guint timestamp, - guint from_handle, - guint message_type, - guint message_flags, - gchar *message_body, - EmpathyTpChat *chat); -static void tp_chat_sent_cb (DBusGProxy *text_iface, - guint timestamp, - guint message_type, - gchar *message_body, - EmpathyTpChat *chat); -static void tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, - guint handle, - TelepathyChannelChatState state, - EmpathyTpChat *chat); -static void tp_chat_emit_message (EmpathyTpChat *chat, - guint type, - guint timestamp, - guint from_handle, - const gchar *message_body); -static void tp_chat_properties_ready_cb (TpPropsIface *props_iface, - EmpathyTpChat *chat); -static void tp_chat_properties_changed_cb (TpPropsIface *props_iface, - guint prop_id, - TpPropsChanged flag, - EmpathyTpChat *chat); +static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass); +static void empathy_tp_chat_init (EmpathyTpChat *chat); +static void tp_chat_finalize (GObject *object); +static GObject * tp_chat_constructor (GType type, + guint n_props, + GObjectConstructParam *props); +static void tp_chat_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void tp_chat_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); +static void tp_chat_destroy_cb (TpChan *text_chan, + EmpathyTpChat *chat); +static void tp_chat_closed_cb (TpChan *text_chan, + EmpathyTpChat *chat); +static void tp_chat_received_cb (DBusGProxy *text_iface, + guint message_id, + guint timestamp, + guint from_handle, + guint message_type, + guint message_flags, + gchar *message_body, + EmpathyTpChat *chat); +static void tp_chat_sent_cb (DBusGProxy *text_iface, + guint timestamp, + guint message_type, + gchar *message_body, + EmpathyTpChat *chat); +static void tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, + guint handle, + TelepathyChannelChatState state, + EmpathyTpChat *chat); +static EmpathyMessage * tp_chat_build_message (EmpathyTpChat *chat, + guint type, + guint timestamp, + guint from_handle, + const gchar *message_body); +static void tp_chat_properties_ready_cb (TpPropsIface *props_iface, + EmpathyTpChat *chat); +static void tp_chat_properties_changed_cb (TpPropsIface *props_iface, + guint prop_id, + TpPropsChanged flag, + EmpathyTpChat *chat); enum { PROP_0, PROP_ACCOUNT, PROP_TP_CHAN, + PROP_ACKNOWLEDGE, PROP_ANONYMOUS, PROP_INVITE_ONLY, @@ -162,6 +164,15 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + /* Normal properties */ + g_object_class_install_property (object_class, + PROP_ACKNOWLEDGE, + g_param_spec_boolean ("acknowledge", + "acknowledge", + "acknowledge", + FALSE, + G_PARAM_READWRITE)); + /* Properties of Text Channel */ g_object_class_install_property (object_class, PROP_ANONYMOUS, @@ -320,17 +331,17 @@ tp_chat_finalize (GObject *object) priv = GET_PRIV (chat); if (priv->tp_chan) { - empathy_debug (DEBUG_DOMAIN, "Closing channel..."); - g_signal_handlers_disconnect_by_func (priv->tp_chan, tp_chat_destroy_cb, object); - - if (!tp_chan_close (DBUS_G_PROXY (priv->tp_chan), &error)) { - empathy_debug (DEBUG_DOMAIN, - "Error closing text channel: %s", - error ? error->message : "No error given"); - g_clear_error (&error); + if (priv->acknowledge) { + empathy_debug (DEBUG_DOMAIN, "Closing channel..."); + if (!tp_chan_close (DBUS_G_PROXY (priv->tp_chan), &error)) { + empathy_debug (DEBUG_DOMAIN, + "Error closing text channel: %s", + error ? error->message : "No error given"); + g_clear_error (&error); + } } g_object_unref (priv->tp_chan); } @@ -453,6 +464,9 @@ tp_chat_get_property (GObject *object, case PROP_TP_CHAN: g_value_set_object (value, priv->tp_chan); break; + case PROP_ACKNOWLEDGE: + g_value_set_boolean (value, priv->acknowledge); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -489,6 +503,10 @@ tp_chat_set_property (GObject *object, case PROP_TP_CHAN: priv->tp_chan = g_object_ref (g_value_get_object (value)); break; + case PROP_ACKNOWLEDGE: + empathy_tp_chat_set_acknowledge (EMPATHY_TP_CHAT (object), + g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -548,39 +566,79 @@ empathy_tp_chat_new_with_contact (EmpathyContact *contact) return chat; } +gboolean +empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat) +{ + EmpathyTpChatPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE); + + priv = GET_PRIV (chat); + + return priv->acknowledge; +} + void -empathy_tp_chat_request_pending (EmpathyTpChat *chat) +empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat, + gboolean acknowledge) +{ + EmpathyTpChatPriv *priv; + + g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); + + priv = GET_PRIV (chat); + + priv->acknowledge = acknowledge; + g_object_notify (G_OBJECT (chat), "acknowledge"); +} + +TpChan * +empathy_tp_chat_get_channel (EmpathyTpChat *chat) +{ + EmpathyTpChatPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL); + + priv = GET_PRIV (chat); + + return priv->tp_chan; +} + +GList * +empathy_tp_chat_get_pendings (EmpathyTpChat *chat) { EmpathyTpChatPriv *priv; GPtrArray *messages_list; guint i; + GList *messages = NULL; GError *error = NULL; - g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); + g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL); priv = GET_PRIV (chat); /* If we do this call async, don't forget to ignore Received signal * until we get the answer */ if (!tp_chan_type_text_list_pending_messages (priv->text_iface, - TRUE, + priv->acknowledge, &messages_list, &error)) { empathy_debug (DEBUG_DOMAIN, "Error retrieving pending messages: %s", error ? error->message : "No error given"); g_clear_error (&error); - return; + return NULL; } for (i = 0; i < messages_list->len; i++) { - GValueArray *message_struct; - const gchar *message_body; - guint message_id; - guint timestamp; - guint from_handle; - guint message_type; - guint message_flags; + EmpathyMessage *message; + GValueArray *message_struct; + const gchar *message_body; + guint message_id; + guint timestamp; + guint from_handle; + guint message_type; + guint message_flags; message_struct = g_ptr_array_index (messages_list, i); @@ -593,16 +651,20 @@ empathy_tp_chat_request_pending (EmpathyTpChat *chat) empathy_debug (DEBUG_DOMAIN, "Message pending: %s", message_body); - tp_chat_emit_message (chat, - message_type, - timestamp, - from_handle, - message_body); + message = tp_chat_build_message (chat, + message_type, + timestamp, + from_handle, + message_body); + + messages = g_list_prepend (messages, message); g_value_array_free (message_struct); } g_ptr_array_free (messages_list, TRUE); + + return messages; } void @@ -722,23 +784,30 @@ tp_chat_received_cb (DBusGProxy *text_iface, EmpathyTpChat *chat) { EmpathyTpChatPriv *priv; - GArray *message_ids; + EmpathyMessage *message; priv = GET_PRIV (chat); empathy_debug (DEBUG_DOMAIN, "Message received: %s", message_body); - tp_chat_emit_message (chat, - message_type, - timestamp, - from_handle, - message_body); - - message_ids = g_array_new (FALSE, FALSE, sizeof (guint)); - g_array_append_val (message_ids, message_id); - tp_chan_type_text_acknowledge_pending_messages (priv->text_iface, - message_ids, NULL); - g_array_free (message_ids, TRUE); + message = tp_chat_build_message (chat, + message_type, + timestamp, + from_handle, + message_body); + + g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message); + g_object_unref (message); + + if (priv->acknowledge) { + GArray *message_ids; + + message_ids = g_array_new (FALSE, FALSE, sizeof (guint)); + g_array_append_val (message_ids, message_id); + tp_chan_type_text_acknowledge_pending_messages (priv->text_iface, + message_ids, NULL); + g_array_free (message_ids, TRUE); + } } static void @@ -748,13 +817,18 @@ tp_chat_sent_cb (DBusGProxy *text_iface, gchar *message_body, EmpathyTpChat *chat) { + EmpathyMessage *message; + empathy_debug (DEBUG_DOMAIN, "Message sent: %s", message_body); - tp_chat_emit_message (chat, - message_type, - timestamp, - 0, - message_body); + message = tp_chat_build_message (chat, + message_type, + timestamp, + 0, + message_body); + + g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message); + g_object_unref (message); } static void @@ -776,21 +850,20 @@ tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, state); g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state); - g_object_unref (contact); } -static void -tp_chat_emit_message (EmpathyTpChat *chat, - guint type, - guint timestamp, - guint from_handle, - const gchar *message_body) +static EmpathyMessage * +tp_chat_build_message (EmpathyTpChat *chat, + guint type, + guint timestamp, + guint from_handle, + const gchar *message_body) { EmpathyTpChatPriv *priv; - EmpathyMessage *message; - EmpathyContact *sender; - EmpathyContact *receiver; + EmpathyMessage *message; + EmpathyContact *sender; + EmpathyContact *receiver; priv = GET_PRIV (chat); @@ -808,10 +881,9 @@ tp_chat_emit_message (EmpathyTpChat *chat, empathy_message_set_receiver (message, receiver); empathy_message_set_timestamp (message, (EmpathyTime) timestamp); - g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message); - - g_object_unref (message); g_object_unref (sender); + + return message; } static void diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h index ce4e2a836..7232a69a7 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -58,10 +58,14 @@ struct _EmpathyTpChatClass { GType empathy_tp_chat_get_type (void) G_GNUC_CONST; EmpathyTpChat *empathy_tp_chat_new (McAccount *account, TpChan *tp_chan); -EmpathyTpChat *empathy_tp_chat_new_with_contact (EmpathyContact *contact); -void empathy_tp_chat_request_pending (EmpathyTpChat *chat); +EmpathyTpChat *empathy_tp_chat_new_with_contact (EmpathyContact *contact); +gboolean empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat); +void empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat, + gboolean acknowledge); +TpChan * empathy_tp_chat_get_channel (EmpathyTpChat *chat); +GList * empathy_tp_chat_get_pendings (EmpathyTpChat *chat); void empathy_tp_chat_send (EmpathyTpChat *chat, - EmpathyMessage *message); + EmpathyMessage *message); void empathy_tp_chat_set_state (EmpathyTpChat *chat, TelepathyChannelChatState state); const gchar * empathy_tp_chat_get_id (EmpathyTpChat *chat); |