* Jonny Lamb <jonny.lamb@collabora.co.uk>
*/
-#include <config.h>
-
-#include <string.h>
-
-#include <telepathy-glib/util.h>
-
-#include <gtk/gtk.h>
+#include "config.h"
+#include "empathy-protocol-chooser.h"
#include <glib/gi18n-lib.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-connection-managers.h>
-
-#include "empathy-protocol-chooser.h"
+#include "empathy-connection-managers.h"
#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
/**
* SECTION:empathy-protocol-chooser
COL_LABEL,
COL_CM,
COL_PROTOCOL_NAME,
- COL_IS_GTALK,
+ COL_SERVICE,
COL_COUNT
};
* non-gtalk */
if (cmp == 0)
{
- gboolean is_gtalk;
+ gchar *service;
+
gtk_tree_model_get (model, iter_a,
- COL_IS_GTALK, &is_gtalk,
+ COL_SERVICE, &service,
-1);
- cmp = is_gtalk ? 1 : -1;
+ if (service != NULL)
+ cmp = 1;
+ else
+ cmp = -1;
+
+ g_free (service);
}
}
TpConnectionManager *cm)
{
EmpathyProtocolChooserPriv *priv = GET_PRIV (chooser);
- const TpConnectionManagerProtocol * const *iter;
+ GList *protocols, *l;
+ const gchar *cm_name;
+
+ cm_name = tp_connection_manager_get_name (cm);
+
+ protocols = tp_connection_manager_dup_protocols (cm);
- for (iter = cm->protocols; iter != NULL && *iter != NULL; iter++)
+ for (l = protocols; l != NULL; l = g_list_next (l))
{
- const TpConnectionManagerProtocol *proto = *iter;
+ TpProtocol *protocol = l->data;
gchar *icon_name;
const gchar *display_name;
const gchar *saved_cm_name;
+ const gchar *proto_name;
+ GdkPixbuf *pixbuf;
- saved_cm_name = g_hash_table_lookup (priv->protocols, proto->name);
+ proto_name = tp_protocol_get_name (protocol);
+ saved_cm_name = g_hash_table_lookup (priv->protocols, proto_name);
- if (!tp_strdiff (cm->name, "haze") && saved_cm_name != NULL &&
+ if (!tp_strdiff (cm_name, "haze") && saved_cm_name != NULL &&
tp_strdiff (saved_cm_name, "haze"))
/* the CM we're adding is a haze implementation of something we already
* have; drop it.
*/
continue;
- if (tp_strdiff (cm->name, "haze") && !tp_strdiff (saved_cm_name, "haze"))
+ if (!tp_strdiff (cm_name, "haze") &&
+ !tp_strdiff (proto_name, "facebook"))
+ /* Facebook now supports XMPP so drop the purple facebook plugin; user
+ * should use Gabble */
+ continue;
+
+ if (!tp_strdiff (cm_name, "haze") &&
+ !tp_strdiff (proto_name, "sip"))
+ /* Haze's SIP implementation is pretty useless (bgo #629736) */
+ continue;
+
+ if (!tp_strdiff (cm_name, "butterfly"))
+ /* Butterfly isn't supported any more */
+ continue;
+
+ if (tp_strdiff (cm_name, "haze") && !tp_strdiff (saved_cm_name, "haze"))
{
GtkTreeIter titer;
gboolean valid;
if (haze_cm == NULL)
continue;
- if (!tp_strdiff (haze_cm->name, "haze") &&
- !tp_strdiff (haze_proto_name, proto->name))
+ if (!tp_strdiff (tp_connection_manager_get_name (haze_cm), "haze")
+ && !tp_strdiff (haze_proto_name, proto_name))
{
gtk_list_store_remove (priv->store, &titer);
g_object_unref (haze_cm);
}
g_hash_table_insert (priv->protocols,
- g_strdup (proto->name), g_strdup (cm->name));
+ g_strdup (proto_name), g_strdup (cm_name));
- icon_name = empathy_protocol_icon_name (proto->name);
- display_name = empathy_protocol_name_to_display_name (proto->name);
+ icon_name = empathy_protocol_icon_name (proto_name);
+ pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
- if (display_name == NULL)
- display_name = proto->name;
+ display_name = empathy_protocol_name_to_display_name (proto_name);
gtk_list_store_insert_with_values (priv->store,
NULL, 0,
- COL_ICON, icon_name,
+ COL_ICON, pixbuf,
COL_LABEL, display_name,
COL_CM, cm,
- COL_PROTOCOL_NAME, proto->name,
- COL_IS_GTALK, FALSE,
+ COL_PROTOCOL_NAME, proto_name,
-1);
- if (!tp_strdiff (proto->name, "jabber") &&
- !tp_strdiff (cm->name, "gabble"))
+ g_clear_object (&pixbuf);
+
+ if (!tp_strdiff (proto_name, "jabber") &&
+ !tp_strdiff (cm_name, "gabble"))
{
- display_name = empathy_protocol_name_to_display_name ("gtalk");
+ display_name = empathy_service_name_to_display_name ("google-talk");
+ pixbuf = empathy_pixbuf_from_icon_name ("im-google-talk",
+ GTK_ICON_SIZE_BUTTON);
+
gtk_list_store_insert_with_values (priv->store,
NULL, 0,
- COL_ICON, "im-google-talk",
+ COL_ICON, pixbuf,
COL_LABEL, display_name,
COL_CM, cm,
- COL_PROTOCOL_NAME, proto->name,
- COL_IS_GTALK, TRUE,
+ COL_PROTOCOL_NAME, proto_name,
+ COL_SERVICE, "google-talk",
-1);
- display_name = empathy_protocol_name_to_display_name ("facebook");
+ g_clear_object (&pixbuf);
+
+ display_name = empathy_service_name_to_display_name ("facebook");
+ pixbuf = empathy_pixbuf_from_icon_name ("im-facebook",
+ GTK_ICON_SIZE_BUTTON);
+
gtk_list_store_insert_with_values (priv->store,
NULL, 0,
- COL_ICON, "im-facebook",
+ COL_ICON, pixbuf,
COL_LABEL, display_name,
COL_CM, cm,
- COL_PROTOCOL_NAME, proto->name,
- COL_IS_GTALK, FALSE,
+ COL_PROTOCOL_NAME, proto_name,
+ COL_SERVICE, "facebook",
-1);
+
+ g_clear_object (&pixbuf);
}
g_free (icon_name);
}
+
+ g_list_free_full (protocols, g_object_unref);
}
static void
/* set up combo box with new store */
priv->store = gtk_list_store_new (COL_COUNT,
- G_TYPE_STRING, /* Icon name */
+ GDK_TYPE_PIXBUF, /* Icon */
G_TYPE_STRING, /* Label */
G_TYPE_OBJECT, /* CM */
G_TYPE_STRING, /* protocol name */
- G_TYPE_BOOLEAN); /* is gtalk */
+ G_TYPE_STRING); /* service */
/* Set the protocol sort function */
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store),
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
- "icon-name", COL_ICON,
+ "pixbuf", COL_ICON,
NULL);
- g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, TRUE);
if (priv->protocols)
{
- g_hash_table_destroy (priv->protocols);
+ g_hash_table_unref (priv->protocols);
priv->protocols = NULL;
}
TpConnectionManager *cm = NULL;
gchar *protocol_name = NULL;
gboolean visible = FALSE;
- gboolean is_gtalk;
+ gchar *service;
gtk_tree_model_get (model, iter,
COL_CM, &cm,
COL_PROTOCOL_NAME, &protocol_name,
- COL_IS_GTALK, &is_gtalk,
+ COL_SERVICE, &service,
-1);
if (cm != NULL && protocol_name != NULL)
{
- TpConnectionManagerProtocol *protocol;
+ TpProtocol *protocol;
- protocol = (TpConnectionManagerProtocol *)
- tp_connection_manager_get_protocol (cm, protocol_name);
+ protocol = tp_connection_manager_get_protocol_object (cm, protocol_name);
if (protocol != NULL)
{
- visible = priv->filter_func (cm, protocol, is_gtalk,
+ visible = priv->filter_func (cm, protocol, service,
priv->filter_user_data);
}
}
if (cm != NULL)
g_object_unref (cm);
+ g_free (service);
return visible;
}
TpConnectionManager *
empathy_protocol_chooser_dup_selected (
EmpathyProtocolChooser *protocol_chooser,
- TpConnectionManagerProtocol **protocol,
- gboolean *is_gtalk)
+ TpProtocol **protocol,
+ gchar **service)
{
GtkTreeIter iter;
TpConnectionManager *cm = NULL;
COL_PROTOCOL_NAME, &protocol_name,
-1);
- *protocol = (TpConnectionManagerProtocol *)
- tp_connection_manager_get_protocol (cm, protocol_name);
+ *protocol = tp_connection_manager_get_protocol_object (cm,
+ protocol_name);
g_free (protocol_name);
+
+ if (*protocol == NULL)
+ {
+ /* For some reason the CM doesn't know about this protocol
+ * any more */
+ g_object_unref (cm);
+ return NULL;
+ }
}
- if (is_gtalk != NULL)
+ if (service != NULL)
{
gtk_tree_model_get (GTK_TREE_MODEL (cur_model), &iter,
- COL_IS_GTALK, is_gtalk,
+ COL_SERVICE, service,
-1);
}
}
gtk_combo_box_set_active (GTK_COMBO_BOX (protocol_chooser), 0);
}
+
+EmpathyAccountSettings *
+empathy_protocol_chooser_create_account_settings (EmpathyProtocolChooser *self)
+{
+ EmpathyAccountSettings *settings = NULL;
+ gchar *str;
+ const gchar *display_name;
+ TpConnectionManager *cm;
+ TpProtocol *proto;
+ gchar *service = NULL;
+
+ cm = empathy_protocol_chooser_dup_selected (self, &proto, &service);
+ if (cm == NULL || proto == NULL)
+ goto out;
+
+ if (service != NULL)
+ display_name = empathy_service_name_to_display_name (service);
+ else
+ display_name = empathy_protocol_name_to_display_name (
+ tp_protocol_get_name (proto));
+
+ /* Create account */
+ /* To translator: %s is the name of the protocol, such as "Google Talk" or
+ * "Yahoo!"
+ */
+ str = g_strdup_printf (_("New %s account"), display_name);
+
+ settings = empathy_account_settings_new (tp_connection_manager_get_name (cm),
+ tp_protocol_get_name (proto), service, str);
+
+ g_free (str);
+
+ if (!tp_strdiff (service, "google-talk"))
+ {
+ const gchar *fallback_servers[] = {
+ "talkx.l.google.com",
+ "talkx.l.google.com:443,oldssl",
+ "talkx.l.google.com:80",
+ NULL};
+
+ const gchar *extra_certificate_identities[] = {
+ "talk.google.com",
+ NULL};
+
+ empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
+ NULL, NULL);
+ empathy_account_settings_set (settings, "server",
+ g_variant_new_string (extra_certificate_identities[0]));
+ empathy_account_settings_set (settings, "require-encryption",
+ g_variant_new_boolean (TRUE));
+ empathy_account_settings_set (settings, "fallback-servers",
+ g_variant_new_strv (fallback_servers, -1));
+
+ if (empathy_account_settings_have_tp_param (settings,
+ "extra-certificate-identities"))
+ {
+ empathy_account_settings_set (settings,
+ "extra-certificate-identities",
+ g_variant_new_strv (extra_certificate_identities, -1));
+ }
+ }
+ else if (!tp_strdiff (service, "facebook"))
+ {
+ const gchar *fallback_servers[] = {
+ "chat.facebook.com:443",
+ NULL };
+
+ empathy_account_settings_set_icon_name_async (settings, "im-facebook",
+ NULL, NULL);
+ empathy_account_settings_set (settings, "require-encryption",
+ g_variant_new_boolean (TRUE));
+ empathy_account_settings_set (settings, "server",
+ g_variant_new_string ("chat.facebook.com"));
+ empathy_account_settings_set (settings, "fallback-servers",
+ g_variant_new_strv (fallback_servers, -1));
+ }
+
+out:
+ tp_clear_object (&cm);
+ g_free (service);
+ return settings;
+}