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