aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2007-05-09 04:08:17 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-05-09 04:08:17 +0800
commitae195f5e93d0f92e0c7714b5b27be8d1740803aa (patch)
tree8db450d3c71386accb1948deb8727fb71fd56973 /src
parentf0f2ad9e9994d43ec6cbae068036e6dd6b76dea6 (diff)
downloadgsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.tar
gsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.tar.gz
gsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.tar.bz2
gsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.tar.lz
gsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.tar.xz
gsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.tar.zst
gsoc2013-empathy-ae195f5e93d0f92e0c7714b5b27be8d1740803aa.zip
[darcs-to-svn @ many changes]
svn path=/trunk/; revision=35
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am46
-rw-r--r--src/empathy-filter-plugin.c110
-rw-r--r--src/empathy-filter.c173
-rw-r--r--src/empathy-filter.h56
-rw-r--r--src/empathy-filter.xml19
-rw-r--r--src/empathy-main.c21
6 files changed, 390 insertions, 35 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 86ffade6b..2eb2d0286 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,33 +1,28 @@
-cflags = $(EMPATHY_CFLAGS) \
- $(WARN_CFLAGS)
-
-libs = $(top_builddir)/libempathy/libempathy.la \
+AM_CPPFLAGS = \
+ -I. \
+ -I$(top_srcdir) \
+ $(EMPATHY_CFLAGS) \
+ $(WARN_CFLAGS)
+
+AM_LDFLAGS = \
+ $(top_builddir)/libempathy/libempathy.la \
$(top_builddir)/libempathy-gtk/libempathy-gtk.la \
$(EMPATHY_LIBS)
bin_PROGRAMS = empathy empathy-accounts empathy-chat empathy-contact-list
-empathy_SOURCES = empathy-main.c
-empathy_CPPFLAGS = $(cflags)
-empathy_LDFLAGS = $(libs)
-
+empathy_SOURCES = \
+ empathy-main.c \
+ empathy-filter.c empathy-filter.h
empathy_accounts_SOURCES = empathy-accounts-main.c
-empathy_accounts_CPPFLAGS = $(cflags)
-empathy_accounts_LDFLAGS = $(libs)
-
empathy_chat_SOURCES = empathy-chat-main.c
-empathy_chat_CPPFLAGS = $(cflags)
-empathy_chat_LDFLAGS = $(libs)
-
empathy_contact_list_SOURCES = empathy-contact-list-main.c
-empathy_contact_list_CPPFLAGS = $(cflags)
-empathy_contact_list_LDFLAGS = $(libs)
# MC plugin
-pluginlib_LTLIBRARIES = libempathy-filter-plugin.la
-libempathy_filter_plugin_la_SOURCES = empathy-filter-plugin.c
-libempathy_filter_plugin_la_CPPFLAGS = $(MISSION_CONTROL_PLUGINS_CFLAGS)
-libempathy_filter_plugin_la_LDFLAGS = $(MISSION_CONTROL_PLUGINS_LIBS)
+#pluginlib_LTLIBRARIES = libempathy-filter-plugin.la
+#libempathy_filter_plugin_la_SOURCES = empathy-filter-plugin.c
+#libempathy_filter_plugin_la_CPPFLAGS = $(MISSION_CONTROL_PLUGINS_CFLAGS)
+#libempathy_filter_plugin_la_LDFLAGS = $(MISSION_CONTROL_PLUGINS_LIBS)
# Dbus service file
servicedir = $(datadir)/dbus-1/services
@@ -46,11 +41,20 @@ autostart_in_files = empathy.desktop.in
autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
+# Empathy filter DBus API
+empathy-filter-glue.h: empathy-filter.xml
+ $(LIBTOOL) --mode=execute $(DBUS_BINDING_TOOL) --prefix=empathy_filter --mode=glib-server --output=$@ $<
+empathy-filter-gen.h: empathy-filter.xml
+ $(LIBTOOL) --mode=execute $(DBUS_BINDING_TOOL) --prefix=empathy_filter --mode=glib-client --output=$@ $<
+
BUILT_SOURCES = \
- org.gnome.Empathy.Chat.service
+ org.gnome.Empathy.Chat.service \
+ empathy-filter-glue.h \
+ empathy-filter-gen.h
EXTRA_DIST = \
org.gnome.Empathy.Chat.service.in \
+ empathy-filter.xml \
$(autostart_DATA) \
$(chandler_DATA)
diff --git a/src/empathy-filter-plugin.c b/src/empathy-filter-plugin.c
index dfd749160..ee90d974e 100644
--- a/src/empathy-filter-plugin.c
+++ b/src/empathy-filter-plugin.c
@@ -22,40 +22,122 @@
#include <glib.h>
-#include <mcd-dispatcher.h>
-#include <mcd-dispatcher-context.h>
+#include <dbus/dbus-glib.h>
-static void filter_plugin_text_channel (McdDispatcherContext *ctx);
+#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}
+ {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)
{
- McdChannel *channel;
- const gchar *channel_name;
+ const TpConn *tp_conn;
+ McdChannel *channel;
+ tp_conn = mcd_dispatcher_context_get_connection_object (ctx);
channel = mcd_dispatcher_context_get_channel (ctx);
- channel_name = mcd_channel_get_name (channel);
- if (strcmp (channel_name, "goerge.w.bush@whitehouse.com") == 0) {
- g_debug ("Blocking contact");
- mcd_dispatcher_context_process (ctx, FALSE);
- return;
- }
+ 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;
- mcd_dispatcher_context_process (ctx, TRUE);
+ g_print ("****processing\n");
+ ctx = g_hash_table_lookup (contexts, GUINT_TO_POINTER (context_handle));
+ mcd_dispatcher_context_process (ctx, result);
}
diff --git a/src/empathy-filter.c b/src/empathy-filter.c
new file mode 100644
index 000000000..3696cc1c9
--- /dev/null
+++ b/src/empathy-filter.c
@@ -0,0 +1,173 @@
+/* -*- 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 <config.h>
+
+#include <dbus/dbus-glib.h>
+
+#include <libtelepathy/tp-helpers.h>
+#include <libtelepathy/tp-conn.h>
+#include <libtelepathy/tp-chan.h>
+
+#include <libempathy/gossip-debug.h>
+#include <libempathy/empathy-marshal.h>
+
+#include "empathy-filter.h"
+
+#define DEBUG_DOMAIN "EmpathyFilter"
+
+static gboolean empathy_filter_handle_channel (EmpathyFilter *filter,
+ const gchar *bus_name,
+ const gchar *connection,
+ const gchar *channel_type,
+ const gchar *channel,
+ guint handle_type,
+ guint handle,
+ guint context_handle,
+ GError **error);
+
+#include "empathy-filter-glue.h"
+
+enum {
+ NEW_CHANNEL,
+ PROCESS,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE (EmpathyFilter, empathy_filter, G_TYPE_OBJECT)
+
+static void
+empathy_filter_class_init (EmpathyFilterClass *klass)
+{
+ signals[NEW_CHANNEL] =
+ g_signal_new ("new-channel",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ empathy_marshal_VOID__OBJECT_OBJECT_UINT,
+ G_TYPE_NONE,
+ 3, TELEPATHY_CONN_TYPE, TELEPATHY_CHAN_TYPE, G_TYPE_UINT);
+
+ signals[PROCESS] =
+ g_signal_new ("process",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ empathy_marshal_VOID__UINT_BOOLEAN,
+ G_TYPE_NONE,
+ 2, G_TYPE_UINT, G_TYPE_BOOLEAN);
+}
+
+static void
+empathy_filter_init (EmpathyFilter *filter)
+{
+}
+
+EmpathyFilter *
+empathy_filter_new (void)
+{
+ static gboolean initialized = FALSE;
+ EmpathyFilter *filter;
+ DBusGProxy *proxy;
+ guint result;
+ GError *error = NULL;
+
+ if (!initialized) {
+ dbus_g_object_type_install_info (EMPATHY_TYPE_FILTER,
+ &dbus_glib_empathy_filter_object_info);
+ initialized = TRUE;
+ }
+
+ proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ if (!dbus_g_proxy_call (proxy, "RequestName", &error,
+ G_TYPE_STRING, "org.gnome.Empathy.Filter",
+ G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &result,
+ G_TYPE_INVALID)) {
+ gossip_debug (DEBUG_DOMAIN,
+ "Failed to request name: %s",
+ error ? error->message : "No error given");
+ g_clear_error (&error);
+
+ return NULL;
+ }
+ g_object_unref (proxy);
+
+ filter = g_object_new (EMPATHY_TYPE_FILTER, NULL);
+ dbus_g_connection_register_g_object (tp_get_bus (),
+ "/org/gnome/Empathy/Filter",
+ G_OBJECT (filter));
+
+ return filter;
+}
+
+void
+empathy_filter_process (EmpathyFilter *filter,
+ guint context_handle,
+ gboolean result)
+{
+ g_print ("hello\n");
+ g_signal_emit (filter, signals[PROCESS], 0, context_handle, result);
+}
+
+static gboolean
+empathy_filter_handle_channel (EmpathyFilter *filter,
+ const gchar *bus_name,
+ const gchar *connection,
+ const gchar *channel_type,
+ const gchar *channel,
+ guint handle_type,
+ guint handle,
+ guint context_handle,
+ GError **error)
+{
+ TpChan *tp_chan;
+ TpConn *tp_conn;
+
+ tp_conn = tp_conn_new (tp_get_bus (),
+ bus_name,
+ connection);
+
+ tp_chan = tp_chan_new (tp_get_bus(),
+ bus_name,
+ channel,
+ channel_type,
+ handle_type,
+ handle);
+g_print ("new channel\n");
+ g_signal_emit (filter, signals[NEW_CHANNEL], 0, tp_conn, tp_chan, context_handle);
+
+ g_object_unref (tp_chan);
+ g_object_unref (tp_conn);
+
+ return TRUE;
+}
+
diff --git a/src/empathy-filter.h b/src/empathy-filter.h
new file mode 100644
index 000000000..071310bd4
--- /dev/null
+++ b/src/empathy-filter.h
@@ -0,0 +1,56 @@
+/* -*- 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>
+ */
+
+#ifndef __EMPATHY_FILTER_H__
+#define __EMPATHY_FILTER_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_FILTER (empathy_filter_get_type ())
+#define EMPATHY_FILTER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_FILTER, EmpathyFilter))
+#define EMPATHY_FILTER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_FILTER, EmpathyFilterClass))
+#define EMPATHY_IS_FILTER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_FILTER))
+#define EMPATHY_IS_FILTER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_FILTER))
+#define EMPATHY_FILTER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_FILTER, EmpathyFilterClass))
+
+typedef struct _EmpathyFilter EmpathyFilter;
+typedef struct _EmpathyFilterClass EmpathyFilterClass;
+
+struct _EmpathyFilter {
+ GObject parent;
+};
+
+struct _EmpathyFilterClass {
+ GObjectClass parent_class;
+};
+
+GType empathy_filter_get_type (void) G_GNUC_CONST;
+EmpathyFilter *empathy_filter_new (void);
+void empathy_filter_process (EmpathyFilter *filter,
+ guint context_handle,
+ gboolean result);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_FILTER_H__ */
diff --git a/src/empathy-filter.xml b/src/empathy-filter.xml
new file mode 100644
index 000000000..e6b8daeef
--- /dev/null
+++ b/src/empathy-filter.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<node name="/Filter">
+ <interface name="org.gnome.Empathy.Filter">
+ <annotation name="org.freedesktop.DBus.GLib.ClientCSymbol" value="empathy_filter"/>
+ <method name="HandleChannel">
+ <arg direction="in" type="s" name="bus_name" />
+ <arg direction="in" type="o" name="connection" />
+ <arg direction="in" type="s" name="channel_type" />
+ <arg direction="in" type="o" name="channel" />
+ <arg direction="in" type="u" name="handle_type" />
+ <arg direction="in" type="u" name="handle" />
+ <arg direction="in" type="u" name="context_handle" />
+ </method>
+ <signal name="Process">
+ <arg type="u" name="context_handle" />
+ <arg type="u" name="result" />
+ </signal>
+ </interface>
+</node>
diff --git a/src/empathy-main.c b/src/empathy-main.c
index fb5684aa3..afa1e119e 100644
--- a/src/empathy-main.c
+++ b/src/empathy-main.c
@@ -39,6 +39,8 @@
#include <libempathy-gtk/gossip-status-presets.h>
#include <libempathy-gtk/gossip-accounts-dialog.h>
+#include "empathy-filter.h"
+
#define DEBUG_DOMAIN "Empathy"
static void error_cb (MissionControl *mc,
@@ -118,6 +120,18 @@ icon_activate_cb (GtkStatusIcon *status_icon,
}
}
+static void
+new_channel_cb (EmpathyFilter *filter,
+ TpConn *tp_conn,
+ TpChan *tp_chan,
+ guint context_handle,
+ gpointer user_data)
+{
+ gossip_debug (DEBUG_DOMAIN, "Filtering context handle: %d",
+ context_handle);
+ empathy_filter_process (filter, context_handle, TRUE);
+}
+
int
main (int argc, char *argv[])
{
@@ -126,9 +140,16 @@ main (int argc, char *argv[])
GtkWidget *window;
MissionControl *mc;
McAccountMonitor *monitor;
+ EmpathyFilter *filter;
gtk_init (&argc, &argv);
+ /* Setting up channel filter */
+ filter = empathy_filter_new ();
+ g_signal_connect (filter, "new-channel",
+ G_CALLBACK (new_channel_cb),
+ NULL);
+
/* Setting up MC */
monitor = mc_account_monitor_new ();
mc = mission_control_new (tp_get_bus ());