aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2009-08-09 23:48:57 +0800
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>2009-08-22 21:25:14 +0800
commit0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be (patch)
tree10e460b9b8288697c0a2174967d891cb14d661c4 /src
parent350ed3dbdba49253b6a94c8066c45ae81e95bed1 (diff)
downloadgsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.tar
gsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.tar.gz
gsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.tar.bz2
gsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.tar.lz
gsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.tar.xz
gsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.tar.zst
gsoc2013-empathy-0e5397ae0e6cc3d75f8e9db19ca872cf28cf41be.zip
Make the import system more future-proof
Split the utilities from the widget and the dialog; we now have an enum for supported applications, with a special value which means "all applications", which is the only one which triggers showing the "Source" column in EmpathyImportWidget. We need this to avoid being redundant in the EmpathyAccountAssistant, as we already choose there the application from which to import.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/empathy-account-assistant.c7
-rw-r--r--src/empathy-accounts-dialog.c3
-rw-r--r--src/empathy-import-dialog.c44
-rw-r--r--src/empathy-import-dialog.h18
-rw-r--r--src/empathy-import-pidgin.c2
-rw-r--r--src/empathy-import-utils.c76
-rw-r--r--src/empathy-import-utils.h56
-rw-r--r--src/empathy-import-widget.c82
-rw-r--r--src/empathy-import-widget.h4
10 files changed, 212 insertions, 81 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5d3bee501..3641835f7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,7 @@ empathy_handwritten_source = \
empathy-import-dialog.c empathy-import-dialog.h \
empathy-import-widget.c empathy-import-widget.h \
empathy-import-pidgin.c empathy-import-pidgin.h \
+ empathy-import-utils.c empathy-import-utils.h \
empathy-main-window.c empathy-main-window.h \
empathy-misc.c empathy-misc.h \
empathy-new-chatroom-dialog.c empathy-new-chatroom-dialog.h \
diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c
index 55a322e24..ab42bbd4f 100644
--- a/src/empathy-account-assistant.c
+++ b/src/empathy-account-assistant.c
@@ -25,8 +25,8 @@
#include <gdk/gdkkeysyms.h>
#include "empathy-account-assistant.h"
-#include "empathy-import-dialog.h"
#include "empathy-import-widget.h"
+#include "empathy-import-utils.h"
#include <libempathy/empathy-account-settings.h>
#include <libempathy/empathy-utils.h>
@@ -492,7 +492,7 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
gtk_container_add (GTK_CONTAINER (w), vbox_1);
gtk_widget_show (vbox_1);
- if (empathy_import_dialog_accounts_to_import ())
+ if (empathy_import_accounts_to_import ())
{
hbox_1 = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0);
@@ -578,7 +578,8 @@ account_assistant_build_import_page (EmpathyAccountAssistant *self)
gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
- iw = empathy_import_widget_new ();
+ /* NOTE: this is hardcoded as we support pidgin only */
+ iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
import = empathy_import_widget_get_widget (iw);
gtk_container_add (GTK_CONTAINER (w), import);
gtk_widget_show (import);
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index 785d20ae0..e985befc8 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -46,6 +46,7 @@
#include "empathy-accounts-dialog.h"
#include "empathy-import-dialog.h"
+#include "empathy-import-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
#include <libempathy/empathy-debug.h>
@@ -1380,7 +1381,7 @@ do_constructed (GObject *object)
EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
- if (empathy_import_dialog_accounts_to_import ())
+ if (empathy_import_accounts_to_import ())
{
if (!import_asked)
diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c
index 1a5f0a25c..7ca0285b1 100644
--- a/src/empathy-import-dialog.c
+++ b/src/empathy-import-dialog.c
@@ -53,46 +53,6 @@ typedef struct {
G_DEFINE_TYPE (EmpathyImportDialog, empathy_import_dialog, GTK_TYPE_DIALOG)
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportDialog)
-EmpathyImportAccountData *
-empathy_import_account_data_new (const gchar *source)
-{
- EmpathyImportAccountData *data;
-
- g_return_val_if_fail (!EMP_STR_EMPTY (source), NULL);
-
- data = g_slice_new0 (EmpathyImportAccountData);
- data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
- (GDestroyNotify) tp_g_value_slice_free);
- data->source = g_strdup (source);
- data->protocol = NULL;
- data->connection_manager = NULL;
-
- return data;
-}
-
-void
-empathy_import_account_data_free (EmpathyImportAccountData *data)
-{
- if (data == NULL)
- return;
- if (data->protocol != NULL)
- g_free (data->protocol);
- if (data->connection_manager != NULL)
- g_free (data->connection_manager);
- if (data->settings != NULL)
- g_hash_table_destroy (data->settings);
- if (data->source != NULL)
- g_free (data->source);
-
- g_slice_free (EmpathyImportAccountData, data);
-}
-
-gboolean
-empathy_import_dialog_accounts_to_import (void)
-{
- return empathy_import_pidgin_accounts_to_import ();
-}
-
static void
import_dialog_add_import_widget (EmpathyImportDialog *self)
{
@@ -102,7 +62,7 @@ import_dialog_add_import_widget (EmpathyImportDialog *self)
area = gtk_dialog_get_content_area (GTK_DIALOG (self));
- iw = empathy_import_widget_new ();
+ iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL);
widget = empathy_import_widget_get_widget (iw);
gtk_box_pack_start (GTK_BOX (area), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
@@ -207,7 +167,7 @@ do_constructed (GObject *obj)
EmpathyImportDialogPriv *priv = GET_PRIV (self);
gboolean have_accounts;
- have_accounts = empathy_import_dialog_accounts_to_import ();
+ have_accounts = empathy_import_accounts_to_import ();
if (!have_accounts)
{
diff --git a/src/empathy-import-dialog.h b/src/empathy-import-dialog.h
index 14ab33b47..0e9d225c4 100644
--- a/src/empathy-import-dialog.h
+++ b/src/empathy-import-dialog.h
@@ -42,18 +42,6 @@ G_BEGIN_DECLS
(G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_IMPORT_DIALOG,\
EmpathyImportDialogClass))
-typedef struct
-{
- /* Table mapping CM param string to a GValue */
- GHashTable *settings;
- /* Protocol name */
- gchar *protocol;
- /* Connection manager name */
- gchar *connection_manager;
- /* The name of the account import source */
- gchar *source;
-} EmpathyImportAccountData;
-
typedef struct {
GtkDialog parent;
@@ -70,12 +58,6 @@ GType empathy_import_dialog_get_type (void);
GtkWidget* empathy_import_dialog_new (GtkWindow *parent_window,
gboolean show_warning);
-EmpathyImportAccountData *empathy_import_account_data_new (
- const gchar *source);
-void empathy_import_account_data_free (EmpathyImportAccountData *data);
-
-gboolean empathy_import_dialog_accounts_to_import (void);
-
G_END_DECLS
#endif /* __EMPATHY_IMPORT_DIALOG_H__ */
diff --git a/src/empathy-import-pidgin.c b/src/empathy-import-pidgin.c
index 6a145ff93..23b1d84f5 100644
--- a/src/empathy-import-pidgin.c
+++ b/src/empathy-import-pidgin.c
@@ -32,7 +32,7 @@
#include <telepathy-glib/util.h>
#include <telepathy-glib/dbus.h>
-#include "empathy-import-dialog.h"
+#include "empathy-import-utils.h"
#include "empathy-import-pidgin.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
diff --git a/src/empathy-import-utils.c b/src/empathy-import-utils.c
new file mode 100644
index 000000000..f84b20609
--- /dev/null
+++ b/src/empathy-import-utils.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 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: Jonny Lamb <jonny.lamb@collabora.co.uk>
+ * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
+ */
+
+#include <telepathy-glib/util.h>
+
+#include <libempathy/empathy-utils.h>
+
+#include "empathy-import-utils.h"
+#include "empathy-import-pidgin.h"
+
+EmpathyImportAccountData *
+empathy_import_account_data_new (const gchar *source)
+{
+ EmpathyImportAccountData *data;
+
+ g_return_val_if_fail (!EMP_STR_EMPTY (source), NULL);
+
+ data = g_slice_new0 (EmpathyImportAccountData);
+ data->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ (GDestroyNotify) tp_g_value_slice_free);
+ data->source = g_strdup (source);
+ data->protocol = NULL;
+ data->connection_manager = NULL;
+
+ return data;
+}
+
+void
+empathy_import_account_data_free (EmpathyImportAccountData *data)
+{
+ if (data == NULL)
+ return;
+ if (data->protocol != NULL)
+ g_free (data->protocol);
+ if (data->connection_manager != NULL)
+ g_free (data->connection_manager);
+ if (data->settings != NULL)
+ g_hash_table_destroy (data->settings);
+ if (data->source != NULL)
+ g_free (data->source);
+
+ g_slice_free (EmpathyImportAccountData, data);
+}
+
+gboolean
+empathy_import_accounts_to_import (void)
+{
+ return empathy_import_pidgin_accounts_to_import ();
+}
+
+GList *
+empathy_import_accounts_load (EmpathyImportApplication id)
+{
+ if (id == EMPATHY_IMPORT_APPLICATION_PIDGIN)
+ return empathy_import_pidgin_load ();
+
+ return empathy_import_pidgin_load ();
+}
diff --git a/src/empathy-import-utils.h b/src/empathy-import-utils.h
new file mode 100644
index 000000000..8c971a04d
--- /dev/null
+++ b/src/empathy-import-utils.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 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: Jonny Lamb <jonny.lamb@collabora.co.uk>
+ * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
+ */
+
+#ifndef __EMPATHY_IMPORT_UTILS_H__
+#define __EMPATHY_IMPORT_UTILS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+ /* Table mapping CM param string to a GValue */
+ GHashTable *settings;
+ /* Protocol name */
+ gchar *protocol;
+ /* Connection manager name */
+ gchar *connection_manager;
+ /* The name of the account import source */
+ gchar *source;
+} EmpathyImportAccountData;
+
+typedef enum {
+ EMPATHY_IMPORT_APPLICATION_ALL = 0,
+ EMPATHY_IMPORT_APPLICATION_PIDGIN,
+ EMPATHY_IMPORT_APPLICATION_INVALID
+} EmpathyImportApplication;
+
+EmpathyImportAccountData *empathy_import_account_data_new (
+ const gchar *source);
+void empathy_import_account_data_free (EmpathyImportAccountData *data);
+
+gboolean empathy_import_accounts_to_import (void);
+GList *empathy_import_accounts_load (EmpathyImportApplication id);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_IMPORT_UTILS_H__ */
diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c
index d276c03e5..03117350c 100644
--- a/src/empathy-import-widget.c
+++ b/src/empathy-import-widget.c
@@ -53,11 +53,16 @@ enum
COL_COUNT
};
+enum {
+ PROP_APPLICATION_ID = 1
+};
+
typedef struct {
GtkWidget *vbox;
GtkWidget *treeview;
GList *accounts;
+ EmpathyImportApplication app_id;
EmpathyConnectionManagers *cms;
@@ -322,16 +327,19 @@ import_widget_set_up_account_list (EmpathyImportWidget *self)
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
- /* Source column */
- column = gtk_tree_view_column_new ();
- gtk_tree_view_column_set_title (column, _("Source"));
- gtk_tree_view_column_set_expand (column, TRUE);
- gtk_tree_view_append_column (view, column);
-
- cell = gtk_cell_renderer_text_new ();
- g_object_set (cell, "editable", FALSE, NULL);
- gtk_tree_view_column_pack_start (column, cell, TRUE);
- gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE);
+ if (priv->app_id == EMPATHY_IMPORT_APPLICATION_ALL)
+ {
+ /* Source column */
+ column = gtk_tree_view_column_new ();
+ gtk_tree_view_column_set_title (column, _("Source"));
+ gtk_tree_view_column_set_expand (column, TRUE);
+ gtk_tree_view_append_column (view, column);
+
+ cell = gtk_cell_renderer_text_new ();
+ g_object_set (cell, "editable", FALSE, NULL);
+ gtk_tree_view_column_pack_start (column, cell, TRUE);
+ gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE);
+ }
import_widget_add_accounts_to_model (self);
}
@@ -353,6 +361,42 @@ import_widget_destroy_cb (GtkWidget *w,
}
static void
+do_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyImportWidgetPriv *priv = GET_PRIV (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION_ID:
+ g_value_set_int (value, priv->app_id);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+do_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyImportWidgetPriv *priv = GET_PRIV (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION_ID:
+ priv->app_id = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
do_finalize (GObject *obj)
{
EmpathyImportWidgetPriv *priv = GET_PRIV (obj);
@@ -393,6 +437,8 @@ do_constructed (GObject *obj)
GtkBuilder *gui;
gchar *filename;
+ priv->accounts = empathy_import_accounts_load (priv->app_id);
+
filename = empathy_file_lookup ("empathy-import-dialog.ui", "src");
gui = empathy_builder_get_file (filename,
"widget_vbox", &priv->vbox,
@@ -416,10 +462,19 @@ static void
empathy_import_widget_class_init (EmpathyImportWidgetClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GParamSpec *param_spec;
oclass->constructed = do_constructed;
oclass->finalize = do_finalize;
oclass->dispose = do_dispose;
+ oclass->set_property = do_set_property;
+ oclass->get_property = do_get_property;
+
+ param_spec = g_param_spec_int ("application-id",
+ "application-id", "The application id to import from",
+ 0, EMPATHY_IMPORT_APPLICATION_INVALID, EMPATHY_IMPORT_APPLICATION_ALL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (oclass, PROP_APPLICATION_ID, param_spec);
g_type_class_add_private (klass, sizeof (EmpathyImportWidgetPriv));
}
@@ -433,16 +488,13 @@ empathy_import_widget_init (EmpathyImportWidget *self)
self->priv = priv;
- /* Load all accounts from all supported applications */
- priv->accounts = empathy_import_pidgin_load ();
-
priv->cms = empathy_connection_managers_dup_singleton ();
}
EmpathyImportWidget *
-empathy_import_widget_new (void)
+empathy_import_widget_new (EmpathyImportApplication id)
{
- return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET, NULL);
+ return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET, "application-id", id, NULL);
}
GtkWidget *
diff --git a/src/empathy-import-widget.h b/src/empathy-import-widget.h
index 8af953d79..48f2e1d48 100644
--- a/src/empathy-import-widget.h
+++ b/src/empathy-import-widget.h
@@ -27,6 +27,8 @@
#include <glib-object.h>
+#include "empathy-import-utils.h"
+
G_BEGIN_DECLS
#define EMPATHY_TYPE_IMPORT_WIDGET empathy_import_widget_get_type()
@@ -57,7 +59,7 @@ typedef struct {
GType empathy_import_widget_get_type (void);
-EmpathyImportWidget* empathy_import_widget_new (void);
+EmpathyImportWidget* empathy_import_widget_new (EmpathyImportApplication id);
GtkWidget * empathy_import_widget_get_widget (EmpathyImportWidget *self);