Merged older cs.po file with newest pot file.
[gliv/czech_localization.git] / src / help.c
blob134d8ccef14545dfdd7359c9e0541314656246b1
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /****************************
22 * The help and about boxes *
23 ****************************/
25 #include <string.h> /* strlen() */
26 #include <gdk-pixbuf/gdk-pixdata.h>
28 #include "gliv.h"
29 #include "help.h"
30 #include "about.h"
31 #include "options.h"
32 #include "params.h"
33 #include "help_text.h"
34 #include "windows.h"
36 extern rt_struct *rt;
38 static GtkWindow *help_win;
40 static gchar *get_help_text(void)
42 gchar **help_lines, **ptr;
43 gchar *res, *res_ptr;
44 gint len = 0;
46 help_lines = get_help_lines();
48 /* Compute the total text length. */
49 for (ptr = help_lines; *ptr != NULL; ptr++)
50 len += strlen(*ptr);
52 res_ptr = res = g_new(gchar, len + 1);
54 /* Concatenate the lines. */
55 for (ptr = help_lines; *ptr != NULL; ptr++)
56 res_ptr = g_stpcpy(res_ptr, *ptr);
58 g_free(help_lines);
60 return res;
63 /* Get a textual widget with the help text in it. */
64 static GtkWidget *get_text_widget(const gchar * text)
66 GtkTextView *widget;
68 widget = GTK_TEXT_VIEW(gtk_text_view_new());
70 gtk_text_view_set_editable(widget, FALSE);
71 gtk_text_view_set_cursor_visible(widget, FALSE);
72 gtk_text_view_set_wrap_mode(widget, GTK_WRAP_WORD);
73 gtk_text_buffer_set_text(gtk_text_view_get_buffer(widget), text, -1);
75 return GTK_WIDGET(widget);
78 static void show_help(void)
80 PangoFontDescription *font;
81 gchar *help_text;
82 GtkWidget *widget;
83 GtkScrolledWindow *win;
85 help_text = get_help_text();
87 widget = get_text_widget(help_text);
88 g_free(help_text);
90 /* We use a fixed font to keep the alignment as in the README file. */
91 font = pango_font_description_from_string(FONT);
92 gtk_widget_modify_font(GTK_WIDGET(widget), font);
94 /* The window containing the text. */
95 win = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
96 gtk_scrolled_window_set_policy(win,
97 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
99 gtk_container_add(GTK_CONTAINER(win), widget);
101 /* The help window. */
102 help_win = new_window(_("GLiv help"));
103 gtk_window_set_default_size(help_win, 500, 500);
105 gtk_container_add(GTK_CONTAINER(help_win), GTK_WIDGET(win));
107 g_signal_connect(help_win, "delete-event", G_CALLBACK(toggle_help), NULL);
109 show_message(GTK_WIDGET(help_win), _("GLiv help"));
112 gboolean toggle_help(void)
114 rt->help ^= TRUE;
116 if (rt->help)
117 show_help();
118 else
119 gtk_widget_destroy(GTK_WIDGET(help_win));
121 return TRUE;
124 #include "include/gliv_logo.h"
126 GdkPixbuf *get_gliv_logo(void)
128 static GdkPixbuf *logo;
130 if (logo == NULL)
131 /* First time */
132 logo = gdk_pixbuf_from_pixdata(&gliv_logo, FALSE, NULL);
134 return logo;
137 gboolean show_about_box(void)
139 GtkDialog *dialog = NULL;
140 GtkLabel *about;
141 GtkHBox *box;
142 gchar *about_text;
143 GdkPixbuf *logo;
144 GtkImage *image;
146 /* Logo */
147 logo = get_gliv_logo();
148 if (logo == NULL)
149 return FALSE;
151 image = GTK_IMAGE(gtk_image_new_from_pixbuf(logo));
153 /* Text */
154 about_text = g_strconcat(_(ABOUT_GLIV), " ", VERSION, "\n",
155 "Guillaume Chazarain <guichaz@yahoo.fr>\n",
156 _(ABOUT_HELP), "\n",
157 "\n", _(ABOUT_URL), "\n", NULL);
159 about = GTK_LABEL(gtk_label_new(about_text));
160 g_free(about_text);
162 /* Dialog */
163 dialog = GTK_DIALOG(gtk_dialog_new_with_buttons(_("GLiv about box"),
164 get_current_window(),
165 GTK_DIALOG_MODAL,
166 GTK_STOCK_CLOSE,
167 GTK_RESPONSE_ACCEPT, NULL));
169 box = GTK_HBOX(gtk_hbox_new(FALSE, 10));
170 gtk_box_pack_start_defaults(GTK_BOX(box), GTK_WIDGET(image));
171 gtk_box_pack_start_defaults(GTK_BOX(box), GTK_WIDGET(about));
172 gtk_widget_show_all(GTK_WIDGET(box));
174 gtk_container_add(GTK_CONTAINER(dialog->vbox), GTK_WIDGET(box));
176 run_modal_dialog(dialog);
178 gtk_widget_destroy(GTK_WIDGET(dialog));
179 return FALSE;