aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-12-21 19:19:13 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-12-22 17:46:20 +0800
commit9e63d5fc6b9c74eb9a9961640be621ea2ce6c931 (patch)
tree4c91244f2e71783279f06a5262bdebc6dc5e906d
parentcab7c95744e79a978a230a10782d236d9d9c414f (diff)
downloadgsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.tar
gsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.tar.gz
gsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.tar.bz2
gsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.tar.lz
gsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.tar.xz
gsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.tar.zst
gsoc2013-empathy-9e63d5fc6b9c74eb9a9961640be621ea2ce6c931.zip
add new-account-dialog
This introduces some code duplication with the assistant but it's going to die soon anyway.
-rw-r--r--libempathy-gtk/Makefile.am2
-rw-r--r--libempathy-gtk/empathy-new-account-dialog.c212
-rw-r--r--libempathy-gtk/empathy-new-account-dialog.h59
3 files changed, 273 insertions, 0 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index 8bcbd3c4b..f511d46a4 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -68,6 +68,7 @@ libempathy_gtk_handwritten_source = \
empathy-irc-network-chooser-dialog.c \
empathy-irc-network-dialog.c \
empathy-log-window.c \
+ empathy-new-account-dialog.c \
empathy-new-message-dialog.c \
empathy-new-call-dialog.c \
empathy-notify-manager.c \
@@ -137,6 +138,7 @@ libempathy_gtk_headers = \
empathy-irc-network-chooser-dialog.h \
empathy-irc-network-dialog.h \
empathy-log-window.h \
+ empathy-new-account-dialog.h \
empathy-new-message-dialog.h \
empathy-new-call-dialog.h \
empathy-notify-manager.h \
diff --git a/libempathy-gtk/empathy-new-account-dialog.c b/libempathy-gtk/empathy-new-account-dialog.c
new file mode 100644
index 000000000..cab22ea4d
--- /dev/null
+++ b/libempathy-gtk/empathy-new-account-dialog.c
@@ -0,0 +1,212 @@
+/*
+ * empathy-new-account-dialog.c - Source for EmpathyNewAccountDialog
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "empathy-new-account-dialog.h"
+
+#include <glib/gi18n-lib.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
+#include <libempathy/empathy-debug.h>
+
+#include <libempathy-gtk/empathy-account-widget.h>
+#include <libempathy-gtk/empathy-protocol-chooser.h>
+
+G_DEFINE_TYPE (EmpathyNewAccountDialog, empathy_new_account_dialog, \
+ GTK_TYPE_DIALOG)
+
+struct _EmpathyNewAccountDialogPrivate
+{
+ GtkWidget *chooser;
+ GtkWidget *current_account_widget;
+ GtkWidget *main_vbox;
+ GtkWidget *connect_button;
+
+ EmpathyAccountWidget *current_widget_object;
+ EmpathyAccountSettings *settings;
+};
+
+static void
+account_created_cb (EmpathyAccountWidget *widget,
+ TpAccount *account,
+ EmpathyNewAccountDialog *self)
+{
+ gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
+}
+
+static void
+cancelled_cb (EmpathyAccountWidget *widget,
+ EmpathyNewAccountDialog *self)
+{
+ gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
+}
+
+static void
+protocol_changed_cb (GtkComboBox *chooser,
+ EmpathyNewAccountDialog *self)
+{
+ EmpathyAccountSettings *settings;
+ GtkWidget *account_widget;
+ EmpathyAccountWidget *widget_object;
+ gchar *password = NULL, *account = NULL;
+
+ settings = empathy_protocol_chooser_create_account_settings (
+ EMPATHY_PROTOCOL_CHOOSER (chooser));
+
+ if (settings == NULL)
+ return;
+
+ /* Save "account" and "password" parameters */
+ if (self->priv->settings != NULL)
+ {
+ account = g_strdup (empathy_account_settings_get_string (
+ self->priv->settings, "account"));
+
+ password = g_strdup (empathy_account_settings_get_string (
+ self->priv->settings, "password"));
+
+ g_object_unref (self->priv->settings);
+ }
+
+ widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
+ account_widget = empathy_account_widget_get_widget (widget_object);
+
+ if (self->priv->current_account_widget != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (self->priv->current_widget_object,
+ account_created_cb, self);
+ g_signal_handlers_disconnect_by_func (self->priv->current_widget_object,
+ cancelled_cb, self);
+
+ gtk_widget_destroy (self->priv->current_account_widget);
+ }
+
+ self->priv->current_account_widget = account_widget;
+ self->priv->current_widget_object = widget_object;
+
+ self->priv->settings = settings;
+
+ g_signal_connect (self->priv->current_widget_object, "account-created",
+ G_CALLBACK (account_created_cb), self);
+ g_signal_connect (self->priv->current_widget_object, "cancelled",
+ G_CALLBACK (cancelled_cb), self);
+
+ /* Restore "account" and "password" parameters in the new widget */
+ if (account != NULL)
+ {
+ empathy_account_widget_set_account_param (widget_object, account);
+ g_free (account);
+ }
+
+ if (password != NULL)
+ {
+ empathy_account_widget_set_password_param (widget_object, password);
+ g_free (password);
+ }
+
+ gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), account_widget,
+ FALSE, FALSE, 0);
+ gtk_widget_show (account_widget);
+}
+
+static void
+empathy_new_account_dialog_init (EmpathyNewAccountDialog *self)
+{
+ GtkWidget *w, *hbox, *content;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialogPrivate);
+
+ self->priv->main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (self->priv->main_vbox), 12);
+ gtk_widget_show (self->priv->main_vbox);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
+ w = gtk_label_new (_("What kind of chat account do you have?"));
+ gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+
+ w = gtk_alignment_new (0, 0, 0, 0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
+ gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), w, FALSE, FALSE, 0);
+ gtk_widget_show (w);
+
+ self->priv->chooser = empathy_protocol_chooser_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), self->priv->chooser, FALSE, FALSE, 0);
+ gtk_widget_show (self->priv->chooser);
+
+ content = gtk_dialog_get_content_area (GTK_DIALOG (self));
+ gtk_container_add (GTK_CONTAINER (content), self->priv->main_vbox);
+
+ g_signal_connect (self->priv->chooser, "changed",
+ G_CALLBACK (protocol_changed_cb), self);
+
+ /* trigger show the first account widget */
+ protocol_changed_cb (GTK_COMBO_BOX (self->priv->chooser), self);
+
+ gtk_window_set_title (GTK_WINDOW (self), _("Adding new account"));
+}
+
+static void
+empathy_new_account_dialog_dispose (GObject *object)
+{
+ EmpathyNewAccountDialog *self = (EmpathyNewAccountDialog *) object;
+
+ g_clear_object (&self->priv->settings);
+
+ G_OBJECT_CLASS (empathy_new_account_dialog_parent_class)->dispose (object);
+}
+
+static void
+empathy_new_account_dialog_class_init (EmpathyNewAccountDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = empathy_new_account_dialog_dispose;
+
+ g_type_class_add_private (object_class,
+ sizeof (EmpathyNewAccountDialogPrivate));
+}
+
+GtkWidget *
+empathy_new_account_dialog_new (GtkWindow *parent)
+{
+ GtkWidget *result;
+
+ g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
+
+ result = g_object_new (EMPATHY_TYPE_NEW_ACCOUNT_DIALOG,
+ "modal", TRUE,
+ "destroy-with-parent", TRUE,
+ NULL);
+
+ if (parent != NULL)
+ gtk_window_set_transient_for (GTK_WINDOW (result), parent);
+
+ return result;
+}
+
+EmpathyAccountSettings *
+empathy_new_account_dialog_get_settings (EmpathyNewAccountDialog *self)
+{
+ return self->priv->settings;
+}
diff --git a/libempathy-gtk/empathy-new-account-dialog.h b/libempathy-gtk/empathy-new-account-dialog.h
new file mode 100644
index 000000000..07fc22f98
--- /dev/null
+++ b/libempathy-gtk/empathy-new-account-dialog.h
@@ -0,0 +1,59 @@
+/*
+ * empathy-new-account-dialog.h - Source for EmpathyNewAccountDialog
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ___EMPATHY_NEW_ACCOUNT_DIALOG_H__
+#define ___EMPATHY_NEW_ACCOUNT_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+#include <libempathy/empathy-account-settings.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_NEW_ACCOUNT_DIALOG (empathy_new_account_dialog_get_type ())
+#define EMPATHY_NEW_ACCOUNT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialog))
+#define EMPATHY_NEW_ACCOUNT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialogClass))
+#define EMPATHY_IS_NEW_ACCOUNT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_NEW_ACCOUNT_DIALOG))
+#define EMPATHY_IS_NEW_ACCOUNT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_NEW_ACCOUNT_DIALOG))
+#define EMPATHY_NEW_ACCOUNT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialogClass))
+
+typedef struct _EmpathyNewAccountDialog EmpathyNewAccountDialog;
+typedef struct _EmpathyNewAccountDialogClass EmpathyNewAccountDialogClass;
+typedef struct _EmpathyNewAccountDialogPrivate EmpathyNewAccountDialogPrivate;
+
+struct _EmpathyNewAccountDialog {
+ GtkDialog parent;
+
+ EmpathyNewAccountDialogPrivate *priv;
+};
+
+struct _EmpathyNewAccountDialogClass {
+ GtkDialogClass parent_class;
+};
+
+GType empathy_new_account_dialog_get_type (void) G_GNUC_CONST;
+
+GtkWidget * empathy_new_account_dialog_new (GtkWindow *parent);
+
+EmpathyAccountSettings * empathy_new_account_dialog_get_settings (
+ EmpathyNewAccountDialog *self);
+
+G_END_DECLS
+
+#endif /* ___EMPATHY_NEW_ACCOUNT_DIALOG_H__ */