Added menuitem to display the PSPP reference manual.
[pspp-builds.git] / src / ui / gui / helper.c
1 #include <config.h>
2
3 #include <glib.h>
4 #include "helper.h"
5 #include "message-dialog.h"
6 #include <data/data-in.h>
7 #include <data/data-out.h>
8 #include <libpspp/message.h>
9
10 #include <libpspp/i18n.h>
11
12 #include <ctype.h>
13 #include <string.h>
14 #include <data/settings.h>
15
16
17 #include <gettext.h>
18
19 /* Formats a value according to FORMAT
20    The returned string must be freed when no longer required */
21 gchar *
22 value_to_text (union value v, struct fmt_spec format)
23 {
24   gchar *s = 0;
25
26   s = g_new (gchar, format.w + 1);
27   data_out (&v, &format, s);
28   s[format.w]='\0';
29   g_strchug (s);
30
31   return s;
32 }
33
34
35
36 gboolean
37 text_to_value (const gchar *text, union value *v,
38               struct fmt_spec format)
39 {
40   bool ok;
41
42   if ( format.type != FMT_A)
43     {
44       if ( ! text ) return FALSE;
45
46       {
47         const gchar *s = text;
48         while (*s)
49           {
50             if ( !isspace (*s))
51               break;
52             s++;
53           }
54
55         if ( !*s) return FALSE;
56       }
57     }
58
59   msg_disable ();
60   ok = data_in (ss_cstr (text), format.type, 0, 0,
61                 v, fmt_var_width (&format));
62   msg_enable ();
63
64   return ok;
65 }
66
67
68 GtkWidget *
69 get_widget_assert (GladeXML *xml, const gchar *name)
70 {
71   GtkWidget *w;
72   g_assert (xml);
73   g_assert (name);
74
75   w = glade_xml_get_widget (xml, name);
76
77   if ( !w )
78     g_warning ("Widget \"%s\" could not be found\n", name);
79
80   return w;
81 }
82
83 /* Converts a string in the pspp locale to utf-8 */
84 char *
85 pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err)
86 {
87   return recode_string (CONV_PSPP_TO_UTF8, text, len);
88 }
89
90 #define _(msgid) gettext (msgid)
91 #define N_(msgid) msgid
92
93
94 static void
95 give_help (void)
96 {
97   static struct msg m = {
98     MSG_GENERAL,
99     MSG_NOTE,
100     {0, -1},
101     0,
102   };
103
104   if (! m.text)
105     m.text=g_strdup (_("Sorry. The help system hasn't yet been implemented."));
106
107   popup_message (&m);
108 }
109
110 void
111 connect_help (GladeXML *xml)
112 {
113   GList *helps = glade_xml_get_widget_prefix (xml, "help_button_");
114
115   GList *i;
116   for ( i = g_list_first (helps); i ; i = g_list_next (i))
117     g_signal_connect (GTK_WIDGET (i->data), "clicked", give_help, 0);
118 }
119
120
121
122 void
123 reference_manual (GtkMenuItem *menu, gpointer data)
124 {
125   GError *err = NULL;
126   if ( ! g_spawn_command_line_async ("yelp info:pspp", &err) )
127     {
128       msg (ME, _("Cannot open reference manual: %s"), err->message);
129     }
130   g_clear_error (&err);
131 }