File: help.c

package info (click to toggle)
denemo 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,724 kB
  • sloc: ansic: 59,006; lisp: 13,874; sh: 11,666; makefile: 2,082; xml: 634; sed: 16
file content (114 lines) | stat: -rw-r--r-- 3,902 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* help.cpp
 * implements the stuff under Help in the menubar
 *
 * for Denemo, a gtk+ frontend to GNU Lilypond
 * (c) 2000-2005 Matthew Hiller
 */

#include <denemo/denemo.h>
#include "config.h"
#include "utils.h"
#include <string.h>		/* for strlen */
/* The tutorial mentioned that the actual gchar * held within a
 * GtkText widget needs to be freed.  I don't do such a free, though,
 * so I think this function has a memory leak in it. */

/** 
 * Create the about dialog
 *
 */
void
about (GtkAction * action, gpointer callback_data)
{
  GtkWidget *dialog;
  DenemoGUI *gui = (DenemoGUI *)callback_data;
  const char *authors[] = { "Richard Shann", "Jeremiah Benham", "Matthew Hiller", "Adam Tee", "Nils Gey", NULL };

  dialog = gtk_about_dialog_new ();
  gtk_about_dialog_set_name (GTK_ABOUT_DIALOG (dialog), _("GNU Denemo"));
  gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (dialog),
				 _("Free and Open Music Notation Editor"));
  gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), VERSION);
  gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog),
				"http://www.denemo.org");
  gtk_about_dialog_set_website_label (GTK_ABOUT_DIALOG (dialog),
				      _("Denemo Website"));
  gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (dialog),
				_
				("(c) 1999 - 2010 Matthew Hiller, Adam Tee, and others.\n\n\
http://www.denemo.org\n\n\
This program is licensed under the terms of the GNU\n\
General Public License and is provided with absolutely\n\
NO WARRANTY; see the file COPYING for details."));


  gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (dialog), authors);
  gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(Denemo.window));
  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(dialog);
}


/** 
 * Function to allow browsing the user manual
 * uses the given web browser to display the manual
 * If param contains a url it opens that
 */
void
browse_manual (GtkAction * action, DenemoScriptParam *param)
{
  GET_1PARAM(action, param, url);
  DenemoGUI *gui = Denemo.gui;
  gboolean retval;
  GError *error = NULL;

  /* get the uri to the manual */
  gchar *manualpath = g_build_filename ("/usr/share/doc/", "denemo-doc",
                                        "denemo-manual.html", NULL);
  gchar *manualuri =  url?g_strdup(url):g_filename_to_uri (manualpath, NULL, NULL);

  /* check that the browser exists */
  gchar *browserpath = g_find_program_in_path (Denemo.prefs.browser->str);
  if (browserpath == NULL)
    {
      if(run_file_association(manualuri))
	return;
      /* show a warning dialog */
      GtkWidget *dialog =
        gtk_message_dialog_new (GTK_WINDOW (Denemo.window),
                                GTK_DIALOG_DESTROY_WITH_PARENT,
                                GTK_MESSAGE_WARNING,
                                GTK_BUTTONS_OK,
                                _("Could not find %s in the path"),
                                Denemo.prefs.browser->str);
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                _("Please edit the chosen "
                                                  "browser in the "
                                                  "preferences."));
      gtk_dialog_run (GTK_DIALOG (dialog));

      /* free the memory and return */
      gtk_widget_destroy (dialog);
      g_free (manualpath);
      g_free (manualuri);
      return;
    }

  /* spawn the process to show the manual */
  gchar *argv[] = {Denemo.prefs.browser->str,
                   manualuri,
                   NULL};
  retval = g_spawn_async (NULL, argv, NULL,
			  G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
  if (!retval)
    {
      g_message (_("Could not execute specified web browser: %s\n"),
		 error->message);
      g_error_free (error);
    }

  /* free the memory */
  g_free (browserpath);
  g_free (manualpath);
  g_free (manualuri);
}