Refactor the Help menu.
[pspp-builds.git] / src / ui / gui / help-menu.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2006, 2007, 2010  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
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
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 #include <config.h>
19
20 #include <gtk/gtk.h>
21
22 #include <libpspp/copyleft.h>
23 #include <libpspp/version.h>
24 #include "help-menu.h"
25 #include <libpspp/message.h>
26
27 #include "gl/configmake.h"
28 #include "gl/relocatable.h"
29
30 #include <gettext.h>
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
33
34
35 static const gchar *artists[] = { "Patrick Brunier", "Dondi Bogusky", NULL};
36
37 static void
38 about_new (GtkMenuItem *m, GtkWindow *parent)
39 {
40   GtkWidget *about =  gtk_about_dialog_new ();
41
42   GdkPixbuf *pb =
43     gdk_pixbuf_new_from_file_at_size (relocate (PKGDATADIR "/pspplogo.png"),
44                                       64, 64, 0);
45
46   gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (about), pb);
47
48
49   gtk_window_set_icon_name (GTK_WINDOW (about), "psppicon");
50
51   gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (about),
52                                 "http://www.gnu.org/software/pspp");
53
54   gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about),
55                                 bare_version);
56
57   gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (about),
58                                 (const gchar **) authors);
59
60   gtk_about_dialog_set_artists (GTK_ABOUT_DIALOG (about),
61                                 artists);
62
63   gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (about),
64                                 copyleft);
65
66   gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (about),
67                                  _("A program for the analysis of sampled data"));
68
69   gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (about),
70                                   "Free Software Foundation");
71
72   gtk_about_dialog_set_translator_credits 
73     (
74      GTK_ABOUT_DIALOG (about),
75      /* TRANSLATORS: Use this string to list the people who have helped with
76         translation to your language. */
77      _("translator-credits")
78      );
79
80   gtk_window_set_transient_for (GTK_WINDOW (about), parent);
81
82   gtk_window_set_modal (GTK_WINDOW (about), TRUE);
83
84   gtk_dialog_run (GTK_DIALOG (about));
85
86   gtk_widget_hide (about);
87 }
88
89
90 static void
91 reference_manual (GtkMenuItem *menu, gpointer data)
92 {
93   GError *err = NULL;
94   gchar *cmd = g_strdup_printf ("yelp file://%s", relocate (DOCDIR "/pspp.xml"));
95
96   if ( ! g_spawn_command_line_async (cmd, &err) )
97     {
98       msg (ME, _("Cannot open reference manual: %s.  The PSPP user manual is "
99                  "also available at "
100                  "http://www.gnu.org/software/pspp/documentation.html"),
101            err->message);
102     }
103
104   g_free (cmd);
105   g_clear_error (&err);
106 }
107
108 void
109 merge_help_menu (GtkUIManager *uim)
110 {
111   GtkActionGroup *action_group = gtk_action_group_new ("help");
112
113   static const GtkActionEntry entries[] =
114     {
115       {
116         "help", NULL,                               /* name, stock id */
117         N_("_Help"), NULL,                          /* label, accelerator */
118         NULL,
119         NULL,
120       },
121     
122       {
123         "help_reference", GTK_STOCK_HELP,            /* name, stock id */
124         N_("_Reference Manual"), NULL,               /* label, accelerator */
125         NULL,                                        /* tooltip */
126         G_CALLBACK (reference_manual)
127       },
128     
129       {
130         "help_about", GTK_STOCK_ABOUT,
131         NULL, NULL, NULL,
132         G_CALLBACK (about_new)
133       },
134     };
135
136   gtk_action_group_set_translation_domain (action_group, PACKAGE);
137
138   gtk_ui_manager_add_ui_from_string   (uim, "\
139       <menubar name=\"menubar\">\
140         <menu action=\"help\">\
141           <menuitem action=\"help_reference\"/>\
142           <menuitem action=\"help_about\"/>\
143         </menu>\
144        </menubar>\
145        ", -1, 0);
146
147   gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), NULL);
148
149   gtk_ui_manager_insert_action_group  (uim, action_group, 0);
150 }