mock-pkcs11: use g_hash_table_unref()
[nijm-empathy.git] / libempathy-gtk / empathy-new-account-dialog.c
blob1d87e21effcabf780d2554140dad5dc61a17188f
1 /*
2 * empathy-new-account-dialog.c - Source for EmpathyNewAccountDialog
4 * Copyright (C) 2011 - Collabora Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with This library. If not, see <http://www.gnu.org/licenses/>.
20 #include "config.h"
21 #include "empathy-new-account-dialog.h"
23 #include <glib/gi18n-lib.h>
24 #include <tp-account-widgets/tpaw-account-widget.h>
26 #include "empathy-protocol-chooser.h"
28 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
29 #include "empathy-debug.h"
31 G_DEFINE_TYPE (EmpathyNewAccountDialog, empathy_new_account_dialog, \
32 GTK_TYPE_DIALOG)
34 struct _EmpathyNewAccountDialogPrivate
36 GtkWidget *chooser;
37 TpawAccountWidget *current_account_widget;
38 GtkWidget *main_vbox;
39 GtkWidget *connect_button;
41 TpawAccountSettings *settings;
44 static void
45 close_cb (TpawAccountWidget *widget,
46 GtkResponseType response,
47 EmpathyNewAccountDialog *self)
49 gtk_dialog_response (GTK_DIALOG (self), response);
52 static void
53 protocol_changed_cb (GtkComboBox *chooser,
54 EmpathyNewAccountDialog *self)
56 TpawAccountSettings *settings;
57 TpawAccountWidget *account_widget;
58 gchar *password = NULL, *account = NULL;
60 settings = empathy_protocol_chooser_create_account_settings (
61 EMPATHY_PROTOCOL_CHOOSER (chooser));
63 if (settings == NULL)
64 return;
66 /* Save "account" and "password" parameters */
67 if (self->priv->settings != NULL)
69 account = tpaw_account_settings_dup_string (
70 self->priv->settings, "account");
72 password = tpaw_account_settings_dup_string (
73 self->priv->settings, "password");
75 g_object_unref (self->priv->settings);
78 account_widget = tpaw_account_widget_new_for_protocol (settings,
79 NULL, TRUE);
81 if (self->priv->current_account_widget != NULL)
83 g_signal_handlers_disconnect_by_func (self->priv->current_account_widget,
84 close_cb, self);
86 gtk_widget_destroy (GTK_WIDGET (self->priv->current_account_widget));
89 self->priv->current_account_widget = account_widget;
91 self->priv->settings = settings;
93 g_signal_connect (self->priv->current_account_widget, "close",
94 G_CALLBACK (close_cb), self);
96 /* Restore "account" and "password" parameters in the new widget */
97 if (account != NULL)
99 tpaw_account_widget_set_account_param (account_widget, account);
100 g_free (account);
103 if (password != NULL)
105 tpaw_account_widget_set_password_param (account_widget, password);
106 g_free (password);
109 gtk_box_pack_start (GTK_BOX (self->priv->main_vbox),
110 GTK_WIDGET (account_widget), FALSE, FALSE, 0);
111 gtk_widget_show (GTK_WIDGET (account_widget));
114 static void
115 empathy_new_account_dialog_init (EmpathyNewAccountDialog *self)
117 GtkWidget *w, *hbox, *content;
119 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
120 EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialogPrivate);
122 self->priv->main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
123 gtk_container_set_border_width (GTK_CONTAINER (self->priv->main_vbox), 12);
124 gtk_widget_show (self->priv->main_vbox);
126 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
127 gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), hbox, FALSE, FALSE, 0);
128 gtk_widget_show (hbox);
130 w = gtk_label_new (_("What kind of chat account do you have?"));
131 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
132 gtk_widget_show (w);
134 w = gtk_alignment_new (0, 0, 0, 0);
135 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
136 gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), w, FALSE, FALSE, 0);
137 gtk_widget_show (w);
139 self->priv->chooser = empathy_protocol_chooser_new ();
140 gtk_box_pack_start (GTK_BOX (hbox), self->priv->chooser, FALSE, FALSE, 0);
141 gtk_widget_show (self->priv->chooser);
143 content = gtk_dialog_get_content_area (GTK_DIALOG (self));
144 gtk_container_add (GTK_CONTAINER (content), self->priv->main_vbox);
146 g_signal_connect (self->priv->chooser, "changed",
147 G_CALLBACK (protocol_changed_cb), self);
149 /* trigger show the first account widget */
150 protocol_changed_cb (GTK_COMBO_BOX (self->priv->chooser), self);
152 gtk_window_set_title (GTK_WINDOW (self), _("Add new account"));
155 static void
156 empathy_new_account_dialog_dispose (GObject *object)
158 EmpathyNewAccountDialog *self = (EmpathyNewAccountDialog *) object;
160 g_clear_object (&self->priv->settings);
162 G_OBJECT_CLASS (empathy_new_account_dialog_parent_class)->dispose (object);
165 static void
166 empathy_new_account_dialog_class_init (EmpathyNewAccountDialogClass *klass)
168 GObjectClass *object_class = G_OBJECT_CLASS (klass);
170 object_class->dispose = empathy_new_account_dialog_dispose;
172 g_type_class_add_private (object_class,
173 sizeof (EmpathyNewAccountDialogPrivate));
176 GtkWidget *
177 empathy_new_account_dialog_new (GtkWindow *parent)
179 GtkWidget *result;
181 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
183 result = g_object_new (EMPATHY_TYPE_NEW_ACCOUNT_DIALOG,
184 "modal", TRUE,
185 "destroy-with-parent", TRUE,
186 NULL);
188 if (parent != NULL)
189 gtk_window_set_transient_for (GTK_WINDOW (result), parent);
191 return result;
194 TpawAccountSettings *
195 empathy_new_account_dialog_get_settings (EmpathyNewAccountDialog *self)
197 return self->priv->settings;