Set prgname instead of program_class
[nijm-empathy.git] / src / empathy-import-dialog.c
blob9d86dd1dec4a69044220c6b23f21abaa10f706e4
1 /*
2 * Copyright (C) 2008-2009 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
20 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 #include "config.h"
24 #include "empathy-import-dialog.h"
26 #include <glib/gi18n-lib.h>
28 #include "empathy-import-widget.h"
29 #include "empathy-utils.h"
31 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
32 #include "empathy-debug.h"
34 enum {
35 PROP_PARENT = 1,
36 PROP_SHOW_WARNING,
37 PROP_CMS,
40 typedef struct {
41 GtkWindow *parent_window;
43 EmpathyImportWidget *iw;
45 gboolean show_warning;
46 TpawConnectionManagers *cms;
47 } EmpathyImportDialogPriv;
49 G_DEFINE_TYPE (EmpathyImportDialog, empathy_import_dialog, GTK_TYPE_DIALOG)
50 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportDialog)
52 static void
53 import_dialog_add_import_widget (EmpathyImportDialog *self)
55 EmpathyImportWidget *iw;
56 EmpathyImportDialogPriv *priv = GET_PRIV (self);
57 GtkWidget *widget, *area;
59 area = gtk_dialog_get_content_area (GTK_DIALOG (self));
61 iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL, priv->cms);
62 widget = empathy_import_widget_get_widget (iw);
63 gtk_box_pack_start (GTK_BOX (area), widget, TRUE, TRUE, 0);
64 gtk_widget_show (widget);
66 priv->iw = iw;
68 gtk_dialog_add_buttons (GTK_DIALOG (self),
69 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
70 _("_Import"), GTK_RESPONSE_OK,
71 NULL);
74 static void
75 import_dialog_show_warning_message (EmpathyImportDialog *self)
77 GtkWidget *hbox, *vbox, *w;
79 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
80 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
82 w = gtk_label_new (_("No accounts to import could be found. Empathy "
83 "currently only supports importing accounts from Pidgin."));
84 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
85 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
86 gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.0);
87 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
89 w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
90 GTK_ICON_SIZE_DIALOG);
91 gtk_misc_set_alignment (GTK_MISC (w), 0.5, 0.0);
92 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
94 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
96 w = gtk_dialog_get_content_area (GTK_DIALOG (self));
97 gtk_box_pack_start (GTK_BOX (w), hbox, FALSE, FALSE, 0);
99 gtk_box_set_spacing (GTK_BOX (w), 14); /* 14 + 2 * 5 = 24 */
101 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE,
102 GTK_RESPONSE_CLOSE);
104 gtk_widget_show_all (w);
107 static void
108 impl_signal_response (GtkDialog *dialog,
109 gint response_id)
111 EmpathyImportDialogPriv *priv = GET_PRIV (dialog);
113 if (response_id == GTK_RESPONSE_OK)
114 empathy_import_widget_add_selected_accounts (priv->iw);
116 gtk_widget_destroy (GTK_WIDGET (dialog));
119 static void
120 do_get_property (GObject *object,
121 guint property_id,
122 GValue *value,
123 GParamSpec *pspec)
125 EmpathyImportDialogPriv *priv = GET_PRIV (object);
127 switch (property_id)
129 case PROP_PARENT:
130 g_value_set_object (value, priv->parent_window);
131 break;
132 case PROP_SHOW_WARNING:
133 g_value_set_boolean (value, priv->show_warning);
134 break;
135 case PROP_CMS:
136 g_value_set_object (value, priv->cms);
137 break;
138 default:
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
143 static void
144 do_set_property (GObject *object,
145 guint property_id,
146 const GValue *value,
147 GParamSpec *pspec)
149 EmpathyImportDialogPriv *priv = GET_PRIV (object);
151 switch (property_id)
153 case PROP_PARENT:
154 priv->parent_window = g_value_get_object (value);
155 break;
156 case PROP_SHOW_WARNING:
157 priv->show_warning = g_value_get_boolean (value);
158 break;
159 case PROP_CMS:
160 priv->cms = g_value_dup_object (value);
161 break;
162 default:
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
167 static void
168 do_constructed (GObject *obj)
170 EmpathyImportDialog *self = EMPATHY_IMPORT_DIALOG (obj);
171 EmpathyImportDialogPriv *priv = GET_PRIV (self);
172 gboolean have_accounts;
174 have_accounts = empathy_import_accounts_to_import ();
176 if (!have_accounts)
178 if (priv->show_warning)
180 import_dialog_show_warning_message (self);
182 else
183 DEBUG ("No accounts to import; closing dialog silently.");
185 else
187 import_dialog_add_import_widget (self);
190 if (priv->parent_window)
191 gtk_window_set_transient_for (GTK_WINDOW (self), priv->parent_window);
194 static void
195 empathy_import_dialog_init (EmpathyImportDialog *self)
197 EmpathyImportDialogPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
198 EMPATHY_TYPE_IMPORT_DIALOG, EmpathyImportDialogPriv);
200 self->priv = priv;
202 gtk_container_set_border_width (GTK_CONTAINER (self), 5);
203 gtk_window_set_title (GTK_WINDOW (self), _("Import Accounts"));
204 gtk_window_set_modal (GTK_WINDOW (self), TRUE);
206 static void
207 do_dispose (GObject *obj)
209 EmpathyImportDialogPriv *priv = GET_PRIV (obj);
211 g_clear_object (&priv->cms);
213 G_OBJECT_CLASS (empathy_import_dialog_parent_class)->dispose (obj);
216 static void
217 empathy_import_dialog_class_init (EmpathyImportDialogClass *klass)
219 GObjectClass *oclass = G_OBJECT_CLASS (klass);
220 GtkDialogClass *gtkclass = GTK_DIALOG_CLASS (klass);
221 GParamSpec *param_spec;
223 oclass->constructed = do_constructed;
224 oclass->get_property = do_get_property;
225 oclass->set_property = do_set_property;
226 oclass->dispose = do_dispose;
228 gtkclass->response = impl_signal_response;
230 param_spec = g_param_spec_object ("parent-window",
231 "parent-window", "The parent window",
232 GTK_TYPE_WINDOW,
233 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
234 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
236 param_spec = g_param_spec_boolean ("show-warning",
237 "show-warning", "Whether a warning should be shown when there are no "
238 "sources for importing accounts.",
239 FALSE,
240 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
241 g_object_class_install_property (oclass, PROP_SHOW_WARNING, param_spec);
243 param_spec = g_param_spec_object ("cms",
244 "TpawConnectionManagers", "EmpathyConnectionManager",
245 TPAW_TYPE_CONNECTION_MANAGERS,
246 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
247 g_object_class_install_property (oclass, PROP_CMS, param_spec);
249 g_type_class_add_private (klass, sizeof (EmpathyImportDialogPriv));
252 GtkWidget *
253 empathy_import_dialog_new (GtkWindow *parent,
254 gboolean warning,
255 TpawConnectionManagers *cms)
257 g_return_val_if_fail (TPAW_IS_CONNECTION_MANAGERS (cms), NULL);
259 return g_object_new (EMPATHY_TYPE_IMPORT_DIALOG,
260 "parent-window", parent,
261 "show-warning", warning,
262 "cms", cms,
263 NULL);