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