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