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