X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fhelper.c;h=c70f8f7c215b15cb31b636c1e10b3bd53be416c6;hb=8ef8acb7c70a321963d30f2264e8f91e16427fcf;hp=cd63c4a68a6ffef42ef6e60782922c02963c06f4;hpb=b48a20de787a6374000174949dcd8f9666ecc51c;p=pspp-builds.git diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index cd63c4a6..c70f8f7c 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007 Free Software Foundation + Copyright (C) 2007, 2009 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -120,7 +120,7 @@ builder_new_real (const gchar *name) GObject * -get_object_assert (GtkBuilder *builder, const gchar *name) +get_object_assert (GtkBuilder *builder, const gchar *name, GType type) { GObject *o = NULL; g_assert (name); @@ -130,36 +130,54 @@ get_object_assert (GtkBuilder *builder, const gchar *name) if ( !o ) g_critical ("Object \"%s\" could not be found\n", name); + if ( ! g_type_is_a (G_OBJECT_TYPE (o), type)) + { + g_critical ("Object \"%s\" was expected to have type %s, but in fact has type %s", + name, g_type_name (type), G_OBJECT_TYPE_NAME (o)); + } + return o; } + +GtkAction * +get_action_assert (GtkBuilder *builder, const gchar *name) +{ + return GTK_ACTION (get_object_assert (builder, name, GTK_TYPE_ACTION)); +} + GtkWidget * -get_widget_assert (gpointer x, const gchar *name) +get_widget_assert (GtkBuilder *builder, const gchar *name) { - GObject *obj = G_OBJECT (x); - GtkWidget *w = NULL; - g_assert (name); + return GTK_WIDGET (get_object_assert (builder, name, GTK_TYPE_WIDGET)); +} - if (GTK_IS_BUILDER (obj)) - w = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (obj), name)); +/* This function must be used whenever a filename generated by glib, + (eg, from gtk_file_chooser_get_filename) and passed to the C library, + (eg through a pspp syntax string). +*/ +gchar * +convert_glib_filename_to_system_filename (const gchar *fname, GError **err) +{ + gchar *output_name; - if (GLADE_IS_XML (obj)) - w = glade_xml_get_widget (GLADE_XML (obj), name); +#ifdef G_OS_WIN32 + const gchar *target_encoding; + gchar *utf8_name = NULL; - if ( !w ) - g_critical ("Widget \"%s\" could not be found\n", name); + g_get_charset (&target_encoding); - return w; -} + output_name = g_convert (fname, -1, target_encoding, + "UTF-8", NULL, NULL, err); +#else + output_name = xstrdup (fname); +#endif -/* Converts a string in the pspp locale to utf-8. - The return value must be freed when no longer required*/ -gchar * -pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err) -{ - return recode_string (CONV_PSPP_TO_UTF8, text, len); + return output_name; } + + #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -180,27 +198,48 @@ give_help (void) } void -connect_help (GladeXML *xml) +connect_help (GtkBuilder *xml) { - GList *helps = glade_xml_get_widget_prefix (xml, "help_button_"); + GSList *helps = gtk_builder_get_objects (xml); + + GSList *i; + for ( i = helps; i ; i = g_slist_next (i)) + { + GObject *o = i->data; + if ( GTK_IS_WIDGET (o) ) + { + gchar *name = NULL; + gchar s[12] = {0}; + g_object_get (o, "name", &name, NULL); - GList *i; - for ( i = g_list_first (helps); i ; i = g_list_next (i)) - g_signal_connect (GTK_WIDGET (i->data), "clicked", give_help, 0); + if ( name) + strncpy (s, name, 11); + s[11] = '\0'; - g_list_free (helps); -} + if ( 0 == strcmp ("help_button", s)) + { + g_signal_connect (o, "clicked", give_help, 0); + } + } + } + + g_slist_free (helps); +} void reference_manual (GtkMenuItem *menu, gpointer data) { GError *err = NULL; - if ( ! g_spawn_command_line_async ("yelp info:pspp", &err) ) + gchar *cmd = g_strdup_printf ("yelp file://%s", relocate (DOCDIR "/pspp.xml")); + + if ( ! g_spawn_command_line_async (cmd, &err) ) { msg (ME, _("Cannot open reference manual: %s"), err->message); } + + g_free (cmd); g_clear_error (&err); }