diff options
author | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2009-07-06 18:29:55 +0800 |
---|---|---|
committer | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2009-07-06 18:29:55 +0800 |
commit | 0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97 (patch) | |
tree | d892e960ddb721aae6f4a56ec1831a50f9868d00 /libempathy-gtk | |
parent | eb9dc0cc2b90d53b87b52e13122f760d291d211e (diff) | |
download | gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.tar gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.tar.gz gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.tar.bz2 gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.tar.lz gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.tar.xz gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.tar.zst gsoc2013-empathy-0ddbfabe32f0d02a63a21fca5bfb015f4e56bf97.zip |
Transform profile chooser into a protocol chooser
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-profile-chooser.c | 324 | ||||
-rw-r--r-- | libempathy-gtk/empathy-profile-chooser.h | 69 | ||||
-rw-r--r-- | libempathy-gtk/empathy-protocol-chooser.c | 339 | ||||
-rw-r--r-- | libempathy-gtk/empathy-protocol-chooser.h | 70 |
5 files changed, 411 insertions, 395 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 10931012a..94cc4ee15 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -52,7 +52,7 @@ libempathy_gtk_handwritten_source = \ empathy-log-window.c \ empathy-new-message-dialog.c \ empathy-presence-chooser.c \ - empathy-profile-chooser.c \ + empathy-protocol-chooser.c \ empathy-smiley-manager.c \ empathy-sound.c \ empathy-spell.c \ @@ -112,7 +112,7 @@ libempathy_gtk_headers = \ empathy-log-window.h \ empathy-new-message-dialog.h \ empathy-presence-chooser.h \ - empathy-profile-chooser.h \ + empathy-protocol-chooser.h \ empathy-smiley-manager.h \ empathy-sound.h \ empathy-spell.h \ diff --git a/libempathy-gtk/empathy-profile-chooser.c b/libempathy-gtk/empathy-profile-chooser.c deleted file mode 100644 index b3cbf90d0..000000000 --- a/libempathy-gtk/empathy-profile-chooser.c +++ /dev/null @@ -1,324 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright (C) 2007-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: Xavier Claessens <xclaesse@gmail.com> - * Jonny Lamb <jonny.lamb@collabora.co.uk> - */ - -#include <config.h> - -#include <string.h> - -#include <gtk/gtk.h> -#include <libmissioncontrol/mc-profile.h> -#include <libmissioncontrol/mc-protocol.h> - -#include <libempathy/empathy-utils.h> - -#include "empathy-profile-chooser.h" -#include "empathy-ui-utils.h" - -/** - * SECTION:empathy-profile-chooser - * @title: EmpathyProfileChooser - * @short_description: A widget used to choose from a list of profiles - * @include: libempathy-gtk/empathy-profile-chooser.h - * - * #EmpathyProfileChooser is a widget which extends #GtkComboBox to provides a - * chooser of available profiles. - */ - -/** - * EmpathyProfileChooser: - * @parent: parent object - * - * Widget which extends #GtkComboBox to provide a chooser of available - * profiles. - */ - -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyProfileChooser) -typedef struct -{ - GtkListStore *store; - gboolean dispose_run; -} EmpathyProfileChooserPriv; - -enum -{ - COL_ICON, - COL_LABEL, - COL_PROFILE, - COL_COUNT -}; - -G_DEFINE_TYPE (EmpathyProfileChooser, empathy_profile_chooser, - GTK_TYPE_COMBO_BOX); - -static gint -profile_chooser_sort_profile_value (McProfile *profile) -{ - guint i; - const gchar *profile_name; - const gchar *names[] = { - "jabber", - "salut", - "gtalk", - NULL - }; - - profile_name = mc_profile_get_unique_name (profile); - - for (i = 0 ; names[i]; i++) - { - if (strcmp (profile_name, names[i]) == 0) - return i; - } - - return i; -} - -static gint -profile_chooser_sort_func (GtkTreeModel *model, - GtkTreeIter *iter_a, - GtkTreeIter *iter_b, - gpointer user_data) -{ - McProfile *profile_a; - McProfile *profile_b; - gint cmp; - - gtk_tree_model_get (model, iter_a, - COL_PROFILE, &profile_a, - -1); - gtk_tree_model_get (model, iter_b, - COL_PROFILE, &profile_b, - -1); - - cmp = profile_chooser_sort_profile_value (profile_a); - cmp -= profile_chooser_sort_profile_value (profile_b); - if (cmp == 0) - { - cmp = strcmp (mc_profile_get_display_name (profile_a), - mc_profile_get_display_name (profile_b)); - } - - g_object_unref (profile_a); - g_object_unref (profile_b); - - return cmp; -} - -static void -profile_chooser_constructed (GObject *object) -{ - EmpathyProfileChooser *profile_chooser; - EmpathyProfileChooserPriv *priv; - - GList *profiles, *l, *seen; - GtkCellRenderer *renderer; - GtkTreeIter iter; - gboolean iter_set = FALSE; - McManager *btf_cm; - - priv = GET_PRIV (object); - profile_chooser = EMPATHY_PROFILE_CHOOSER (object); - - /* set up combo box with new store */ - priv->store = gtk_list_store_new (COL_COUNT, - G_TYPE_STRING, /* Icon name */ - G_TYPE_STRING, /* Label */ - MC_TYPE_PROFILE); /* Profile */ - - gtk_combo_box_set_model (GTK_COMBO_BOX (object), - GTK_TREE_MODEL (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, - 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); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer, - "text", COL_LABEL, - NULL); - - btf_cm = mc_manager_lookup ("butterfly"); - profiles = mc_profiles_list (); - seen = NULL; - for (l = profiles; l; l = g_list_next (l)) - { - McProfile *profile; - McProtocol *protocol; - const gchar *unique_name; - - profile = l->data; - - /* Check if the CM is installed, otherwise skip that profile. - * Workaround SF bug #1688779 */ - protocol = mc_profile_get_protocol (profile); - if (!protocol) - continue; - - g_object_unref (protocol); - - /* Skip MSN-Haze if we have butterfly */ - unique_name = mc_profile_get_unique_name (profile); - if (btf_cm && strcmp (unique_name, "msn-haze") == 0) - continue; - - if (g_list_find_custom (seen, unique_name, (GCompareFunc) strcmp)) - continue; - - seen = g_list_append (seen, (char *) unique_name); - - gtk_list_store_insert_with_values (priv->store, &iter, 0, - COL_ICON, mc_profile_get_icon_name (profile), - COL_LABEL, mc_profile_get_display_name (profile), - COL_PROFILE, profile, - -1); - iter_set = TRUE; - } - - g_list_free (seen); - - if (btf_cm) - g_object_unref (btf_cm); - - /* Set the profile sort function */ - gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), - COL_PROFILE, - profile_chooser_sort_func, - NULL, NULL); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), - COL_PROFILE, - GTK_SORT_ASCENDING); - - if (iter_set) - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (object), &iter); - - mc_profiles_free_list (profiles); - - if (G_OBJECT_CLASS (empathy_profile_chooser_parent_class)->constructed) - G_OBJECT_CLASS (empathy_profile_chooser_parent_class)->constructed (object); -} - -static void -empathy_profile_chooser_init (EmpathyProfileChooser *profile_chooser) -{ - EmpathyProfileChooserPriv *priv = - G_TYPE_INSTANCE_GET_PRIVATE (profile_chooser, - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooserPriv); - - priv->dispose_run = FALSE; - - profile_chooser->priv = priv; -} - -static void -profile_chooser_dispose (GObject *object) -{ - EmpathyProfileChooser *profile_chooser = EMPATHY_PROFILE_CHOOSER (object); - EmpathyProfileChooserPriv *priv = GET_PRIV (profile_chooser); - - if (priv->dispose_run) - return; - - priv->dispose_run = TRUE; - - if (priv->store) - { - g_object_unref (priv->store); - priv->store = NULL; - } - - (G_OBJECT_CLASS (empathy_profile_chooser_parent_class)->dispose) (object); -} - -static void -empathy_profile_chooser_class_init (EmpathyProfileChooserClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructed = profile_chooser_constructed; - object_class->dispose = profile_chooser_dispose; - - g_type_class_add_private (object_class, sizeof (EmpathyProfileChooserPriv)); -} - -/** - * empathy_profile_chooser_dup_selected: - * @profile_chooser: an #EmpathyProfileChooser - * - * Returns a new reference to the selected #McProfile in @profile_chooser. The - * returned #McProfile should be unrefed with g_object_unref() when finished - * with. - * - * Return value: a new reference to the selected #McProfile - */ -McProfile * -empathy_profile_chooser_dup_selected (EmpathyProfileChooser *profile_chooser) -{ - EmpathyProfileChooserPriv *priv = GET_PRIV (profile_chooser); - GtkTreeIter iter; - McProfile *profile = NULL; - - g_return_val_if_fail (EMPATHY_IS_PROFILE_CHOOSER (profile_chooser), NULL); - - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (profile_chooser), &iter)) - { - gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, - COL_PROFILE, &profile, - -1); - } - - return profile; -} - -/** - * empathy_profile_chooser_n_profiles: - * @profile_chooser: an #EmpathyProfileChooser - * - * Returns the number of profiles in @profile_chooser. - * - * Return value: the number of profiles in @profile_chooser - */ -gint -empathy_profile_chooser_n_profiles (EmpathyProfileChooser *profile_chooser) -{ - EmpathyProfileChooserPriv *priv = GET_PRIV (profile_chooser); - - g_return_val_if_fail (EMPATHY_IS_PROFILE_CHOOSER (profile_chooser), 0); - - return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL); -} - -/** - * empathy_profile_chooser_new: - * - * Creates a new #EmpathyProfileChooser widget. - * - * Return value: a new #EmpathyProfileChooser widget - */ -GtkWidget * -empathy_profile_chooser_new (void) -{ - return GTK_WIDGET (g_object_new (EMPATHY_TYPE_PROFILE_CHOOSER, NULL)); -} diff --git a/libempathy-gtk/empathy-profile-chooser.h b/libempathy-gtk/empathy-profile-chooser.h deleted file mode 100644 index 37d7241a9..000000000 --- a/libempathy-gtk/empathy-profile-chooser.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright (C) 2007-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: Xavier Claessens <xclaesse@gmail.com> - * Jonny Lamb <jonny.lamb@collabora.co.uk - */ - -#ifndef __EMPATHY_PROFILE_CHOOSER_H__ -#define __EMPATHY_PROFILE_CHOOSER_H__ - -#include <glib-object.h> -#include <gtk/gtk.h> - -#include <libmissioncontrol/mc-profile.h> - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_PROFILE_CHOOSER (empathy_profile_chooser_get_type ()) -#define EMPATHY_PROFILE_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooser)) -#define EMPATHY_PROFILE_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooserClass)) -#define EMPATHY_IS_PROFILE_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_PROFILE_CHOOSER)) -#define EMPATHY_IS_PROFILE_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_PROFILE_CHOOSER)) -#define EMPATHY_PROFILE_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ - EMPATHY_TYPE_PROFILE_CHOOSER, EmpathyProfileChooserClass)) - -typedef struct _EmpathyProfileChooser EmpathyProfileChooser; -typedef struct _EmpathyProfileChooserClass EmpathyProfileChooserClass; - -struct _EmpathyProfileChooser -{ - GtkComboBox parent; - - /*<private>*/ - gpointer priv; -}; - -struct _EmpathyProfileChooserClass -{ - GtkComboBoxClass parent_class; -}; - -GType empathy_profile_chooser_get_type (void) G_GNUC_CONST; -GtkWidget * empathy_profile_chooser_new (void); -McProfile * empathy_profile_chooser_dup_selected ( - EmpathyProfileChooser *profile_chooser); -gint empathy_profile_chooser_n_profiles ( - EmpathyProfileChooser *profile_chooser); - -G_END_DECLS -#endif /* __EMPATHY_PROFILE_CHOOSER_H__ */ diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c new file mode 100644 index 000000000..45442156e --- /dev/null +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -0,0 +1,339 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* + * Copyright (C) 2007-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: Xavier Claessens <xclaesse@gmail.com> + * Jonny Lamb <jonny.lamb@collabora.co.uk> + */ + +#include <config.h> + +#include <string.h> + +#include <telepathy-glib/util.h> + +#include <gtk/gtk.h> + +#include <libempathy/empathy-utils.h> + +#include "empathy-protocol-chooser.h" +#include "empathy-ui-utils.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT +#include <libempathy/empathy-debug.h> + +/** + * SECTION:empathy-protocol-chooser + * @title: EmpathyProtocolChooser + * @short_description: A widget used to choose from a list of protocols + * @include: libempathy-gtk/empathy-protocol-chooser.h + * + * #EmpathyProtocolChooser is a widget which extends #GtkComboBox to provides a + * chooser of available protocols. + */ + +/** + * EmpathyProtocolChooser: + * @parent: parent object + * + * Widget which extends #GtkComboBox to provide a chooser of available + * protocols. + */ + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyProtocolChooser) +typedef struct +{ + GtkListStore *store; + gboolean dispose_run; + +} EmpathyProtocolChooserPriv; + +enum +{ + COL_ICON, + COL_LABEL, + COL_CM, + COL_PROTOCOL, + COL_COUNT +}; + +G_DEFINE_TYPE (EmpathyProtocolChooser, empathy_protocol_chooser, + GTK_TYPE_COMBO_BOX); + +static gint +protocol_chooser_sort_protocol_value (TpConnectionManagerProtocol *protocol) +{ + guint i; + const gchar *names[] = { + "jabber", + "salut", + "gtalk", + NULL + }; + + for (i = 0 ; names[i]; i++) + { + if (strcmp (protocol->name, names[i]) == 0) + return i; + } + + return i; +} + +static gint +protocol_chooser_sort_func (GtkTreeModel *model, + GtkTreeIter *iter_a, + GtkTreeIter *iter_b, + gpointer user_data) +{ + TpConnectionManagerProtocol *protocol_a; + TpConnectionManagerProtocol *protocol_b; + gint cmp; + + gtk_tree_model_get (model, iter_a, + COL_PROTOCOL, &protocol_a, + -1); + gtk_tree_model_get (model, iter_b, + COL_PROTOCOL, &protocol_b, + -1); + + cmp = protocol_chooser_sort_protocol_value (protocol_a); + cmp -= protocol_chooser_sort_protocol_value (protocol_b); + if (cmp == 0) + { + cmp = strcmp (protocol_a->name, protocol_b->name); + } + + return cmp; +} + +static void +protocol_choosers_add_cm (EmpathyProtocolChooser *chooser, + TpConnectionManager *cm) +{ + EmpathyProtocolChooserPriv *priv = GET_PRIV (chooser); + const TpConnectionManagerProtocol * const *iter; + + for (iter = cm->protocols; iter != NULL && *iter != NULL; iter++) + { + const TpConnectionManagerProtocol *proto = *iter; + gchar *icon_name; + gchar *display_name; + + + icon_name = g_strdup_printf ("im-%s", proto->name); + + if (!tp_strdiff (cm->name, "haze") && !tp_strdiff (proto->name, "msn")) + display_name = g_strdup_printf ("msn (Haze)"); + else + display_name = g_strdup (proto->name); + + gtk_list_store_insert_with_values (priv->store, NULL, 0, + COL_ICON, icon_name, + COL_LABEL, display_name, + COL_CM, cm, + COL_PROTOCOL, proto, + -1); + + g_free (display_name); + g_free (icon_name); + } +} + + +static void +protocol_choosers_cms_listed (TpConnectionManager * const *cms, + gsize n_cms, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + TpConnectionManager * const *iter; + + if (error !=NULL) + { + DEBUG ("Failed to get connection managers: %s", error->message); + return; + } + + for (iter = cms ; iter != NULL && *iter != NULL; iter++) + protocol_choosers_add_cm (EMPATHY_PROTOCOL_CHOOSER (weak_object), + *iter); + + gtk_combo_box_set_active (GTK_COMBO_BOX (weak_object), 0); +} + +static void +protocol_chooser_constructed (GObject *object) +{ + EmpathyProtocolChooser *protocol_chooser; + EmpathyProtocolChooserPriv *priv; + + GtkCellRenderer *renderer; + TpDBusDaemon *dbus; + + priv = GET_PRIV (object); + protocol_chooser = EMPATHY_PROTOCOL_CHOOSER (object); + + /* set up combo box with new store */ + priv->store = gtk_list_store_new (COL_COUNT, + G_TYPE_STRING, /* Icon name */ + G_TYPE_STRING, /* Label */ + G_TYPE_OBJECT, /* CM */ + G_TYPE_POINTER); /* protocol */ + + gtk_combo_box_set_model (GTK_COMBO_BOX (object), + GTK_TREE_MODEL (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, + 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); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer, + "text", COL_LABEL, + NULL); + + dbus = tp_dbus_daemon_dup (NULL); + tp_list_connection_managers (dbus, protocol_choosers_cms_listed, + NULL, NULL, object); + g_object_unref (dbus); + + /* Set the protocol sort function */ + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store), + COL_PROTOCOL, + protocol_chooser_sort_func, + NULL, NULL); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store), + COL_PROTOCOL, + GTK_SORT_ASCENDING); + + if (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed) + G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed (object); +} + +static void +empathy_protocol_chooser_init (EmpathyProtocolChooser *protocol_chooser) +{ + EmpathyProtocolChooserPriv *priv = + G_TYPE_INSTANCE_GET_PRIVATE (protocol_chooser, + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserPriv); + + priv->dispose_run = FALSE; + + protocol_chooser->priv = priv; +} + +static void +protocol_chooser_dispose (GObject *object) +{ + EmpathyProtocolChooser *protocol_chooser = EMPATHY_PROTOCOL_CHOOSER (object); + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + + if (priv->dispose_run) + return; + + priv->dispose_run = TRUE; + + if (priv->store) + { + g_object_unref (priv->store); + priv->store = NULL; + } + + (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->dispose) (object); +} + +static void +empathy_protocol_chooser_class_init (EmpathyProtocolChooserClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = protocol_chooser_constructed; + object_class->dispose = protocol_chooser_dispose; + + g_type_class_add_private (object_class, sizeof (EmpathyProtocolChooserPriv)); +} + +/** + * empathy_protocol_chooser_get_selected_protocol: + * @protocol_chooser: an #EmpathyProtocolChooser + * + * Returns a pointer to the selected #TpConnectionManagerProtocol in + * @protocol_chooser. + * + * Return value: a pointer to the selected #TpConnectionManagerProtocol + */ +TpConnectionManager *empathy_protocol_chooser_dup_selected ( + EmpathyProtocolChooser *protocol_chooser, + TpConnectionManagerProtocol **protocol) +{ + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + GtkTreeIter iter; + TpConnectionManager *cm = NULL; + + g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), NULL); + + if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (protocol_chooser), &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, + COL_CM, &cm, + -1); + + if (protocol != NULL) + gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, + COL_PROTOCOL, protocol, + -1); + } + + return cm; +} + +/** + * empathy_protocol_chooser_n_protocols: + * @protocol_chooser: an #EmpathyProtocolChooser + * + * Returns the number of protocols in @protocol_chooser. + * + * Return value: the number of protocols in @protocol_chooser + */ +gint +empathy_protocol_chooser_n_protocols (EmpathyProtocolChooser *protocol_chooser) +{ + EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser); + + g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), 0); + + return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL); +} + +/** + * empathy_protocol_chooser_new: + * + * Creates a new #EmpathyProtocolChooser widget. + * + * Return value: a new #EmpathyProtocolChooser widget + */ +GtkWidget * +empathy_protocol_chooser_new (void) +{ + return GTK_WIDGET (g_object_new (EMPATHY_TYPE_PROTOCOL_CHOOSER, NULL)); +} diff --git a/libempathy-gtk/empathy-protocol-chooser.h b/libempathy-gtk/empathy-protocol-chooser.h new file mode 100644 index 000000000..75f9343cc --- /dev/null +++ b/libempathy-gtk/empathy-protocol-chooser.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* + * Copyright (C) 2007-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: Xavier Claessens <xclaesse@gmail.com> + * Jonny Lamb <jonny.lamb@collabora.co.uk + */ + +#ifndef __EMPATHY_PROTOCOL_CHOOSER_H__ +#define __EMPATHY_PROTOCOL_CHOOSER_H__ + +#include <glib-object.h> +#include <gtk/gtk.h> + +#include <telepathy-glib/connection-manager.h> + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_PROTOCOL_CHOOSER (empathy_protocol_chooser_get_type ()) +#define EMPATHY_PROTOCOL_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooser)) +#define EMPATHY_PROTOCOL_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserClass)) +#define EMPATHY_IS_PROTOCOL_CHOOSER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER)) +#define EMPATHY_IS_PROTOCOL_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER)) +#define EMPATHY_PROTOCOL_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ + EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserClass)) + +typedef struct _EmpathyProtocolChooser EmpathyProtocolChooser; +typedef struct _EmpathyProtocolChooserClass EmpathyProtocolChooserClass; + +struct _EmpathyProtocolChooser +{ + GtkComboBox parent; + + /*<private>*/ + gpointer priv; +}; + +struct _EmpathyProtocolChooserClass +{ + GtkComboBoxClass parent_class; +}; + +GType empathy_protocol_chooser_get_type (void) G_GNUC_CONST; +GtkWidget * empathy_protocol_chooser_new (void); +TpConnectionManager *empathy_protocol_chooser_dup_selected ( + EmpathyProtocolChooser *protocol_chooser, + TpConnectionManagerProtocol **protocol); +gint empathy_protocol_chooser_n_protocols ( + EmpathyProtocolChooser *protocol_chooser); + +G_END_DECLS +#endif /* __EMPATHY_PROTOCOL_CHOOSER_H__ */ |