aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--libempathy-gtk/empathy-chat-window.c50
-rw-r--r--libempathy-gtk/empathy-chat.c141
-rw-r--r--libempathy-gtk/empathy-chat.h77
-rw-r--r--libempathy-gtk/empathy-group-chat.c19
-rw-r--r--libempathy-gtk/empathy-group-chat.h18
-rw-r--r--libempathy-gtk/empathy-private-chat.c125
-rw-r--r--libempathy-gtk/empathy-private-chat.h13
-rw-r--r--libempathy/empathy-tp-chat.c55
-rw-r--r--libempathy/empathy-tp-chat.h2
-rw-r--r--python/pyempathy/pyempathy.defs8
-rw-r--r--python/pyempathygtk/pyempathygtk.defs8
-rw-r--r--src/empathy-chat-chandler.c24
13 files changed, 310 insertions, 246 deletions
diff --git a/ChangeLog b/ChangeLog
index 13781d4fe..d89ee9cac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2007-12-03 Xavier Claessens <xclaesse@gmail.com>
+ * libempathy-gtk/empathy-chat-window.c:
+ * libempathy-gtk/empathy-chat.c:
+ * libempathy-gtk/empathy-chat.h:
+ * libempathy-gtk/empathy-group-chat.c:
+ * libempathy-gtk/empathy-group-chat.h:
+ * libempathy-gtk/empathy-private-chat.c:
+ * libempathy-gtk/empathy-private-chat.h:
+ * libempathy/empathy-tp-chat.c:
+ * libempathy/empathy-tp-chat.h:
+ * python/pyempathy/pyempathy.defs:
+ * python/pyempathygtk/pyempathygtk.defs:
+ * src/empathy-chat-chandler.c: Cleanup chat objects API and request a
+ new Text channel if account gets reconnected.
+
+2007-12-03 Xavier Claessens <xclaesse@gmail.com>
+
* libempathy/empathy-debug.c: Call tp_debug_set_flags to get tp-glib
debug output.
diff --git a/libempathy-gtk/empathy-chat-window.c b/libempathy-gtk/empathy-chat-window.c
index 49950d3ea..b4475ff7a 100644
--- a/libempathy-gtk/empathy-chat-window.c
+++ b/libempathy-gtk/empathy-chat-window.c
@@ -34,6 +34,8 @@
#include <glade/glade.h>
#include <glib/gi18n.h>
+#include <libmissioncontrol/mission-control.h>
+
#include <libempathy/empathy-contact-factory.h>
#include <libempathy/empathy-contact-list.h>
#include <libempathy/empathy-log-manager.h>
@@ -749,8 +751,8 @@ chat_window_update_menu (EmpathyChatWindow *window)
* connected to the room?
*/
chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
- priv->current_chat->account,
- empathy_chat_get_id (priv->current_chat));
+ empathy_chat_get_account (priv->current_chat),
+ empathy_chat_get_id (priv->current_chat));
gtk_widget_set_sensitive (priv->menu_room_add, chatroom == NULL);
gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
@@ -881,10 +883,10 @@ chat_window_log_activate_cb (GtkWidget *menuitem,
priv = GET_PRIV (window);
- empathy_log_window_show (priv->current_chat->account,
- empathy_chat_get_id (priv->current_chat),
- empathy_chat_is_group_chat (priv->current_chat),
- GTK_WINDOW (priv->dialog));
+ empathy_log_window_show (empathy_chat_get_account (priv->current_chat),
+ empathy_chat_get_id (priv->current_chat),
+ empathy_chat_is_group_chat (priv->current_chat),
+ GTK_WINDOW (priv->dialog));
}
static void
@@ -960,7 +962,7 @@ chat_window_conv_activate_cb (GtkWidget *menuitem,
manager = empathy_log_manager_new ();
log_exists = empathy_log_manager_exists (manager,
- priv->current_chat->account,
+ empathy_chat_get_account (priv->current_chat),
empathy_chat_get_id (priv->current_chat),
empathy_chat_is_group_chat (priv->current_chat));
g_object_unref (manager);
@@ -1077,10 +1079,10 @@ chat_window_room_add_activate_cb (GtkWidget *menuitem,
return;
}
- chatroom = empathy_chatroom_new_full (priv->current_chat->account,
- empathy_chat_get_id (priv->current_chat),
- empathy_chat_get_name (priv->current_chat),
- FALSE);
+ chatroom = empathy_chatroom_new_full (empathy_chat_get_account (priv->current_chat),
+ empathy_chat_get_id (priv->current_chat),
+ empathy_chat_get_name (priv->current_chat),
+ FALSE);
manager = empathy_chatroom_manager_new ();
empathy_chatroom_manager_add (manager, chatroom);
@@ -1571,7 +1573,6 @@ chat_window_drag_data_received (GtkWidget *widget,
guint time,
EmpathyChatWindow *window)
{
- /* FIXME: DnD of contact do not seems to work... */
if (info == DND_DRAG_TYPE_CONTACT_ID) {
EmpathyContactFactory *factory;
EmpathyContact *contact = NULL;
@@ -1607,17 +1608,25 @@ chat_window_drag_data_received (GtkWidget *widget,
account = empathy_contact_get_account (contact);
chat = empathy_chat_window_find_chat (account, id);
- if (chat) {
- g_object_ref (chat);
- } else {
- chat = EMPATHY_CHAT (empathy_private_chat_new_with_contact (contact));
+
+ if (!chat) {
+ MissionControl *mc;
+
+ mc = empathy_mission_control_new ();
+ mission_control_request_channel (mc,
+ empathy_contact_get_account (contact),
+ TP_IFACE_CHANNEL_TYPE_TEXT,
+ empathy_contact_get_handle (contact),
+ TP_HANDLE_TYPE_CONTACT,
+ NULL, NULL);
+ g_object_unref (mc);
+ return;
}
- old_window = empathy_chat_get_window (chat);
-
+
+ old_window = empathy_chat_get_window (chat);
if (old_window) {
if (old_window == window) {
gtk_drag_finish (context, TRUE, FALSE, time);
- g_object_unref (chat);
return;
}
@@ -1635,7 +1644,6 @@ chat_window_drag_data_received (GtkWidget *widget,
* anyway with add_chat() and remove_chat().
*/
gtk_drag_finish (context, TRUE, FALSE, time);
- g_object_unref (chat);
}
else if (info == DND_DRAG_TYPE_TAB) {
EmpathyChat *chat = NULL;
@@ -1873,7 +1881,7 @@ empathy_chat_window_find_chat (McAccount *account,
chat = ll->data;
- if (empathy_account_equal (account, chat->account) &&
+ if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
strcmp (id, empathy_chat_get_id (chat)) == 0) {
return chat;
}
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 1ea2985ce..d07b84b07 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -34,6 +34,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <libmissioncontrol/mission-control.h>
+
#include <libempathy/empathy-contact-manager.h>
#include <libempathy/empathy-log-manager.h>
#include <libempathy/empathy-debug.h>
@@ -65,7 +67,9 @@
struct _EmpathyChatPriv {
EmpathyLogManager *log_manager;
EmpathyTpChat *tp_chat;
- EmpathyChatWindow *window;
+ EmpathyChatWindow *window;
+ McAccount *account;
+ MissionControl *mc;
guint composing_stop_timeout_id;
gboolean sensitive;
gchar *id;
@@ -75,6 +79,7 @@ struct _EmpathyChatPriv {
guint scroll_idle_id;
gboolean first_tp_chat;
time_t last_log_timestamp;
+ gboolean is_first_char;
/* Used to automatically shrink a window that has temporarily
* grown due to long input.
*/
@@ -155,11 +160,90 @@ enum {
LAST_SIGNAL
};
+enum {
+ PROP_0,
+ PROP_TP_CHAT
+};
+
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (EmpathyChat, empathy_chat, G_TYPE_OBJECT);
static void
+chat_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyChatPriv *priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_TP_CHAT:
+ g_value_set_object (value, priv->tp_chat);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+chat_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyChat *chat = EMPATHY_CHAT (object);
+
+ switch (param_id) {
+ case PROP_TP_CHAT:
+ empathy_chat_set_tp_chat (chat,
+ EMPATHY_TP_CHAT (g_value_get_object (value)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+chat_status_changed_cb (MissionControl *mc,
+ TpConnectionStatus status,
+ McPresence presence,
+ TpConnectionStatusReason reason,
+ const gchar *unique_name,
+ EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ McAccount *account;
+
+ account = mc_account_lookup (unique_name);
+
+ if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
+ empathy_account_equal (account, priv->account)) {
+ TpHandleType handle_type;
+
+ empathy_debug (DEBUG_DOMAIN,
+ "Account reconnected, request a new Text channel");
+
+ if (empathy_chat_is_group_chat (chat)) {
+ handle_type = TP_HANDLE_TYPE_ROOM;
+ } else {
+ handle_type = TP_HANDLE_TYPE_CONTACT;
+ }
+
+ mission_control_request_channel_with_string_handle (mc,
+ priv->account,
+ TP_IFACE_CHANNEL_TYPE_TEXT,
+ priv->id,
+ handle_type,
+ NULL, NULL);
+ }
+
+ g_object_unref (account);
+}
+
+static void
empathy_chat_class_init (EmpathyChatClass *klass)
{
GObjectClass *object_class;
@@ -167,6 +251,17 @@ empathy_chat_class_init (EmpathyChatClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = chat_finalize;
+ object_class->get_property = chat_get_property;
+ object_class->set_property = chat_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_TP_CHAT,
+ g_param_spec_object ("tp-chat",
+ "Empathy tp chat",
+ "The tp chat object",
+ EMPATHY_TYPE_TP_CHAT,
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE));
signals[COMPOSING] =
g_signal_new ("composing",
@@ -214,13 +309,13 @@ empathy_chat_class_init (EmpathyChatClass *klass)
static void
empathy_chat_init (EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
+ EmpathyChatPriv *priv = GET_PRIV (chat);
GtkTextBuffer *buffer;
chat->view = empathy_chat_view_new ();
chat->input_text_view = gtk_text_view_new ();
- chat->is_first_char = TRUE;
+ priv->is_first_char = TRUE;
g_object_set (chat->input_text_view,
"pixels-above-lines", 2,
@@ -231,8 +326,6 @@ empathy_chat_init (EmpathyChat *chat)
"wrap-mode", GTK_WRAP_WORD_CHAR,
NULL);
- priv = GET_PRIV (chat);
-
priv->log_manager = empathy_log_manager_new ();
priv->default_window_height = -1;
priv->vscroll_visible = FALSE;
@@ -240,6 +333,11 @@ empathy_chat_init (EmpathyChat *chat)
priv->sent_messages = NULL;
priv->sent_messages_index = -1;
priv->first_tp_chat = TRUE;
+ priv->mc = empathy_mission_control_new ();
+
+ dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged",
+ G_CALLBACK (chat_status_changed_cb),
+ chat, NULL);
g_signal_connect (chat->input_text_view,
"key_press_event",
@@ -296,13 +394,22 @@ chat_finalize (GObject *object)
g_list_free (priv->compositors);
chat_composing_remove_timeout (chat);
- g_object_unref (chat->account);
g_object_unref (priv->log_manager);
+ dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged",
+ G_CALLBACK (chat_status_changed_cb),
+ chat);
+ g_object_unref (priv->mc);
+
+
if (priv->tp_chat) {
g_object_unref (priv->tp_chat);
}
+ if (priv->account) {
+ g_object_unref (priv->account);
+ }
+
if (priv->scroll_idle_id) {
g_source_remove (priv->scroll_idle_id);
}
@@ -386,7 +493,7 @@ chat_input_text_view_send (EmpathyChat *chat)
g_free (msg);
- chat->is_first_char = TRUE;
+ priv->is_first_char = TRUE;
}
static void
@@ -683,7 +790,7 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
&spell_checker);
- if (chat->is_first_char) {
+ if (priv->is_first_char) {
GtkRequisition req;
gint window_height;
GtkWidget *dialog;
@@ -702,7 +809,7 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
priv->last_input_height = req.height;
priv->padding_height = window_height - req.height - allocation->height;
- chat->is_first_char = FALSE;
+ priv->is_first_char = FALSE;
}
gtk_text_buffer_get_start_iter (buffer, &start);
@@ -1150,7 +1257,7 @@ chat_add_logs (EmpathyChat *chat)
/* Add messages from last conversation */
messages = empathy_log_manager_get_last_messages (priv->log_manager,
- chat->account,
+ priv->account,
empathy_chat_get_id (chat),
empathy_chat_is_group_chat (chat));
num_messages = g_list_length (messages);
@@ -1360,10 +1467,14 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
chat);
g_object_unref (priv->tp_chat);
}
+ if (priv->account) {
+ g_object_unref (priv->account);
+ }
g_free (priv->id);
priv->tp_chat = g_object_ref (tp_chat);
priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
+ priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
if (priv->first_tp_chat) {
chat_add_logs (chat);
@@ -1401,6 +1512,8 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
if (EMPATHY_CHAT_GET_CLASS (chat)->set_tp_chat) {
EMPATHY_CHAT_GET_CLASS (chat)->set_tp_chat (chat, tp_chat);
}
+
+ g_object_notify (G_OBJECT (chat), "tp-chat");
}
const gchar *
@@ -1413,6 +1526,14 @@ empathy_chat_get_id (EmpathyChat *chat)
return priv->id;
}
+McAccount *
+empathy_chat_get_account (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ return priv->account;
+}
+
void
empathy_chat_clear (EmpathyChat *chat)
{
diff --git a/libempathy-gtk/empathy-chat.h b/libempathy-gtk/empathy-chat.h
index c030dd292..5bf456e48 100644
--- a/libempathy-gtk/empathy-chat.h
+++ b/libempathy-gtk/empathy-chat.h
@@ -56,11 +56,8 @@ struct _EmpathyChat {
GObject parent;
/* Protected */
- EmpathyChatView *view;
- EmpathyTpChat *tp_chat;
+ EmpathyChatView *view;
GtkWidget *input_text_view;
- gboolean is_first_char;
- McAccount *account;
};
struct _EmpathyChatClass {
@@ -78,47 +75,47 @@ struct _EmpathyChatClass {
GdkEventKey *event);
};
-GType empathy_chat_get_type (void);
+GType empathy_chat_get_type (void);
EmpathyChatView * empathy_chat_get_view (EmpathyChat *chat);
EmpathyChatWindow *empathy_chat_get_window (EmpathyChat *chat);
-void empathy_chat_set_window (EmpathyChat *chat,
- EmpathyChatWindow *window);
-void empathy_chat_present (EmpathyChat *chat);
-void empathy_chat_clear (EmpathyChat *chat);
-void empathy_chat_scroll_down (EmpathyChat *chat);
-void empathy_chat_cut (EmpathyChat *chat);
-void empathy_chat_copy (EmpathyChat *chat);
-void empathy_chat_paste (EmpathyChat *chat);
-const gchar * empathy_chat_get_name (EmpathyChat *chat);
-gchar * empathy_chat_get_tooltip (EmpathyChat *chat);
-const gchar * empathy_chat_get_status_icon_name (EmpathyChat *chat);
-GtkWidget * empathy_chat_get_widget (EmpathyChat *chat);
-gboolean empathy_chat_is_group_chat (EmpathyChat *chat);
-gboolean empathy_chat_is_connected (EmpathyChat *chat);
-
-void empathy_chat_save_geometry (EmpathyChat *chat,
- gint x,
- gint y,
- gint w,
- gint h);
-void empathy_chat_load_geometry (EmpathyChat *chat,
- gint *x,
- gint *y,
- gint *w,
- gint *h);
-void empathy_chat_set_tp_chat (EmpathyChat *chat,
- EmpathyTpChat *tp_chat);
-const gchar * empathy_chat_get_id (EmpathyChat *chat);
+void empathy_chat_set_window (EmpathyChat *chat,
+ EmpathyChatWindow *window);
+void empathy_chat_present (EmpathyChat *chat);
+void empathy_chat_clear (EmpathyChat *chat);
+void empathy_chat_scroll_down (EmpathyChat *chat);
+void empathy_chat_cut (EmpathyChat *chat);
+void empathy_chat_copy (EmpathyChat *chat);
+void empathy_chat_paste (EmpathyChat *chat);
+const gchar * empathy_chat_get_name (EmpathyChat *chat);
+gchar * empathy_chat_get_tooltip (EmpathyChat *chat);
+const gchar * empathy_chat_get_status_icon_name (EmpathyChat *chat);
+GtkWidget * empathy_chat_get_widget (EmpathyChat *chat);
+gboolean empathy_chat_is_group_chat (EmpathyChat *chat);
+gboolean empathy_chat_is_connected (EmpathyChat *chat);
+void empathy_chat_save_geometry (EmpathyChat *chat,
+ gint x,
+ gint y,
+ gint w,
+ gint h);
+void empathy_chat_load_geometry (EmpathyChat *chat,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+void empathy_chat_set_tp_chat (EmpathyChat *chat,
+ EmpathyTpChat *tp_chat);
+const gchar * empathy_chat_get_id (EmpathyChat *chat);
+McAccount * empathy_chat_get_account (EmpathyChat *chat);
/* For spell checker dialog to correct the misspelled word. */
-gboolean empathy_chat_get_is_command (const gchar *str);
-void empathy_chat_correct_word (EmpathyChat *chat,
- GtkTextIter start,
- GtkTextIter end,
- const gchar *new_word);
-gboolean empathy_chat_should_play_sound (EmpathyChat *chat);
-gboolean empathy_chat_should_highlight_nick (EmpathyMessage *message);
+gboolean empathy_chat_get_is_command (const gchar *str);
+void empathy_chat_correct_word (EmpathyChat *chat,
+ GtkTextIter start,
+ GtkTextIter end,
+ const gchar *new_word);
+gboolean empathy_chat_should_play_sound (EmpathyChat *chat);
+gboolean empathy_chat_should_highlight_nick (EmpathyMessage *message);
G_END_DECLS
diff --git a/libempathy-gtk/empathy-group-chat.c b/libempathy-gtk/empathy-group-chat.c
index 948f728e5..777514652 100644
--- a/libempathy-gtk/empathy-group-chat.c
+++ b/libempathy-gtk/empathy-group-chat.c
@@ -175,22 +175,15 @@ group_chat_finalize (GObject *object)
}
EmpathyGroupChat *
-empathy_group_chat_new (McAccount *account,
- TpChan *tp_chan)
+empathy_group_chat_new (EmpathyTpChatroom *tp_chat)
{
- EmpathyGroupChat *chat;
- EmpathyGroupChatPriv *priv;
-
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
+ EmpathyGroupChat *chat;
- chat = g_object_new (EMPATHY_TYPE_GROUP_CHAT, NULL);
-
- priv = GET_PRIV (chat);
+ g_return_val_if_fail (EMPATHY_IS_TP_CHAT (tp_chat), NULL);
- EMPATHY_CHAT (chat)->account = g_object_ref (account);
- priv->tp_chat = empathy_tp_chatroom_new (account, tp_chan);
- empathy_chat_set_tp_chat (EMPATHY_CHAT (chat), EMPATHY_TP_CHAT (priv->tp_chat));
+ chat = g_object_new (EMPATHY_TYPE_GROUP_CHAT,
+ "tp-chat", tp_chat,
+ NULL);
return chat;
}
diff --git a/libempathy-gtk/empathy-group-chat.h b/libempathy-gtk/empathy-group-chat.h
index fc7567856..e0ce79462 100644
--- a/libempathy-gtk/empathy-group-chat.h
+++ b/libempathy-gtk/empathy-group-chat.h
@@ -29,9 +29,8 @@
G_BEGIN_DECLS
-#include <libtelepathy/tp-chan.h>
-
-#include <libmissioncontrol/mc-account.h>
+#include <libempathy/empathy-tp-chatroom.h>
+#include <libempathy/empathy-contact.h>
#define EMPATHY_TYPE_GROUP_CHAT (empathy_group_chat_get_type ())
#define EMPATHY_GROUP_CHAT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_GROUP_CHAT, EmpathyGroupChat))
@@ -56,13 +55,12 @@ struct _EmpathyGroupChatClass {
EmpathyChatClass parent_class;
};
-GType empathy_group_chat_get_type (void) G_GNUC_CONST;
-EmpathyGroupChat *empathy_group_chat_new (McAccount *account,
- TpChan *tp_chan);
-gboolean empathy_group_chat_get_show_contacts (EmpathyGroupChat *chat);
-void empathy_group_chat_set_show_contacts (EmpathyGroupChat *chat,
- gboolean show);
-void empathy_group_chat_set_topic (EmpathyGroupChat *chat);
+GType empathy_group_chat_get_type (void) G_GNUC_CONST;
+EmpathyGroupChat *empathy_group_chat_new (EmpathyTpChatroom *tp_chat);
+gboolean empathy_group_chat_get_show_contacts (EmpathyGroupChat *chat);
+void empathy_group_chat_set_show_contacts (EmpathyGroupChat *chat,
+ gboolean show);
+void empathy_group_chat_set_topic (EmpathyGroupChat *chat);
G_END_DECLS
diff --git a/libempathy-gtk/empathy-private-chat.c b/libempathy-gtk/empathy-private-chat.c
index 81b804d05..9af944174 100644
--- a/libempathy-gtk/empathy-private-chat.c
+++ b/libempathy-gtk/empathy-private-chat.c
@@ -81,6 +81,49 @@ static GtkWidget * private_chat_get_widget (EmpathyChat
G_DEFINE_TYPE (EmpathyPrivateChat, empathy_private_chat, EMPATHY_TYPE_CHAT);
+
+static GObject *
+private_chat_constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
+{
+ GObject *chat;
+ EmpathyPrivateChatPriv *priv;
+ EmpathyTpChat *tp_chat;
+ TpChan *tp_chan;
+ McAccount *account;
+
+ chat = G_OBJECT_CLASS (empathy_private_chat_parent_class)->constructor (type, n_props, props);
+
+ priv = GET_PRIV (chat);
+
+ g_object_get (chat, "tp-chat", &tp_chat, NULL);
+ tp_chan = empathy_tp_chat_get_channel (tp_chat);
+ account = empathy_tp_chat_get_account (tp_chat);
+
+ priv->factory = empathy_contact_factory_new ();
+ priv->contact = empathy_contact_factory_get_from_handle (priv->factory,
+ account,
+ tp_chan->handle);
+
+ priv->name = g_strdup (empathy_contact_get_name (priv->contact));
+
+ g_signal_connect (priv->contact,
+ "notify::name",
+ G_CALLBACK (private_chat_contact_updated_cb),
+ chat);
+ g_signal_connect (priv->contact,
+ "notify::presence",
+ G_CALLBACK (private_chat_contact_presence_updated_cb),
+ chat);
+
+ priv->is_online = empathy_contact_is_online (priv->contact);
+
+ g_object_unref (tp_chat);
+
+ return chat;
+}
+
static void
empathy_private_chat_class_init (EmpathyPrivateChatClass *klass)
{
@@ -88,6 +131,7 @@ empathy_private_chat_class_init (EmpathyPrivateChatClass *klass)
EmpathyChatClass *chat_class = EMPATHY_CHAT_CLASS (klass);
object_class->finalize = private_chat_finalize;
+ object_class->constructor = private_chat_constructor;
chat_class->get_name = private_chat_get_name;
chat_class->get_tooltip = private_chat_get_tooltip;
@@ -101,12 +145,6 @@ empathy_private_chat_class_init (EmpathyPrivateChatClass *klass)
static void
empathy_private_chat_init (EmpathyPrivateChat *chat)
{
- EmpathyPrivateChatPriv *priv;
-
- priv = GET_PRIV (chat);
-
- priv->is_online = FALSE;
-
private_chat_create_ui (chat);
}
@@ -317,79 +355,16 @@ private_chat_get_widget (EmpathyChat *chat)
return priv->widget;
}
-static void
-private_chat_setup (EmpathyPrivateChat *chat,
- EmpathyContact *contact,
- EmpathyTpChat *tp_chat)
-{
- EmpathyPrivateChatPriv *priv;
-
- priv = GET_PRIV (chat);
-
- EMPATHY_CHAT (chat)->account = g_object_ref (empathy_contact_get_account (contact));
- priv->contact = g_object_ref (contact);
- priv->name = g_strdup (empathy_contact_get_name (contact));
-
- empathy_chat_set_tp_chat (EMPATHY_CHAT (chat), tp_chat);
-
- g_signal_connect (priv->contact,
- "notify::name",
- G_CALLBACK (private_chat_contact_updated_cb),
- chat);
- g_signal_connect (priv->contact,
- "notify::presence",
- G_CALLBACK (private_chat_contact_presence_updated_cb),
- chat);
-
- priv->is_online = empathy_contact_is_online (priv->contact);
-}
-
EmpathyPrivateChat *
-empathy_private_chat_new (McAccount *account,
- TpChan *tp_chan)
+empathy_private_chat_new (EmpathyTpChat *tp_chat)
{
- EmpathyPrivateChat *chat;
- EmpathyPrivateChatPriv *priv;
- EmpathyTpChat *tp_chat;
- EmpathyContact *contact;
+ EmpathyPrivateChat *chat;
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
+ g_return_val_if_fail (EMPATHY_IS_TP_CHAT (tp_chat), NULL);
- chat = g_object_new (EMPATHY_TYPE_PRIVATE_CHAT, NULL);
- priv = GET_PRIV (chat);
-
- priv->factory = empathy_contact_factory_new ();
- contact = empathy_contact_factory_get_from_handle (priv->factory,
- account,
- tp_chan->handle);
-
- tp_chat = empathy_tp_chat_new (account, tp_chan);
- private_chat_setup (chat, contact, tp_chat);
-
- g_object_unref (tp_chat);
- g_object_unref (contact);
-
- return chat;
-}
-
-EmpathyPrivateChat *
-empathy_private_chat_new_with_contact (EmpathyContact *contact)
-{
- EmpathyPrivateChat *chat;
- EmpathyPrivateChatPriv *priv;
- EmpathyTpChat *tp_chat;
-
- g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
-
- chat = g_object_new (EMPATHY_TYPE_PRIVATE_CHAT, NULL);
-
- priv = GET_PRIV (chat);
- priv->factory = empathy_contact_factory_new ();
-
- tp_chat = empathy_tp_chat_new_with_contact (contact);
- private_chat_setup (chat, contact, tp_chat);
- g_object_unref (tp_chat);
+ chat = g_object_new (EMPATHY_TYPE_PRIVATE_CHAT,
+ "tp-chat", tp_chat,
+ NULL);
return chat;
}
diff --git a/libempathy-gtk/empathy-private-chat.h b/libempathy-gtk/empathy-private-chat.h
index b13eede7f..169809bb0 100644
--- a/libempathy-gtk/empathy-private-chat.h
+++ b/libempathy-gtk/empathy-private-chat.h
@@ -28,10 +28,7 @@
#ifndef __EMPATHY_PRIVATE_CHAT_H__
#define __EMPATHY_PRIVATE_CHAT_H__
-#include <libtelepathy/tp-chan.h>
-
-#include <libmissioncontrol/mc-account.h>
-
+#include <libempathy/empathy-tp-chat.h>
#include <libempathy/empathy-contact.h>
G_BEGIN_DECLS
@@ -57,11 +54,9 @@ struct _EmpathyPrivateChatClass {
EmpathyChatClass parent;
};
-GType empathy_private_chat_get_type (void);
-EmpathyPrivateChat * empathy_private_chat_new (McAccount *account,
- TpChan *tp_chan);
-EmpathyPrivateChat * empathy_private_chat_new_with_contact (EmpathyContact *contact);
-EmpathyContact * empathy_private_chat_get_contact (EmpathyPrivateChat *chat);
+GType empathy_private_chat_get_type (void);
+EmpathyPrivateChat * empathy_private_chat_new (EmpathyTpChat *tp_chat);
+EmpathyContact * empathy_private_chat_get_contact (EmpathyPrivateChat *chat);
G_END_DECLS
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 6a871822e..68a0af174 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -561,49 +561,6 @@ empathy_tp_chat_new (McAccount *account,
NULL);
}
-EmpathyTpChat *
-empathy_tp_chat_new_with_contact (EmpathyContact *contact)
-{
- EmpathyTpChat *chat;
- MissionControl *mc;
- McAccount *account;
- TpConn *tp_conn;
- TpChan *text_chan;
- const gchar *bus_name;
- guint handle;
-
- g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
-
- mc = empathy_mission_control_new ();
- account = empathy_contact_get_account (contact);
-
- if (mission_control_get_connection_status (mc, account, NULL) != 0) {
- /* The account is not connected, nothing to do. */
- return NULL;
- }
-
- tp_conn = mission_control_get_connection (mc, account, NULL);
- g_return_val_if_fail (tp_conn != NULL, NULL);
- bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn));
- handle = empathy_contact_get_handle (contact);
-
- text_chan = tp_conn_new_channel (tp_get_bus (),
- tp_conn,
- bus_name,
- TP_IFACE_CHANNEL_TYPE_TEXT,
- TP_HANDLE_TYPE_CONTACT,
- handle,
- TRUE);
-
- chat = empathy_tp_chat_new (account, text_chan);
-
- g_object_unref (tp_conn);
- g_object_unref (text_chan);
- g_object_unref (mc);
-
- return chat;
-}
-
gboolean
empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat)
{
@@ -642,6 +599,18 @@ empathy_tp_chat_get_channel (EmpathyTpChat *chat)
return priv->tp_chan;
}
+McAccount *
+empathy_tp_chat_get_account (EmpathyTpChat *chat)
+{
+ EmpathyTpChatPriv *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
+
+ priv = GET_PRIV (chat);
+
+ return priv->account;
+}
+
GList *
empathy_tp_chat_get_pendings (EmpathyTpChat *chat)
{
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index cd807c983..7f5ef212e 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -57,10 +57,10 @@ 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);
gboolean empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat);
void empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat,
gboolean acknowledge);
+McAccount * empathy_tp_chat_get_account (EmpathyTpChat *chat);
TpChan * empathy_tp_chat_get_channel (EmpathyTpChat *chat);
GList * empathy_tp_chat_get_pendings (EmpathyTpChat *chat);
void empathy_tp_chat_send (EmpathyTpChat *chat,
diff --git a/python/pyempathy/pyempathy.defs b/python/pyempathy/pyempathy.defs
index f9c032cf0..d3329ff21 100644
--- a/python/pyempathy/pyempathy.defs
+++ b/python/pyempathy/pyempathy.defs
@@ -1338,14 +1338,6 @@
)
)
-(define-function empathy_tp_chat_new_with_contact
- (c-name "empathy_tp_chat_new_with_contact")
- (return-type "EmpathyTpChat*")
- (parameters
- '("EmpathyContact*" "contact")
- )
-)
-
(define-method get_acknowledge
(of-object "EmpathyTpChat")
(c-name "empathy_tp_chat_get_acknowledge")
diff --git a/python/pyempathygtk/pyempathygtk.defs b/python/pyempathygtk/pyempathygtk.defs
index e3f878061..c4db60148 100644
--- a/python/pyempathygtk/pyempathygtk.defs
+++ b/python/pyempathygtk/pyempathygtk.defs
@@ -1150,14 +1150,6 @@
)
)
-(define-function empathy_private_chat_new_with_contact
- (c-name "empathy_private_chat_new_with_contact")
- (return-type "EmpathyPrivateChat*")
- (parameters
- '("EmpathyContact*" "contact")
- )
-)
-
(define-method get_contact
(of-object "EmpathyPrivateChat")
(c-name "empathy_private_chat_get_contact")
diff --git a/src/empathy-chat-chandler.c b/src/empathy-chat-chandler.c
index 2064f16d6..dc2eb60f7 100644
--- a/src/empathy-chat-chandler.c
+++ b/src/empathy-chat-chandler.c
@@ -54,9 +54,10 @@ chat_chandler_new_channel_cb (EmpathyChandler *chandler,
TpChan *tp_chan,
MissionControl *mc)
{
- McAccount *account;
- EmpathyChat *chat;
- gchar *id;
+ EmpathyTpChat *tp_chat;
+ McAccount *account;
+ EmpathyChat *chat;
+ gchar *id;
account = mission_control_get_account_for_connection (mc, tp_conn, NULL);
id = empathy_inspect_channel (account, tp_chan);
@@ -66,8 +67,6 @@ chat_chandler_new_channel_cb (EmpathyChandler *chandler,
if (chat) {
/* The chat already exists */
if (!empathy_chat_is_connected (chat)) {
- EmpathyTpChat *tp_chat;
-
/* The chat died, give him the new text channel */
if (empathy_chat_is_group_chat (chat)) {
tp_chat = EMPATHY_TP_CHAT (empathy_tp_chatroom_new (account, tp_chan));
@@ -85,17 +84,26 @@ chat_chandler_new_channel_cb (EmpathyChandler *chandler,
if (tp_chan->handle_type == TP_HANDLE_TYPE_CONTACT) {
/* We have a new private chat channel */
- chat = EMPATHY_CHAT (empathy_private_chat_new (account, tp_chan));
+ tp_chat = empathy_tp_chat_new (account, tp_chan);
+ chat = EMPATHY_CHAT (empathy_private_chat_new (tp_chat));
}
else if (tp_chan->handle_type == TP_HANDLE_TYPE_ROOM) {
/* We have a new group chat channel */
- chat = EMPATHY_CHAT (empathy_group_chat_new (account, tp_chan));
+ tp_chat = EMPATHY_TP_CHAT (empathy_tp_chatroom_new (account, tp_chan));
+ chat = EMPATHY_CHAT (empathy_group_chat_new (EMPATHY_TP_CHATROOM (tp_chat)));
+ } else {
+ empathy_debug (DEBUG_DOMAIN,
+ "Unknown handle type (%d) for Text channel",
+ tp_chan->handle_type);
+ g_object_unref (account);
+ return;
}
- empathy_chat_present (EMPATHY_CHAT (chat));
+ empathy_chat_present (chat);
g_object_unref (chat);
g_object_unref (account);
+ g_object_unref (tp_chat);
}
int