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