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