aboutsummaryrefslogtreecommitdiffstats
path: root/src/empathy-filter-plugin.c
blob: ee90d974ee7fbb1dd6675f1bae3cd102fbc09876 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2007 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
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 * 
 * Authors: Xavier Claessens <xclaesse@gmail.com>
 */

#include <glib.h>

#include <dbus/dbus-glib.h>

#include <libtelepathy/tp-helpers.h>
#include <libtelepathy/tp-conn.h>

#include <mission-control/mcd-dispatcher.h>
#include <mission-control/mcd-dispatcher-context.h>
#include <mission-control/mcd-channel.h>

#include <libempathy/empathy-marshal-main.c>

#include "empathy-filter-gen.h"

static void filter_plugin_text_channel      (McdDispatcherContext *ctx);
static void filter_plugin_handle_channel_cb (DBusGProxy           *proxy,
                         GError               *error,
                         McdDispatcherContext *ctx);
static void filter_plugin_process_cb        (DBusGProxy           *filter,
                         guint                 context_handle,
                         gboolean              result,
                         McdDispatcher        *dispatcher);

static McdFilter text_in_filters[] = {
    {filter_plugin_text_channel, MCD_FILTER_PRIORITY_USER},
    {NULL, 0}
};

static DBusGProxy *filter = NULL;
static GHashTable *contexts = NULL;
static guint n_contexts = 0;

void
mcd_filters_init (McdDispatcher *dispatcher)
{
    static gboolean initialized = FALSE;

    if (initialized) {
        return;
    }

    filter = dbus_g_proxy_new_for_name (tp_get_bus (),
                        "org.gnome.Empathy.Filter",
                        "/org/gnome/Empathy/Filter",
                        "org.gnome.Empathy.Filter");

    dbus_g_object_register_marshaller (
        empathy_marshal_VOID__UINT_BOOLEAN,
        G_TYPE_NONE,
        G_TYPE_UINT,
        G_TYPE_BOOLEAN,
        G_TYPE_INVALID);

    dbus_g_proxy_add_signal (filter, "Process",
                 G_TYPE_UINT,
                 G_TYPE_BOOLEAN,
                 G_TYPE_INVALID);
    dbus_g_proxy_connect_signal (filter, "Process",
                     G_CALLBACK (filter_plugin_process_cb),
                     dispatcher,
                     NULL);
    contexts = g_hash_table_new_full (g_direct_hash,
                      g_direct_equal,
                      NULL,
                      (GDestroyNotify) g_object_unref);

    mcd_dispatcher_register_filters (dispatcher,
                     text_in_filters,
                     TELEPATHY_CHAN_IFACE_TEXT_QUARK,
                     MCD_FILTER_IN);

    initialized = TRUE;
}

static void
filter_plugin_text_channel (McdDispatcherContext *ctx)
{
    const TpConn *tp_conn;
    McdChannel   *channel;

    tp_conn = mcd_dispatcher_context_get_connection_object (ctx);
    channel = mcd_dispatcher_context_get_channel (ctx);

    n_contexts++;
    g_hash_table_insert (contexts,
                 GUINT_TO_POINTER (n_contexts),
                 ctx);

    empathy_filter_handle_channel_async (filter,
                         dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn)),
                         dbus_g_proxy_get_path (DBUS_G_PROXY (tp_conn)),
                         mcd_channel_get_channel_type (channel),
                         mcd_channel_get_object_path (channel),
                         mcd_channel_get_handle_type (channel),
                         mcd_channel_get_handle (channel),
                         n_contexts,
                         (empathy_filter_handle_channel_reply) filter_plugin_handle_channel_cb,
                         ctx);
}

static void
filter_plugin_handle_channel_cb (DBusGProxy           *proxy,
                 GError               *error,
                 McdDispatcherContext *ctx)
{
}

static void
filter_plugin_process_cb (DBusGProxy    *filter,
              guint          context_handle,
              gboolean       result,
              McdDispatcher *dispatcher)
{
    McdDispatcherContext *ctx;

    g_print ("****processing\n");
    ctx = g_hash_table_lookup (contexts, GUINT_TO_POINTER (context_handle));
    mcd_dispatcher_context_process (ctx, result);
}