1 /* help.cpp
2 * implements the stuff under Help in the menubar
3 *
4 * for Denemo, a gtk+ frontend to GNU Lilypond
5 * (c) 2000-2005 Matthew Hiller
6 */
7
8 #include <denemo/denemo.h>
9 #include "config.h"
10 #include "core/utils.h"
11 #include "core/kbd-custom.h"
12 #include <string.h> /* for strlen */
13 /* The tutorial mentioned that the actual gchar * held within a
14 * GtkText widget needs to be freed. I don't do such a free, though,
15 * so I think this function has a memory leak in it. */
16
17 /**
18 * Create the about dialog
19 *
20 */
21 void
about(GtkAction * action,DenemoScriptParam * callback_data)22 about (GtkAction * action, DenemoScriptParam* callback_data)
23 {
24 GtkWidget *dialog;
25 const char *authors[] = { "Richard Shann", "Jeremiah Benham", "Matthew Hiller", "Adam Tee", "Nils Gey", NULL };
26
27 dialog = gtk_about_dialog_new ();
28 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG (dialog), _("GNU Denemo"));
29 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (dialog), _("Free and Open Music Notation Editor"));
30 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), VERSION);
31 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), "http://www.denemo.org");
32 gtk_about_dialog_set_website_label (GTK_ABOUT_DIALOG (dialog), _("Denemo Website"));
33 gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (dialog), _("(c) 1999 - 2010 Matthew Hiller, Adam Tee, and others.\n\n\
34 http://www.denemo.org\n\n\
35 This program is licensed under the terms of the GNU\n\
36 General Public License and is provided with absolutely\n\
37 NO WARRANTY; see the file COPYING for details."));
38
39
40 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (dialog), authors);
41 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (Denemo.window));
42 gtk_dialog_run (GTK_DIALOG (dialog));
43 gtk_widget_destroy (dialog);
44 }
45
46
47 /**
48 * Function to allow browsing the user manual
49 * uses the given web browser to display the manual
50 * If param contains a url it opens that
51 */
52 void
browse_manual(GtkAction * action,DenemoScriptParam * param)53 browse_manual (GtkAction * action, DenemoScriptParam * param)
54 {
55 GET_1PARAM (action, param, url);
56 gboolean retval;
57 GError *error = NULL;
58
59 /* get the uri to the manual */
60 gchar *manualpath = g_build_filename (get_system_data_dir (), "..", "doc", "denemo", "manual",
61 "denemo-manual.html", NULL);
62 gchar *manualuri = url ? g_strdup (url) : g_filename_to_uri (manualpath, NULL, NULL);
63
64 /* check that the browser exists */
65 gchar *browserpath = g_find_program_in_path (Denemo.prefs.browser->str);
66 if (browserpath == NULL)
67 {
68 if (run_file_association (manualuri))
69 return;
70 /* show a warning dialog */
71 GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (Denemo.window),
72 GTK_DIALOG_DESTROY_WITH_PARENT,
73 GTK_MESSAGE_WARNING,
74 GTK_BUTTONS_OK,
75 _("Could not find %s in the path"),
76 Denemo.prefs.browser->str);
77 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Please edit the chosen " "browser in the " "preferences."));
78 gtk_dialog_run (GTK_DIALOG (dialog));
79
80 /* free the memory and return */
81 gtk_widget_destroy (dialog);
82 g_free (manualpath);
83 g_free (manualuri);
84 return;
85 }
86
87 /* spawn the process to show the manual */
88 gchar *argv[] = { Denemo.prefs.browser->str,
89 manualuri,
90 NULL
91 };
92 retval = g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
93 if (!retval)
94 {
95 g_message (_("Could not execute specified web browser: %s"), error->message);
96 g_error_free (error);
97 }
98
99 /* free the memory */
100 g_free (browserpath);
101 g_free (manualpath);
102 g_free (manualuri);
103 }
104
display_shortcuts(void)105 void display_shortcuts (void)
106 {
107 GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
108 GtkTextView *text_view = (GtkTextView*)gtk_text_view_new ();
109 gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
110 GtkWidget *scrolled_text_view = gtk_scrolled_window_new (gtk_adjustment_new (1.0, 1.0, 2.0, 1.0, 4.0, 1.0), gtk_adjustment_new (1.0, 1.0, 2.0, 1.0, 4.0, 1.0));
111 gtk_container_add (GTK_CONTAINER (scrolled_text_view), GTK_WIDGET(text_view));
112 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_text_view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
113 gtk_widget_set_size_request (GTK_WIDGET (scrolled_text_view), 150, 300);
114 gtk_container_add (GTK_CONTAINER (window), scrolled_text_view);
115 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
116 GString *shortcuts = keymap_get_bindings (Denemo.map);
117 gtk_text_buffer_set_text (buffer, shortcuts->str, -1);
118 gtk_widget_show_all(window);
119 Denemo.prefs.learning = TRUE;
120 g_string_free(shortcuts, TRUE);
121 }
122