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/>.
21 #include "empathy-new-account-dialog.h"
23 #include <glib/gi18n-lib.h>
25 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
26 #include <libempathy/empathy-debug.h>
28 #include <libempathy-gtk/empathy-account-widget.h>
29 #include <libempathy-gtk/empathy-protocol-chooser.h>
31 G_DEFINE_TYPE (EmpathyNewAccountDialog
, empathy_new_account_dialog
, \
34 struct _EmpathyNewAccountDialogPrivate
37 GtkWidget
*current_account_widget
;
39 GtkWidget
*connect_button
;
41 EmpathyAccountWidget
*current_widget_object
;
42 EmpathyAccountSettings
*settings
;
46 account_created_cb (EmpathyAccountWidget
*widget
,
48 EmpathyNewAccountDialog
*self
)
50 gtk_dialog_response (GTK_DIALOG (self
), GTK_RESPONSE_OK
);
54 cancelled_cb (EmpathyAccountWidget
*widget
,
55 EmpathyNewAccountDialog
*self
)
57 gtk_dialog_response (GTK_DIALOG (self
), GTK_RESPONSE_CANCEL
);
61 protocol_changed_cb (GtkComboBox
*chooser
,
62 EmpathyNewAccountDialog
*self
)
64 EmpathyAccountSettings
*settings
;
65 GtkWidget
*account_widget
;
66 EmpathyAccountWidget
*widget_object
;
67 gchar
*password
= NULL
, *account
= NULL
;
69 settings
= empathy_protocol_chooser_create_account_settings (
70 EMPATHY_PROTOCOL_CHOOSER (chooser
));
75 /* Save "account" and "password" parameters */
76 if (self
->priv
->settings
!= NULL
)
78 account
= g_strdup (empathy_account_settings_get_string (
79 self
->priv
->settings
, "account"));
81 password
= g_strdup (empathy_account_settings_get_string (
82 self
->priv
->settings
, "password"));
84 g_object_unref (self
->priv
->settings
);
87 widget_object
= empathy_account_widget_new_for_protocol (settings
, TRUE
);
88 account_widget
= empathy_account_widget_get_widget (widget_object
);
90 if (self
->priv
->current_account_widget
!= NULL
)
92 g_signal_handlers_disconnect_by_func (self
->priv
->current_widget_object
,
93 account_created_cb
, self
);
94 g_signal_handlers_disconnect_by_func (self
->priv
->current_widget_object
,
97 gtk_widget_destroy (self
->priv
->current_account_widget
);
100 self
->priv
->current_account_widget
= account_widget
;
101 self
->priv
->current_widget_object
= widget_object
;
103 self
->priv
->settings
= settings
;
105 g_signal_connect (self
->priv
->current_widget_object
, "account-created",
106 G_CALLBACK (account_created_cb
), self
);
107 g_signal_connect (self
->priv
->current_widget_object
, "cancelled",
108 G_CALLBACK (cancelled_cb
), self
);
110 /* Restore "account" and "password" parameters in the new widget */
113 empathy_account_widget_set_account_param (widget_object
, account
);
117 if (password
!= NULL
)
119 empathy_account_widget_set_password_param (widget_object
, password
);
123 gtk_box_pack_start (GTK_BOX (self
->priv
->main_vbox
), account_widget
,
125 gtk_widget_show (account_widget
);
129 empathy_new_account_dialog_init (EmpathyNewAccountDialog
*self
)
131 GtkWidget
*w
, *hbox
, *content
;
133 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
134 EMPATHY_TYPE_NEW_ACCOUNT_DIALOG
, EmpathyNewAccountDialogPrivate
);
136 self
->priv
->main_vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 12);
137 gtk_container_set_border_width (GTK_CONTAINER (self
->priv
->main_vbox
), 12);
138 gtk_widget_show (self
->priv
->main_vbox
);
140 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 6);
141 gtk_box_pack_start (GTK_BOX (self
->priv
->main_vbox
), hbox
, FALSE
, FALSE
, 0);
142 gtk_widget_show (hbox
);
144 w
= gtk_label_new (_("What kind of chat account do you have?"));
145 gtk_box_pack_start (GTK_BOX (hbox
), w
, FALSE
, FALSE
, 0);
148 w
= gtk_alignment_new (0, 0, 0, 0);
149 gtk_alignment_set_padding (GTK_ALIGNMENT (w
), 0, 0, 12, 0);
150 gtk_box_pack_start (GTK_BOX (self
->priv
->main_vbox
), w
, FALSE
, FALSE
, 0);
153 self
->priv
->chooser
= empathy_protocol_chooser_new ();
154 gtk_box_pack_start (GTK_BOX (hbox
), self
->priv
->chooser
, FALSE
, FALSE
, 0);
155 gtk_widget_show (self
->priv
->chooser
);
157 content
= gtk_dialog_get_content_area (GTK_DIALOG (self
));
158 gtk_container_add (GTK_CONTAINER (content
), self
->priv
->main_vbox
);
160 g_signal_connect (self
->priv
->chooser
, "changed",
161 G_CALLBACK (protocol_changed_cb
), self
);
163 /* trigger show the first account widget */
164 protocol_changed_cb (GTK_COMBO_BOX (self
->priv
->chooser
), self
);
166 gtk_window_set_title (GTK_WINDOW (self
), _("Adding new account"));
170 empathy_new_account_dialog_dispose (GObject
*object
)
172 EmpathyNewAccountDialog
*self
= (EmpathyNewAccountDialog
*) object
;
174 g_clear_object (&self
->priv
->settings
);
176 G_OBJECT_CLASS (empathy_new_account_dialog_parent_class
)->dispose (object
);
180 empathy_new_account_dialog_class_init (EmpathyNewAccountDialogClass
*klass
)
182 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
184 object_class
->dispose
= empathy_new_account_dialog_dispose
;
186 g_type_class_add_private (object_class
,
187 sizeof (EmpathyNewAccountDialogPrivate
));
191 empathy_new_account_dialog_new (GtkWindow
*parent
)
195 g_return_val_if_fail (parent
== NULL
|| GTK_IS_WINDOW (parent
), NULL
);
197 result
= g_object_new (EMPATHY_TYPE_NEW_ACCOUNT_DIALOG
,
199 "destroy-with-parent", TRUE
,
203 gtk_window_set_transient_for (GTK_WINDOW (result
), parent
);
208 EmpathyAccountSettings
*
209 empathy_new_account_dialog_get_settings (EmpathyNewAccountDialog
*self
)
211 return self
->priv
->settings
;