]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-account-dialog.c
Fix broken nl translation
[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 #include <tp-account-widgets/tpaw-account-widget.h>
25
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   TpawAccountWidget *current_account_widget;
38   GtkWidget *main_vbox;
39   GtkWidget *connect_button;
40
41   TpawAccountSettings *settings;
42 };
43
44 static void
45 close_cb (TpawAccountWidget *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   TpawAccountSettings *settings;
57   TpawAccountWidget *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 = tpaw_account_settings_dup_string (
70             self->priv->settings, "account");
71
72       password = tpaw_account_settings_dup_string (
73             self->priv->settings, "password");
74
75       g_object_unref (self->priv->settings);
76     }
77
78   account_widget = tpaw_account_widget_new_for_protocol (settings,
79       NULL, TRUE);
80
81   if (self->priv->current_account_widget != NULL)
82     {
83       g_signal_handlers_disconnect_by_func (self->priv->current_account_widget,
84           close_cb, self);
85
86       gtk_widget_destroy (GTK_WIDGET (self->priv->current_account_widget));
87     }
88
89   self->priv->current_account_widget = account_widget;
90
91   self->priv->settings = settings;
92
93   g_signal_connect (self->priv->current_account_widget, "close",
94       G_CALLBACK (close_cb), self);
95
96   /* Restore "account" and "password" parameters in the new widget */
97   if (account != NULL)
98     {
99       tpaw_account_widget_set_account_param (account_widget, account);
100       g_free (account);
101     }
102
103   if (password != NULL)
104     {
105       tpaw_account_widget_set_password_param (account_widget, password);
106       g_free (password);
107     }
108
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));
112 }
113
114 static void
115 empathy_new_account_dialog_init (EmpathyNewAccountDialog *self)
116 {
117   GtkWidget *w, *hbox, *content;
118
119   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
120       EMPATHY_TYPE_NEW_ACCOUNT_DIALOG, EmpathyNewAccountDialogPrivate);
121
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);
125
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);
129
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);
133
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);
138
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);
142
143   content = gtk_dialog_get_content_area (GTK_DIALOG (self));
144   gtk_container_add (GTK_CONTAINER (content), self->priv->main_vbox);
145
146   g_signal_connect (self->priv->chooser, "changed",
147       G_CALLBACK (protocol_changed_cb), self);
148
149   /* trigger show the first account widget */
150   protocol_changed_cb (GTK_COMBO_BOX (self->priv->chooser), self);
151
152   gtk_window_set_title (GTK_WINDOW (self), _("Add new account"));
153 }
154
155 static void
156 empathy_new_account_dialog_dispose (GObject *object)
157 {
158   EmpathyNewAccountDialog *self = (EmpathyNewAccountDialog *) object;
159
160   g_clear_object (&self->priv->settings);
161
162   G_OBJECT_CLASS (empathy_new_account_dialog_parent_class)->dispose (object);
163 }
164
165 static void
166 empathy_new_account_dialog_class_init (EmpathyNewAccountDialogClass *klass)
167 {
168   GObjectClass *object_class = G_OBJECT_CLASS (klass);
169
170   object_class->dispose = empathy_new_account_dialog_dispose;
171
172   g_type_class_add_private (object_class,
173       sizeof (EmpathyNewAccountDialogPrivate));
174 }
175
176 GtkWidget *
177 empathy_new_account_dialog_new (GtkWindow *parent)
178 {
179   GtkWidget *result;
180
181   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
182
183   result = g_object_new (EMPATHY_TYPE_NEW_ACCOUNT_DIALOG,
184       "modal", TRUE,
185       "destroy-with-parent", TRUE,
186       NULL);
187
188   if (parent != NULL)
189     gtk_window_set_transient_for (GTK_WINDOW (result), parent);
190
191   return result;
192 }
193
194 TpawAccountSettings *
195 empathy_new_account_dialog_get_settings (EmpathyNewAccountDialog *self)
196 {
197   return self->priv->settings;
198 }