2005-12-19 [cleroy] 1.9.100cvs95
[claws.git] / src / gtk / about.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2005 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <gtk/gtkwidget.h>
30 #include <gtk/gtkwindow.h>
31 #include <gtk/gtksignal.h>
32 #include <gtk/gtkvbox.h>
33 #include <gtk/gtkhbox.h>
34 #include <gtk/gtklabel.h>
35 #include <gtk/gtkhseparator.h>
36 #include <gtk/gtkscrolledwindow.h>
37 #include <gtk/gtktext.h>
38 #include <gtk/gtkbutton.h>
39 #if HAVE_SYS_UTSNAME_H
40 #  include <sys/utsname.h>
41 #endif
42
43 #include "about.h"
44 #include "gtkutils.h"
45 #include "stock_pixmap.h"
46 #include "prefs_common.h"
47 #include "utils.h"
48 #include "version.h"
49 #include "authors.h"
50 #include "codeconv.h"
51 #include "menu.h"
52 #include "textview.h"
53
54 static GtkWidget *window;
55 static gchar* uri_hover = NULL;
56 static GtkTextIter uri_hover_start_iter;
57 static GtkTextIter uri_hover_end_iter;
58 static GdkCursor *hand_cursor = NULL;
59 static GdkCursor *text_cursor = NULL;
60
61 static void about_create(void);
62 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event);
63 static void about_uri_clicked(GtkButton *button, gpointer data);
64 static gboolean about_textview_uri_clicked(GtkTextTag *tag, GObject *obj,
65                                         GdkEvent *event, GtkTextIter *iter,
66                                         GtkWidget *textview);
67 static void about_open_link_cb(GtkWidget *widget, guint action, void *data);
68 static void about_copy_link_cb(GtkWidget *widget, guint action, void *data);
69 static gboolean about_textview_motion_notify(GtkWidget *widget,
70                                         GdkEventMotion *event,
71                                         GtkWidget *textview);
72 static gboolean about_textview_leave_notify(GtkWidget *widget,
73                                         GdkEventCrossing *event,
74                                         GtkWidget *textview);
75 static void about_textview_uri_update(GtkWidget *textview, gint x, gint y);
76
77 static GtkItemFactoryEntry textview_link_popup_entries[] = 
78 {
79         {N_("/_Open with Web browser"), NULL, about_open_link_cb, 0, NULL},
80         {N_("/Copy this _link"),        NULL, about_copy_link_cb, 0, NULL},
81 };
82
83 static GtkWidget *link_popupmenu;
84
85
86 void about_show(void)
87 {
88         if (!window)
89                 about_create();
90         else
91                 gtk_window_present(GTK_WINDOW(window));
92 }
93
94 static void about_create(void)
95 {
96         GtkWidget *vbox1;
97         GtkWidget *table;
98         GtkWidget *table2;
99         GtkWidget *image;       
100         GtkWidget *vbox2;
101         GtkWidget *label;
102         GtkWidget *button;
103         GtkWidget *scrolledwin;
104         GtkWidget *notebook;
105         GtkStyle *style;
106         GdkColormap *cmap;
107         GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
108         gboolean success[2];
109         char *markup;
110         GtkWidget *text;
111         GtkWidget *confirm_area;
112         GtkWidget *close_button;
113         GtkTextBuffer *buffer;
114         GtkTextIter iter;
115         GtkTextTag *tag;
116
117 #if HAVE_SYS_UTSNAME_H
118         struct utsname utsbuf;
119 #endif
120         gchar buf[1024];
121         gint i;
122
123         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
124         gtk_window_set_title(GTK_WINDOW(window), _("About Sylpheed-Claws"));
125         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
126         gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
127         gtk_widget_set_size_request(window, -1, -1);
128         g_signal_connect(G_OBJECT(window), "delete_event",
129                          G_CALLBACK(gtk_widget_hide_on_delete), NULL);
130         g_signal_connect(G_OBJECT(window), "key_press_event",
131                          G_CALLBACK(key_pressed), NULL);
132         gtk_widget_realize(window);
133
134         vbox1 = gtk_vbox_new(FALSE, 0);
135         gtk_container_add(GTK_CONTAINER(window), vbox1);
136
137         table = gtk_table_new (1, 2, FALSE);
138         gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0);
139
140         image = stock_pixmap_widget(window, STOCK_PIXMAP_SYLPHEED_LOGO);
141         gtk_table_attach(GTK_TABLE(table), image, 0, 1, 0, 1,
142                          (GtkAttachOptions) (GTK_SHRINK),
143                          (GtkAttachOptions) (GTK_SHRINK), 8, 0);
144
145         vbox2 = gtk_vbox_new (TRUE, 0);
146         gtk_table_attach(GTK_TABLE(table), vbox2, 1, 2, 0, 1,
147                          (GtkAttachOptions) (GTK_EXPAND),
148                          (GtkAttachOptions) (GTK_FILL), 0, 0);
149
150         label = gtk_label_new("");
151         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
152         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
153         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
154         markup = g_markup_printf_escaped
155                 ("<span weight=\"bold\" size=\"xx-large\">Sylpheed-Claws</span>\nversion %s",
156                  VERSION);
157         gtk_label_set_markup(GTK_LABEL(label), markup);
158         g_free(markup);
159
160         button = gtk_button_new_with_label(" "HOMEPAGE_URI" ");
161         gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0);
162         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
163         g_signal_connect(G_OBJECT(button), "clicked",
164                          G_CALLBACK(about_uri_clicked), NULL);
165         buf[0] = ' ';
166         for (i = 1; i <= strlen(HOMEPAGE_URI); i++) buf[i] = '_';
167         strcpy(buf + i, " ");
168         gtk_label_set_pattern(GTK_LABEL(GTK_BIN(button)->child), buf);
169         cmap = gdk_drawable_get_colormap(window->window);
170         gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
171         if (success[0] == TRUE && success[1] == TRUE) {
172                 gtk_widget_ensure_style(GTK_BIN(button)->child);
173                 style = gtk_style_copy
174                         (gtk_widget_get_style(GTK_BIN(button)->child));
175                 style->fg[GTK_STATE_NORMAL]   = uri_color[0];
176                 style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
177                 style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
178                 gtk_widget_set_style(GTK_BIN(button)->child, style);
179         } else
180                 g_warning("about_create(): color allocation failed.\n");
181
182 #if HAVE_SYS_UTSNAME_H
183         uname(&utsbuf);
184         g_snprintf(buf, sizeof(buf),
185                    _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
186                    "Operating System: %s %s (%s)"),
187                    gtk_major_version, gtk_minor_version, gtk_micro_version,
188                    glib_major_version, glib_minor_version, glib_micro_version,
189                    utsbuf.sysname, utsbuf.release, utsbuf.machine);
190 #elif defined(G_OS_WIN32)
191         g_snprintf(buf, sizeof(buf),
192                    _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
193                    "Operating System: %s"),
194                    gtk_major_version, gtk_minor_version, gtk_micro_version,
195                    glib_major_version, glib_minor_version, glib_micro_version,
196                    "Win32");
197 #else
198         g_snprintf(buf, sizeof(buf),
199                    _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
200                    "Operating System: unknown"),
201                    gtk_major_version, gtk_minor_version, gtk_micro_version,
202                    glib_major_version, glib_minor_version, glib_micro_version);
203 #endif
204
205         label = gtk_label_new(buf);
206         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
207         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
208         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
209         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
210
211         g_snprintf(buf, sizeof(buf),
212                    _("Compiled-in features:\n%s"),
213 #if USE_THREADS
214                    " gthread"
215 #endif
216 #if INET6
217                    " IPv6"
218 #endif
219 #if HAVE_ICONV
220                    " iconv"
221 #endif
222 #if HAVE_LIBCOMPFACE
223                    " compface"
224 #endif
225 #if USE_OPENSSL
226                    " OpenSSL"
227 #endif
228 #if USE_LDAP
229                    " LDAP"
230 #endif
231 #if USE_JPILOT
232                    " JPilot"
233 #endif
234 #if USE_ASPELL
235                    " GNU/aspell"
236 #endif
237 #if HAVE_LIBETPAN
238                    " libetpan"
239 #endif
240 #if USE_GNOMEPRINT
241                    " libgnomeprint"
242 #endif
243         "");
244
245         label = gtk_label_new(buf);
246         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
247         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
248         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
249         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
250
251         table2 = gtk_table_new (2, 3, FALSE);
252         gtk_box_pack_start(GTK_BOX(vbox1), table2, FALSE, FALSE, 0);
253
254         label = gtk_label_new
255                 ("Copyright (C) 1999-2005 Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>\n"
256                  "and the Sylpheed-Claws team");
257         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
258         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
259         gtk_table_attach(GTK_TABLE(table2), label, 0, 1, 0, 1,
260                          (GtkAttachOptions) (GTK_EXPAND),
261                          (GtkAttachOptions) (GTK_SHRINK), 0, 6);
262
263         notebook = gtk_notebook_new();
264         gtk_widget_set_size_request(notebook, -1, 200);
265         gtk_widget_show(notebook);
266
267         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
268         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
269                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
270         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
271                                             GTK_SHADOW_IN);
272
273         text = gtk_text_view_new();
274         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
275         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
276         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
277         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
278         gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
279         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
280         gtk_widget_add_events(text, GDK_LEAVE_NOTIFY_MASK);
281
282         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
283         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
284
285         /* textview link style (based upon main prefs) */
286         gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
287                                 (GdkColor*)&uri_color);
288         tag = gtk_text_buffer_create_tag(buffer, "link",
289                                 "foreground-gdk", &uri_color,
290                                 "wrap-mode", GTK_WRAP_NONE,
291                                 NULL);
292         gtk_text_buffer_create_tag(buffer, "link-hover",
293                                 "foreground-gdk", &uri_color,
294                                 "underline", PANGO_UNDERLINE_SINGLE,
295                                 NULL);
296
297         gtk_text_buffer_insert(buffer, &iter, _(
298                                 "Sylpheed-Claws is a lightweight, fast and "
299                                 "highly-configurable e-mail client.\n\n"
300                                 "For further information visit the Sylpheed-"
301                                 "Claws website:\n"), -1);
302         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, HOMEPAGE_URI, -1,
303                                 "link", NULL);
304         gtk_text_buffer_insert(buffer, &iter, _("\n\n"
305                                 "Sylpheed-Claws is free software released "
306                                 "under the GPL license. If you wish to donate "
307                                 "to the Sylpheed-Claws project you can do "
308                                 "so at:\n"), -1);
309         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, DONATE_URI, -1,
310                                 "link", NULL);
311         gtk_text_buffer_insert(buffer, &iter, _("\n"), -1);
312
313         g_signal_connect(G_OBJECT(tag), "event",
314                                 G_CALLBACK(about_textview_uri_clicked), text);
315         g_signal_connect(G_OBJECT(text), "motion-notify-event",
316                                 G_CALLBACK(about_textview_motion_notify), text);
317         g_signal_connect(G_OBJECT(text), "leave-notify-event",
318                                 G_CALLBACK(about_textview_leave_notify), text);
319
320         gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
321                                 scrolledwin,
322                                 gtk_label_new(_("Info")));
323
324         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
325         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
326                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
327         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
328                                             GTK_SHADOW_IN);
329
330         text = gtk_text_view_new();
331         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
332         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
333         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
334         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
335         gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
336         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
337         gtk_widget_add_events(text, GDK_LEAVE_NOTIFY_MASK);
338
339         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
340         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
341
342         /* init formatting tag: indentation  for list items */
343         gtk_text_buffer_create_tag(buffer, "indented-list-item",
344                                 "indent", 24,
345                                 NULL);
346         gtk_text_buffer_create_tag(buffer, "underlined-list-title",
347                                 "underline", PANGO_UNDERLINE_SINGLE,
348                                 NULL);
349
350         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("The Sylpheed-Claws Team\n")), -1,
351                         "underlined-list-title", NULL);
352
353         for (i = 0; TEAM_LIST[i] != NULL; i++) {
354                 if (g_utf8_validate(TEAM_LIST[i], -1, NULL))
355                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, TEAM_LIST[i], -1,
356                                         "indented-list-item", NULL);
357                 else {
358                         gchar *conv = conv_codeset_strdup(TEAM_LIST[i], CS_ISO_8859_1, CS_UTF_8);
359                         if (conv)
360                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
361                                                 "indented-list-item", NULL);
362                         g_free(conv);
363                 }
364                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
365         }
366
367         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("\nPrevious team members\n")), -1,
368                         "underlined-list-title", NULL);
369
370         for (i = 0; EX_TEAM_LIST[i] != NULL; i++) {
371                 if (g_utf8_validate(EX_TEAM_LIST[i], -1, NULL))
372                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, EX_TEAM_LIST[i], -1,
373                                         "indented-list-item", NULL);
374                 else {
375                         gchar *conv = conv_codeset_strdup(EX_TEAM_LIST[i], CS_ISO_8859_1, CS_UTF_8);
376                         if (conv)
377                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
378                                                 "indented-list-item", NULL);
379                         g_free(conv);
380                 }
381                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
382         }
383
384         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("\nThe translation team\n")), -1,
385                         "underlined-list-title", NULL);
386
387         for (i = 0; TRANS_TEAM_LIST[i] != NULL; i++) {
388                 if (g_utf8_validate(TRANS_TEAM_LIST[i], -1, NULL))
389                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, TRANS_TEAM_LIST[i], -1,
390                                         "indented-list-item", NULL);
391                 else {
392                         gchar *conv = conv_codeset_strdup(TRANS_TEAM_LIST[i], CS_ISO_8859_1, CS_UTF_8);
393                         if (conv)
394                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
395                                                 "indented-list-item", NULL);
396                         g_free(conv);
397                 }
398                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
399         }
400
401         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("\nDocumentation team\n")), -1,
402                         "underlined-list-title", NULL);
403
404         for (i = 0; DOC_TEAM_LIST[i] != NULL; i++) {
405                 if (g_utf8_validate(DOC_TEAM_LIST[i], -1, NULL))
406                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, DOC_TEAM_LIST[i], -1,
407                                         "indented-list-item", NULL);
408                 else {
409                         gchar *conv = conv_codeset_strdup(DOC_TEAM_LIST[i], CS_ISO_8859_1, CS_UTF_8);
410                         if (conv)
411                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
412                                                 "undeindented-list-itemitle", NULL);
413                         g_free(conv);
414                 }
415                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
416         }
417
418         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("\nLogo\n")), -1,
419                         "underlined-list-title", NULL);
420
421         for (i = 0; LOGO_LIST[i] != NULL; i++) {
422                 if (g_utf8_validate(LOGO_LIST[i], -1, NULL))
423                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, LOGO_LIST[i], -1,
424                                         "indented-list-item", NULL);
425                 else {
426                         gchar *conv = conv_codeset_strdup(LOGO_LIST[i], CS_ISO_8859_1, CS_UTF_8);
427                         if (conv)
428                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
429                                                 "indented-list-item", NULL);
430                         g_free(conv);
431                 }
432                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
433         }
434
435         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("\nIcons\n")), -1,
436                         "underlined-list-title", NULL);
437
438         for (i = 0; ICONS_LIST[i] != NULL; i++) {
439                 if (g_utf8_validate(ICONS_LIST[i], -1, NULL))
440                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, ICONS_LIST[i], -1,
441                                         "indented-list-item", NULL);
442                 else {
443                         gchar *conv = conv_codeset_strdup(ICONS_LIST[i], CS_ISO_8859_1, CS_UTF_8);
444                         if (conv)
445                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
446                                                 "indented-list-item", NULL);
447                         g_free(conv);
448                 }
449                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
450         }
451
452         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (_("\nContributors\n")), -1,
453                         "underlined-list-title", NULL);
454
455         for (i = 0; CONTRIBS_LIST[i] != NULL; i++) {
456                 if (g_utf8_validate(CONTRIBS_LIST[i], -1, NULL))
457                         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, CONTRIBS_LIST[i], -1,
458                                         "indented-list-item", NULL);
459                 else {
460                         gchar *conv = conv_codeset_strdup(CONTRIBS_LIST[i], CS_ISO_8859_1, CS_UTF_8);
461                         if (conv)
462                                 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, conv, -1,
463                                                 "indented-list-item", NULL);
464                         g_free(conv);
465                 }
466                 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
467         }
468
469         gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
470                                  scrolledwin,
471                                  gtk_label_new(_("Authors")));
472
473         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
474         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
475                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
476         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
477                                             GTK_SHADOW_IN);
478
479         text = gtk_text_view_new();
480         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
481         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
482         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
483         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
484         gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
485         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
486
487         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
488         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
489
490         gtk_text_buffer_insert(buffer, &iter,
491                 _("This program is free software; you can redistribute it and/or modify "
492                   "it under the terms of the GNU General Public License as published by "
493                   "the Free Software Foundation; either version 2, or (at your option) "
494                   "any later version.\n\n"), -1);
495
496         gtk_text_buffer_insert(buffer, &iter,
497                 _("This program is distributed in the hope that it will be useful, "
498                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
499                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
500                   "See the GNU General Public License for more details.\n\n"), -1);
501
502         gtk_text_buffer_insert(buffer, &iter,
503                 _("You should have received a copy of the GNU General Public License "
504                   "along with this program; if not, write to the Free Software "
505                   "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, "
506                   "MA 02110-1301, USA.\n\n"), -1);
507 #ifdef USE_OPENSSL
508         tag = gtk_text_buffer_create_tag(buffer, "link",
509                 "foreground-gdk", &uri_color,
510                 NULL);
511         gtk_text_buffer_create_tag(buffer, "link-hover",
512                 "foreground-gdk", &uri_color,
513                 "underline", PANGO_UNDERLINE_SINGLE,
514                 NULL);
515
516         gtk_text_buffer_insert(buffer, &iter,
517                 _("This product includes software developed by the OpenSSL Project "
518                   "for use in the OpenSSL Toolkit ("), -1);
519         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "http://www.openssl.org/", -1,
520                 "link", NULL);
521         gtk_text_buffer_insert(buffer, &iter, _(").\n"), -1);
522
523         g_signal_connect(G_OBJECT(tag), "event",
524                                 G_CALLBACK(about_textview_uri_clicked), text);
525         g_signal_connect(G_OBJECT(text), "motion-notify-event",
526                          G_CALLBACK(about_textview_motion_notify), text);
527         g_signal_connect(G_OBJECT(text), "leave-notify-event",
528                                 G_CALLBACK(about_textview_leave_notify), text);
529 #endif
530
531         gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
532                                  scrolledwin,
533                                  gtk_label_new(_("License")));
534
535         gtk_box_pack_start(GTK_BOX(vbox1), notebook, TRUE, TRUE, 0);
536
537         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
538                                       NULL, NULL, NULL, NULL);
539         gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 4);
540         gtk_widget_grab_default(close_button);
541         gtk_widget_grab_focus(close_button);
542         g_signal_connect_closure
543                 (G_OBJECT(close_button), "clicked",
544                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
545                                      window, NULL), FALSE);
546
547         gtk_widget_show_all(window);
548 }
549
550 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
551 {
552         if (event && event->keyval == GDK_Escape)
553                 gtk_widget_hide(window);
554         return FALSE;
555 }
556
557 static void about_uri_clicked(GtkButton *button, gpointer data)
558 {
559         open_uri(HOMEPAGE_URI, prefs_common.uri_cmd);
560 }
561
562 static gboolean about_textview_uri_clicked(GtkTextTag *tag, GObject *obj,
563                                         GdkEvent *event, GtkTextIter *iter,
564                                         GtkWidget *textview)
565 {
566         GtkTextIter start_iter, end_iter;
567         GdkEventButton *bevent;
568         gchar *link = NULL;
569
570         if (!event || !tag) {
571                 return FALSE;
572         }
573
574         if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS
575                 && event->type != GDK_BUTTON_RELEASE) {
576                 return FALSE;
577         }
578
579         /* get link text from tag */
580         if (get_tag_range(iter, tag, &start_iter,
581                                    &end_iter) == FALSE) {
582                 return FALSE;
583         }
584         link = gtk_text_iter_get_text(&start_iter, &end_iter);
585         if (link == NULL) {
586                 return FALSE;
587         }
588
589         bevent = (GdkEventButton *) event;
590         if (bevent->button == 1 && event->type == GDK_BUTTON_RELEASE) {
591                 GtkTextBuffer *buffer;
592
593                 /* we shouldn't follow a link if the user has selected something */
594                 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
595                 gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter);
596                 if (gtk_text_iter_get_offset(&start_iter) != gtk_text_iter_get_offset(&end_iter)) {
597                         return FALSE;
598                 }
599                 /* open link and do *not* return TRUE so that
600                    further gtk processing of the signal is done */
601                 open_uri(link, prefs_common.uri_cmd);
602
603         } else {
604                 if (bevent->button == 3 && event->type == GDK_BUTTON_PRESS) {
605                         GtkItemFactory *link_popupfactory;
606                         gint n_entries;
607
608                         n_entries = sizeof(textview_link_popup_entries) /
609                                         sizeof(textview_link_popup_entries[0]);
610                         link_popupmenu = menu_create_items(
611                                                         textview_link_popup_entries, n_entries,
612                                                 "<UriPopupMenu>", &link_popupfactory,
613                                                 textview);
614
615                         g_object_set_data(
616                                         G_OBJECT(link_popupmenu),
617                                         "menu_button", link);
618                         gtk_menu_popup(GTK_MENU(link_popupmenu), 
619                                         NULL, NULL, NULL, NULL, 
620                                         bevent->button, bevent->time);
621
622                         return TRUE;
623                 }
624         }
625         return FALSE;
626 }
627
628 static void about_open_link_cb(GtkWidget *widget, guint action, void *data)
629 {
630         gchar *link = g_object_get_data(G_OBJECT(link_popupmenu),
631                                            "menu_button");
632
633         if (link == NULL) {
634                 return;
635         }
636
637         open_uri(link, prefs_common.uri_cmd);
638         g_object_set_data(G_OBJECT(link_popupmenu), "menu_button",
639                           NULL);
640 }
641
642 static void about_copy_link_cb(GtkWidget *widget, guint action, void *data)
643 {
644         gchar *link = g_object_get_data(G_OBJECT(link_popupmenu),
645                                            "menu_button");
646
647         if (link == NULL) {
648                 return;
649         }
650
651         gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), link, -1);
652         gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), link, -1);
653         g_object_set_data(G_OBJECT(link_popupmenu), "menu_button", NULL);
654 }
655
656 static gboolean about_textview_motion_notify(GtkWidget *widget,
657                                         GdkEventMotion *event,
658                                         GtkWidget *textview)
659 {
660         about_textview_uri_update(textview, event->x, event->y);
661         gdk_window_get_pointer(widget->window, NULL, NULL, NULL);
662
663         return FALSE;
664 }
665
666 static gboolean about_textview_leave_notify(GtkWidget *widget,
667                                         GdkEventCrossing *event,
668                                         GtkWidget *textview)
669 {
670         about_textview_uri_update(textview, -1, -1);
671
672         return FALSE;
673 }
674
675 static void about_textview_uri_update(GtkWidget *textview, gint x, gint y)
676 {
677         GtkTextBuffer *buffer;
678         GtkTextIter start_iter, end_iter;
679         gchar *uri = NULL;
680         gboolean same;
681         
682         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
683
684         if (x != -1 && y != -1) {
685                 gint bx, by;
686                 GtkTextIter iter;
687                 GSList *tags;
688                 GSList *cur;
689             
690                 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(textview), 
691                                 GTK_TEXT_WINDOW_WIDGET,
692                                 x, y, &bx, &by);
693                 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(textview),
694                                 &iter, bx, by);
695
696                 tags = gtk_text_iter_get_tags(&iter);
697                 for (cur = tags; cur != NULL; cur = cur->next) {
698                         GtkTextTag *tag = cur->data;
699                         char *name;
700
701                         g_object_get(G_OBJECT(tag), "name", &name, NULL);
702                         if (strcmp(name, "link") == 0
703                             && get_tag_range(&iter, tag, &start_iter, &end_iter)) {
704                                 uri = gtk_text_iter_get_text(&start_iter, &end_iter);
705                         }
706                         g_free(name);
707
708                         if (uri) {
709                                 break;
710                         }
711                 }
712                 g_slist_free(tags);
713         }
714
715         /* compare previous hovered link and this one
716            (here links must be unique in text buffer otherwise RemoteURI structures should be
717            used as in textview.c) */
718         same = (uri != NULL && uri_hover != NULL
719                 && strcmp((char*)uri, (char*)uri_hover) == 0);
720
721         if (same == FALSE) {
722                 GdkWindow *window;
723
724                 if (uri_hover) {
725                         gtk_text_buffer_remove_tag_by_name(buffer,
726                                         "link-hover",
727                                         &uri_hover_start_iter,
728                                         &uri_hover_end_iter);
729                 }
730                     
731                 uri_hover = uri;
732                 if (uri) {
733                         uri_hover_start_iter = start_iter;
734                         uri_hover_end_iter = end_iter;
735
736                         gtk_text_buffer_apply_tag_by_name(buffer,
737                                         "link-hover",
738                                         &start_iter,
739                                         &end_iter);
740                 }
741                 
742                 window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview),
743                                                 GTK_TEXT_WINDOW_TEXT);
744                 if (!hand_cursor)
745                         hand_cursor = gdk_cursor_new(GDK_HAND2);
746                 if (!text_cursor)
747                         text_cursor = gdk_cursor_new(GDK_XTERM);
748                 gdk_window_set_cursor(window, uri ? hand_cursor : text_cursor);
749         }
750 }