~ubuntu-branches/ubuntu/natty/empathy/natty-updates

« back to all changes in this revision

Viewing changes to libempathy/empathy-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons
  • Date: 2008-03-10 16:39:07 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080310163907-tv41g2zmf0qqgi85
Tags: 0.22.0-1
New upstream release

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
3
 * Copyright (C) 2003-2007 Imendio AB
4
 
 * Copyright (C) 2007 Collabora Ltd.
 
4
 * Copyright (C) 2007-2008 Collabora Ltd.
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License as
34
34
 
35
35
#include <libxml/uri.h>
36
36
#include <libtelepathy/tp-helpers.h>
 
37
#include <libtelepathy/tp-conn.h>
37
38
 
38
39
#include "empathy-debug.h"
39
40
#include "empathy-utils.h"
 
41
#include "empathy-contact-factory.h"
40
42
#include "empathy-contact-manager.h"
41
43
#include "empathy-tp-group.h"
42
44
 
57
59
 */
58
60
#define USERCHARS "-A-Za-z0-9"
59
61
#define PASSCHARS "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
60
 
#define HOSTCHARS "-A-Za-z0-9"
 
62
#define HOSTCHARS "-A-Za-z0-9_"
61
63
#define PATHCHARS "-A-Za-z0-9_$.+!*(),;:@&=?/~#%"
62
64
#define SCHEME    "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
63
65
#define USER      "[" USERCHARS "]+(:["PASSCHARS "]+)?"
208
210
        xmlDtd       *dtd;
209
211
        gboolean      ret;
210
212
 
211
 
        path = g_build_filename (UNINSTALLED_DTD_DIR, dtd_filename, NULL);
 
213
        path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "libempathy",
 
214
                                 dtd_filename, NULL);
212
215
        if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
213
216
                g_free (path);
214
217
                path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL);
397
400
}
398
401
 
399
402
void
400
 
empathy_call_with_contact (EmpathyContact  *contact)
 
403
empathy_call_with_contact (EmpathyContact *contact)
401
404
{
402
405
#ifdef HAVE_VOIP
403
 
        MissionControl *mc;
 
406
        MissionControl        *mc;
 
407
        McAccount             *account;
 
408
        TpConn                *tp_conn;
 
409
        gchar                 *object_path;
 
410
        const gchar           *bus_name;
 
411
        TpChan                *new_chan;
 
412
        EmpathyContactFactory *factory;
 
413
        EmpathyTpGroup        *group;
 
414
        EmpathyContact        *self_contact;
 
415
        GError                *error = NULL;
 
416
 
 
417
        g_return_if_fail (EMPATHY_IS_CONTACT (contact));
 
418
 
 
419
        /* StreamedMedia channels must have handle=0 and handle_type=none.
 
420
         * To call a contact we have to add him in the group interface of the
 
421
         * channel. MissionControl will detect the channel creation and 
 
422
         * dispatch it to the VoIP chandler automatically. */
404
423
 
405
424
        mc = empathy_mission_control_new ();
406
 
        mission_control_request_channel (mc,
407
 
                                         empathy_contact_get_account (contact),
408
 
                                         TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
409
 
                                         empathy_contact_get_handle (contact),
410
 
                                         TP_HANDLE_TYPE_CONTACT,
411
 
                                         NULL, NULL);
 
425
        account = empathy_contact_get_account (contact);
 
426
        tp_conn = mission_control_get_connection (mc, account, NULL);
 
427
        /* FIXME: Should be async */
 
428
        if (!tp_conn_request_channel (DBUS_G_PROXY (tp_conn),
 
429
                                      TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
 
430
                                      TP_HANDLE_TYPE_NONE,
 
431
                                      0,
 
432
                                      FALSE,
 
433
                                      &object_path,
 
434
                                      &error)) {
 
435
                empathy_debug (DEBUG_DOMAIN, 
 
436
                              "Couldn't request channel: %s",
 
437
                              error ? error->message : "No error given");
 
438
                g_clear_error (&error);
 
439
                g_object_unref (mc);
 
440
                g_object_unref (tp_conn);
 
441
                return;
 
442
        }
 
443
 
 
444
        bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn));
 
445
        new_chan = tp_chan_new (tp_get_bus (),
 
446
                                bus_name,
 
447
                                object_path,
 
448
                                TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
 
449
                                TP_HANDLE_TYPE_NONE,
 
450
                                0);
 
451
 
 
452
        group = empathy_tp_group_new (account, new_chan);
 
453
        factory = empathy_contact_factory_new ();
 
454
        self_contact = empathy_contact_factory_get_user (factory, account);
 
455
        empathy_tp_group_add_member (group, contact, "");
 
456
        empathy_tp_group_add_member (group, self_contact, "");  
 
457
 
 
458
        g_object_unref (factory);
 
459
        g_object_unref (self_contact);
 
460
        g_object_unref (group);
412
461
        g_object_unref (mc);
413
 
#endif
414
 
}
 
462
        g_object_unref (tp_conn);
 
463
        g_object_unref (new_chan);
 
464
        g_free (object_path);
 
465
#endif
 
466
}
 
467
 
 
468
#ifdef HAVE_VOIP
 
469
static void
 
470
got_handle_cb (EmpathyContact        *contact, 
 
471
               GParamSpec            *property,
 
472
               EmpathyContactFactory *factory)
 
473
{
 
474
        g_signal_handlers_disconnect_by_func (contact,
 
475
                                              got_handle_cb,
 
476
                                              factory);
 
477
 
 
478
        empathy_call_with_contact (contact);
 
479
        g_object_unref (factory);
 
480
        g_object_unref (contact);
 
481
}
 
482
#endif
415
483
 
416
484
void
417
485
empathy_call_with_contact_id (McAccount *account, const gchar *contact_id)
418
486
{
419
487
#ifdef HAVE_VOIP
420
 
        MissionControl *mc;
421
 
 
422
 
        mc = empathy_mission_control_new ();
423
 
        mission_control_request_channel_with_string_handle (mc,
424
 
                                                            account,
425
 
                                                            TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
426
 
                                                            contact_id,
427
 
                                                            TP_HANDLE_TYPE_CONTACT,
428
 
                                                            NULL, NULL);
429
 
        g_object_unref (mc);
 
488
        EmpathyContactFactory *factory;
 
489
        EmpathyContact        *contact;
 
490
 
 
491
        factory = empathy_contact_factory_new ();
 
492
        contact = empathy_contact_factory_get_from_id (factory, account, contact_id);
 
493
 
 
494
        if (empathy_contact_get_handle (contact) != 0) {
 
495
                empathy_call_with_contact (contact);
 
496
                g_object_unref (contact);
 
497
                g_object_unref (factory);
 
498
        } else {
 
499
                g_signal_connect (contact, "notify::handle",
 
500
                                  G_CALLBACK (got_handle_cb),
 
501
                                  factory);
 
502
        }
430
503
#endif
431
504
}
432
505