~ubuntu-branches/ubuntu/utopic/gossip/utopic

« back to all changes in this revision

Viewing changes to src/gossip-group-chat.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-03-05 08:21:49 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20070305082149-9hnkboi8t8fizggz
Tags: 0.23-0ubuntu1
* New upstream release.
* debian/control.in:
  - changed Maintainer field.
  - bumped dbus requirement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
2
/*
3
 
 * Copyright (C) 2002-2006 Imendio AB
 
3
 * Copyright (C) 2002-2007 Imendio AB
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
6
6
 * modify it under the terms of the GNU General Public License as
16
16
 * License along with this program; if not, write to the
17
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
18
 * Boston, MA 02111-1307, USA.
 
19
 *
 
20
 * Authors: Mikael Hallendal <micke@imendio.com>
 
21
 *          Richard Hult <richard@imendio.com>
 
22
 *          Martyn Russell <martyn@imendio.com>
19
23
 */
20
24
 
21
 
#include <config.h>
 
25
#include "config.h"
 
26
 
22
27
#include <string.h>
 
28
 
23
29
#include <gtk/gtk.h>
24
30
#include <gdk/gdkkeysyms.h>
25
31
#include <glade/glade.h>
26
32
#include <glib/gi18n.h>
27
33
 
28
 
#include <libgossip/gossip-chatroom-contact.h>
29
 
#include <libgossip/gossip-chatroom-provider.h>
 
34
#include <libgossip/gossip-contact.h>
 
35
#include <libgossip/gossip-session.h>
 
36
#include <libgossip/gossip-protocol.h>
 
37
#include <libgossip/gossip-utils.h>
 
38
#include <libgossip/gossip-account.h>
 
39
#include <libgossip/gossip-log.h>
30
40
#include <libgossip/gossip-debug.h>
31
 
#include <libgossip/gossip-log.h>
32
41
#include <libgossip/gossip-message.h>
33
42
 
34
43
#include "gossip-app.h"
44
53
#include "gossip-stock.h"
45
54
#include "gossip-ui-utils.h"
46
55
 
 
56
#define DEBUG_DOMAIN "GroupChat"
 
57
 
 
58
#define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
 
59
 
47
60
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_GROUP_CHAT, GossipGroupChatPriv))
48
61
 
49
 
#define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
50
 
 
51
 
#define DEBUG_DOMAIN "GroupChat"
52
 
 
53
62
struct _GossipGroupChatPriv {
54
63
        GossipContact          *own_contact;
55
64
 
174
183
static void            group_chat_topic_response_cb           (GtkWidget                    *dialog,
175
184
                                                               gint                          response,
176
185
                                                               GossipGroupChat              *chat);
177
 
static void            group_chat_contact_joined_cb           (GossipChatroomProvider       *provider,
178
 
                                                               gint                          id,
179
 
                                                               GossipContact                *contact,
180
 
                                                               GossipGroupChat              *chat);
181
 
static void            group_chat_contact_left_cb             (GossipChatroomProvider       *provider,
182
 
                                                               gint                          id,
183
 
                                                               GossipContact                *contact,
184
 
                                                               GossipGroupChat              *chat);
 
186
static void            group_chat_contact_joined_cb           (GossipChatroom               *chatroom,
 
187
                                                               GossipContact                *contact,
 
188
                                                               GossipGroupChat              *chat);
 
189
static void            group_chat_contact_left_cb             (GossipChatroom               *chatroom,
 
190
                                                               GossipContact                *contact,
 
191
                                                               GossipGroupChat              *chat);
 
192
static void            group_chat_contact_info_changed_cb     (GossipChatroom               *chatroom,
 
193
                                                               GossipContact                *contact,
 
194
                                                               GossipGroupChat              *chat);
 
195
static void            group_chat_contact_add                 (GossipGroupChat              *chat,
 
196
                                                               GossipContact                *contact);
 
197
static void            group_chat_contact_remove              (GossipGroupChat              *chat,
 
198
                                                               GossipContact                *contact);
185
199
static void            group_chat_contact_presence_updated_cb (GossipContact                *contact,
186
200
                                                               GParamSpec                   *param,
187
201
                                                               GossipGroupChat              *chat);
360
374
        g_signal_handlers_disconnect_by_func (priv->chatroom_provider,
361
375
                                              group_chat_topic_changed_cb,
362
376
                                              chat);
363
 
        g_signal_handlers_disconnect_by_func (priv->chatroom_provider,
 
377
        g_signal_handlers_disconnect_by_func (priv->chatroom,
364
378
                                              group_chat_contact_joined_cb,
365
379
                                              chat);
366
 
        g_signal_handlers_disconnect_by_func (priv->chatroom_provider,
 
380
        g_signal_handlers_disconnect_by_func (priv->chatroom,
367
381
                                              group_chat_contact_left_cb,
368
382
                                              chat);
 
383
        g_signal_handlers_disconnect_by_func (priv->chatroom,
 
384
                                              group_chat_contact_info_changed_cb,
 
385
                                              chat);
369
386
        
370
387
        g_object_unref (priv->chatroom_provider);
371
388
 
1084
1101
{
1085
1102
        GossipGroupChatPriv  *priv;
1086
1103
        GossipChatroomInvite *invite;
 
1104
        GossipLogManager     *log_manager;
1087
1105
 
1088
1106
        priv = GET_PRIV (chat);
1089
1107
 
1121
1139
                gossip_sound_play (GOSSIP_SOUND_CHAT);
1122
1140
        }
1123
1141
 
1124
 
        gossip_log_message_for_chatroom (priv->chatroom, message, FALSE);
 
1142
        log_manager = gossip_session_get_log_manager (gossip_app_get_session ());
 
1143
        gossip_log_message_for_chatroom (log_manager, priv->chatroom, message, FALSE);
1125
1144
 
1126
1145
        g_signal_emit_by_name (chat, "new-message", message);
1127
1146
}
1254
1273
}
1255
1274
 
1256
1275
static void
1257
 
group_chat_contact_joined_cb (GossipChatroomProvider *provider,
1258
 
                              gint                    id,
1259
 
                              GossipContact          *contact,
1260
 
                              GossipGroupChat        *chat)
1261
 
{
1262
 
        GossipGroupChatPriv *priv;
1263
 
        GtkTreeModel        *model;
1264
 
        GtkTreeIter          iter;
1265
 
        GtkTreeIter          parent;
1266
 
        GdkPixbuf           *pixbuf;
1267
 
        GossipChatroomRole   role;
1268
 
        GtkTreePath         *path;
1269
 
 
1270
 
        priv = GET_PRIV (chat);
1271
 
 
1272
 
        if (id != gossip_chatroom_get_id (priv->chatroom)) {
1273
 
                return;
1274
 
        }
1275
 
 
1276
 
        gossip_debug (DEBUG_DOMAIN, "[%d] Contact joined:'%s'",
1277
 
                      id, gossip_contact_get_id (contact));
1278
 
 
1279
 
        pixbuf = gossip_pixbuf_for_contact (contact);
1280
 
 
1281
 
        role = gossip_chatroom_contact_get_role (GOSSIP_CHATROOM_CONTACT (contact));
1282
 
        group_chat_get_role_iter (chat, role, &parent);
1283
 
 
1284
 
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1285
 
        gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent);
1286
 
 
1287
 
        gtk_tree_store_set (GTK_TREE_STORE (model),
1288
 
                            &iter,
1289
 
                            COL_CONTACT, contact,
1290
 
                            COL_NAME, gossip_contact_get_name (contact),
1291
 
                            COL_STATUS, pixbuf,
1292
 
                            COL_IS_HEADER, FALSE,
1293
 
                            -1);
1294
 
 
1295
 
        path = gtk_tree_model_get_path (model, &parent);
1296
 
        gtk_tree_view_expand_row (GTK_TREE_VIEW (priv->treeview), path, TRUE);
1297
 
        gtk_tree_path_free (path);
1298
 
 
1299
 
        g_object_unref (pixbuf);
1300
 
 
1301
 
        g_signal_connect (contact, "notify::presences",
1302
 
                          G_CALLBACK (group_chat_contact_presence_updated_cb),
1303
 
                          chat);
1304
 
        g_signal_connect (contact, "notify::name",
1305
 
                          G_CALLBACK (group_chat_contact_updated_cb),
1306
 
                          chat);
1307
 
 
1308
 
        g_signal_emit_by_name (chat, "contact_added", contact);
1309
 
        
1310
 
        /* Add event to chatroom */
1311
 
        if (!gossip_contact_equal (priv->own_contact, contact)) {
1312
 
                gchar *str;
1313
 
 
1314
 
                str = g_strdup_printf (_("%s has joined the room"),
1315
 
                                       gossip_contact_get_name (contact));
1316
 
                gossip_chat_view_append_event (GOSSIP_CHAT (chat)->view, str);
1317
 
                g_free (str);
1318
 
        }
1319
 
}
1320
 
 
1321
 
static void
1322
1276
group_chat_cl_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
1323
1277
                                     GtkCellRenderer   *cell,
1324
1278
                                     GtkTreeModel      *model,
1450
1404
}
1451
1405
 
1452
1406
static void
1453
 
group_chat_contact_left_cb (GossipChatroomProvider *provider,
1454
 
                            gint                    id,
1455
 
                            GossipContact          *contact,
1456
 
                            GossipGroupChat        *chat)
 
1407
group_chat_contact_joined_cb (GossipChatroom  *chatroom,
 
1408
                              GossipContact   *contact,
 
1409
                              GossipGroupChat *chat)
 
1410
{
 
1411
        GossipGroupChatPriv       *priv;
 
1412
 
 
1413
        priv = GET_PRIV (chat);
 
1414
 
 
1415
        gossip_debug (DEBUG_DOMAIN, "Contact joined:'%s'",
 
1416
                      gossip_contact_get_id (contact));
 
1417
 
 
1418
        group_chat_contact_add (chat, contact);
 
1419
 
 
1420
        g_signal_connect (contact, "notify::presences",
 
1421
                          G_CALLBACK (group_chat_contact_presence_updated_cb),
 
1422
                          chat);
 
1423
        g_signal_connect (contact, "notify::name",
 
1424
                          G_CALLBACK (group_chat_contact_updated_cb),
 
1425
                          chat);
 
1426
 
 
1427
        g_signal_emit_by_name (chat, "contact_added", contact);
 
1428
        
 
1429
        /* Add event to chatroom */
 
1430
        if (!gossip_contact_equal (priv->own_contact, contact)) {
 
1431
                gchar *str;
 
1432
 
 
1433
                str = g_strdup_printf (_("%s has joined the room"),
 
1434
                                       gossip_contact_get_name (contact));
 
1435
                gossip_chat_view_append_event (GOSSIP_CHAT (chat)->view, str);
 
1436
                g_free (str);
 
1437
        }
 
1438
}
 
1439
 
 
1440
static void
 
1441
group_chat_contact_left_cb (GossipChatroom  *chatroom,
 
1442
                            GossipContact   *contact,
 
1443
                            GossipGroupChat *chat)
1457
1444
{
1458
1445
        GossipGroupChatPriv *priv;
1459
 
        GtkTreeIter          iter;
1460
1446
 
1461
1447
        priv = GET_PRIV (chat);
1462
1448
 
1463
 
        if (id != gossip_chatroom_get_id (priv->chatroom)) {
1464
 
                return;
1465
 
        }
1466
 
 
1467
 
        gossip_debug (DEBUG_DOMAIN, "[%d] Contact left:'%s'",
1468
 
                      id, gossip_contact_get_id (contact));
 
1449
        gossip_debug (DEBUG_DOMAIN, "Contact left:'%s'",
 
1450
                      gossip_contact_get_id (contact));
1469
1451
 
1470
1452
        g_signal_handlers_disconnect_by_func (contact,
1471
1453
                                              group_chat_contact_updated_cb,
1474
1456
                                              group_chat_contact_presence_updated_cb,
1475
1457
                                              chat);
1476
1458
 
 
1459
        group_chat_contact_remove (chat, contact);
 
1460
 
 
1461
        g_signal_emit_by_name (chat, "contact_removed", contact);
 
1462
 
 
1463
        /* Add event to chatroom */
 
1464
        if (!gossip_contact_equal (priv->own_contact, contact)) {
 
1465
                gchar *str;
 
1466
                str = g_strdup_printf (_("%s has left the room"),
 
1467
                                       gossip_contact_get_name (contact));
 
1468
                gossip_chat_view_append_event (GOSSIP_CHAT (chat)->view, str);
 
1469
                g_free (str);
 
1470
        }
 
1471
}
 
1472
 
 
1473
static void
 
1474
group_chat_contact_info_changed_cb (GossipChatroom            *chatroom,
 
1475
                                    GossipContact             *contact,
 
1476
                                    GossipGroupChat           *chat)
 
1477
{
 
1478
        group_chat_contact_remove (chat, contact);
 
1479
        group_chat_contact_add (chat, contact);
 
1480
}
 
1481
 
 
1482
static void
 
1483
group_chat_contact_add (GossipGroupChat *chat,
 
1484
                        GossipContact   *contact)
 
1485
{
 
1486
        GossipGroupChatPriv       *priv;
 
1487
        GossipChatroomContactInfo *info;
 
1488
        GossipChatroomRole         role = GOSSIP_CHATROOM_ROLE_NONE;
 
1489
        GtkTreeModel              *model;
 
1490
        GtkTreeIter                iter;
 
1491
        GtkTreeIter                parent;
 
1492
        GdkPixbuf                 *pixbuf;
 
1493
        GtkTreePath               *path;
 
1494
 
 
1495
        priv = GET_PRIV (chat);
 
1496
 
 
1497
        pixbuf = gossip_pixbuf_for_contact (contact);
 
1498
 
 
1499
        info = gossip_chatroom_get_contact_info (priv->chatroom, contact);
 
1500
        if (info) {
 
1501
                role = info->role;
 
1502
        }
 
1503
        group_chat_get_role_iter (chat, role, &parent);
 
1504
 
 
1505
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
 
1506
        gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent);
 
1507
 
 
1508
        gtk_tree_store_set (GTK_TREE_STORE (model),
 
1509
                            &iter,
 
1510
                            COL_CONTACT, contact,
 
1511
                            COL_NAME, gossip_contact_get_name (contact),
 
1512
                            COL_STATUS, pixbuf,
 
1513
                            COL_IS_HEADER, FALSE,
 
1514
                            -1);
 
1515
 
 
1516
        path = gtk_tree_model_get_path (model, &parent);
 
1517
        gtk_tree_view_expand_row (GTK_TREE_VIEW (priv->treeview), path, TRUE);
 
1518
        gtk_tree_path_free (path);
 
1519
 
 
1520
        g_object_unref (pixbuf);
 
1521
}
 
1522
 
 
1523
static void
 
1524
group_chat_contact_remove (GossipGroupChat *chat,
 
1525
                           GossipContact   *contact)
 
1526
{
 
1527
        GossipGroupChatPriv *priv;
 
1528
        GtkTreeIter          iter;
 
1529
 
 
1530
        priv = GET_PRIV (chat);
 
1531
 
1477
1532
        if (group_chat_contacts_find (chat, contact, &iter)) {
1478
1533
                GtkTreeModel *model;
1479
1534
                GtkTreeIter   parent;
1486
1541
                if (!gtk_tree_model_iter_has_child (model, &parent)) {
1487
1542
                        gtk_tree_store_remove (GTK_TREE_STORE (model), &parent);
1488
1543
                }
1489
 
 
1490
 
                g_signal_emit_by_name (chat, "contact_removed", contact);
1491
 
 
1492
 
                /* Add event to chatroom */
1493
 
                if (!gossip_contact_equal (priv->own_contact, contact)) {
1494
 
                        gchar *str;
1495
 
                        str = g_strdup_printf (_("%s has left the room"),
1496
 
                                               gossip_contact_get_name (contact));
1497
 
                        gossip_chat_view_append_event (GOSSIP_CHAT (chat)->view, str);
1498
 
                        g_free (str);
1499
 
                }
1500
1544
        }
1501
1545
}
1502
1546
 
2062
2106
        g_signal_connect (provider, "chatroom-topic-changed",
2063
2107
                          G_CALLBACK (group_chat_topic_changed_cb),
2064
2108
                          chat);
2065
 
        g_signal_connect (provider, "chatroom-contact-joined",
 
2109
        g_signal_connect (chatroom, "contact-joined",
2066
2110
                          G_CALLBACK (group_chat_contact_joined_cb),
2067
2111
                          chat);
2068
 
        g_signal_connect (provider, "chatroom-contact-left",
 
2112
        g_signal_connect (chatroom, "contact-left",
2069
2113
                          G_CALLBACK (group_chat_contact_left_cb),
2070
2114
                          chat);
 
2115
        g_signal_connect (chatroom, "contact-info-changed",
 
2116
                          G_CALLBACK (group_chat_contact_info_changed_cb),
 
2117
                          chat);
2071
2118
 
2072
2119
        /* Actually join the chat room */
2073
2120
        group_chat_join (chat);