e670c0b555b5b80f0ab5110dff05474d950408fb
[pspp] / src / ui / gui / help-menu.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013  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[] = { "Bastián Díaz", "Hugo Alejandro", NULL};
36
37 static void
38 about_new (GtkMenuItem *m, GtkWindow *parent)
39 {
40   GtkWidget *about =  gtk_about_dialog_new ();
41
42   gtk_about_dialog_set_logo_icon_name (GTK_ABOUT_DIALOG (about), "pspp");
43
44   gtk_window_set_icon_name (GTK_WINDOW (about), "pspp");
45
46   gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (about), PACKAGE_URL);
47
48   gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about),
49                                 bare_version);
50
51   gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (about),
52                                 (const gchar **) authors);
53
54   gtk_about_dialog_set_artists (GTK_ABOUT_DIALOG (about),
55                                 artists);
56
57   gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (about),
58                                 copyleft);
59
60   gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (about),
61                                  _("A program for the analysis of sampled data"));
62
63   gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (about),
64                                   "Free Software Foundation");
65
66   gtk_about_dialog_set_translator_credits 
67     (
68      GTK_ABOUT_DIALOG (about),
69      /* TRANSLATORS: Do not translate this string.  Instead, put the names of the people
70         who have helped in the translation. */
71      _("translator-credits")
72      );
73
74   gtk_window_set_transient_for (GTK_WINDOW (about), parent);
75
76   gtk_window_set_modal (GTK_WINDOW (about), TRUE);
77
78   gtk_dialog_run (GTK_DIALOG (about));
79
80   gtk_widget_hide (about);
81 }
82
83 /* Open the manual at PAGE */
84 void
85 online_help (const char *page)
86 {
87   GError *err = NULL;
88   gchar *cmd = NULL;
89
90   gchar *argv[3] = { "yelp", 0, 0};
91
92   if (page == NULL)
93     argv[1] = g_strdup_printf ("file://%s", relocate (DOCDIR "/pspp.xml"));
94   else
95     argv[1] = g_strdup_printf ("file://%s#%s", relocate (DOCDIR "/pspp.xml"), page);
96
97   if (! g_spawn_async (NULL, argv,
98                        NULL, G_SPAWN_SEARCH_PATH,
99                        NULL, NULL,   NULL,   &err))
100     {
101       msg (ME, _("Cannot open reference manual: %s.  The PSPP user manual is "
102                  "also available at %s"),
103                   err->message,
104                   PACKAGE_URL "documentation.html");
105     }
106
107   g_free (cmd);
108   g_clear_error (&err);
109 }
110
111 static void
112 reference_manual (GtkMenuItem *menu, gpointer data)
113 {
114   online_help (NULL);
115 }
116
117
118
119 void
120 merge_help_menu (GtkUIManager *uim)
121 {
122   GtkActionGroup *action_group = gtk_action_group_new ("help");
123
124   static const GtkActionEntry entries[] =
125     {
126       {
127         "help", NULL,                               /* name, stock id */
128         N_("_Help"), NULL,                          /* label, accelerator */
129         NULL,
130         NULL,
131       },
132     
133       {
134         "help_reference", "help-reference-manual",            /* name, stock id */
135         N_("_Reference Manual"), NULL,               /* label, accelerator */
136         NULL,                                        /* tooltip */
137         G_CALLBACK (reference_manual)
138       },
139     
140       {
141         "help_about", "help-about",
142         NULL, NULL, NULL,
143         G_CALLBACK (about_new)
144       },
145     };
146
147   gtk_action_group_set_translation_domain (action_group, PACKAGE);
148
149   gtk_ui_manager_add_ui_from_string   (uim, "\
150       <menubar name=\"menubar\">\
151         <menu action=\"help\">\
152           <menuitem action=\"help_reference\"/>\
153           <menuitem action=\"help_about\"/>\
154         </menu>\
155        </menubar>\
156        ", -1, 0);
157
158   gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), NULL);
159
160   gtk_ui_manager_insert_action_group  (uim, action_group, 0);
161 }