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>
27 #include <glib/gi18n.h>
29 #include <telepathy-glib/util.h>
31 #include "empathy-import-dialog.h"
32 #include "empathy-import-pidgin.h"
33 #include "empathy-import-widget.h"
35 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
36 #include <libempathy/empathy-debug.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
46 GtkWindow
*parent_window
;
48 EmpathyImportWidget
*iw
;
50 gboolean show_warning
;
51 } EmpathyImportDialogPriv
;
53 G_DEFINE_TYPE (EmpathyImportDialog
, empathy_import_dialog
, GTK_TYPE_DIALOG
)
54 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyImportDialog)
57 import_dialog_add_import_widget (EmpathyImportDialog
*self
)
59 EmpathyImportWidget
*iw
;
60 EmpathyImportDialogPriv
*priv
= GET_PRIV (self
);
61 GtkWidget
*widget
, *area
;
63 area
= gtk_dialog_get_content_area (GTK_DIALOG (self
));
65 iw
= empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL
);
66 widget
= empathy_import_widget_get_widget (iw
);
67 gtk_box_pack_start (GTK_BOX (area
), widget
, FALSE
, FALSE
, 0);
68 gtk_widget_show (widget
);
72 gtk_dialog_add_buttons (GTK_DIALOG (self
), GTK_STOCK_CANCEL
,
73 GTK_RESPONSE_CANCEL
, GTK_STOCK_OK
, GTK_RESPONSE_OK
, NULL
);
77 import_dialog_show_warning_message (EmpathyImportDialog
*self
)
79 GtkWidget
*hbox
, *vbox
, *w
;
81 vbox
= gtk_vbox_new (FALSE
, 12);
82 hbox
= gtk_hbox_new (FALSE
, 12);
84 w
= gtk_label_new (_("No accounts to import could be found. Empathy "
85 "currently only supports importing accounts from Pidgin."));
86 gtk_label_set_line_wrap (GTK_LABEL (w
), TRUE
);
87 gtk_label_set_selectable (GTK_LABEL (w
), TRUE
);
88 gtk_misc_set_alignment (GTK_MISC (w
), 0.0, 0.0);
89 gtk_box_pack_start (GTK_BOX (vbox
), w
, FALSE
, FALSE
, 0);
91 w
= gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING
,
92 GTK_ICON_SIZE_DIALOG
);
93 gtk_misc_set_alignment (GTK_MISC (w
), 0.5, 0.0);
94 gtk_box_pack_start (GTK_BOX (hbox
), w
, FALSE
, FALSE
, 0);
96 gtk_box_pack_start (GTK_BOX (hbox
), vbox
, TRUE
, TRUE
, 0);
98 w
= gtk_dialog_get_content_area (GTK_DIALOG (self
));
99 gtk_box_pack_start (GTK_BOX (w
), hbox
, FALSE
, FALSE
, 0);
101 gtk_box_set_spacing (GTK_BOX (w
), 14); /* 14 + 2 * 5 = 24 */
103 gtk_dialog_add_button (GTK_DIALOG (self
), GTK_STOCK_CLOSE
,
106 gtk_widget_show_all (w
);
110 impl_signal_response (GtkDialog
*dialog
,
113 EmpathyImportDialogPriv
*priv
= GET_PRIV (dialog
);
115 if (response_id
== GTK_RESPONSE_OK
)
116 empathy_import_widget_add_selected_accounts (priv
->iw
);
118 gtk_widget_destroy (GTK_WIDGET (dialog
));
122 do_get_property (GObject
*object
,
127 EmpathyImportDialogPriv
*priv
= GET_PRIV (object
);
132 g_value_set_object (value
, priv
->parent_window
);
134 case PROP_SHOW_WARNING
:
135 g_value_set_boolean (value
, priv
->show_warning
);
138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
143 do_set_property (GObject
*object
,
148 EmpathyImportDialogPriv
*priv
= GET_PRIV (object
);
153 priv
->parent_window
= g_value_get_object (value
);
155 case PROP_SHOW_WARNING
:
156 priv
->show_warning
= g_value_get_boolean (value
);
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
164 do_constructed (GObject
*obj
)
166 EmpathyImportDialog
*self
= EMPATHY_IMPORT_DIALOG (obj
);
167 EmpathyImportDialogPriv
*priv
= GET_PRIV (self
);
168 gboolean have_accounts
;
170 have_accounts
= empathy_import_accounts_to_import ();
174 if (priv
->show_warning
)
176 import_dialog_show_warning_message (self
);
179 DEBUG ("No accounts to import; closing dialog silently.");
183 import_dialog_add_import_widget (self
);
186 if (priv
->parent_window
)
187 gtk_window_set_transient_for (GTK_WINDOW (self
), priv
->parent_window
);
191 empathy_import_dialog_init (EmpathyImportDialog
*self
)
193 EmpathyImportDialogPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
194 EMPATHY_TYPE_IMPORT_DIALOG
, EmpathyImportDialogPriv
);
198 gtk_container_set_border_width (GTK_CONTAINER (self
), 5);
199 gtk_window_set_title (GTK_WINDOW (self
), _("Import Accounts"));
200 gtk_window_set_modal (GTK_WINDOW (self
), TRUE
);
201 gtk_dialog_set_has_separator (GTK_DIALOG (self
), FALSE
);
205 empathy_import_dialog_class_init (EmpathyImportDialogClass
*klass
)
207 GObjectClass
*oclass
= G_OBJECT_CLASS (klass
);
208 GtkDialogClass
*gtkclass
= GTK_DIALOG_CLASS (klass
);
209 GParamSpec
*param_spec
;
211 oclass
->constructed
= do_constructed
;
212 oclass
->get_property
= do_get_property
;
213 oclass
->set_property
= do_set_property
;
215 gtkclass
->response
= impl_signal_response
;
217 param_spec
= g_param_spec_object ("parent-window",
218 "parent-window", "The parent window",
220 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
221 g_object_class_install_property (oclass
, PROP_PARENT
, param_spec
);
223 param_spec
= g_param_spec_boolean ("show-warning",
224 "show-warning", "Whether a warning should be shown when there are no "
225 "sources for importing accounts.",
227 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
228 g_object_class_install_property (oclass
, PROP_SHOW_WARNING
, param_spec
);
230 g_type_class_add_private (klass
, sizeof (EmpathyImportDialogPriv
));
234 empathy_import_dialog_new (GtkWindow
*parent
,
237 return g_object_new (EMPATHY_TYPE_IMPORT_DIALOG
, "parent-window",
238 parent
, "show-warning", warning
, NULL
);