aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/Makefile.am8
-rw-r--r--libempathy/empathy-call-handler.c101
-rw-r--r--libempathy/empathy-connectivity.c433
-rw-r--r--libempathy/empathy-connectivity.h71
-rw-r--r--libempathy/empathy-debug.c1
-rw-r--r--libempathy/empathy-debug.h1
-rw-r--r--libempathy/empathy-idle.c159
-rw-r--r--libempathy/empathy-idle.h3
-rw-r--r--libempathy/empathy-tp-chat.c17
-rw-r--r--libempathy/empathy-tp-contact-factory.c14
-rw-r--r--libempathy/empathy-tp-contact-list.c28
11 files changed, 592 insertions, 244 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index cdaa144fc..5fe4a9df7 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"empathy\" \
$(LIBEMPATHY_CFLAGS) \
$(GEOCLUE_CFLAGS) \
- $(NETWORK_MANAGER_CFLAGS) \
+ $(NETWORK_MANAGER_CFLAGS) \
+ $(CONNMAN_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED)
@@ -31,6 +32,7 @@ libempathy_la_SOURCES = \
empathy-chatroom-manager.c \
empathy-call-factory.c \
empathy-call-handler.c \
+ empathy-connectivity.c \
empathy-contact.c \
empathy-contact-groups.c \
empathy-contact-list.c \
@@ -70,7 +72,8 @@ libempathy_la_LIBADD = \
$(top_builddir)/extensions/libemp-extensions.la \
$(LIBEMPATHY_LIBS) \
$(GEOCLUE_LIBS) \
- $(NETWORK_MANAGER_LIBS)
+ $(NETWORK_MANAGER_LIBS) \
+ $(CONNMAN_LIBS)
libempathy_la_LDFLAGS = \
-version-info ${LIBEMPATHY_CURRENT}:${LIBEMPATHY_REVISION}:${LIBEMPATHY_AGE} \
@@ -84,6 +87,7 @@ libempathy_headers = \
empathy-chatroom-manager.h \
empathy-call-factory.h \
empathy-call-handler.h \
+ empathy-connectivity.h \
empathy-contact.h \
empathy-contact-groups.h \
empathy-contact-list.h \
diff --git a/libempathy/empathy-call-handler.c b/libempathy/empathy-call-handler.c
index 39f950f86..1c6e53c6c 100644
--- a/libempathy/empathy-call-handler.c
+++ b/libempathy/empathy-call-handler.c
@@ -28,8 +28,6 @@
#include <telepathy-farsight/channel.h>
#include <telepathy-farsight/stream.h>
-#include <gst/farsight/fs-element-added-notifier.h>
-
#include "empathy-call-handler.h"
#include "empathy-dispatcher.h"
#include "empathy-marshal.h"
@@ -66,7 +64,6 @@ typedef struct {
TfChannel *tfchannel;
gboolean initial_audio;
gboolean initial_video;
- FsElementAddedNotifier *fsnotifier;
} EmpathyCallHandlerPriv;
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
@@ -99,12 +96,6 @@ empathy_call_handler_dispose (GObject *object)
priv->call = NULL;
- if (priv->fsnotifier != NULL)
- {
- g_object_unref (priv->fsnotifier);
- }
- priv->fsnotifier = NULL;
-
/* release any references held by the object here */
if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose)
G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
@@ -323,49 +314,10 @@ empathy_call_handler_bus_message (EmpathyCallHandler *handler,
}
static void
-conference_element_added (FsElementAddedNotifier *notifier,
- GstBin *bin,
- GstElement *element,
- gpointer user_data)
-{
- GstElementFactory *factory;
- const gchar *name;
-
- factory = gst_element_get_factory (element);
- name = gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory));
-
- if (!tp_strdiff (name, "x264enc"))
- {
- /* Ensure that the encoder creates the baseline profile */
- g_object_set (element,
- "byte-stream", TRUE,
- "bframes", 0,
- "b-adapt", FALSE,
- "cabac", FALSE,
- "dct8x8", FALSE,
- NULL);
- }
- else if (!tp_strdiff (name, "gstrtpbin"))
- {
- /* Lower the jitterbuffer latency to make it more suitable for video
- * conferencing */
- g_object_set (element, "latency", 100, NULL);
- }
-}
-
-static void
empathy_call_handler_tf_channel_session_created_cb (TfChannel *tfchannel,
FsConference *conference, FsParticipant *participant,
EmpathyCallHandler *self)
{
- EmpathyCallHandlerPriv *priv = GET_PRIV (self);
-
- priv->fsnotifier = fs_element_added_notifier_new ();
- fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (conference));
-
- g_signal_connect (priv->fsnotifier, "element-added",
- G_CALLBACK (conference_element_added), NULL);
-
g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
GST_ELEMENT (conference));
}
@@ -428,53 +380,24 @@ empathy_call_handler_tf_channel_closed_cb (TfChannel *tfchannel,
}
static GList *
-empathy_call_handler_tf_channel_codec_config_get_defaults (FsCodec *codecs)
-{
- GList *l = NULL;
- int i;
-
- for (i = 0; codecs[i].encoding_name != NULL; i++)
- l = g_list_append (l, fs_codec_copy (codecs + i));
-
- return l;
-}
-
-static GList *
empathy_call_handler_tf_channel_codec_config_cb (TfChannel *channel,
guint stream_id, FsMediaType media_type, guint direction, gpointer user_data)
{
- FsCodec audio_codecs[] = {
- { FS_CODEC_ID_ANY, "SPEEX", FS_MEDIA_TYPE_AUDIO, 16000, },
- { FS_CODEC_ID_ANY, "SPEEX", FS_MEDIA_TYPE_AUDIO, 8000, },
-
- { FS_CODEC_ID_DISABLE, "DV", FS_MEDIA_TYPE_AUDIO, },
- { FS_CODEC_ID_DISABLE, "MPA", FS_MEDIA_TYPE_AUDIO, },
- { FS_CODEC_ID_DISABLE, "VORBIS", FS_MEDIA_TYPE_AUDIO, },
- { FS_CODEC_ID_DISABLE, "MP3", FS_MEDIA_TYPE_AUDIO, },
- { 0, NULL, 0,}
- };
- FsCodec video_codecs[] = {
- { FS_CODEC_ID_ANY, "H264", FS_MEDIA_TYPE_VIDEO, },
- { FS_CODEC_ID_ANY, "THEORA", FS_MEDIA_TYPE_VIDEO, },
- { FS_CODEC_ID_ANY, "H263", FS_MEDIA_TYPE_VIDEO, },
-
- { FS_CODEC_ID_DISABLE, "DV", FS_MEDIA_TYPE_VIDEO, },
- { FS_CODEC_ID_DISABLE, "JPEG", FS_MEDIA_TYPE_VIDEO, },
- { FS_CODEC_ID_DISABLE, "MPV", FS_MEDIA_TYPE_VIDEO, },
- { 0, NULL, 0}
- };
-
- switch (media_type)
+ gchar *filename = empathy_file_lookup ("codec-preferences", "data");
+ GList *codecs;
+ GError *error = NULL;
+
+ codecs = fs_codec_list_from_keyfile (filename, &error);
+ g_free (filename);
+
+ if (!codecs)
{
- case FS_MEDIA_TYPE_AUDIO:
- return empathy_call_handler_tf_channel_codec_config_get_defaults
- (audio_codecs);
- case FS_MEDIA_TYPE_VIDEO:
- return empathy_call_handler_tf_channel_codec_config_get_defaults
- (video_codecs);
+ g_warning ("No codec-preferences file: %s",
+ error ? error->message : "No error message");
}
+ g_clear_error (&error);
- return NULL;
+ return codecs;
}
static void
diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c
new file mode 100644
index 000000000..bbbcba467
--- /dev/null
+++ b/libempathy/empathy-connectivity.c
@@ -0,0 +1,433 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
+ */
+
+#include "config.h"
+#include "empathy-connectivity.h"
+
+#ifdef HAVE_NM
+#include <nm-client.h>
+#endif
+
+#ifdef HAVE_CONNMAN
+#include <dbus/dbus-glib.h>
+#endif
+
+#include <telepathy-glib/util.h>
+
+#include "empathy-utils.h"
+#include "empathy-marshal.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_CONNECTIVITY
+#include "empathy-debug.h"
+
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyConnectivity)
+
+typedef struct {
+#ifdef HAVE_NM
+ NMClient *nm_client;
+ gulong state_change_signal_id;
+#endif
+
+#ifdef HAVE_CONNMAN
+ DBusGProxy *proxy;
+#endif
+
+ gboolean connected;
+ gboolean use_conn;
+} EmpathyConnectivityPriv;
+
+enum {
+ STATE_CHANGE,
+ LAST_SIGNAL
+};
+
+enum {
+ PROP_0,
+ PROP_USE_CONN,
+};
+
+static guint signals[LAST_SIGNAL];
+static EmpathyConnectivity *connectivity_singleton = NULL;
+
+G_DEFINE_TYPE (EmpathyConnectivity, empathy_connectivity, G_TYPE_OBJECT);
+
+static void
+connectivity_change_state (EmpathyConnectivity *connectivity,
+ gboolean new_state)
+{
+ EmpathyConnectivityPriv *priv;
+
+ priv = GET_PRIV (connectivity);
+
+ if (priv->connected == new_state)
+ return;
+
+ priv->connected = new_state;
+
+ g_signal_emit (connectivity, signals[STATE_CHANGE], 0,
+ priv->connected);
+}
+
+#ifdef HAVE_NM
+static void
+connectivity_nm_state_change_cb (NMClient *client,
+ const GParamSpec *pspec,
+ EmpathyConnectivity *connectivity)
+{
+ EmpathyConnectivityPriv *priv;
+ gboolean new_nm_connected;
+ NMState state;
+
+ priv = GET_PRIV (connectivity);
+
+ if (!priv->use_conn)
+ return;
+
+ state = nm_client_get_state (priv->nm_client);
+ new_nm_connected = !(state == NM_STATE_CONNECTING
+ || state == NM_STATE_DISCONNECTED);
+
+ DEBUG ("New NetworkManager network state %d", state);
+
+ connectivity_change_state (connectivity, new_nm_connected);
+}
+#endif
+
+#ifdef HAVE_CONNMAN
+static void
+connectivity_connman_state_changed_cb (DBusGProxy *proxy,
+ const gchar *new_state,
+ EmpathyConnectivity *connectivity)
+{
+ EmpathyConnectivityPriv *priv;
+ gboolean new_connected;
+
+ priv = GET_PRIV (connectivity);
+
+ if (!priv->use_conn)
+ return;
+
+ new_connected = !tp_strdiff (new_state, "online");
+
+ DEBUG ("New ConnMan network state %s", new_state);
+
+ connectivity_change_state (connectivity, new_connected);
+}
+
+static void
+connectivity_connman_check_state_cb (DBusGProxy *proxy,
+ DBusGProxyCall *call_id,
+ gpointer user_data)
+{
+ EmpathyConnectivity *connectivity = (EmpathyConnectivity *) user_data;
+ GError *error = NULL;
+ gchar *state;
+
+ if (dbus_g_proxy_end_call (proxy, call_id, &error,
+ G_TYPE_STRING, &state, G_TYPE_INVALID))
+ {
+ connectivity_connman_state_changed_cb (proxy, state,
+ connectivity);
+ g_free (state);
+ }
+ else
+ {
+ DEBUG ("Failed to call GetState: %s", error->message);
+ connectivity_connman_state_changed_cb (proxy, "offline",
+ connectivity);
+ }
+}
+
+static void
+connectivity_connman_check_state (EmpathyConnectivity *connectivity)
+{
+ EmpathyConnectivityPriv *priv;
+
+ priv = GET_PRIV (connectivity);
+
+ dbus_g_proxy_begin_call (priv->proxy, "GetState",
+ connectivity_connman_check_state_cb, connectivity, NULL,
+ G_TYPE_INVALID);
+}
+#endif
+
+static void
+empathy_connectivity_init (EmpathyConnectivity *connectivity)
+{
+ EmpathyConnectivityPriv *priv;
+#ifdef HAVE_CONNMAN
+ DBusGConnection *connection;
+ GError *error = NULL;
+#endif
+
+ priv = G_TYPE_INSTANCE_GET_PRIVATE (connectivity,
+ EMPATHY_TYPE_CONNECTIVITY, EmpathyConnectivityPriv);
+
+ connectivity->priv = priv;
+
+ priv->use_conn = TRUE;
+
+#ifdef HAVE_NM
+ priv->nm_client = nm_client_new ();
+ if (priv->nm_client != NULL)
+ {
+ priv->state_change_signal_id = g_signal_connect (priv->nm_client,
+ "notify::" NM_CLIENT_STATE,
+ G_CALLBACK (connectivity_nm_state_change_cb), connectivity);
+
+ connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity);
+ }
+ else
+ {
+ DEBUG ("Failed to get NetworkManager proxy");
+ }
+#endif
+
+#ifdef HAVE_CONNMAN
+ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (connection != NULL)
+ {
+ priv->proxy = dbus_g_proxy_new_for_name (connection,
+ "org.moblin.connman", "/",
+ "org.moblin.connman.Manager");
+
+ dbus_g_object_register_marshaller (
+ _empathy_marshal_VOID__STRING,
+ G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);
+
+ dbus_g_proxy_add_signal (priv->proxy, "StateChanged",
+ G_TYPE_STRING, G_TYPE_INVALID);
+
+ dbus_g_proxy_connect_signal (priv->proxy, "StateChanged",
+ G_CALLBACK (connectivity_connman_state_changed_cb),
+ connectivity, NULL);
+
+ connectivity_connman_check_state (connectivity);
+ }
+ else
+ {
+ DEBUG ("Failed to get system bus connection: %s", error->message);
+ g_error_free (error);
+ }
+#endif
+
+#if !defined(HAVE_NM) || !defined(HAVE_CONNMAN)
+ priv->connected = TRUE;
+#endif
+}
+
+static void
+connectivity_finalize (GObject *object)
+{
+#ifdef HAVE_NM
+ EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object);
+ EmpathyConnectivityPriv *priv = GET_PRIV (connectivity);
+
+ if (priv->nm_client != NULL)
+ {
+ g_signal_handler_disconnect (priv->nm_client,
+ priv->state_change_signal_id);
+ priv->state_change_signal_id = 0;
+ g_object_unref (priv->nm_client);
+ priv->nm_client = NULL;
+ }
+#endif
+
+#ifdef HAVE_CONNMAN
+ EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object);
+ EmpathyConnectivityPriv *priv = GET_PRIV (connectivity);
+
+ if (priv->proxy != NULL)
+ {
+ dbus_g_proxy_disconnect_signal (priv->proxy, "StateChanged",
+ G_CALLBACK (connectivity_connman_state_changed_cb), connectivity);
+
+ g_object_unref (priv->proxy);
+ priv->proxy = NULL;
+ }
+#endif
+
+ G_OBJECT_CLASS (empathy_connectivity_parent_class)->finalize (object);
+}
+
+static void
+connectivity_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (empathy_connectivity_parent_class)->dispose (object);
+}
+
+static GObject *
+connectivity_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *retval;
+
+ if (!connectivity_singleton)
+ {
+ retval = G_OBJECT_CLASS (empathy_connectivity_parent_class)->constructor
+ (type, n_construct_params, construct_params);
+
+ connectivity_singleton = EMPATHY_CONNECTIVITY (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &connectivity_singleton);
+ }
+ else
+ {
+ retval = g_object_ref (connectivity_singleton);
+ }
+
+ return retval;
+}
+
+static void
+connectivity_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object);
+
+ switch (param_id)
+ {
+ case PROP_USE_CONN:
+ g_value_set_boolean (value, empathy_connectivity_get_use_conn (
+ connectivity));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+connectivity_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object);
+
+ switch (param_id)
+ {
+ case PROP_USE_CONN:
+ empathy_connectivity_set_use_conn (connectivity,
+ g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+empathy_connectivity_class_init (EmpathyConnectivityClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ oclass->finalize = connectivity_finalize;
+ oclass->dispose = connectivity_dispose;
+ oclass->constructor = connectivity_constructor;
+ oclass->get_property = connectivity_get_property;
+ oclass->set_property = connectivity_set_property;
+
+ signals[STATE_CHANGE] =
+ g_signal_new ("state-change",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ _empathy_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE,
+ 1, G_TYPE_BOOLEAN, NULL);
+
+ g_object_class_install_property (oclass,
+ PROP_USE_CONN,
+ g_param_spec_boolean ("use-conn",
+ "Use connectivity managers",
+ "Set presence according to connectivity managers",
+ TRUE,
+ G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+ g_type_class_add_private (oclass, sizeof (EmpathyConnectivityPriv));
+}
+
+/* public methods */
+
+EmpathyConnectivity *
+empathy_connectivity_dup_singleton (void)
+{
+ return g_object_new (EMPATHY_TYPE_CONNECTIVITY, NULL);
+}
+
+gboolean
+empathy_connectivity_is_online (EmpathyConnectivity *connectivity)
+{
+ EmpathyConnectivityPriv *priv = GET_PRIV (connectivity);
+
+ if (priv->use_conn)
+ {
+ return priv->connected;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
+
+gboolean
+empathy_connectivity_get_use_conn (EmpathyConnectivity *connectivity)
+{
+ EmpathyConnectivityPriv *priv = GET_PRIV (connectivity);
+
+ return priv->use_conn;
+}
+
+void
+empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity,
+ gboolean use_conn)
+{
+ EmpathyConnectivityPriv *priv = GET_PRIV (connectivity);
+
+ if (use_conn == priv->use_conn)
+ return;
+
+ DEBUG ("use_conn gconf key changed; new value = %s",
+ use_conn ? "true" : "false");
+
+ priv->use_conn = use_conn;
+
+#if defined(HAVE_NM) || defined(HAVE_CONNMAN)
+ if (use_conn)
+ {
+#if defined(HAVE_NM)
+ connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity);
+#elif defined(HAVE_CONNMAN)
+ connectivity_connman_check_state (connectivity);
+#endif
+ }
+ else
+#endif
+ {
+ connectivity_change_state (connectivity, TRUE);
+ }
+
+ g_object_notify (G_OBJECT (connectivity), "use-conn");
+}
diff --git a/libempathy/empathy-connectivity.h b/libempathy/empathy-connectivity.h
new file mode 100644
index 000000000..ca507e910
--- /dev/null
+++ b/libempathy/empathy-connectivity.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/*
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
+ */
+
+#ifndef __EMPATHY_CONNECTIVITY_H__
+#define __EMPATHY_CONNECTIVITY_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_CONNECTIVITY (empathy_connectivity_get_type ())
+#define EMPATHY_CONNECTIVITY(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CONNECTIVITY, \
+ EmpathyConnectivity))
+#define EMPATHY_CONNECTIVITY_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CONNECTIVITY, \
+ EmpathyConnectivityClass))
+#define EMPATHY_IS_CONNECTIVITY(o) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CONNECTIVITY))
+#define EMPATHY_IS_CONNECTIVITY_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CONNECTIVITY))
+#define EMPATHY_CONNECTIVITY_GET_CLASS(o) \
+ (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CONNECTIVITY, \
+ EmpathyConnectivityClass))
+
+typedef struct _EmpathyConnectivity EmpathyConnectivity;
+typedef struct _EmpathyConnectivityClass EmpathyConnectivityClass;
+
+struct _EmpathyConnectivity {
+ GObject parent;
+ gpointer priv;
+};
+
+struct _EmpathyConnectivityClass {
+ GObjectClass parent_class;
+};
+
+GType empathy_connectivity_get_type (void);
+
+/* public methods */
+
+EmpathyConnectivity * empathy_connectivity_dup_singleton (void);
+
+gboolean empathy_connectivity_is_online (EmpathyConnectivity *connectivity);
+
+gboolean empathy_connectivity_get_use_conn (EmpathyConnectivity *connectivity);
+void empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity,
+ gboolean use_conn);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_CONNECTIVITY_H__ */
+
diff --git a/libempathy/empathy-debug.c b/libempathy/empathy-debug.c
index 99111deec..9d69b801c 100644
--- a/libempathy/empathy-debug.c
+++ b/libempathy/empathy-debug.c
@@ -49,6 +49,7 @@ static GDebugKey keys[] = {
{ "Ft", EMPATHY_DEBUG_FT },
{ "Location", EMPATHY_DEBUG_LOCATION },
{ "Other", EMPATHY_DEBUG_OTHER },
+ { "Connectivity", EMPATHY_DEBUG_CONNECTIVITY },
{ 0, }
};
diff --git a/libempathy/empathy-debug.h b/libempathy/empathy-debug.h
index 0d25f22dd..edfa05d95 100644
--- a/libempathy/empathy-debug.h
+++ b/libempathy/empathy-debug.h
@@ -42,6 +42,7 @@ typedef enum
EMPATHY_DEBUG_LOCATION = 1 << 8,
EMPATHY_DEBUG_OTHER = 1 << 9,
EMPATHY_DEBUG_SHARE_DESKTOP = 1 << 10,
+ EMPATHY_DEBUG_CONNECTIVITY = 1 << 11,
} EmpathyDebugFlags;
gboolean empathy_debug_flag_is_set (EmpathyDebugFlags flag);
diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c
index 94764f420..c86b997af 100644
--- a/libempathy/empathy-idle.c
+++ b/libempathy/empathy-idle.c
@@ -25,9 +25,6 @@
#include <glib/gi18n-lib.h>
#include <dbus/dbus-glib.h>
-#ifdef HAVE_NM
-#include <nm-client.h>
-#endif
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/util.h>
@@ -35,6 +32,7 @@
#include "empathy-account-manager.h"
#include "empathy-idle.h"
#include "empathy-utils.h"
+#include "empathy-connectivity.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include "empathy-debug.h"
@@ -45,22 +43,19 @@
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIdle)
typedef struct {
DBusGProxy *gs_proxy;
-#ifdef HAVE_NM
- NMClient *nm_client;
-#endif
+ EmpathyConnectivity *connectivity;
+ gulong state_change_signal_id;
TpConnectionPresenceType state;
gchar *status;
TpConnectionPresenceType flash_state;
gboolean auto_away;
- gboolean use_nm;
TpConnectionPresenceType away_saved_state;
- TpConnectionPresenceType nm_saved_state;
- gchar *nm_saved_status;
+ TpConnectionPresenceType saved_state;
+ gchar *saved_status;
gboolean is_idle;
- gboolean nm_connected;
guint ext_away_timeout;
EmpathyAccountManager *manager;
@@ -79,8 +74,7 @@ enum {
PROP_STATE,
PROP_STATUS,
PROP_FLASH_STATE,
- PROP_AUTO_AWAY,
- PROP_USE_NM
+ PROP_AUTO_AWAY
};
G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT);
@@ -175,7 +169,7 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy,
is_idle ? "yes" : "no");
if (!priv->auto_away ||
- (priv->nm_saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
+ (priv->saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
(priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
/* We don't want to go auto away OR we explicitely asked to be
@@ -190,11 +184,11 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy,
idle_ext_away_start (idle);
- if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
+ if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
/* We are disconnected, when coming back from away
* we want to restore the presence before the
* disconnection. */
- priv->away_saved_state = priv->nm_saved_state;
+ priv->away_saved_state = priv->saved_state;
} else {
priv->away_saved_state = priv->state;
}
@@ -234,56 +228,37 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy,
priv->is_idle = is_idle;
}
-#ifdef HAVE_NM
static void
-idle_nm_state_change_cb (NMClient *client,
- const GParamSpec *pspec,
- EmpathyIdle *idle)
+idle_state_change_cb (EmpathyConnectivity *connectivity,
+ gboolean new_online,
+ EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
- gboolean old_nm_connected;
- gboolean new_nm_connected;
- NMState state;
priv = GET_PRIV (idle);
- if (!priv->use_nm) {
- return;
- }
-
- state = nm_client_get_state (priv->nm_client);
- old_nm_connected = priv->nm_connected;
- new_nm_connected = !(state == NM_STATE_CONNECTING ||
- state == NM_STATE_DISCONNECTED);
- priv->nm_connected = TRUE; /* To be sure _set_state will work */
-
- DEBUG ("New network state %d", state);
-
- if (old_nm_connected && !new_nm_connected) {
- /* We are no more connected */
+ if (!new_online) {
+ /* We are no longer connected */
DEBUG ("Disconnected: Save state %d (%s)",
priv->state, priv->status);
- priv->nm_saved_state = priv->state;
- g_free (priv->nm_saved_status);
- priv->nm_saved_status = g_strdup (priv->status);
+ priv->saved_state = priv->state;
+ g_free (priv->saved_status);
+ priv->saved_status = g_strdup (priv->status);
empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
}
- else if (!old_nm_connected && new_nm_connected
- && priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
+ else if (new_online
+ && priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
/* We are now connected */
DEBUG ("Reconnected: Restore state %d (%s)",
- priv->nm_saved_state, priv->nm_saved_status);
+ priv->saved_state, priv->saved_status);
empathy_idle_set_presence (idle,
- priv->nm_saved_state,
- priv->nm_saved_status);
- priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
- g_free (priv->nm_saved_status);
- priv->nm_saved_status = NULL;
+ priv->saved_state,
+ priv->saved_status);
+ priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
+ g_free (priv->saved_status);
+ priv->saved_status = NULL;
}
-
- priv->nm_connected = new_nm_connected;
}
-#endif
static void
idle_finalize (GObject *object)
@@ -298,14 +273,11 @@ idle_finalize (GObject *object)
g_object_unref (priv->gs_proxy);
}
- if (priv->manager != NULL)
- g_object_unref (priv->manager);
+ g_signal_handler_disconnect (priv->connectivity,
+ priv->state_change_signal_id);
+ priv->state_change_signal_id = 0;
-#ifdef HAVE_NM
- if (priv->nm_client) {
- g_object_unref (priv->nm_client);
- }
-#endif
+ g_object_unref (priv->connectivity);
idle_ext_away_stop (EMPATHY_IDLE (object));
}
@@ -355,9 +327,6 @@ idle_get_property (GObject *object,
case PROP_AUTO_AWAY:
g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
break;
- case PROP_USE_NM:
- g_value_set_boolean (value, empathy_idle_get_use_nm (idle));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -389,9 +358,6 @@ idle_set_property (GObject *object,
case PROP_AUTO_AWAY:
empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
break;
- case PROP_USE_NM:
- empathy_idle_set_use_nm (idle, g_value_get_boolean (value));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -440,14 +406,6 @@ empathy_idle_class_init (EmpathyIdleClass *klass)
FALSE,
G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_USE_NM,
- g_param_spec_boolean ("use-nm",
- "Use Network Manager",
- "Set presence according to Network Manager",
- TRUE,
- G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
-
g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
}
@@ -482,16 +440,9 @@ empathy_idle_init (EmpathyIdle *idle)
DEBUG ("Failed to get gs proxy");
}
-#ifdef HAVE_NM
- priv->nm_client = nm_client_new ();
- if (priv->nm_client) {
- g_signal_connect (priv->nm_client, "notify::" NM_CLIENT_STATE,
- G_CALLBACK (idle_nm_state_change_cb),
- idle);
- } else {
- DEBUG ("Failed to get nm proxy");
- }
-#endif
+ priv->connectivity = empathy_connectivity_dup_singleton ();
+ priv->state_change_signal_id = g_signal_connect (priv->connectivity,
+ "state-change", G_CALLBACK (idle_state_change_cb), idle);
}
EmpathyIdle *
@@ -619,10 +570,9 @@ empathy_idle_set_presence (EmpathyIdle *idle,
status = NULL;
}
- if (!priv->nm_connected) {
- DEBUG ("NM not connected");
+ if (!empathy_connectivity_is_online (priv->connectivity)) {
+ DEBUG ("Empathy is not online");
- priv->nm_saved_state = state;
if (tp_strdiff (priv->status, status)) {
g_free (priv->status);
priv->status = NULL;
@@ -631,8 +581,6 @@ empathy_idle_set_presence (EmpathyIdle *idle,
}
g_object_notify (G_OBJECT (idle), "status");
}
-
- return;
}
empathy_idle_do_set_presence (idle, state, status);
@@ -657,42 +605,3 @@ empathy_idle_set_auto_away (EmpathyIdle *idle,
g_object_notify (G_OBJECT (idle), "auto-away");
}
-gboolean
-empathy_idle_get_use_nm (EmpathyIdle *idle)
-{
- EmpathyIdlePriv *priv = GET_PRIV (idle);
-
- return priv->use_nm;
-}
-
-void
-empathy_idle_set_use_nm (EmpathyIdle *idle,
- gboolean use_nm)
-{
- EmpathyIdlePriv *priv = GET_PRIV (idle);
-
-#ifdef HAVE_NM
- if (!priv->nm_client || use_nm == priv->use_nm) {
- return;
- }
-#endif
-
- priv->use_nm = use_nm;
-
-#ifdef HAVE_NM
- if (use_nm) {
- idle_nm_state_change_cb (priv->nm_client, NULL, idle);
-#else
- if (0) {
-#endif
- } else {
- priv->nm_connected = TRUE;
- if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
- empathy_idle_set_state (idle, priv->nm_saved_state);
- }
- priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
- }
-
- g_object_notify (G_OBJECT (idle), "use-nm");
-}
-
diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h
index d2a802335..47dcfee23 100644
--- a/libempathy/empathy-idle.h
+++ b/libempathy/empathy-idle.h
@@ -64,9 +64,6 @@ void empathy_idle_set_presence (EmpathyIdle *idle,
gboolean empathy_idle_get_auto_away (EmpathyIdle *idle);
void empathy_idle_set_auto_away (EmpathyIdle *idle,
gboolean auto_away);
-gboolean empathy_idle_get_use_nm (EmpathyIdle *idle);
-void empathy_idle_set_use_nm (EmpathyIdle *idle,
- gboolean use_nm);
G_END_DECLS
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 51ce79bb6..69057a878 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -1329,13 +1329,16 @@ empathy_tp_chat_set_state (EmpathyTpChat *chat,
g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
g_return_if_fail (priv->ready);
- DEBUG ("Set state: %d", state);
- tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
- state,
- tp_chat_async_cb,
- "setting chat state",
- NULL,
- G_OBJECT (chat));
+ if (tp_proxy_has_interface_by_id (priv->channel,
+ TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE)) {
+ DEBUG ("Set state: %d", state);
+ tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
+ state,
+ tp_chat_async_cb,
+ "setting chat state",
+ NULL,
+ G_OBJECT (chat));
+ }
}
diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c
index 29148feec..6b4c20b53 100644
--- a/libempathy/empathy-tp-contact-factory.c
+++ b/libempathy/empathy-tp-contact-factory.c
@@ -130,7 +130,7 @@ tp_contact_factory_set_aliases_cb (TpConnection *connection,
}
static void
-tp_contact_factory_set_location_cb (TpProxy *proxy,
+tp_contact_factory_set_location_cb (TpConnection *tp_conn,
const GError *error,
gpointer user_data,
GObject *weak_object)
@@ -570,7 +570,7 @@ tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
}
static void
-tp_contact_factory_got_locations (TpProxy *tp_proxy,
+tp_contact_factory_got_locations (TpConnection *tp_conn,
GHashTable *locations,
const GError *error,
gpointer user_data,
@@ -626,7 +626,7 @@ tp_contact_factory_capabilities_changed_cb (TpConnection *connection,
}
static void
-tp_contact_factory_location_updated_cb (TpProxy *proxy,
+tp_contact_factory_location_updated_cb (TpConnection *tp_conn,
guint handle,
GHashTable *location,
gpointer user_data,
@@ -797,8 +797,8 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
g_clear_error (&error);
if (tp_proxy_has_interface_by_id (TP_PROXY (priv->connection),
- EMP_IFACE_QUARK_CONNECTION_INTERFACE_LOCATION)) {
- emp_cli_connection_interface_location_call_get_locations (TP_PROXY (priv->connection),
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_LOCATION)) {
+ tp_cli_connection_interface_location_call_get_locations (priv->connection,
-1,
&handles,
tp_contact_factory_got_locations,
@@ -1204,7 +1204,7 @@ empathy_tp_contact_factory_set_location (EmpathyTpContactFactory *tp_factory,
DEBUG ("Setting location");
- emp_cli_connection_interface_location_call_set_location (TP_PROXY (priv->connection),
+ tp_cli_connection_interface_location_call_set_location (priv->connection,
-1,
location,
tp_contact_factory_set_location_cb,
@@ -1318,7 +1318,7 @@ tp_contact_factory_constructor (GType type,
NULL);
- emp_cli_connection_interface_location_connect_to_location_updated (TP_PROXY (priv->connection),
+ tp_cli_connection_interface_location_connect_to_location_updated (priv->connection,
tp_contact_factory_location_updated_cb,
NULL, NULL,
G_OBJECT (tp_factory),
diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c
index 4bbe46b4f..2bf2ec416 100644
--- a/libempathy/empathy-tp-contact-list.c
+++ b/libempathy/empathy-tp-contact-list.c
@@ -974,10 +974,13 @@ tp_contact_list_add (EmpathyContactList *list,
tp_cli_channel_interface_group_call_add_members (priv->subscribe,
-1, &handles, message, NULL, NULL, NULL, NULL);
}
- if (priv->publish &&
- g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle))) {
- tp_cli_channel_interface_group_call_add_members (priv->publish,
- -1, &handles, message, NULL, NULL, NULL, NULL);
+ if (priv->publish) {
+ TpChannelGroupFlags flags = tp_channel_group_get_flags (priv->subscribe);
+ if (flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD ||
+ g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle))) {
+ tp_cli_channel_interface_group_call_add_members (priv->publish,
+ -1, &handles, message, NULL, NULL, NULL, NULL);
+ }
}
}
@@ -1166,21 +1169,24 @@ tp_contact_list_get_flags (EmpathyContactList *list)
{
EmpathyTpContactListPriv *priv;
EmpathyContactListFlags flags;
- TpChannelGroupFlags group_flags;
g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), FALSE);
priv = GET_PRIV (list);
flags = priv->flags;
- group_flags = tp_channel_group_get_flags (priv->subscribe);
+ if (priv->subscribe != NULL) {
+ TpChannelGroupFlags group_flags;
- if (group_flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD) {
- flags |= EMPATHY_CONTACT_LIST_CAN_ADD;
- }
+ group_flags = tp_channel_group_get_flags (priv->subscribe);
+
+ if (group_flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD) {
+ flags |= EMPATHY_CONTACT_LIST_CAN_ADD;
+ }
- if (group_flags & TP_CHANNEL_GROUP_FLAG_CAN_REMOVE) {
- flags |= EMPATHY_CONTACT_LIST_CAN_REMOVE;
+ if (group_flags & TP_CHANNEL_GROUP_FLAG_CAN_REMOVE) {
+ flags |= EMPATHY_CONTACT_LIST_CAN_REMOVE;
+ }
}
return flags;