|
Packit |
79f644 |
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
|
Packit |
79f644 |
/*
|
|
Packit |
79f644 |
* Copyright (C) 2007-2013 Collabora Ltd.
|
|
Packit |
79f644 |
* Copyright (C) 2013 Intel Corporation
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
79f644 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License as published by the Free Software Foundation; either
|
|
Packit |
79f644 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
79f644 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
79f644 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
79f644 |
* Lesser General Public License for more details.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
79f644 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* Authors: Xavier Claessens <xclaesse@gmail.com>
|
|
Packit |
79f644 |
* Jonny Lamb <jonny.lamb@collabora.co.uk>
|
|
Packit |
79f644 |
* Marco Barisione <marco.barisione@collabora.co.uk>
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "config.h"
|
|
Packit |
79f644 |
#include "tpaw-protocol.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include <glib/gi18n-lib.h>
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "tpaw-connection-managers.h"
|
|
Packit |
79f644 |
#include "tpaw-utils.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
struct _TpawProtocolPriv
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpConnectionManager *cm;
|
|
Packit |
79f644 |
gchar *protocol_name;
|
|
Packit |
79f644 |
gchar *service_name;
|
|
Packit |
79f644 |
gchar *display_name;
|
|
Packit |
79f644 |
gchar *icon_name;
|
|
Packit |
79f644 |
};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
enum {
|
|
Packit |
79f644 |
PROP_CM = 1,
|
|
Packit |
79f644 |
PROP_CM_NAME,
|
|
Packit |
79f644 |
PROP_PROTOCOL_NAME,
|
|
Packit |
79f644 |
PROP_SERVICE_NAME,
|
|
Packit |
79f644 |
PROP_DISPLAY_NAME,
|
|
Packit |
79f644 |
PROP_ICON_NAME,
|
|
Packit |
79f644 |
};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
G_DEFINE_TYPE (TpawProtocol, tpaw_protocol, G_TYPE_OBJECT);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
TpawAccountSettings *
|
|
Packit |
79f644 |
tpaw_protocol_create_account_settings (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawAccountSettings *settings = NULL;
|
|
Packit |
79f644 |
gchar *str;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* Create account */
|
|
Packit |
79f644 |
/* To translator: %s is the name of the protocol, such as "Google Talk" or
|
|
Packit |
79f644 |
* "Yahoo!"
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
str = g_strdup_printf (_("New %s account"), self->priv->display_name);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
settings = tpaw_account_settings_new (tpaw_protocol_get_cm_name (self),
|
|
Packit |
79f644 |
self->priv->protocol_name,
|
|
Packit |
79f644 |
self->priv->service_name,
|
|
Packit |
79f644 |
str);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (str);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tp_strdiff (self->priv->service_name, "google-talk"))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *fallback_servers[] = {
|
|
Packit |
79f644 |
"talkx.l.google.com",
|
|
Packit |
79f644 |
"talkx.l.google.com:443,oldssl",
|
|
Packit |
79f644 |
"talkx.l.google.com:80",
|
|
Packit |
79f644 |
NULL};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *extra_certificate_identities[] = {
|
|
Packit |
79f644 |
"talk.google.com",
|
|
Packit |
79f644 |
NULL};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
tpaw_account_settings_set_icon_name_async (settings, "im-google-talk",
|
|
Packit |
79f644 |
NULL, NULL);
|
|
Packit |
79f644 |
tpaw_account_settings_set (settings, "server",
|
|
Packit |
79f644 |
g_variant_new_string (extra_certificate_identities[0]));
|
|
Packit |
79f644 |
tpaw_account_settings_set (settings, "require-encryption",
|
|
Packit |
79f644 |
g_variant_new_boolean (TRUE));
|
|
Packit |
79f644 |
tpaw_account_settings_set (settings, "fallback-servers",
|
|
Packit |
79f644 |
g_variant_new_strv (fallback_servers, -1));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (tpaw_account_settings_have_tp_param (settings,
|
|
Packit |
79f644 |
"extra-certificate-identities"))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
tpaw_account_settings_set (settings,
|
|
Packit |
79f644 |
"extra-certificate-identities",
|
|
Packit |
79f644 |
g_variant_new_strv (extra_certificate_identities, -1));
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return settings;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
TpConnectionManager *
|
|
Packit |
79f644 |
tpaw_protocol_get_cm (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return self->priv->cm;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_protocol_get_cm_name (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return tp_connection_manager_get_name (self->priv->cm);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_protocol_get_protocol_name (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return self->priv->protocol_name;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_protocol_get_service_name (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return self->priv->service_name;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_protocol_get_display_name (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return self->priv->display_name;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
const gchar *
|
|
Packit |
79f644 |
tpaw_protocol_get_icon_name (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return self->priv->icon_name;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
tpaw_protocol_get_property (GObject *object,
|
|
Packit |
79f644 |
guint prop_id,
|
|
Packit |
79f644 |
GValue *value,
|
|
Packit |
79f644 |
GParamSpec *pspec)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawProtocol *self = TPAW_PROTOCOL (object);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
switch (prop_id)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
case PROP_CM:
|
|
Packit |
79f644 |
g_value_set_object (value, self->priv->cm);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_CM_NAME:
|
|
Packit |
79f644 |
g_value_set_string (value,
|
|
Packit |
79f644 |
tp_connection_manager_get_name (self->priv->cm));
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_PROTOCOL_NAME:
|
|
Packit |
79f644 |
g_value_set_string (value, self->priv->protocol_name);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_SERVICE_NAME:
|
|
Packit |
79f644 |
g_value_set_string (value, self->priv->service_name);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_DISPLAY_NAME:
|
|
Packit |
79f644 |
g_value_set_string (value, self->priv->display_name);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_ICON_NAME:
|
|
Packit |
79f644 |
g_value_set_string (value, self->priv->icon_name);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
default:
|
|
Packit |
79f644 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
tpaw_protocol_set_property (GObject *object,
|
|
Packit |
79f644 |
guint prop_id,
|
|
Packit |
79f644 |
const GValue *value,
|
|
Packit |
79f644 |
GParamSpec *pspec)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawProtocol *self = TPAW_PROTOCOL (object);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
switch (prop_id)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
case PROP_CM:
|
|
Packit |
79f644 |
self->priv->cm = g_value_dup_object (value);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_PROTOCOL_NAME:
|
|
Packit |
79f644 |
self->priv->protocol_name = g_value_dup_string (value);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_SERVICE_NAME:
|
|
Packit |
79f644 |
self->priv->service_name = g_value_dup_string (value);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_DISPLAY_NAME:
|
|
Packit |
79f644 |
self->priv->display_name = g_value_dup_string (value);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
case PROP_ICON_NAME:
|
|
Packit |
79f644 |
self->priv->icon_name = g_value_dup_string (value);
|
|
Packit |
79f644 |
break;
|
|
Packit |
79f644 |
default:
|
|
Packit |
79f644 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
tpaw_protocol_constructed (GObject *object)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawProtocol *self = TPAW_PROTOCOL (object);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (G_OBJECT_CLASS (tpaw_protocol_parent_class)->constructed != NULL)
|
|
Packit |
79f644 |
G_OBJECT_CLASS (tpaw_protocol_parent_class)->constructed (object);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (g_strcmp0 (self->priv->protocol_name, self->priv->service_name) == 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
/* We want the service name only if it's different from the
|
|
Packit |
79f644 |
* protocol name */
|
|
Packit |
79f644 |
g_clear_pointer (&self->priv->service_name, g_free);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
tpaw_protocol_init (TpawProtocol *self)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TPAW_TYPE_PROTOCOL,
|
|
Packit |
79f644 |
TpawProtocolPriv);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
tpaw_protocol_finalize (GObject *object)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawProtocol *self = TPAW_PROTOCOL (object);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_clear_object (&self->priv->cm);
|
|
Packit |
79f644 |
g_free (self->priv->protocol_name);
|
|
Packit |
79f644 |
g_free (self->priv->service_name);
|
|
Packit |
79f644 |
g_free (self->priv->display_name);
|
|
Packit |
79f644 |
g_free (self->priv->icon_name);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
(G_OBJECT_CLASS (tpaw_protocol_parent_class)->finalize) (object);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
tpaw_protocol_class_init (TpawProtocolClass *klass)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GObjectClass *oclass = G_OBJECT_CLASS (klass);
|
|
Packit |
79f644 |
GParamSpec *param_spec;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
oclass->finalize = tpaw_protocol_finalize;
|
|
Packit |
79f644 |
oclass->constructed = tpaw_protocol_constructed;
|
|
Packit |
79f644 |
oclass->get_property = tpaw_protocol_get_property;
|
|
Packit |
79f644 |
oclass->set_property = tpaw_protocol_set_property;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_type_class_add_private (oclass, sizeof (TpawProtocolPriv));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
param_spec = g_param_spec_object ("cm",
|
|
Packit |
79f644 |
"CM", "The connection manager",
|
|
Packit |
79f644 |
TP_TYPE_CONNECTION_MANAGER,
|
|
Packit |
79f644 |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
Packit |
79f644 |
g_object_class_install_property (oclass, PROP_CM, param_spec);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
param_spec = g_param_spec_string ("cm-name",
|
|
Packit |
79f644 |
"CM name", "The connection manager name",
|
|
Packit |
79f644 |
NULL,
|
|
Packit |
79f644 |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit |
79f644 |
g_object_class_install_property (oclass, PROP_CM_NAME, param_spec);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
param_spec = g_param_spec_string ("protocol-name",
|
|
Packit |
79f644 |
"Protocol name", "The name of the protocol",
|
|
Packit |
79f644 |
NULL,
|
|
Packit |
79f644 |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
Packit |
79f644 |
g_object_class_install_property (oclass, PROP_PROTOCOL_NAME, param_spec);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
param_spec = g_param_spec_string ("service-name",
|
|
Packit |
79f644 |
"Service name", "The name of the service",
|
|
Packit |
79f644 |
NULL,
|
|
Packit |
79f644 |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
Packit |
79f644 |
g_object_class_install_property (oclass, PROP_SERVICE_NAME, param_spec);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
param_spec = g_param_spec_string ("display-name",
|
|
Packit |
79f644 |
"Display name", "The human-readable name of the protocol",
|
|
Packit |
79f644 |
NULL,
|
|
Packit |
79f644 |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
Packit |
79f644 |
g_object_class_install_property (oclass, PROP_DISPLAY_NAME, param_spec);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
param_spec = g_param_spec_string ("icon-name",
|
|
Packit |
79f644 |
"Icon name", "The name of the icon for the protocol",
|
|
Packit |
79f644 |
NULL,
|
|
Packit |
79f644 |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
Packit |
79f644 |
g_object_class_install_property (oclass, PROP_ICON_NAME, param_spec);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
typedef struct
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *result;
|
|
Packit |
79f644 |
GList *protocols; /* List of (owned) TpawProtocol* */
|
|
Packit |
79f644 |
GHashTable *seen_protocols; /* Table of (owned) protocol names -> (owned) cm names */
|
|
Packit |
79f644 |
} GetProtocolsData;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
add_protocol (GetProtocolsData *data,
|
|
Packit |
79f644 |
TpConnectionManager *cm,
|
|
Packit |
79f644 |
const gchar *protocol_name,
|
|
Packit |
79f644 |
const gchar *service_name,
|
|
Packit |
79f644 |
const gchar *display_name,
|
|
Packit |
79f644 |
const gchar *icon_name)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawProtocol *protocol;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
protocol = g_object_new (TPAW_TYPE_PROTOCOL,
|
|
Packit |
79f644 |
"cm", cm,
|
|
Packit |
79f644 |
"protocol-name", protocol_name,
|
|
Packit |
79f644 |
"service-name", service_name,
|
|
Packit |
79f644 |
"display-name", display_name,
|
|
Packit |
79f644 |
"icon-name", icon_name,
|
|
Packit |
79f644 |
NULL);
|
|
Packit |
79f644 |
data->protocols = g_list_prepend (data->protocols, protocol);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static gint
|
|
Packit |
79f644 |
compare_protocol_to_name (TpawProtocol *protocol,
|
|
Packit |
79f644 |
const gchar *proto_name)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return g_strcmp0 (tpaw_protocol_get_protocol_name (protocol), proto_name);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
add_cm (GetProtocolsData *data,
|
|
Packit |
79f644 |
TpConnectionManager *cm)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GList *protocols, *l;
|
|
Packit |
79f644 |
const gchar *cm_name;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
cm_name = tp_connection_manager_get_name (cm);
|
|
Packit |
79f644 |
protocols = tp_connection_manager_dup_protocols (cm);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (l = protocols; l != NULL; l = l->next)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpProtocol *tp_protocol = l->data;
|
|
Packit |
79f644 |
gchar *icon_name;
|
|
Packit |
79f644 |
const gchar *display_name;
|
|
Packit |
79f644 |
const gchar *proto_name;
|
|
Packit |
79f644 |
const gchar *saved_cm_name;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
proto_name = tp_protocol_get_name (tp_protocol);
|
|
Packit |
79f644 |
saved_cm_name = g_hash_table_lookup (data->seen_protocols, proto_name);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tp_strdiff (cm_name, "haze") && saved_cm_name != NULL &&
|
|
Packit |
79f644 |
tp_strdiff (saved_cm_name, "haze"))
|
|
Packit |
79f644 |
/* the CM we're adding is a haze implementation of something we already
|
|
Packit |
79f644 |
* have; drop it. */
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tp_strdiff (cm_name, "haze") &&
|
|
Packit |
79f644 |
!tp_strdiff (proto_name, "irc"))
|
|
Packit |
79f644 |
/* Use Idle for IRC (bgo #711226) */
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tp_strdiff (cm_name, "haze") &&
|
|
Packit |
79f644 |
!tp_strdiff (proto_name, "sip"))
|
|
Packit |
79f644 |
/* Haze's SIP implementation is pretty useless (bgo #629736) */
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tp_strdiff (cm_name, "butterfly"))
|
|
Packit |
79f644 |
/* Butterfly isn't supported any more */
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (tp_strdiff (cm_name, "haze") && !tp_strdiff (saved_cm_name, "haze"))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
/* Let this CM replace the haze implementation */
|
|
Packit |
79f644 |
GList *existing = g_list_find_custom (data->protocols, proto_name,
|
|
Packit |
79f644 |
(GCompareFunc) compare_protocol_to_name);
|
|
Packit |
79f644 |
g_assert (existing);
|
|
Packit |
79f644 |
g_object_unref (existing->data);
|
|
Packit |
79f644 |
data->protocols = g_list_delete_link (data->protocols, existing);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_hash_table_replace (data->seen_protocols,
|
|
Packit |
79f644 |
g_strdup (proto_name), g_strdup (cm_name));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
display_name = tpaw_protocol_name_to_display_name (proto_name);
|
|
Packit |
79f644 |
icon_name = tpaw_protocol_icon_name (proto_name);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
add_protocol (data, cm, proto_name, proto_name, display_name,
|
|
Packit |
79f644 |
icon_name);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tp_strdiff (proto_name, "jabber") &&
|
|
Packit |
79f644 |
!tp_strdiff (cm_name, "gabble"))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
add_protocol (data, cm, proto_name, "google-talk",
|
|
Packit |
79f644 |
tpaw_service_name_to_display_name ("google-talk"),
|
|
Packit |
79f644 |
"im-google-talk");
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (icon_name);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_list_free_full (protocols, g_object_unref);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static gint
|
|
Packit |
79f644 |
sort_protocol_value (const gchar *protocol_name)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
guint i;
|
|
Packit |
79f644 |
const gchar *names[] = {
|
|
Packit |
79f644 |
"jabber",
|
|
Packit |
79f644 |
"local-xmpp",
|
|
Packit |
79f644 |
"gtalk",
|
|
Packit |
79f644 |
NULL
|
|
Packit |
79f644 |
};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (i = 0 ; names[i]; i++)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
if (g_strcmp0 (protocol_name, names[i]) == 0)
|
|
Packit |
79f644 |
return i;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return i;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static gint
|
|
Packit |
79f644 |
protocol_sort_func (TpawProtocol *proto_a,
|
|
Packit |
79f644 |
TpawProtocol *proto_b)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *name_a = tpaw_protocol_get_protocol_name (proto_a);
|
|
Packit |
79f644 |
const gchar *name_b = tpaw_protocol_get_protocol_name (proto_b);
|
|
Packit |
79f644 |
gint cmp = 0;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
cmp = sort_protocol_value (name_a);
|
|
Packit |
79f644 |
cmp -= sort_protocol_value (name_b);
|
|
Packit |
79f644 |
if (cmp == 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
cmp = g_strcmp0 (name_a, name_b);
|
|
Packit |
79f644 |
/* only happens for jabber where there is one entry for gtalk and one for
|
|
Packit |
79f644 |
* non-gtalk */
|
|
Packit |
79f644 |
if (cmp == 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *service = tpaw_protocol_get_service_name (proto_a);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (service != NULL)
|
|
Packit |
79f644 |
cmp = 1;
|
|
Packit |
79f644 |
else
|
|
Packit |
79f644 |
cmp = -1;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return cmp;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
cms_prepare_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawConnectionManagers *cms = TPAW_CONNECTION_MANAGERS (source);
|
|
Packit |
79f644 |
GetProtocolsData *data = user_data;
|
|
Packit |
79f644 |
GList *l = NULL;
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tpaw_connection_managers_prepare_finish (cms, result, &error))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_simple_async_result_take_error (data->result, error);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (l = tpaw_connection_managers_get_cms (cms); l != NULL; l = l->next)
|
|
Packit |
79f644 |
add_cm (data, l->data);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
data->protocols = g_list_sort (data->protocols,
|
|
Packit |
79f644 |
(GCompareFunc) protocol_sort_func);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
out:
|
|
Packit |
79f644 |
g_simple_async_result_complete_in_idle (data->result);
|
|
Packit |
79f644 |
g_object_unref (data->result);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
destroy_get_protocols_data (GetProtocolsData *data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_hash_table_unref (data->seen_protocols);
|
|
Packit |
79f644 |
g_list_free_full (data->protocols, g_object_unref);
|
|
Packit |
79f644 |
g_slice_free (GetProtocolsData, data);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_protocol_get_all_async (GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GetProtocolsData *data;
|
|
Packit |
79f644 |
TpawConnectionManagers *cms;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
data = g_slice_new0 (GetProtocolsData);
|
|
Packit |
79f644 |
data->result = g_simple_async_result_new (NULL, callback, user_data,
|
|
Packit |
79f644 |
tpaw_protocol_get_all_async);
|
|
Packit |
79f644 |
g_simple_async_result_set_op_res_gpointer (data->result, data,
|
|
Packit |
79f644 |
(GDestroyNotify) destroy_get_protocols_data);
|
|
Packit |
79f644 |
data->seen_protocols = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
Packit |
79f644 |
g_free, g_free);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
cms = tpaw_connection_managers_dup_singleton ();
|
|
Packit |
79f644 |
tpaw_connection_managers_prepare_async (cms,
|
|
Packit |
79f644 |
cms_prepare_cb, data);
|
|
Packit |
79f644 |
g_object_unref (cms);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gboolean
|
|
Packit |
79f644 |
tpaw_protocol_get_all_finish (GList **out_protocols,
|
|
Packit |
79f644 |
GAsyncResult *result,
|
|
Packit |
79f644 |
GError **error)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GSimpleAsyncResult *simple = (GSimpleAsyncResult *) result;
|
|
Packit |
79f644 |
GetProtocolsData *data;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
|
Packit |
79f644 |
tpaw_protocol_get_all_async), FALSE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (g_simple_async_result_propagate_error (simple, error))
|
|
Packit |
79f644 |
return FALSE;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (out_protocols != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
Packit |
79f644 |
*out_protocols = g_list_copy_deep (data->protocols, (GCopyFunc) g_object_ref, NULL);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return TRUE;
|
|
Packit |
79f644 |
}
|