119
129
G_CALLBACK (context_destroyed), swidget);
133
seahorse_widget_constructor (GType type, guint n_props, GObjectConstructParam* props)
135
SeahorseWidget *swidget;
140
gchar *widthkey, *heightkey;
142
obj = G_OBJECT_CLASS (parent_class)->constructor (type, n_props, props);
143
swidget = SEAHORSE_WIDGET (obj);
145
widthkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_width");
146
width = seahorse_gconf_get_integer (widthkey);
148
heightkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_height");
149
height = seahorse_gconf_get_integer (heightkey);
151
if (width != 0 && height != 0) {
152
window = GTK_WINDOW (seahorse_widget_get_toplevel (swidget));
153
gtk_window_resize (window, width, height);
122
162
/* Disconnects callbacks, destroys main window widget,
123
163
* and frees the xml definition and any other data */
311
351
seahorse_widget_show_help (SeahorseWidget *swidget)
353
GError *error = NULL;
354
gchar *document = NULL;
355
GtkWidget *dialog = NULL;
315
357
if (g_str_equal (swidget->name, "key-manager") ||
316
g_str_equal (swidget->name, "keyserver-results"))
317
gnome_help_display_with_doc_id (NULL, PACKAGE, PACKAGE, "introduction", &err);
319
gnome_help_display_with_doc_id (NULL, PACKAGE, PACKAGE, swidget->name, &err);
324
dialog = gtk_message_dialog_new (GTK_WINDOW (seahorse_widget_get_top (swidget)), GTK_DIALOG_MODAL,
325
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
326
_("Could not display help: %s"),
328
g_signal_connect (G_OBJECT (dialog), "response",
329
G_CALLBACK (gtk_widget_destroy), NULL);
358
g_str_equal (swidget->name, "keyserver-results")) {
359
document = g_strdup ("ghelp:" PACKAGE "?introduction");
361
document = g_strdup_printf ("ghelp:" PACKAGE "?%s", swidget->name);
364
if (!g_app_info_launch_default_for_uri (document, NULL, &error)) {
365
dialog = gtk_message_dialog_new (GTK_WINDOW (seahorse_widget_get_toplevel (swidget)),
366
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
367
_("Could not display help: %s"), error->message);
368
g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL);
330
369
gtk_widget_show (dialog);
375
g_error_free (error);
379
seahorse_widget_get_name (SeahorseWidget *swidget)
381
g_return_val_if_fail (SEAHORSE_IS_WIDGET (swidget), NULL);
382
return swidget->name;
336
* seahorse_widget_get_top
386
* seahorse_widget_get_toplevel
337
387
* @swidget: The seahorse widget
339
389
* Return the top level widget in this seahorse widget
407
454
seahorse_widget_destroy (SeahorseWidget *swidget)
457
gchar *widthkey, *heightkey;
409
460
g_return_if_fail (swidget != NULL && SEAHORSE_IS_WIDGET (swidget));
462
/* Save window size */
463
widget = seahorse_widget_get_toplevel (swidget);
464
gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
466
widthkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_width");
467
seahorse_gconf_set_integer (widthkey, width);
469
heightkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_height");
470
seahorse_gconf_set_integer (heightkey, height);
410
476
if (!swidget->destroying) {
411
477
swidget->destroying = TRUE;
412
478
g_object_unref (swidget);
416
/* UI MANAGER CODE ---------------------------------------------------------- */
419
ui_add_widget (GtkUIManager *ui, GtkWidget *widget, SeahorseWidget *swidget)
424
/* We automatically add menus and toolbars */
425
if (GTK_IS_MENU_BAR (widget))
426
name = "menu-placeholder";
428
name = "toolbar-placeholder";
431
/* Find the appropriate position in the glade file */
432
holder = glade_xml_get_widget (swidget->xml, name);
434
gtk_container_add (GTK_CONTAINER (holder), widget);
436
g_warning ("no place holder found for: %s", name);
441
ui_load (SeahorseWidget *swidget)
449
/* Load the menu/toolbar description file */
450
swidget->ui = gtk_ui_manager_new ();
451
path = g_strdup_printf ("%sseahorse-%s.ui", SEAHORSE_GLADEDIR, swidget->name);
452
gtk_ui_manager_add_ui_from_file (swidget->ui, path, &err);
456
g_warning ("couldn't load ui description for '%s': %s", swidget->name, err->message);
461
/* The widgets get added in an idle loop later */
462
g_signal_connect (swidget->ui, "add-widget", G_CALLBACK (ui_add_widget), swidget);
464
/* Attach accelerators to the window */
465
w = glade_xml_get_widget (swidget->xml, swidget->name);
466
if (GTK_IS_WINDOW (w))
467
gtk_window_add_accel_group (GTK_WINDOW (w), gtk_ui_manager_get_accel_group (swidget->ui));
472
cleanup_actions (GtkActionGroup *group)
476
#define ELIPSIS "..."
477
#define ELIPSIS_LEN 3
479
actions = gtk_action_group_list_actions (group);
481
for (l = actions; l; l = g_list_next (l)) {
482
GtkAction *action = GTK_ACTION (l->data);
486
/* Remove the ellipsis from the end of action labels if present */
487
g_object_get (action, "short-label", &label, NULL);
489
len = strlen (label);
490
if (strcmp (ELIPSIS, label + (len - ELIPSIS_LEN)) == 0) {
491
label[len - ELIPSIS_LEN] = 0;
492
g_object_set (action, "short-label", label, NULL);
498
g_list_free (actions);
502
* seahorse_widget_get_ui_widget
503
* @swidget: The #SeahorseWidget.
504
* @path: The path to the widget. See gtk_ui_manager_get_widget
506
* Returns a piece of generated UI. Note this doesn't look in the glade
507
* file but rather looks in the GtkUIManager UI. If no UI has been loaded
508
* then one will be loaded. The UI file has the same name as the glade file
509
* but with a 'ui' extension.
512
seahorse_widget_get_ui_widget (SeahorseWidget *swidget, const gchar *path)
514
g_return_val_if_fail (SEAHORSE_IS_WIDGET (swidget), NULL);
517
g_return_val_if_fail (swidget->ui, NULL);
519
return gtk_ui_manager_get_widget (swidget->ui, path);
523
* seahorse_widget_add_actions
524
* @swidget: The #SeahorseWidget.
525
* @actions: A #GtkActionGroup to add to the UI.
527
* Adds a GtkActionGroup to this widget's GtkUIManager UI. If no UI
528
* has been loaded then one will be loaded. The UI file has the same
529
* name as the glade file but with a 'ui' extension.
532
seahorse_widget_add_actions (SeahorseWidget *swidget, GtkActionGroup *actions)
534
g_return_if_fail (SEAHORSE_IS_WIDGET (swidget));
537
g_return_if_fail (swidget->ui);
539
cleanup_actions (actions);
540
gtk_ui_manager_insert_action_group (swidget->ui, actions, -1);
544
* seahorse_widget_find_actions
545
* @swidget: The #SeahorseWidget.
546
* @name: The name of the action group.
548
* Find an #GtkActionGroup previously added to this widget.
550
* Returns: The action group.
553
seahorse_widget_find_actions (SeahorseWidget *swidget, const gchar *name)
557
g_return_val_if_fail (SEAHORSE_IS_WIDGET (swidget), NULL);
562
for (l = gtk_ui_manager_get_action_groups (swidget->ui); l; l = g_list_next (l)) {
563
if (g_str_equal (gtk_action_group_get_name (GTK_ACTION_GROUP (l->data)), name))
564
return GTK_ACTION_GROUP (l->data);
483
seahorse_widget_connect_glade_signal (SeahorseWidget *swidget, const char *event,
484
GtkCallback callback, gpointer userdata)
486
g_return_if_fail (SEAHORSE_IS_WIDGET (swidget));
487
glade_xml_signal_connect_data (swidget->xml, event, G_CALLBACK (callback), userdata);