1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* e-shell-settings-dialog.c
4 * Copyright (C) 2002 Ximian, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program 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 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Author: Ettore Perazzoli <ettore@ximian.com>
28 #include "e-shell-settings-dialog.h"
30 #include "e-corba-config-page.h"
31 #include <e-util/e-icon-factory.h>
33 #include <bonobo/bonobo-widget.h>
34 #include <bonobo/bonobo-exception.h>
36 #include <bonobo-activation/bonobo-activation.h>
40 struct _EShellSettingsDialogPrivate
{
44 G_DEFINE_TYPE (EShellSettingsDialog
, e_shell_settings_dialog
, E_TYPE_MULTI_CONFIG_DIALOG
)
47 /* FIXME ugly hack to work around that sizing of invisible widgets is broken
51 set_dialog_size (EShellSettingsDialog
*dialog
)
54 PangoContext
*context
;
55 PangoFontMetrics
*metrics
;
58 layout
= gtk_widget_create_pango_layout (GTK_WIDGET (dialog
), "M");
59 context
= pango_layout_get_context (layout
);
60 metrics
= pango_context_get_metrics (context
,
61 gtk_widget_get_style (GTK_WIDGET (dialog
))->font_desc
,
62 pango_context_get_language (context
));
64 pango_layout_get_pixel_size (layout
, &width
, NULL
);
67 height
= PANGO_PIXELS (pango_font_metrics_get_ascent (metrics
)
68 + pango_font_metrics_get_descent (metrics
)) * 30;
70 gtk_window_set_default_size((GtkWindow
*)dialog
, width
, height
);
71 g_object_unref (layout
);
72 pango_font_metrics_unref (metrics
);
82 Bonobo_ActivationProperty
*type
;
84 EConfigPage
*page_widget
;
86 typedef struct _Page Page
;
89 page_new (const char *title
,
90 const char *description
,
92 Bonobo_ActivationProperty
*type
,
94 EConfigPage
*page_widget
)
101 page
= g_new (Page
, 1);
102 page
->title
= g_strdup (title
);
103 page
->description
= g_strdup (description
);
106 page
->priority
= priority
;
107 page
->page_widget
= page_widget
;
113 page_free (Page
*page
)
115 g_free (page
->title
);
116 g_free (page
->description
);
118 if (page
->icon
!= NULL
)
119 g_object_unref (page
->icon
);
125 compare_page_func (const void *a
,
131 page_a
= (const Page
*) a
;
132 page_b
= (const Page
*) b
;
134 if (page_a
->priority
== page_b
->priority
)
135 return strcmp (page_a
->title
, page_b
->title
);
137 return page_a
->priority
- page_b
->priority
;
141 sort_page_list (GList
*list
)
143 return g_list_sort (list
, compare_page_func
);
147 load_pages (EShellSettingsDialog
*dialog
)
149 EShellSettingsDialogPrivate
*priv
;
150 Bonobo_ServerInfoList
*control_list
;
151 CORBA_Environment ev
;
153 GSList
*language_list
;
160 CORBA_exception_init (&ev
);
162 control_list
= bonobo_activation_query ("repo_ids.has('IDL:GNOME/Evolution/ConfigControl:" BASE_VERSION
"')", NULL
, &ev
);
163 if (ev
._major
!= CORBA_NO_EXCEPTION
|| control_list
== NULL
) {
164 g_warning ("Cannot load configuration pages -- %s", BONOBO_EX_REPOID (&ev
));
165 CORBA_exception_free (&ev
);
169 CORBA_exception_free (&ev
);
171 /* Great, one uses GList the other GSList (!) */
172 l
= gnome_i18n_get_language_list("LC_MESSAGES");
173 for (language_list
=NULL
;l
;l
=l
->next
)
174 language_list
= g_slist_append(language_list
, l
->data
);
177 for (i
= 0; i
< control_list
->_length
; i
++) {
178 CORBA_Object corba_object
;
179 Bonobo_ServerInfo
*info
;
181 const char *description
;
182 const char *icon_path
;
183 const char *priority_string
;
184 Bonobo_ActivationProperty
*type
;
188 CORBA_exception_init (&ev
);
190 info
= & control_list
->_buffer
[i
];
192 title
= bonobo_server_info_prop_lookup (info
, "evolution2:config_item:title", language_list
);
193 description
= bonobo_server_info_prop_lookup (info
, "evolution2:config_item:description", language_list
);
194 icon_path
= bonobo_server_info_prop_lookup (info
, "evolution2:config_item:icon_name", NULL
);
195 type
= bonobo_server_info_prop_find (info
, "evolution2:config_item:type");
196 priority_string
= bonobo_server_info_prop_lookup (info
, "evolution2:config_item:priority", NULL
);
198 if (icon_path
== NULL
) {
201 if (g_path_is_absolute (icon_path
)) {
202 icon
= gdk_pixbuf_new_from_file (icon_path
, NULL
);
204 icon
= e_icon_factory_get_icon (icon_path
, E_ICON_SIZE_DIALOG
);
208 if (type
!= NULL
&& type
->v
._d
!= Bonobo_ACTIVATION_P_STRINGV
)
210 if (priority_string
== NULL
)
213 priority
= atoi (priority_string
);
215 corba_object
= bonobo_activation_activate_from_id ((char *) info
->iid
, 0, NULL
, &ev
);
217 if (! BONOBO_EX (&ev
)) {
220 page
= page_new (title
, description
, icon
, type
, priority
,
221 E_CONFIG_PAGE (e_corba_config_page_new_from_objref (corba_object
)));
223 page_list
= g_list_prepend (page_list
, page
);
225 char *bonobo_ex_text
= bonobo_exception_get_text (&ev
);
226 g_warning ("Cannot activate %s -- %s", info
->iid
, bonobo_ex_text
);
227 g_free (bonobo_ex_text
);
231 g_object_unref (icon
);
233 CORBA_exception_free (&ev
);
235 g_slist_free(language_list
);
237 page_list
= sort_page_list (page_list
);
238 for (p
= page_list
, i
= 0; p
!= NULL
; p
= p
->next
, i
++) {
241 page
= (Page
*) p
->data
;
243 e_multi_config_dialog_add_page (E_MULTI_CONFIG_DIALOG (dialog
),
249 if (page
->type
!= NULL
) {
250 Bonobo_StringList list
= page
->type
->v
._u
.value_stringv
;
252 for (j
= 0; j
< list
._length
; j
++) {
253 if (g_hash_table_lookup (priv
->types
, list
._buffer
[j
]) == NULL
)
254 g_hash_table_insert (priv
->types
, g_strdup (list
._buffer
[j
]),
255 GINT_TO_POINTER (i
));
263 g_list_free (page_list
);
264 CORBA_free (control_list
);
268 /* GtkObject methods. */
271 destroy_type_entry (gpointer key
, gpointer value
, gpointer data
)
279 impl_finalize (GObject
*object
)
281 EShellSettingsDialog
*dialog
;
282 EShellSettingsDialogPrivate
*priv
;
284 dialog
= E_SHELL_SETTINGS_DIALOG (object
);
287 g_hash_table_foreach_remove (priv
->types
, destroy_type_entry
, NULL
);
288 g_hash_table_destroy (priv
->types
);
292 (* G_OBJECT_CLASS (e_shell_settings_dialog_parent_class
)->finalize
) (object
);
297 e_shell_settings_dialog_class_init (EShellSettingsDialogClass
*klass
)
299 GObjectClass
*object_class
;
301 object_class
= G_OBJECT_CLASS (klass
);
302 object_class
->finalize
= impl_finalize
;
306 e_shell_settings_dialog_init (EShellSettingsDialog
*dialog
)
308 EShellSettingsDialogPrivate
*priv
;
310 priv
= g_new (EShellSettingsDialogPrivate
, 1);
311 priv
->types
= g_hash_table_new (g_str_hash
, g_str_equal
);
316 set_dialog_size (dialog
);
318 gtk_window_set_title (GTK_WINDOW (dialog
), _("Evolution Settings"));
319 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
324 e_shell_settings_dialog_new ()
326 EShellSettingsDialog
*new;
328 new = g_object_new (e_shell_settings_dialog_get_type (), NULL
);
330 return GTK_WIDGET (new);
334 e_shell_settings_dialog_show_type (EShellSettingsDialog
*dialog
, const char *type
)
336 EShellSettingsDialogPrivate
*priv
;
340 g_return_if_fail (dialog
!= NULL
);
341 g_return_if_fail (E_IS_SHELL_SETTINGS_DIALOG (dialog
));
342 g_return_if_fail (type
!= NULL
);
346 if (!g_hash_table_lookup_extended (priv
->types
, type
, &key
, &value
)) {
347 char *slash
, *supertype
;
349 slash
= strchr (type
, '/');
351 supertype
= g_strndup (type
, slash
- type
);
352 value
= g_hash_table_lookup (priv
->types
, type
);
357 page
= GPOINTER_TO_INT (value
);
359 e_multi_config_dialog_show_page (E_MULTI_CONFIG_DIALOG (dialog
), page
);