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