1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id: manpage.c 2649 2007-09-17 15:35:08Z roms $ */
3
4 /* tilp - Ti Linking Program
5 * Copyright (C) 1999-2004 Romain Lievin
6 *
7 * This program is free software you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif /* */
25
26 #include <gtk/gtk.h>
27 #include <glade/glade.h>
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #include "intl.h"
36 #include "manpage.h"
37 #include "paths.h"
38 #include "engine.h"
39
display_manpage_dbox()40 gint display_manpage_dbox()
41 {
42 GladeXML *xml;
43 GtkWidget *dbox;
44 GtkTextBuffer *txtbuf;
45 GtkWidget *text;
46 FILE *fd;
47 gchar *filename;
48 gchar buffer[32768];
49 gint len = 0;
50 struct stat stbuf;
51 gint result;
52 PangoFontDescription *font_desc;
53
54 filename =
55 g_strconcat(inst_paths.manpage_dir, "Manpage.txt", NULL);
56 if (access(filename, F_OK) == 0) {
57 if (stat(filename, &stbuf) != -1) {
58 len = stbuf.st_size;
59 len -= 2;
60 }
61 if ((fd = fopen(filename, "r")) != NULL) {
62 memset(buffer, 0, sizeof(buffer));
63 len = fread(buffer, 1, len, fd);
64 fclose(fd);
65 }
66 }
67
68 xml = glade_xml_new
69 (tilp_paths_build_glade("manpage-2.glade"), "manpage_dbox",
70 PACKAGE);
71 if (!xml)
72 g_error(_("%s: GUI loading failed!\n"), __FILE__);
73 glade_xml_signal_autoconnect(xml);
74
75 dbox = glade_xml_get_widget(xml, "manpage_dbox");
76 text = glade_xml_get_widget(xml, "textview1");
77
78 // Change font
79 font_desc = pango_font_description_from_string ("Courier");
80 gtk_widget_modify_font (text, font_desc);
81 pango_font_description_free (font_desc);
82
83 // Set text
84 txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
85 gtk_text_buffer_set_text(txtbuf, buffer, len);
86
87 while (gtk_events_pending())
88 gtk_main_iteration();
89
90 result = gtk_dialog_run(GTK_DIALOG(dbox));
91 switch (result) {
92 case GTK_RESPONSE_OK:
93 break;
94 default:
95 break;
96 }
97
98 gtk_widget_destroy(dbox);
99
100 return 0;
101 }
102