aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-08-26 20:53:01 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-08-29 17:47:40 +0800
commit41515259986697a443e892ad31043d2275915eea (patch)
treef05c34ff7f58105bea352997ac84e6ca43fdfa10 /libempathy-gtk
parent04f88a3959838b95972664ce99cf24f94be06457 (diff)
downloadgsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.tar
gsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.tar.gz
gsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.tar.bz2
gsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.tar.lz
gsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.tar.xz
gsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.tar.zst
gsoc2013-empathy-41515259986697a443e892ad31043d2275915eea.zip
add EmpathyAccountSelectorDialog
Dialog asking user to pick an account from a pre-defined list. https://bugzilla.gnome.org/show_bug.cgi?id=650112
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/Makefile.am2
-rw-r--r--libempathy-gtk/empathy-account-selector-dialog.c198
-rw-r--r--libempathy-gtk/empathy-account-selector-dialog.h68
3 files changed, 268 insertions, 0 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index 33dcbfb93..31e0ec8cc 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -29,6 +29,7 @@ noinst_LTLIBRARIES = libempathy-gtk.la
libempathy_gtk_handwritten_source = \
empathy-account-chooser.c \
+ empathy-account-selector-dialog.c \
empathy-account-widget-irc.c \
empathy-account-widget-private.h \
empathy-account-widget-sip.c \
@@ -96,6 +97,7 @@ libempathy_gtk_handwritten_source = \
libempathy_gtk_headers = \
empathy-account-chooser.h \
+ empathy-account-selector-dialog.h \
empathy-account-widget-irc.h \
empathy-account-widget-sip.h \
empathy-account-widget.h \
diff --git a/libempathy-gtk/empathy-account-selector-dialog.c b/libempathy-gtk/empathy-account-selector-dialog.c
new file mode 100644
index 000000000..72a7b2ffd
--- /dev/null
+++ b/libempathy-gtk/empathy-account-selector-dialog.c
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2011 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: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
+ */
+
+#include "config.h"
+
+#include "empathy-account-selector-dialog.h"
+
+enum
+{
+ PROP_ACCOUNTS = 1
+};
+
+struct _EmpathyAccountSelectorDialogPrivate
+{
+ GList *accounts;
+
+ GtkWidget *treeview;
+ GtkListStore *model;
+};
+
+enum
+{
+ COL_ACCOUNT,
+ COL_ICON,
+ COL_NAME,
+ NUM_COL
+};
+
+G_DEFINE_TYPE (EmpathyAccountSelectorDialog, empathy_account_selector_dialog, \
+ GTK_TYPE_DIALOG)
+
+static void
+empathy_account_selector_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyAccountSelectorDialog *self = (EmpathyAccountSelectorDialog *) object;
+
+ switch (property_id)
+ {
+ case PROP_ACCOUNTS:
+ {
+ GList *list;
+
+ list = g_value_get_pointer (value);
+
+ self->priv->accounts = g_list_copy (list);
+ g_list_foreach (self->priv->accounts, (GFunc) g_object_ref, NULL);
+ break;
+ }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+empathy_account_selector_dialog_constructed (GObject *obj)
+{
+ EmpathyAccountSelectorDialog *self = (EmpathyAccountSelectorDialog *) obj;
+ GList *l;
+
+ for (l = self->priv->accounts; l != NULL; l = g_list_next (l))
+ {
+ TpAccount *account = l->data;
+
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (self->priv->model),
+ NULL, -1,
+ COL_ACCOUNT, account,
+ COL_ICON, tp_account_get_icon_name (account),
+ COL_NAME, tp_account_get_display_name (account),
+ -1);
+ }
+
+ G_OBJECT_CLASS (empathy_account_selector_dialog_parent_class)->constructed (
+ obj);
+}
+
+static void
+empathy_account_selector_dialog_dispose (GObject *obj)
+{
+ EmpathyAccountSelectorDialog *self = (EmpathyAccountSelectorDialog *) obj;
+
+ g_list_free_full (self->priv->accounts, g_object_unref);
+ self->priv->accounts = NULL;
+
+ tp_clear_object (&self->priv->model);
+
+ G_OBJECT_CLASS (empathy_account_selector_dialog_parent_class)->dispose (obj);
+}
+
+static void
+empathy_account_selector_dialog_class_init (
+ EmpathyAccountSelectorDialogClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GParamSpec *spec;
+
+ oclass->set_property = empathy_account_selector_dialog_set_property;
+ oclass->constructed = empathy_account_selector_dialog_constructed;
+ oclass->dispose = empathy_account_selector_dialog_dispose;
+
+ spec = g_param_spec_pointer ("accounts", "accounts", "GList of TpAccount",
+ G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
+ g_object_class_install_property (oclass, PROP_ACCOUNTS, spec);
+
+ g_type_class_add_private (klass,
+ sizeof (EmpathyAccountSelectorDialogPrivate));
+}
+
+static void
+empathy_account_selector_dialog_init (EmpathyAccountSelectorDialog *self)
+{
+ GtkWidget *box;
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *column;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG,
+ EmpathyAccountSelectorDialogPrivate);
+
+ self->priv->model = gtk_list_store_new (NUM_COL,
+ TP_TYPE_ACCOUNT, /* account */
+ G_TYPE_STRING, /* icon name */
+ G_TYPE_STRING); /* name */
+
+ /* Create treeview */
+ self->priv->treeview = gtk_tree_view_new_with_model (
+ GTK_TREE_MODEL (self->priv->model));
+
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (self->priv->treeview),
+ FALSE);
+
+ column = gtk_tree_view_column_new ();
+ gtk_tree_view_column_set_expand (column, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->treeview), column);
+
+ /* icon */
+ cell = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_column_pack_start (column, cell, FALSE);
+ gtk_tree_view_column_add_attribute (column, cell, "icon-name", COL_ICON);
+
+ /* text */
+ cell = gtk_cell_renderer_text_new ();
+
+ gtk_tree_view_column_pack_start (column, cell, TRUE);
+ gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
+
+ box = gtk_dialog_get_content_area (GTK_DIALOG (self));
+ gtk_box_pack_start (GTK_BOX (box), self->priv->treeview, TRUE, TRUE, 0);
+
+ gtk_widget_show (self->priv->treeview);
+}
+
+GtkWidget *
+empathy_account_selector_dialog_new (GList *accounts)
+{
+ return g_object_new (EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG,
+ "accounts", accounts,
+ NULL);
+}
+
+TpAccount *
+empathy_account_selector_dialog_dup_selected (
+ EmpathyAccountSelectorDialog *self)
+{
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ TpAccount *account;
+
+ selection = gtk_tree_view_get_selection (
+ GTK_TREE_VIEW (self->priv->treeview));
+
+ if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+ return NULL;
+
+ gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
+
+ return account;
+}
diff --git a/libempathy-gtk/empathy-account-selector-dialog.h b/libempathy-gtk/empathy-account-selector-dialog.h
new file mode 100644
index 000000000..96bafb2d4
--- /dev/null
+++ b/libempathy-gtk/empathy-account-selector-dialog.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 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: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
+ */
+
+#ifndef __EMPATHY_ACCOUNT_SELECTOR_DIALOG_H__
+#define __EMPATHY_ACCOUNT_SELECTOR_DIALOG_H__
+
+#include <gtk/gtk.h>
+#include <telepathy-glib/telepathy-glib.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG \
+ (empathy_account_selector_dialog_get_type ())
+#define EMPATHY_ACCOUNT_SELECTOR_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),\
+ EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG, EmpathyAccountSelectorDialog))
+#define EMPATHY_ACCOUNT_SELECTOR_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\
+ EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG, EmpathyAccountSelectorDialogClass))
+#define EMPATHY_IS_ACCOUNT_SELECTOR_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),\
+ EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG))
+#define EMPATHY_IS_ACCOUNT_SELECTOR_DIALOG_CLASS(k) (\
+ G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG))
+#define EMPATHY_ACCOUNT_SELECTOR_DIALOG_GET_CLASS(o) (\
+ G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_ACCOUNT_SELECTOR_DIALOG,\
+ EmpathyAccountSelectorDialogClass))
+
+typedef struct _EmpathyAccountSelectorDialog EmpathyAccountSelectorDialog;
+typedef struct _EmpathyAccountSelectorDialogClass \
+ EmpathyAccountSelectorDialogClass;
+typedef struct _EmpathyAccountSelectorDialogPrivate \
+ EmpathyAccountSelectorDialogPrivate;
+
+struct _EmpathyAccountSelectorDialog {
+ GtkDialog parent;
+
+ EmpathyAccountSelectorDialogPrivate *priv;
+};
+
+struct _EmpathyAccountSelectorDialogClass {
+ GtkDialogClass parent_class;
+};
+
+GType empathy_account_selector_dialog_get_type (void) G_GNUC_CONST;
+
+GtkWidget * empathy_account_selector_dialog_new (GList *accounts);
+
+TpAccount * empathy_account_selector_dialog_dup_selected (
+ EmpathyAccountSelectorDialog *self);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_ACCOUNT_SELECTOR_DIALOG_H__ */