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