/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2002-2007 Imendio AB
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 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
#include <glade/glade.h>
#include <glib/gi18n.h>
+#include <libmissioncontrol/mission-control.h>
+
#include <libempathy/empathy-debug.h>
#include <libempathy/empathy-tp-chat.h>
#include <libempathy/empathy-tp-contact-list.h>
-#include <libempathy/empathy-contact-manager.h>
+#include <libempathy/empathy-contact-factory.h>
+#include <libempathy/empathy-utils.h>
#include "empathy-private-chat.h"
#include "empathy-chat-view.h"
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_PRIVATE_CHAT, EmpathyPrivateChatPriv))
struct _EmpathyPrivateChatPriv {
- EmpathyContact *contact;
- gchar *name;
- gboolean is_online;
- GtkWidget *widget;
- GtkWidget *text_view_sw;
+ EmpathyContactFactory *factory;
+ EmpathyContact *contact;
+ gchar *name;
+ gboolean is_online;
+ GtkWidget *widget;
+ GtkWidget *text_view_sw;
};
static void empathy_private_chat_class_init (EmpathyPrivateChatClass *klass);
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)
{
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;
static void
empathy_private_chat_init (EmpathyPrivateChat *chat)
{
- EmpathyPrivateChatPriv *priv;
-
- priv = GET_PRIV (chat);
-
- priv->is_online = FALSE;
-
private_chat_create_ui (chat);
}
if (priv->contact) {
g_object_unref (priv->contact);
}
-
+ if (priv->factory) {
+ g_object_unref (priv->factory);
+ }
g_free (priv->name);
G_OBJECT_CLASS (empathy_private_chat_parent_class)->finalize (object);
static void
private_chat_contact_presence_updated_cb (EmpathyContact *contact,
- GParamSpec *param,
+ GParamSpec *param,
EmpathyPrivateChat *chat)
{
EmpathyPrivateChatPriv *priv;
empathy_contact_get_id (contact));
if (!empathy_contact_is_online (contact)) {
- if (priv->is_online) {
+ if (priv->is_online && !EMPATHY_CHAT (chat)->block_events) {
gchar *msg;
msg = g_strdup_printf (_("%s went offline"),
g_signal_emit_by_name (chat, "composing", FALSE);
} else {
- if (!priv->is_online) {
+ if (!priv->is_online && !EMPATHY_CHAT (chat)->block_events) {
gchar *msg;
msg = g_strdup_printf (_("%s has come online"),
}
priv->is_online = TRUE;
+
+ /* If offline message is not supported by CM we need to
+ * request a new Text Channel. */
+ if (!empathy_chat_is_connected (EMPATHY_CHAT (chat))) {
+ empathy_chat_with_contact (contact);
+ }
}
g_signal_emit_by_name (chat, "status-changed");
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)
-{
- EmpathyPrivateChat *chat;
- EmpathyTpChat *tp_chat;
- EmpathyContactManager *manager;
- EmpathyTpContactList *list;
- EmpathyContact *contact;
-
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
-
- manager = empathy_contact_manager_new ();
- list = empathy_contact_manager_get_list (manager, account);
- contact = empathy_tp_contact_list_get_from_handle (list, tp_chan->handle);
-
- chat = g_object_new (EMPATHY_TYPE_PRIVATE_CHAT, NULL);
- 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);
- g_object_unref (manager);
-
- return chat;
-}
-
EmpathyPrivateChat *
-empathy_private_chat_new_with_contact (EmpathyContact *contact)
+empathy_private_chat_new (EmpathyTpChat *tp_chat)
{
EmpathyPrivateChat *chat;
- EmpathyTpChat *tp_chat;
- g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+ g_return_val_if_fail (EMPATHY_IS_TP_CHAT (tp_chat), NULL);
- chat = g_object_new (EMPATHY_TYPE_PRIVATE_CHAT, NULL);
- 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;
}