2008-06-21 [paul] 3.4.0cvs101
[claws.git] / src / gtk / about.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2008 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 GENERIC_UMPC
160         gtk_text_buffer_insert(buffer, &iter, _(
161                                 "\n\nCopyright (C) 1999-2008\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 HAVE_LIBCOMPFACE
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, (" compface "), -1,
421                                                  "bold", NULL);
422         gtk_text_buffer_insert(buffer, &iter, 
423                 (gchar *)Q_("compface|adds support for the X-Face header\n"), -1);
424
425 #if USE_ASPELL
426         gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
427 #else
428         gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
429 #endif
430         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" GNU/aspell "), -1,
431                                                  "bold", NULL);
432         gtk_text_buffer_insert(buffer, &iter, 
433                 (gchar *)Q_("GNU/aspell|adds support for spell checking\n"), -1);
434
435 #if USE_GNUTLS
436         gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
437 #else
438         gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
439 #endif
440         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" GnuTLS "), -1,
441                                                  "bold", NULL);
442         gtk_text_buffer_insert(buffer, &iter, 
443                 (gchar *)Q_("GnuTLS|adds support for encrypted connections to servers\n"), -1);
444
445 #if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
446         gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
447 #else
448         gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
449 #endif
450         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" GTK+ >= 2.10.0 "), -1,
451                                                  "bold", NULL);
452         gtk_text_buffer_insert(buffer, &iter, 
453                 (gchar *)Q_("GTK+ >= 2.10.0|adds support for a complete print dialog\n"), -1);
454
455 #if INET6
456         gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
457 #else
458         gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
459 #endif
460         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" IPv6 "), -1,
461                                                  "bold", NULL);
462         gtk_text_buffer_insert(buffer, &iter, 
463                 (gchar *)Q_("IPv6|adds support for IPv6 addresses, the new Internet "
464                             "addressing protocol\n"), -1);
465
466 #if HAVE_ICONV
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, (" iconv "), -1,
472                                                  "bold", NULL);
473         gtk_text_buffer_insert(buffer, &iter, 
474                 (gchar *)Q_("iconv|allows converting to and from different character sets\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_LDAP
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, (" LDAP "), -1,
492                                                  "bold", NULL);
493         gtk_text_buffer_insert(buffer, &iter, 
494                 (gchar *)Q_("LDAP|adds support for LDAP shared addressbooks\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 and NNTP 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 #if HAVE_NETWORKMANAGER_SUPPORT
527         gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
528 #else
529         gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
530 #endif
531         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" NetworkManager "), -1,
532                                                  "bold", NULL);
533         gtk_text_buffer_insert(buffer, &iter,
534                 (gchar *)Q_("NetworkManager|adds support for detection of network connection changes\n"), -1);
535
536 #if USE_OPENSSL
537         gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
538 #else
539         gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
540 #endif
541         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" OpenSSL "), -1,
542                                                  "bold", NULL);
543         gtk_text_buffer_insert(buffer, &iter, 
544                 (gchar *)Q_("OpenSSL|adds support for encrypted connections to servers\n"), -1);
545
546         return scrolledwin;
547 }
548
549 static GtkWidget *about_create_child_page_license(void)
550 {
551         GtkWidget *scrolledwin;
552         GtkWidget *text;
553         GtkTextBuffer *buffer;
554         GtkTextIter iter;
555         GdkColor uri_color;
556         GtkTextTag *tag;
557
558         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
559         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
560                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
561         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
562                                             GTK_SHADOW_IN);
563
564         text = gtk_text_view_new();
565         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
566         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
567         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
568         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
569         gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
570         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
571
572         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
573         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
574
575         gtk_text_buffer_insert(buffer, &iter,
576                 _("This program is free software; you can redistribute it and/or modify "
577                   "it under the terms of the GNU General Public License as published by "
578                   "the Free Software Foundation; either version 3, or (at your option) "
579                   "any later version.\n\n"), -1);
580
581         gtk_text_buffer_insert(buffer, &iter,
582                 _("This program is distributed in the hope that it will be useful, "
583                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
584                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
585                   "See the GNU General Public License for more details.\n\n"), -1);
586
587         /* textview link style (based upon main prefs) */
588         gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
589                         (GdkColor*)&uri_color);
590
591         tag = gtk_text_buffer_create_tag(buffer, "link",
592                 "foreground-gdk", &uri_color,
593                 NULL);
594         gtk_text_buffer_create_tag(buffer, "link-hover",
595                 "foreground-gdk", &uri_color,
596                 "underline", PANGO_UNDERLINE_SINGLE,
597                 NULL);
598
599         gtk_text_buffer_insert(buffer, &iter,
600                 _("You should have received a copy of the GNU General Public License "
601                   "along with this program. If not, see "), -1);
602         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, 
603                 "http://www.gnu.org/licenses/", -1,
604                 "link", NULL);
605         gtk_text_buffer_insert(buffer, &iter, ".\n\n", -1);
606 #ifdef USE_OPENSSL
607         gtk_text_buffer_insert(buffer, &iter,
608                 _("This product includes software developed by the OpenSSL Project "
609                   "for use in the OpenSSL Toolkit ("), -1);
610         gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, OPENSSL_URI, -1,
611                 "link", NULL);
612         gtk_text_buffer_insert(buffer, &iter, _(").\n"), -1);
613 #endif
614
615         g_signal_connect(G_OBJECT(tag), "event",
616                                 G_CALLBACK(about_textview_uri_clicked), text);
617         g_signal_connect(G_OBJECT(text), "motion-notify-event",
618                          G_CALLBACK(about_textview_motion_notify), text);
619         g_signal_connect(G_OBJECT(text), "leave-notify-event",
620                                 G_CALLBACK(about_textview_leave_notify), text);
621
622         return scrolledwin;
623 }
624
625 static gboolean release_notes_available(void)
626 {
627         gboolean ret = FALSE;
628         gchar *path = NULL;
629
630         path = g_strconcat(DOCDIR, G_DIR_SEPARATOR_S, RELEASE_NOTES_FILE, NULL);
631         ret = (is_file_exist(path));
632         g_free(path);
633
634         return ret;
635 }
636
637 static GtkWidget *about_create_child_page_release_notes(void)
638 {
639         GtkWidget *scrolledwin;
640         GtkWidget *text;
641         GtkTextBuffer *buffer;
642         GtkTextIter iter;
643         gchar *path, buf[1024];
644         FILE *fp;
645
646         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
647         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
648                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
649         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
650                         GTK_SHADOW_IN);
651         text = gtk_text_view_new();
652         gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
653         gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
654         gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
655         gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
656         gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
657         gtk_container_add(GTK_CONTAINER(scrolledwin), text);
658
659         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
660         gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
661
662         path = g_strconcat(DOCDIR, G_DIR_SEPARATOR_S, RELEASE_NOTES_FILE, NULL);
663         if ((fp = g_fopen(path, "rb")) == NULL) {
664                 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
665                 g_free(path);
666                 return scrolledwin;
667         }
668         g_free(path);
669
670         while (fgets(buf, sizeof(buf), fp) != NULL) {
671                 const gchar *src_codeset = conv_get_locale_charset_str();
672                 const gchar *dest_codeset = CS_UTF_8;
673                 gchar *tmp;
674
675                 tmp = conv_codeset_strdup(buf, src_codeset, dest_codeset);
676                 if (!tmp) {
677                         g_warning("Failed to convert character set of action configuration\n");
678                         tmp = g_strdup(buf);
679                 }
680
681                 gtk_text_buffer_insert(buffer, &iter, tmp, -1);
682                 g_free(tmp);
683         }
684         fclose(fp);
685
686         return scrolledwin;
687 }
688
689 static void about_create(void)
690 {
691         GtkWidget *vbox1;
692         GtkWidget *image;       
693         GtkWidget *vbox2;
694         GtkWidget *label;
695         GtkWidget *button;
696         GtkWidget *scrolledwin;
697         GtkWidget *notebook;
698         GtkWidget *table;
699         char *markup;
700         GtkWidget *confirm_area;
701         GtkWidget *close_button;
702         static GdkGeometry geometry;
703
704         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "about");
705         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
706         gtk_window_set_title(GTK_WINDOW(window), _("About Claws Mail"));
707         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
708         gtk_widget_set_size_request(window, -1, -1);
709         g_signal_connect(G_OBJECT(window), "delete_event",
710                          G_CALLBACK(gtk_widget_hide_on_delete), NULL);
711         g_signal_connect(G_OBJECT(window), "key_press_event",
712                          G_CALLBACK(key_pressed), NULL);
713         gtk_widget_realize(window);
714
715         if (!geometry.min_width) {
716                 geometry.min_width = 450;
717                 geometry.min_height = 500;
718         }
719
720         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
721                                       GDK_HINT_MIN_SIZE);
722
723         vbox1 = gtk_vbox_new(FALSE, 8);
724         gtk_container_add(GTK_CONTAINER(window), vbox1);
725
726         table = gtk_table_new (2, 1, FALSE);
727         gtk_box_pack_start(GTK_BOX(vbox1), table,
728                         FALSE, FALSE, 0);
729         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
730         gtk_table_set_row_spacings (GTK_TABLE (table), 8);
731         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
732
733         image = stock_pixmap_widget(window, STOCK_PIXMAP_CLAWS_MAIL_LOGO);
734         gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 1,
735                         (GtkAttachOptions) (GTK_EXPAND),
736                         (GtkAttachOptions) (0), 0, 0);
737
738         vbox2 = gtk_vbox_new (FALSE, 4);
739         gtk_table_attach (GTK_TABLE (table), vbox2, 1, 2, 0, 1,
740                         (GtkAttachOptions) (GTK_EXPAND),
741                         (GtkAttachOptions) (0), 0, 0);
742
743         label = gtk_label_new("");
744         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
745         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
746         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
747         markup = g_markup_printf_escaped
748                 ("<span weight=\"bold\" size=\"xx-large\">Claws Mail</span>\nversion %s",
749                  VERSION);
750         gtk_label_set_markup(GTK_LABEL(label), markup);
751         g_free(markup);
752
753         button = gtkut_get_link_btn(window, HOMEPAGE_URI, " "HOMEPAGE_URI" ");
754         gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0);
755 #ifndef GENERIC_UMPC
756         label = gtk_label_new
757                 (_("Copyright (C) 1999-2008\nHiroyuki Yamamoto <hiro-y@kcn.ne.jp>\n"
758                  "and the Claws Mail team"));
759         gtk_label_set_selectable(GTK_LABEL(label), TRUE);
760         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
761         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
762         gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
763 #endif
764         notebook = gtk_notebook_new();
765         gtk_widget_set_size_request(notebook, -1, 220);
766         gtk_widget_show(notebook);
767
768         if ((scrolledwin = about_create_child_page_info()) != NULL) {
769                 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
770                                 scrolledwin,
771                                 gtk_label_new_with_mnemonic(_("_Info")));
772         }
773
774         if ((scrolledwin = about_create_child_page_authors()) != NULL) {
775                 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
776                                 scrolledwin,
777                                 gtk_label_new_with_mnemonic(_("_Authors")));
778         }
779
780         if ((scrolledwin = about_create_child_page_features()) != NULL) {
781                 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
782                                 scrolledwin,
783                                 gtk_label_new_with_mnemonic(_("_Features")));
784         }
785
786         if ((scrolledwin = about_create_child_page_license()) != NULL) {
787                 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
788                                 scrolledwin,
789                                 gtk_label_new_with_mnemonic(_("_License")));
790         }
791
792         if (release_notes_available() &&
793                         (scrolledwin = about_create_child_page_release_notes()) != NULL) {
794
795                 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
796                                 scrolledwin,
797                                 gtk_label_new_with_mnemonic(_("_Release Notes")));
798         }
799
800         gtk_box_pack_start(GTK_BOX(vbox1), notebook, TRUE, TRUE, 0);
801
802         gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,
803                                       NULL, NULL, NULL, NULL);
804         gtk_box_pack_end(GTK_BOX(vbox1), confirm_area, FALSE, FALSE, 4);
805         gtk_widget_grab_default(close_button);
806         gtk_widget_grab_focus(close_button);
807         g_signal_connect_closure
808                 (G_OBJECT(close_button), "clicked",
809                  g_cclosure_new_swap(G_CALLBACK(gtk_widget_hide_on_delete),
810                                      window, NULL), FALSE);
811
812         gtk_widget_show_all(window);
813 }
814
815 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event)
816 {
817         if (event && event->keyval == GDK_Escape)
818                 gtk_widget_hide(window);
819         return FALSE;
820 }
821
822 static gboolean about_textview_uri_clicked(GtkTextTag *tag, GObject *obj,
823                                         GdkEvent *event, GtkTextIter *iter,
824                                         GtkWidget *textview)
825 {
826         GtkTextIter start_iter, end_iter;
827         GdkEventButton *bevent;
828         gchar *link = NULL;
829
830         if (!event || !tag) {
831                 return FALSE;
832         }
833
834         if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS
835                 && event->type != GDK_BUTTON_RELEASE) {
836                 return FALSE;
837         }
838
839         /* get link text from tag */
840         if (get_tag_range(iter, tag, &start_iter,
841                                    &end_iter) == FALSE) {
842                 return FALSE;
843         }
844         link = gtk_text_iter_get_text(&start_iter, &end_iter);
845         if (link == NULL) {
846                 return FALSE;
847         }
848
849         bevent = (GdkEventButton *) event;
850         if (bevent->button == 1 && event->type == GDK_BUTTON_RELEASE) {
851                 GtkTextBuffer *buffer;
852
853                 /* we shouldn't follow a link if the user has selected something */
854                 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
855                 gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter);
856                 if (gtk_text_iter_get_offset(&start_iter) != gtk_text_iter_get_offset(&end_iter)) {
857                         return FALSE;
858                 }
859                 /* open link and do *not* return TRUE so that
860                    further gtk processing of the signal is done */
861                 open_uri(link, prefs_common_get_uri_cmd());
862
863         } else {
864                 if (bevent->button == 3 && event->type == GDK_BUTTON_PRESS) {
865                         GtkItemFactory *link_popupfactory;
866                         gint n_entries;
867
868                         n_entries = sizeof(textview_link_popup_entries) /
869                                         sizeof(textview_link_popup_entries[0]);
870                         link_popupmenu = menu_create_items(
871                                                         textview_link_popup_entries, n_entries,
872                                                 "<UriPopupMenu>", &link_popupfactory,
873                                                 textview);
874
875                         g_object_set_data(
876                                         G_OBJECT(link_popupmenu),
877                                         "menu_button", link);
878                         gtk_menu_popup(GTK_MENU(link_popupmenu), 
879                                         NULL, NULL, NULL, NULL, 
880                                         bevent->button, bevent->time);
881
882                         return TRUE;
883                 }
884         }
885         return FALSE;
886 }
887
888 static void about_open_link_cb(GtkWidget *widget, guint action, void *data)
889 {
890         gchar *link = g_object_get_data(G_OBJECT(link_popupmenu),
891                                            "menu_button");
892
893         if (link == NULL) {
894                 return;
895         }
896
897         open_uri(link, prefs_common_get_uri_cmd());
898         g_object_set_data(G_OBJECT(link_popupmenu), "menu_button",
899                           NULL);
900 }
901
902 static void about_copy_link_cb(GtkWidget *widget, guint action, void *data)
903 {
904         gchar *link = g_object_get_data(G_OBJECT(link_popupmenu),
905                                            "menu_button");
906
907         if (link == NULL) {
908                 return;
909         }
910
911         gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), link, -1);
912         gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), link, -1);
913         g_object_set_data(G_OBJECT(link_popupmenu), "menu_button", NULL);
914 }
915
916 static gboolean about_textview_motion_notify(GtkWidget *widget,
917                                         GdkEventMotion *event,
918                                         GtkWidget *textview)
919 {
920         about_textview_uri_update(textview, event->x, event->y);
921         gdk_window_get_pointer(widget->window, NULL, NULL, NULL);
922
923         return FALSE;
924 }
925
926 static gboolean about_textview_leave_notify(GtkWidget *widget,
927                                         GdkEventCrossing *event,
928                                         GtkWidget *textview)
929 {
930         about_textview_uri_update(textview, -1, -1);
931
932         return FALSE;
933 }
934
935 static void about_textview_uri_update(GtkWidget *textview, gint x, gint y)
936 {
937         GtkTextBuffer *buffer;
938         GtkTextIter start_iter, end_iter;
939         gchar *uri = NULL;
940         gboolean same;
941         
942         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
943
944         if (x != -1 && y != -1) {
945                 gint bx, by;
946                 GtkTextIter iter;
947                 GSList *tags;
948                 GSList *cur;
949             
950                 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(textview), 
951                                 GTK_TEXT_WINDOW_WIDGET,
952                                 x, y, &bx, &by);
953                 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(textview),
954                                 &iter, bx, by);
955
956                 tags = gtk_text_iter_get_tags(&iter);
957                 for (cur = tags; cur != NULL; cur = cur->next) {
958                         GtkTextTag *tag = cur->data;
959                         char *name;
960
961                         g_object_get(G_OBJECT(tag), "name", &name, NULL);
962                         if (strcmp(name, "link") == 0
963                             && get_tag_range(&iter, tag, &start_iter, &end_iter)) {
964                                 uri = gtk_text_iter_get_text(&start_iter, &end_iter);
965                         }
966                         g_free(name);
967
968                         if (uri) {
969                                 break;
970                         }
971                 }
972                 g_slist_free(tags);
973         }
974
975         /* compare previous hovered link and this one
976            (here links must be unique in text buffer otherwise ClickableText structures should be
977            used as in textview.c) */
978         same = (uri != NULL && uri_hover != NULL
979                 && strcmp((char*)uri, (char*)uri_hover) == 0);
980
981         if (same == FALSE) {
982                 GdkWindow *window;
983
984                 if (uri_hover) {
985                         gtk_text_buffer_remove_tag_by_name(buffer,
986                                         "link-hover",
987                                         &uri_hover_start_iter,
988                                         &uri_hover_end_iter);
989                 }
990                     
991                 uri_hover = uri;
992                 if (uri) {
993                         uri_hover_start_iter = start_iter;
994                         uri_hover_end_iter = end_iter;
995
996                         gtk_text_buffer_apply_tag_by_name(buffer,
997                                         "link-hover",
998                                         &start_iter,
999                                         &end_iter);
1000                 }
1001                 
1002                 window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview),
1003                                                 GTK_TEXT_WINDOW_TEXT);
1004                 if (!hand_cursor)
1005                         hand_cursor = gdk_cursor_new(GDK_HAND2);
1006                 if (!text_cursor)
1007                         text_cursor = gdk_cursor_new(GDK_XTERM);
1008                 gdk_window_set_cursor(window, uri ? hand_cursor : text_cursor);
1009         }
1010 }