X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fhelp-menu.c;h=e63829cb06c7a143b80bca16d5bfe0d76e8031a3;hb=91240a3a96a0ffed8b1bcc4866378b4d865e6f6e;hp=c24125d78aa1f995393de8b955720012b93dd4a8;hpb=cd7df218e1f2798b4ac8e193558a67e6ad59e3ed;p=pspp diff --git a/src/ui/gui/help-menu.c b/src/ui/gui/help-menu.c index c24125d78a..e63829cb06 100644 --- a/src/ui/gui/help-menu.c +++ b/src/ui/gui/help-menu.c @@ -1,5 +1,6 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2006, 2007, 2010 Free Software Foundation + Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013, 2015, 2016, + 2021 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 @@ -19,10 +20,11 @@ #include -#include -#include -#include "help-menu.h" -#include +#include "libpspp/cast.h" +#include "libpspp/copyleft.h" +#include "libpspp/message.h" +#include "libpspp/version.h" +#include "ui/gui/help-menu.h" #include "gl/configmake.h" #include "gl/relocatable.h" @@ -31,28 +33,116 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid +/* Try to open html documentation uri via the default + browser on the operating system */ +#ifdef __APPLE__ +#define HTMLOPENAPP "open" +#elif _WIN32 +#define HTMLOPENAPP "wscript" +#else +#define HTMLOPENAPP "xdg-open" +#endif + +static const gchar *artists[] = { "Bastián Díaz", "Hugo Alejandro", NULL}; + +/* Opening the htmluri in windows via cmd /start uri opens + the windows command shell for a moment. The alternative is + to start a script via wscript. This will not be visible*/ +#ifdef _WIN32 +static gboolean +open_windows_help (const gchar *helpuri, GError **err) +{ + SHELLEXECUTEINFOA info; + memset (&info, 0, sizeof (info)); + + info.cbSize = sizeof (info); + info.fMask = SEE_MASK_FLAG_NO_UI; + info.lpVerb = "open"; + info.lpFile = helpuri; + info.nShow = SW_SHOWNORMAL; + + BOOL ret = ShellExecuteExA (&info); + + if (ret) + return TRUE; + + /* Contrary to what the microsoft documentation indicates, ShellExecuteExA does + not seem to setLastError. So we have to deal with errors ourselves here. */ + const char *msg = 0; + switch (GPOINTER_TO_INT (info.hInstApp)) + { + case SE_ERR_FNF: + msg = "File not found"; + break; + case SE_ERR_PNF: + msg = "Path not found"; + break; + case SE_ERR_ACCESSDENIED: + msg = "Access denied"; + break; + case SE_ERR_OOM: + msg = "Out of memory"; + break; + case SE_ERR_DLLNOTFOUND: + msg = "Dynamic-link library not found"; + break; + case SE_ERR_SHARE: + msg = "Cannot share an open file"; + break; + case SE_ERR_ASSOCINCOMPLETE: + msg = "File association information not complete"; + break; + case SE_ERR_DDETIMEOUT: + msg = "DDE operation timed out"; + break; + case SE_ERR_DDEFAIL: + msg = "DDE operation failed"; + break; + case SE_ERR_DDEBUSY: + msg = "DDE operation is busy"; + break; + case SE_ERR_NOASSOC: + msg = "File association not available"; + break; + default: + msg = "Unknown error"; + break; + } + + *err = g_error_new_literal (g_quark_from_static_string ("pspp-help-error"), + 0, + msg); + + return FALSE; +} -static const gchar *artists[] = { "Patrick Brunier", "Dondi Bogusky", NULL}; +static gboolean +on_activate_link (GtkAboutDialog *label, + gchar *uri, + gpointer user_data) +{ + return open_windows_help (uri, NULL); +} +#endif static void -about_new (GtkMenuItem *m, GtkWindow *parent) +about_new (GtkMenuItem *mmm, GtkWindow *parent) { GtkWidget *about = gtk_about_dialog_new (); - GdkPixbuf *pb = - gdk_pixbuf_new_from_file_at_size (relocate (PKGDATADIR "/pspplogo.png"), - 64, 64, 0); - - gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (about), pb); +#ifdef _WIN32 + /* The default handler for Windows doesn't appear to work. */ + g_signal_connect (about, "activate-link", G_CALLBACK (on_activate_link), parent); +#endif + gtk_about_dialog_set_logo_icon_name (GTK_ABOUT_DIALOG (about), "pspp"); - gtk_window_set_icon_name (GTK_WINDOW (about), "psppicon"); + gtk_window_set_icon_name (GTK_WINDOW (about), "pspp"); - gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (about), - "http://www.gnu.org/software/pspp"); + gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (about), PACKAGE_URL); gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about), - bare_version); + announced_version); gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (about), (const gchar **) authors); @@ -69,13 +159,13 @@ about_new (GtkMenuItem *m, GtkWindow *parent) gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (about), "Free Software Foundation"); - gtk_about_dialog_set_translator_credits + gtk_about_dialog_set_translator_credits ( GTK_ABOUT_DIALOG (about), - /* TRANSLATORS: Use this string to list the people who have helped with - translation to your language. */ + /* TRANSLATORS: Do not translate this string. Instead, put the names of the people + who have helped in the translation. */ _("translator-credits") - ); +); gtk_window_set_transient_for (GTK_WINDOW (about), parent); @@ -87,64 +177,116 @@ about_new (GtkMenuItem *m, GtkWindow *parent) } -static void -reference_manual (GtkMenuItem *menu, gpointer data) + +/* Open the manual at PAGE with the following priorities + First: local yelp help system + Second: browser with local html doc dir in path pspp.html/.html + Third: browers with Internet html help at gnu.org */ +void +online_help (const char *page) { - GError *err = NULL; - gchar *cmd = g_strdup_printf ("yelp file://%s", relocate (DOCDIR "/pspp.xml")); + GError *htmlerr = NULL; + gchar *htmlfilename = NULL; + gchar *htmlfullname = NULL; + gchar *htmluri = NULL; - if ( ! g_spawn_command_line_async (cmd, &err) ) + if (page == NULL) { - msg (ME, _("Cannot open reference manual: %s. The PSPP user manual is " - "also available at " - "http://www.gnu.org/software/pspp/documentation.html"), - err->message); + htmlfilename = g_strdup ("index.html"); + } + else + { + gchar **tokens = NULL; + const int maxtokens = 5; + int idx ; + /* The page will be translated to the htmlfilename + page htmlfilename + GRAPH#SCATTERPLOT SCATTERPLOT.html + QUICK-CLUSTER QUICK-CLUSTER.html + which is valid for the multiple page html doc*/ + tokens = g_strsplit (page, "#", maxtokens); + for (idx = 0; idx < maxtokens && tokens[idx]; idx++) + ; + htmlfilename = g_strdup_printf ("%s.html", tokens[idx-1]); + g_strfreev (tokens); + } + /* Hint: pspp.html is a directory...*/ + htmlfullname = g_strdup_printf ("%s/%s", relocate (DOCDIR "/pspp.html"), + htmlfilename); + if (g_file_test (relocate (DOCDIR "/pspp.html"), G_FILE_TEST_IS_DIR)) + { + GError *urierr = NULL; + htmluri = g_filename_to_uri (htmlfullname,NULL, &urierr); + if (!htmluri) + { + msg (ME, _("Help path conversion error: %s"), urierr->message); + htmluri = htmlfullname; + } + g_clear_error (&urierr); + } + else + htmluri = g_strdup_printf (PACKAGE_URL "manual/html_node/%s", + htmlfilename); + g_free (htmlfullname); + g_free (htmlfilename); + +#ifdef _WIN32 + bool ok = open_windows_help (htmluri, &htmlerr); +#else + gchar *htmlargv[3] = {CONST_CAST (char *, HTMLOPENAPP), htmluri, 0}; + bool ok = g_spawn_async (NULL, htmlargv, + NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, &htmlerr); +#endif + if (!ok) + { + msg (ME, _("Cannot open via html: %s " + "with uri: %s " + "The PSSP manual is also available at %s"), + htmlerr->message, + htmluri, + PACKAGE_URL "documentation.html"); } - g_free (cmd); - g_clear_error (&err); + g_free (htmluri); + g_clear_error (&htmlerr); } -void -merge_help_menu (GtkUIManager *uim) +static void +reference_manual (GtkMenuItem *menu, gpointer data) { - GtkActionGroup *action_group = gtk_action_group_new ("help"); + online_help (NULL); +} - static const GtkActionEntry entries[] = - { - { - "help", NULL, /* name, stock id */ - N_("_Help"), NULL, /* label, accelerator */ - NULL, - NULL, - }, - - { - "help_reference", GTK_STOCK_HELP, /* name, stock id */ - N_("_Reference Manual"), NULL, /* label, accelerator */ - NULL, /* tooltip */ - G_CALLBACK (reference_manual) - }, - - { - "help_about", GTK_STOCK_ABOUT, - NULL, NULL, NULL, - G_CALLBACK (about_new) - }, - }; - - gtk_action_group_set_translation_domain (action_group, PACKAGE); - - gtk_ui_manager_add_ui_from_string (uim, "\ - \ - \ - \ - \ - \ - \ - ", -1, 0); - - gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), NULL); - - gtk_ui_manager_insert_action_group (uim, action_group, 0); +GtkWidget * +create_help_menu (GtkWindow *toplevel) +{ + GtkWidget *menuitem = gtk_menu_item_new_with_mnemonic (_("_Help")); + GtkWidget *menu = gtk_menu_new (); + + GtkWidget *help_about = gtk_menu_item_new_with_mnemonic (_("_About")); + GtkWidget *help_ref = gtk_menu_item_new_with_mnemonic (_("_Reference Manual")); + + GtkAccelGroup *accel_group = gtk_accel_group_new (); + + gtk_window_add_accel_group (toplevel, accel_group); + + gtk_widget_add_accelerator (help_ref, + "activate", accel_group, + GDK_KEY_F1, 0, + GTK_ACCEL_VISIBLE); + + gtk_menu_attach (GTK_MENU (menu), help_ref, 0, 1, 0, 1); + gtk_menu_attach (GTK_MENU (menu), help_about, 0, 1, 1, 2); + + g_signal_connect (help_about, "activate", G_CALLBACK (about_new), toplevel); + g_signal_connect (help_ref, "activate", G_CALLBACK (reference_manual), NULL); + + g_object_set (menuitem, "submenu", menu, NULL); + + gtk_widget_show_all (menuitem); + + g_object_unref (accel_group); + + return menuitem; }