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