]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-account-dialog.c
GNOME Goal: Update icon names
[empathy.git] / libempathy-gtk / empathy-new-account-dialog.c
1 /*
2  * empathy-new-account-dialog.c - Source for EmpathyNewAccountDialog
3  *
4  * Copyright (C) 2011 - Collabora Ltd.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include "config.h"
21 #include "empathy-new-account-dialog.h"
22
23 #include <glib/gi18n-lib.h>
24
25 #include "empathy-account-widget.h"
26 #include "empathy-protocol-chooser.h"
27
28 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
29 #include "empathy-debug.h"
30
31 G_DEFINE_TYPE (EmpathyNewAccountDialog, empathy_new_account_dialog, \
32     GTK_TYPE_DIALOG)
33
34 struct _EmpathyNewAccountDialogPrivate
35 {
36   GtkWidget *chooser;
37   EmpathyAccountWidget *current_account_widget;
38   GtkWidget *main_vbox;
39   GtkWidget *connect_button;
40
41   EmpathyAccountSettings *settings;
42 };
43
44 static void
45 close_cb (EmpathyAccountWidget *widget,
46     GtkResponseType response,
47     EmpathyNewAccountDialog *self)
48 {
49   gtk_dialog_response (GTK_DIALOG (self), response);
50 }
51
52 static void
53 protocol_changed_cb (GtkComboBox *chooser,
54     EmpathyNewAccountDialog *self)
55 {
56   EmpathyAccountSettings *settings;
57   EmpathyAccountWidget *account_widget;
58   gchar *password = NULL, *account = NULL;
59
60   settings = empathy_protocol_chooser_create_account_settings (
61       EMPATHY_PROTOCOL_CHOOSER (chooser));
62
63   if (settings == NULL)
64     return;
65
66   /* Save "account" and "password" parameters */
67   if (self->priv->settings != NULL)
68     {
69       account = empathy_account_settings_dup_string (
70             self->priv->settings, "account");
71
72       password = empathy_account_settings_dup_string (
73             self->priv->settings, "password");
74
75       g_object_unref (self->priv->settings);
76     }
77
78   account_widget = empathy_account_widget_new_for_protocol (settings, TRUE);
79
80   if (self->priv->current_account_widget != NULL)
81     {
82       g_signal_handlers_disconnect_by_func (self->priv->current_account_widget,
83           close_cb, self);
84
85       gtk_widget_destroy (GTK_WIDGET (self->priv->current_account_widget));
86     }
87
88   self->priv->current_account_widget = account_widget;
89
90   self->priv->settings = settings;
91
92   g_signal_connect (self->priv->current_account_widget, "close",
93       G_CALLBACK (close_cb), self);
94
95   /* Restore "account" and "password" parameters in the new widget */
96   if (account != NULL)
97     {
98       empathy_account_widget_set_account_param (account_widget, account);
99       g_free (account);
100     }
101
102   if (password != NULL)
103     {
104       empathy_account_widget_set_password_param (account_widget, password);
105       g_free (password);
106     }
107
108   gtk_box_pack_start (GTK_BOX (self->priv->main_vbox),
109       GTK_WIDGET (account_widget), FALSE, FALSE, 0);
110   gtk_widget_show (GTK_WIDGET (account_widget));
111 }
112
113 static void
114 empathy_new_account_dialog_init (EmpathyNewAccountDialog *self)
115 {
116   GtkWidget *w, *hbox, *content;
117
118   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
119       EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialogPrivate);
120
121   self->priv->main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
122   gtk_container_set_border_width (GTK_CONTAINER (self->priv->main_vbox), 12);
123   gtk_widget_show (self->priv->main_vbox);
124
125   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
126   gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), hbox, FALSE, FALSE, 0);
127   gtk_widget_show (hbox);
128
129   w = gtk_label_new (_("What kind of chat account do you have?"));
130   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
131   gtk_widget_show (w);
132
133   w = gtk_alignment_new (0, 0, 0, 0);
134   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
135   gtk_box_pack_start (GTK_BOX (self->priv->main_vbox), w, FALSE, FALSE, 0);
136   gtk_widget_show (w);
137
138   self->priv->chooser = empathy_protocol_chooser_new ();
139   gtk_box_pack_start (GTK_BOX (hbox), self->priv->chooser, FALSE, FALSE, 0);
140   gtk_widget_show (self->priv->chooser);
141
142   content = gtk_dialog_get_content_area (GTK_DIALOG (self));
143   gtk_container_add (GTK_CONTAINER (content), self->priv->main_vbox);
144
145   g_signal_connect (self->priv->chooser, "changed",
146       G_CALLBACK (protocol_changed_cb), self);
147
148   /* trigger show the first account widget */
149   protocol_changed_cb (GTK_COMBO_BOX (self->priv->chooser), self);
150
151   gtk_window_set_title (GTK_WINDOW (self), _("Adding new account"));
152 }
153
154 static void
155 empathy_new_account_dialog_dispose (GObject *object)
156 {
157   EmpathyNewAccountDialog *self = (EmpathyNewAccountDialog *) object;
158
159   g_clear_object (&self->priv->settings);
160
161   G_OBJECT_CLASS (empathy_new_account_dialog_parent_class)->dispose (object);
162 }
163
164 static void
165 empathy_new_account_dialog_class_init (EmpathyNewAccountDialogClass *klass)
166 {
167   GObjectClass *object_class = G_OBJECT_CLASS (klass);
168
169   object_class->dispose = empathy_new_account_dialog_dispose;
170
171   g_type_class_add_private (object_class,
172       sizeof (EmpathyNewAccountDialogPrivate));
173 }
174
175 GtkWidget *
176 empathy_new_account_dialog_new (GtkWindow *parent)
177 {
178   GtkWidget *result;
179
180   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
181
182   result = g_object_new (EMPATHY_TYPE_NEW_ACCOUNT_DIALOG,
183       "modal", TRUE,
184       "destroy-with-parent", TRUE,
185       NULL);
186
187   if (parent != NULL)
188     gtk_window_set_transient_for (GTK_WINDOW (result), parent);
189
190   return result;
191 }
192
193 EmpathyAccountSettings *
194 empathy_new_account_dialog_get_settings (EmpathyNewAccountDialog *self)
195 {
196   return self->priv->settings;
197 }