]> git.0d.be Git - empathy.git/blob - src/empathy-chat-main.c
7fde26ae0f16b779e5eec4147f1dafe1d2724fcc
[empathy.git] / src / empathy-chat-main.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  * 
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24
25 #include <stdlib.h>
26
27 #include <glib.h>
28 #include <gtk/gtk.h>
29
30 #include <libtelepathy/tp-conn.h>
31 #include <libtelepathy/tp-chan.h>
32 #include <libtelepathy/tp-helpers.h>
33 #include <libmissioncontrol/mc-account.h>
34
35 #include <libempathy/gossip-contact.h>
36 #include <libempathy/empathy-chandler.h>
37 #include <libempathy/empathy-contact-manager.h>
38 #include <libempathy/empathy-contact-list.h>
39 #include <libempathy-gtk/gossip-private-chat.h>
40 #include <libempathy-gtk/gossip-stock.h>
41
42 #define BUS_NAME "org.gnome.Empathy.Chat"
43 #define OBJECT_PATH "/org/freedesktop/Telepathy/ChannelHandler"
44
45 static void
46 new_channel_cb (EmpathyChandler *chandler,
47                 TpConn          *tp_conn,
48                 TpChan          *tp_chan,
49                 gpointer         user_data)
50 {
51         if (tp_chan->handle_type == TP_HANDLE_TYPE_CONTACT) {
52                 MissionControl        *mc;
53                 McAccount             *account;
54                 EmpathyContactManager *manager;
55                 EmpathyContactList    *list;
56                 GossipContact         *contact;
57                 GossipPrivateChat     *chat;
58
59                 /* We have a private chat channel */
60                 mc = mission_control_new (tp_get_bus ());
61                 account = mission_control_get_account_for_connection (mc, tp_conn, NULL);
62                 manager = empathy_contact_manager_new ();
63                 list = empathy_contact_manager_get_list (manager, account);
64                 contact = empathy_contact_list_get_from_handle (list, tp_chan->handle);
65
66                 chat = gossip_private_chat_new_with_channel (contact, tp_chan);
67                 gossip_chat_present (GOSSIP_CHAT (chat));
68
69                 g_object_unref (mc);
70                 g_object_unref (account);
71                 g_object_unref (contact);
72                 g_object_unref (chat);
73                 g_object_unref (manager);
74         }
75 }
76
77 int
78 main (int argc, char *argv[])
79 {
80         EmpathyChandler *chandler;
81
82         gtk_init (&argc, &argv);
83         /* FIXME: This is a horrible hack */
84         gossip_stock_init (gtk_window_new (GTK_WINDOW_TOPLEVEL));
85
86         chandler = empathy_chandler_new (BUS_NAME, OBJECT_PATH);
87
88         g_signal_connect (chandler, "new-channel",
89                           G_CALLBACK (new_channel_cb),
90                           NULL);
91
92         gtk_main ();
93
94         return EXIT_SUCCESS;
95 }
96