aboutsummaryrefslogtreecommitdiffstats
path: root/tp-account-widgets
diff options
context:
space:
mode:
authorMarco Barisione <marco.barisione@collabora.co.uk>2013-05-08 22:14:35 +0800
committerMarco Barisione <marco.barisione@collabora.co.uk>2013-08-20 18:03:05 +0800
commit53a376be8d68d95c30cb66495d42d3c18947473f (patch)
tree456a2dd22c0e58f81396aad2dca31c96e678ea57 /tp-account-widgets
parenteaa41abfebc3fbf9c2d6a673940e36a4af008cac (diff)
downloadgsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.tar
gsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.tar.gz
gsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.tar.bz2
gsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.tar.lz
gsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.tar.xz
gsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.tar.zst
gsoc2013-empathy-53a376be8d68d95c30cb66495d42d3c18947473f.zip
connection-managers: move from Empathy to tp-account-widgets
https://bugzilla.gnome.org/show_bug.cgi?id=699492
Diffstat (limited to 'tp-account-widgets')
-rw-r--r--tp-account-widgets/Makefile.am2
-rw-r--r--tp-account-widgets/tpaw-account-settings.c10
-rw-r--r--tp-account-widgets/tpaw-connection-managers.c349
-rw-r--r--tp-account-widgets/tpaw-connection-managers.h87
4 files changed, 443 insertions, 5 deletions
diff --git a/tp-account-widgets/Makefile.am b/tp-account-widgets/Makefile.am
index 554c1a639..7c615e4b0 100644
--- a/tp-account-widgets/Makefile.am
+++ b/tp-account-widgets/Makefile.am
@@ -21,6 +21,7 @@ libtp_account_widgets_sources = \
tpaw-account-widget-irc.c \
tpaw-account-widget-private.h \
tpaw-account-widget-sip.c \
+ tpaw-connection-managers.c \
tpaw-irc-network-chooser.c \
tpaw-irc-network-chooser-dialog.c \
tpaw-irc-network-dialog.c \
@@ -35,6 +36,7 @@ libtp_account_widgets_headers = \
tpaw-account-widget.h \
tpaw-account-widget-irc.h \
tpaw-account-widget-sip.h \
+ tpaw-connection-managers.h \
tpaw-irc-network-chooser-dialog.h \
tpaw-irc-network-chooser.h \
tpaw-irc-network-dialog.h \
diff --git a/tp-account-widgets/tpaw-account-settings.c b/tp-account-widgets/tpaw-account-settings.c
index 1559da4bf..a837a251e 100644
--- a/tp-account-widgets/tpaw-account-settings.c
+++ b/tp-account-widgets/tpaw-account-settings.c
@@ -21,7 +21,7 @@
#include "config.h"
#include "tpaw-account-settings.h"
-#include "empathy-connection-managers.h"
+#include "tpaw-connection-managers.h"
#include "empathy-keyring.h"
#include "empathy-presence-manager.h"
#include "empathy-utils.h"
@@ -56,7 +56,7 @@ typedef struct _TpawAccountSettingsPriv TpawAccountSettingsPriv;
struct _TpawAccountSettingsPriv
{
gboolean dispose_has_run;
- EmpathyConnectionManagers *managers;
+ TpawConnectionManagers *managers;
TpAccountManager *account_manager;
TpConnectionManager *manager;
@@ -112,7 +112,7 @@ tpaw_account_settings_init (TpawAccountSettings *obj)
obj->priv = priv;
/* allocate any data required by the object here */
- priv->managers = empathy_connection_managers_dup_singleton ();
+ priv->managers = tpaw_connection_managers_dup_singleton ();
priv->account_manager = tp_account_manager_dup ();
priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -474,12 +474,12 @@ tpaw_account_settings_check_readyness (TpawAccountSettings *self)
&& !tp_account_is_prepared (priv->account, TP_ACCOUNT_FEATURE_CORE))
return;
- if (!empathy_connection_managers_is_ready (priv->managers))
+ if (!tpaw_connection_managers_is_ready (priv->managers))
return;
if (priv->manager == NULL)
{
- priv->manager = empathy_connection_managers_get_cm (
+ priv->manager = tpaw_connection_managers_get_cm (
priv->managers, priv->cm_name);
}
diff --git a/tp-account-widgets/tpaw-connection-managers.c b/tp-account-widgets/tpaw-connection-managers.c
new file mode 100644
index 000000000..f648340aa
--- /dev/null
+++ b/tp-account-widgets/tpaw-connection-managers.c
@@ -0,0 +1,349 @@
+/*
+ * tpaw-connection-managers.c - Source for TpawConnectionManagers
+ * Copyright (C) 2009 Collabora Ltd.
+ * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
+ *
+ * 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
+ */
+
+#include "config.h"
+#include "tpaw-connection-managers.h"
+
+#include "empathy-utils.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
+
+static GObject *managers = NULL;
+
+G_DEFINE_TYPE(TpawConnectionManagers, tpaw_connection_managers,
+ G_TYPE_OBJECT)
+
+/* signal enum */
+enum
+{
+ UPDATED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = {0};
+
+/* properties */
+enum {
+ PROP_READY = 1
+};
+
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, TpawConnectionManagers)
+
+
+/* private structure */
+typedef struct _TpawConnectionManagersPriv
+ TpawConnectionManagersPriv;
+
+struct _TpawConnectionManagersPriv
+{
+ gboolean dispose_has_run;
+ gboolean ready;
+
+ GList *cms;
+
+ TpDBusDaemon *dbus;
+};
+
+static void
+tpaw_connection_managers_init (TpawConnectionManagers *obj)
+{
+ TpawConnectionManagersPriv *priv =
+ G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ TPAW_TYPE_CONNECTION_MANAGERS, TpawConnectionManagersPriv);
+
+ obj->priv = priv;
+
+ priv->dbus = tp_dbus_daemon_dup (NULL);
+ g_assert (priv->dbus != NULL);
+
+ tpaw_connection_managers_update (obj);
+
+ /* allocate any data required by the object here */
+}
+
+static void tpaw_connection_managers_dispose (GObject *object);
+
+static GObject *
+tpaw_connection_managers_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ if (managers != NULL)
+ return g_object_ref (managers);
+
+ managers =
+ G_OBJECT_CLASS (tpaw_connection_managers_parent_class)->constructor
+ (type, n_construct_params, construct_params);
+
+ g_object_add_weak_pointer (managers, (gpointer) &managers);
+
+ return managers;
+}
+
+
+
+static void
+tpaw_connection_managers_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TpawConnectionManagers *self = TPAW_CONNECTION_MANAGERS (object);
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+
+ switch (prop_id)
+ {
+ case PROP_READY:
+ g_value_set_boolean (value, priv->ready);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tpaw_connection_managers_class_init (
+ TpawConnectionManagersClass *tpaw_connection_managers_class)
+{
+ GObjectClass *object_class =
+ G_OBJECT_CLASS (tpaw_connection_managers_class);
+
+ g_type_class_add_private (tpaw_connection_managers_class, sizeof
+ (TpawConnectionManagersPriv));
+
+ object_class->constructor = tpaw_connection_managers_constructor;
+ object_class->dispose = tpaw_connection_managers_dispose;
+ object_class->get_property = tpaw_connection_managers_get_property;
+
+ g_object_class_install_property (object_class, PROP_READY,
+ g_param_spec_boolean ("ready",
+ "Ready",
+ "Whether the connection manager information is ready to be used",
+ FALSE,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+ signals[UPDATED] = g_signal_new ("updated",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 0);
+}
+
+static void
+tpaw_connection_managers_free_cm_list (TpawConnectionManagers *self)
+{
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+ GList *l;
+
+ for (l = priv->cms ; l != NULL ; l = g_list_next (l))
+ {
+ g_object_unref (l->data);
+ }
+ g_list_free (priv->cms);
+
+ priv->cms = NULL;
+}
+
+static void
+tpaw_connection_managers_dispose (GObject *object)
+{
+ TpawConnectionManagers *self = TPAW_CONNECTION_MANAGERS (object);
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+
+ if (priv->dispose_has_run)
+ return;
+
+ priv->dispose_has_run = TRUE;
+
+ if (priv->dbus != NULL)
+ g_object_unref (priv->dbus);
+ priv->dbus = NULL;
+
+ tpaw_connection_managers_free_cm_list (self);
+
+ /* release any references held by the object here */
+
+ if (G_OBJECT_CLASS (tpaw_connection_managers_parent_class)->dispose)
+ G_OBJECT_CLASS (tpaw_connection_managers_parent_class)->dispose (object);
+}
+
+TpawConnectionManagers *
+tpaw_connection_managers_dup_singleton (void)
+{
+ return TPAW_CONNECTION_MANAGERS (
+ g_object_new (TPAW_TYPE_CONNECTION_MANAGERS, NULL));
+}
+
+gboolean
+tpaw_connection_managers_is_ready (TpawConnectionManagers *self)
+{
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+ return priv->ready;
+}
+
+static void
+tpaw_connection_managers_listed_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpWeakRef *wr = user_data;
+ GError *error = NULL;
+ TpawConnectionManagers *self = tp_weak_ref_dup_object (wr);
+ GList *cms, *l;
+ TpawConnectionManagersPriv *priv;
+
+ if (self == NULL)
+ {
+ tp_weak_ref_destroy (wr);
+ return;
+ }
+
+ priv = GET_PRIV (self);
+
+ tpaw_connection_managers_free_cm_list (self);
+
+ cms = tp_list_connection_managers_finish (result, &error);
+ if (error != NULL)
+ {
+ DEBUG ("Failed to get connection managers: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ for (l = cms ; l != NULL; l = g_list_next (l))
+ {
+ TpConnectionManager *cm = l->data;
+
+ /* only list cms that didn't hit errors */
+ if (tp_proxy_is_prepared (cm, TP_CONNECTION_MANAGER_FEATURE_CORE))
+ priv->cms = g_list_prepend (priv->cms, g_object_ref (cm));
+ }
+
+out:
+ if (!priv->ready)
+ {
+ priv->ready = TRUE;
+ g_object_notify (G_OBJECT (self), "ready");
+ }
+
+ g_signal_emit (self, signals[UPDATED], 0);
+ g_object_unref (self);
+ tp_weak_ref_destroy (wr);
+}
+
+void
+tpaw_connection_managers_update (TpawConnectionManagers *self)
+{
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+
+ tp_list_connection_managers_async (priv->dbus,
+ tpaw_connection_managers_listed_cb,
+ tp_weak_ref_new (self, NULL, NULL));
+}
+
+GList *
+tpaw_connection_managers_get_cms (TpawConnectionManagers *self)
+{
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+
+ return priv->cms;
+}
+
+TpConnectionManager *
+tpaw_connection_managers_get_cm (TpawConnectionManagers *self,
+ const gchar *cm)
+{
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+ GList *l;
+
+ for (l = priv->cms ; l != NULL; l = g_list_next (l))
+ {
+ TpConnectionManager *c = TP_CONNECTION_MANAGER (l->data);
+
+ if (!tp_strdiff (tp_connection_manager_get_name (c), cm))
+ return c;
+ }
+
+ return NULL;
+}
+
+guint
+tpaw_connection_managers_get_cms_num (TpawConnectionManagers *self)
+{
+ TpawConnectionManagersPriv *priv;
+
+ g_return_val_if_fail (TPAW_IS_CONNECTION_MANAGERS (self), 0);
+
+ priv = GET_PRIV (self);
+
+ return g_list_length (priv->cms);
+}
+
+static void
+notify_ready_cb (TpawConnectionManagers *self,
+ GParamSpec *spec,
+ GSimpleAsyncResult *result)
+{
+ g_simple_async_result_complete (result);
+ g_object_unref (result);
+}
+
+void
+tpaw_connection_managers_prepare_async (
+ TpawConnectionManagers *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ TpawConnectionManagersPriv *priv = GET_PRIV (self);
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (managers),
+ callback, user_data, tpaw_connection_managers_prepare_finish);
+
+ if (priv->ready)
+ {
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+ return;
+ }
+
+ g_signal_connect (self, "notify::ready", G_CALLBACK (notify_ready_cb),
+ result);
+}
+
+gboolean
+tpaw_connection_managers_prepare_finish (
+ TpawConnectionManagers *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (self), tpaw_connection_managers_prepare_finish), FALSE);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/tp-account-widgets/tpaw-connection-managers.h b/tp-account-widgets/tpaw-connection-managers.h
new file mode 100644
index 000000000..33e5aa081
--- /dev/null
+++ b/tp-account-widgets/tpaw-connection-managers.h
@@ -0,0 +1,87 @@
+/*
+ * tpaw-connection-managers.h - Header for TpawConnectionManagers
+ * Copyright (C) 2009 Collabora Ltd.
+ * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
+ *
+ * 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
+ */
+
+#ifndef __TPAW_CONNECTION_MANAGERS_H__
+#define __TPAW_CONNECTION_MANAGERS_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include <telepathy-glib/telepathy-glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _TpawConnectionManagers TpawConnectionManagers;
+typedef struct _TpawConnectionManagersClass TpawConnectionManagersClass;
+
+struct _TpawConnectionManagersClass {
+ GObjectClass parent_class;
+};
+
+struct _TpawConnectionManagers {
+ GObject parent;
+ gpointer priv;
+};
+
+GType tpaw_connection_managers_get_type (void);
+
+/* TYPE MACROS */
+#define TPAW_TYPE_CONNECTION_MANAGERS \
+ (tpaw_connection_managers_get_type ())
+#define TPAW_CONNECTION_MANAGERS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), TPAW_TYPE_CONNECTION_MANAGERS, \
+ TpawConnectionManagers))
+#define TPAW_CONNECTION_MANAGERS_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), TPAW_TYPE_CONNECTION_MANAGERS, \
+ TpawConnectionManagersClass))
+#define TPAW_IS_CONNECTION_MANAGERS(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), TPAW_TYPE_CONNECTION_MANAGERS))
+#define TPAW_IS_CONNECTION_MANAGERS_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), TPAW_TYPE_CONNECTION_MANAGERS))
+#define TPAW_CONNECTION_MANAGERS_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), TPAW_TYPE_CONNECTION_MANAGERS, \
+ TpawConnectionManagersClass))
+
+TpawConnectionManagers *tpaw_connection_managers_dup_singleton (void);
+gboolean tpaw_connection_managers_is_ready (
+ TpawConnectionManagers *managers);
+
+void tpaw_connection_managers_update (TpawConnectionManagers *managers);
+
+GList * tpaw_connection_managers_get_cms (
+ TpawConnectionManagers *managers);
+guint tpaw_connection_managers_get_cms_num
+ (TpawConnectionManagers *managers);
+
+TpConnectionManager *tpaw_connection_managers_get_cm (
+ TpawConnectionManagers *managers, const gchar *cm);
+
+void tpaw_connection_managers_prepare_async (
+ TpawConnectionManagers *managers,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean tpaw_connection_managers_prepare_finish (
+ TpawConnectionManagers *managers,
+ GAsyncResult *result,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* #ifndef __TPAW_CONNECTION_MANAGERS_H__*/