|
Packit |
79f644 |
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
Packit |
79f644 |
/*
|
|
Packit |
79f644 |
* Copyright © 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 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
|
|
Packit |
79f644 |
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "config.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include <tp-account-widgets/tpaw-protocol.h>
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "goatelepathyfactory.h"
|
|
Packit |
79f644 |
#include "goaprovider-priv.h"
|
|
Packit |
79f644 |
#include "goatelepathyprovider.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/*
|
|
Packit |
79f644 |
* SECTION:goatelepathyfactory
|
|
Packit |
79f644 |
* @title: GoaTelepathyFactory
|
|
Packit |
79f644 |
* @short_description: Factory for #GoaTelepathyProvider instances
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* #GoaTelepathyFactory dynamically creates instances of #GoaTelepathyProvider
|
|
Packit |
79f644 |
* based on the protocols available through Telepathy.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* It accepts the protocol names from the Telepathy specification as
|
|
Packit |
79f644 |
* @provider_name in goa_provider_factory_get_provider().
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
G_DEFINE_TYPE_WITH_CODE (GoaTelepathyFactory, goa_telepathy_factory, GOA_TYPE_PROVIDER_FACTORY,
|
|
Packit |
79f644 |
goa_provider_ensure_extension_points_registered ();
|
|
Packit |
79f644 |
g_io_extension_point_implement (GOA_PROVIDER_FACTORY_EXTENSION_POINT_NAME,
|
|
Packit |
79f644 |
g_define_type_id,
|
|
Packit |
79f644 |
GOA_TELEPATHY_NAME,
|
|
Packit |
79f644 |
0));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* ---------------------------------------------------------------------------------------------------- */
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static GoaProvider *
|
|
Packit |
79f644 |
get_provider (GoaProviderFactory *factory,
|
|
Packit |
79f644 |
const gchar *provider_name)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_return_val_if_fail (GOA_IS_TELEPATHY_FACTORY (factory), NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return GOA_PROVIDER (goa_telepathy_provider_new_from_protocol_name (provider_name));
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* ---------------------------------------------------------------------------------------------------- */
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
free_list_and_unref (gpointer data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_list_free_full (data, g_object_unref);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
get_protocols_cb (GObject *source,
|
|
Packit |
79f644 |
GAsyncResult *res,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GTask *outer_task = user_data;
|
|
Packit |
79f644 |
GList *protocols = NULL;
|
|
Packit |
79f644 |
GList *ret;
|
|
Packit |
79f644 |
GList *l;
|
|
Packit |
79f644 |
GError *error = NULL;
|
|
Packit |
79f644 |
GQuark facebook_quark;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#if GOA_GOOGLE_ENABLED
|
|
Packit |
79f644 |
GQuark google_talk_quark;
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (!tpaw_protocol_get_all_finish (&protocols, res, &error))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_task_return_error (outer_task, error);
|
|
Packit |
79f644 |
g_object_unref (outer_task);
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
facebook_quark = g_quark_from_static_string ("facebook");
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#if GOA_GOOGLE_ENABLED
|
|
Packit |
79f644 |
google_talk_quark = g_quark_from_static_string ("google-talk");
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
ret = NULL;
|
|
Packit |
79f644 |
for (l = protocols; l != NULL; l = l->next)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpawProtocol *protocol = l->data;
|
|
Packit |
79f644 |
const gchar *service_name = tpaw_protocol_get_service_name (protocol);
|
|
Packit |
79f644 |
GQuark service_quark = g_quark_try_string (service_name);
|
|
Packit |
79f644 |
GoaTelepathyProvider *provider;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* This service does not exist anymore, so skip it. */
|
|
Packit |
79f644 |
if (service_quark == facebook_quark)
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* If the service is handled natively by GOA, so we don't allow
|
|
Packit |
79f644 |
* the creation of a Telepathy-only account. */
|
|
Packit |
79f644 |
#if GOA_GOOGLE_ENABLED
|
|
Packit |
79f644 |
if (service_quark == google_talk_quark)
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
#endif
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
provider = goa_telepathy_provider_new_from_protocol (protocol);
|
|
Packit |
79f644 |
ret = g_list_prepend (ret, provider);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
ret = g_list_reverse (ret);
|
|
Packit |
79f644 |
g_list_free_full (protocols, g_object_unref);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_task_return_pointer (outer_task, ret, free_list_and_unref);
|
|
Packit |
79f644 |
g_object_unref (outer_task);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
get_providers (GoaProviderFactory *factory,
|
|
Packit |
79f644 |
GAsyncReadyCallback callback,
|
|
Packit |
79f644 |
gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GTask *task;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_return_if_fail (GOA_IS_TELEPATHY_FACTORY (factory));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
task = g_task_new (factory, NULL, callback, user_data);
|
|
Packit |
79f644 |
tpaw_protocol_get_all_async (get_protocols_cb, task);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* ---------------------------------------------------------------------------------------------------- */
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
goa_telepathy_factory_init (GoaTelepathyFactory *provider)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
goa_telepathy_factory_class_init (GoaTelepathyFactoryClass *klass)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GoaProviderFactoryClass *factory_class;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
factory_class = GOA_PROVIDER_FACTORY_CLASS (klass);
|
|
Packit |
79f644 |
factory_class->get_provider = get_provider;
|
|
Packit |
79f644 |
factory_class->get_providers = get_providers;
|
|
Packit |
79f644 |
}
|