]> git.0d.be Git - empathy.git/blob - chat/empathy-chat-main.c
f279449945d5686da6850e260b67afcd32f19949
[empathy.git] / chat / empathy-chat-main.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Xavier Claessens <xclaesse@gmail.com>
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  */
21
22 #include <config.h>
23
24 #include <stdlib.h>
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28
29 #include <libtelepathy/tp-conn.h>
30 #include <libtelepathy/tp-chan.h>
31 #include <libmissioncontrol/mc-account.h>
32
33 #include <libempathy/gossip-contact.h>
34 #include <libempathy/empathy-chandler.h>
35 #include <libempathy/empathy-session.h>
36 #include <libempathy/empathy-contact-manager.h>
37 #include <libempathy/empathy-contact-list.h>
38 #include <libempathy-gtk/gossip-private-chat.h>
39 #include <libempathy-gtk/gossip-stock.h>
40
41 #define BUS_NAME "org.gnome.Empathy.Chat"
42 #define OBJECT_PATH "/org/freedesktop/Telepathy/ChannelHandler"
43
44 static void
45 new_channel_cb (EmpathyChandler *chandler,
46                 TpConn          *tp_conn,
47                 TpChan          *tp_chan,
48                 gpointer         user_data)
49 {
50         if (tp_chan->handle_type == TP_HANDLE_TYPE_CONTACT) {
51                 MissionControl        *mc;
52                 McAccount             *account;
53                 EmpathyContactManager *manager;
54                 EmpathyContactList    *list;
55                 GossipContact         *contact;
56                 GossipPrivateChat     *chat;
57
58                 /* We have a private chat channel */
59                 mc = empathy_session_get_mission_control ();
60                 account = mission_control_get_account_for_connection (mc, tp_conn, NULL);
61                 manager = empathy_session_get_contact_manager ();
62                 list = empathy_contact_manager_get_list (manager, account);
63                 contact = empathy_contact_list_get_from_handle (list, tp_chan->handle);
64
65                 chat = gossip_private_chat_new_with_channel (contact, tp_chan);
66                 gossip_chat_present (GOSSIP_CHAT (chat));
67
68                 g_object_unref (account);
69                 g_object_unref (contact);
70                 g_object_unref (chat);
71         }
72 }
73
74 int
75 main (int argc, char *argv[])
76 {
77         EmpathyChandler *chandler;
78
79         gtk_init (&argc, &argv);
80         /* FIXME: This is a horrible hack */
81         gossip_stock_init (gtk_window_new (GTK_WINDOW_TOPLEVEL));
82
83         chandler = empathy_chandler_new (BUS_NAME, OBJECT_PATH);
84
85         g_signal_connect (chandler, "new-channel",
86                           G_CALLBACK (new_channel_cb),
87                           NULL);
88
89         gtk_main ();
90
91         return EXIT_SUCCESS;
92 }
93