]> Pileus Git - ~andy/gtk/blob - gtk/gtkaboutdialog.c
Unseal GtkAboutDialog's private_data member, convert from gpointer to GtkAboutDialogP...
[~andy/gtk] / gtk / gtkaboutdialog.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2001 CodeFactory AB
3  * Copyright (C) 2001, 2002 Anders Carlsson
4  * Copyright (C) 2003, 2004 Matthias Clasen <mclasen@redhat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /*
23  * Author: Anders Carlsson <andersca@gnome.org>
24  *
25  * Modified by the GTK+ Team and others 1997-2004.  See the AUTHORS
26  * file for a list of people on the GTK+ Team.  See the ChangeLog
27  * files for a list of changes.  These files are distributed with
28  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29  */
30
31 #include "config.h"
32
33 #include <string.h>
34
35 #include <gdk/gdkkeysyms.h>
36
37 #include "gtkaboutdialog.h"
38 #include "gtkbutton.h"
39 #include "gtkbbox.h"
40 #include "gtkdialog.h"
41 #include "gtkhbox.h"
42 #include "gtkimage.h"
43 #include "gtklabel.h"
44 #include "gtklinkbutton.h"
45 #include "gtkmarshalers.h"
46 #include "gtknotebook.h"
47 #include "gtkscrolledwindow.h"
48 #include "gtkstock.h"
49 #include "gtktextview.h"
50 #include "gtkvbox.h"
51 #include "gtkiconfactory.h"
52 #include "gtkshow.h"
53 #include "gtkmain.h"
54 #include "gtkmessagedialog.h"
55 #include "gtkprivate.h"
56 #include "gtkintl.h"
57
58 #include "gtkalias.h"
59
60
61 /**
62  * SECTION:gtkaboutdialog
63  * @Short_description: Display information about an application
64  * @Title: GtkAboutDialog
65  * @See_also:#GTK_STOCK_ABOUT
66  *
67  * The #GtkAboutDialog offers a simple way to display information about
68  * a program like its logo, name, copyright, website and license. It is
69  * also possible to give credits to the authors, documenters, translators
70  * and artists who have worked on the program. An about dialog is typically
71  * opened when the user selects the <literal>About</literal> option from
72  * the <literal>Help</literal> menu. All parts of the dialog are optional.
73  *
74  * About dialog often contain links and email addresses. #GtkAboutDialog
75  * supports this by offering global hooks, which are called when the user
76  * clicks on a link or email address, see gtk_about_dialog_set_email_hook()
77  * and gtk_about_dialog_set_url_hook(). Email addresses in the
78  * authors, documenters and artists properties are recognized by looking for
79  * <literal>&lt;user@<!-- -->host&gt;</literal>, URLs are
80  * recognized by looking for <literal>http://url</literal>, with
81  * <literal>url</literal> extending to the next space, tab or line break.
82  *
83  * <para id="gtk-about-dialog-hook-setup">
84  * Since 2.18 #GtkAboutDialog provides default website and email hooks that
85  * use gtk_show_uri().
86  * </para>
87  *
88  * If you want provide your own hooks overriding the default ones, it is
89  * important to do so before setting the website and email URL properties,
90  * like this:
91  * <informalexample><programlisting>
92  * gtk_about_dialog_set_url_hook (GTK_ABOUT_DIALOG (dialog), launch_url, NULL, NULL);
93  * gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), app_url);
94  * </programlisting></informalexample>
95  * To disable the default hooks, you can pass %NULL as the hook func. Then,
96  * the #GtkAboutDialog widget will not display the website or the
97  * email addresses as clickable.
98  *
99  * To make constructing a #GtkAboutDialog as convenient as possible, you can
100  * use the function gtk_show_about_dialog() which constructs and shows a dialog
101  * and keeps it around so that it can be shown again.
102  *
103  * Note that GTK+ sets a default title of <literal>_("About &percnt;s")</literal>
104  * on the dialog window (where &percnt;s is replaced by the name of the
105  * application, but in order to ensure proper translation of the title,
106  * applications should set the title property explicitly when constructing
107  * a #GtkAboutDialog, as shown in the following example:
108  * <informalexample><programlisting>
109  * gtk_show_about_dialog (NULL,
110  *                        "program-name", "ExampleCode",
111  *                        "logo", example_logo,
112  *                        "title" _("About ExampleCode"),
113  *                        NULL);
114  * </programlisting></informalexample>
115  * Note that prior to GTK+ 2.12, the #GtkAboutDialog:program-name property
116  * was called "name". This was changed to avoid the conflict with the
117  * #GtkWidget:name property.
118  */
119
120
121 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
122 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
123
124 struct _GtkAboutDialogPrivate 
125 {
126   gchar *name;
127   gchar *version;
128   gchar *copyright;
129   gchar *comments;
130   gchar *website_url;
131   gchar *website_text;
132   gchar *translator_credits;
133   gchar *license;
134
135   gchar **authors;
136   gchar **documenters;
137   gchar **artists;
138
139   GtkWidget *logo_image;
140   GtkWidget *name_label;
141   GtkWidget *comments_label;
142   GtkWidget *copyright_label;
143   GtkWidget *website_label;
144
145   GtkWidget *credits_button;
146   GtkWidget *credits_dialog;
147   GtkWidget *license_button;
148   GtkWidget *license_dialog;
149
150   GdkCursor *hand_cursor;
151   GdkCursor *regular_cursor;
152
153   GSList *visited_links;
154
155   guint hovering_over_link : 1;
156   guint wrap_license : 1;
157 };
158
159 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
160
161
162 enum
163 {
164   PROP_0,
165   PROP_NAME,
166   PROP_VERSION,
167   PROP_COPYRIGHT,
168   PROP_COMMENTS,
169   PROP_WEBSITE,
170   PROP_WEBSITE_LABEL,
171   PROP_LICENSE,
172   PROP_AUTHORS,
173   PROP_DOCUMENTERS,
174   PROP_TRANSLATOR_CREDITS,
175   PROP_ARTISTS,
176   PROP_LOGO,
177   PROP_LOGO_ICON_NAME,
178   PROP_WRAP_LICENSE
179 };
180
181 static void                 gtk_about_dialog_finalize       (GObject            *object);
182 static void                 gtk_about_dialog_get_property   (GObject            *object,
183                                                              guint               prop_id,
184                                                              GValue             *value,
185                                                              GParamSpec         *pspec);
186 static void                 gtk_about_dialog_set_property   (GObject            *object,
187                                                              guint               prop_id,
188                                                              const GValue       *value,
189                                                              GParamSpec         *pspec);
190 static void                 gtk_about_dialog_show           (GtkWidget          *widge);
191 static void                 update_name_version             (GtkAboutDialog     *about);
192 static GtkIconSet *         icon_set_new_from_pixbufs       (GList              *pixbufs);
193 static void                 follow_if_link                  (GtkAboutDialog     *about,
194                                                              GtkTextView        *text_view,
195                                                              GtkTextIter        *iter);
196 static void                 set_cursor_if_appropriate       (GtkAboutDialog     *about,
197                                                              GtkTextView        *text_view,
198                                                              gint                x,
199                                                              gint                y);
200 static void                 display_credits_dialog          (GtkWidget          *button,
201                                                              gpointer            data);
202 static void                 display_license_dialog          (GtkWidget          *button,
203                                                              gpointer            data);
204 static void                 close_cb                        (GtkAboutDialog     *about);
205 static void                 default_url_hook                (GtkAboutDialog     *about,
206                                                              const gchar        *uri,
207                                                              gpointer            user_data);
208 static void                 default_email_hook              (GtkAboutDialog     *about,
209                                                              const gchar        *email_address,
210                                                              gpointer            user_data);
211
212 static gboolean activate_email_hook_set = FALSE;
213 static GtkAboutDialogActivateLinkFunc activate_email_hook = NULL;
214 static gpointer activate_email_hook_data = NULL;
215 static GDestroyNotify activate_email_hook_destroy = NULL;
216
217 static gboolean activate_url_hook_set = FALSE;
218 static GtkAboutDialogActivateLinkFunc activate_url_hook = NULL;
219 static gpointer activate_url_hook_data = NULL;
220 static GDestroyNotify activate_url_hook_destroy = NULL;
221
222 static void
223 default_url_hook (GtkAboutDialog *about,
224                   const gchar    *uri,
225                   gpointer        user_data)
226 {
227   GdkScreen *screen;
228   GError *error = NULL;
229
230   screen = gtk_widget_get_screen (GTK_WIDGET (about));
231
232   if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
233     {
234       GtkWidget *dialog;
235
236       dialog = gtk_message_dialog_new (GTK_WINDOW (about),
237                                        GTK_DIALOG_DESTROY_WITH_PARENT |
238                                        GTK_DIALOG_MODAL,
239                                        GTK_MESSAGE_ERROR,
240                                        GTK_BUTTONS_CLOSE,
241                                        "%s", _("Could not show link"));
242       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
243                                                 "%s", error->message);
244       g_error_free (error);
245
246       g_signal_connect (dialog, "response",
247                         G_CALLBACK (gtk_widget_destroy), NULL);
248
249       gtk_window_present (GTK_WINDOW (dialog));
250     }
251 }
252
253 static void
254 default_email_hook (GtkAboutDialog *about,
255                     const gchar    *email_address,
256                     gpointer        user_data)
257 {
258   char *escaped, *uri;
259
260   escaped = g_uri_escape_string (email_address, NULL, FALSE);
261   uri = g_strdup_printf ("mailto:%s", escaped);
262   g_free (escaped);
263
264   default_url_hook (about, uri, user_data);
265   g_free (uri);
266 }
267
268 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
269
270 static void
271 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
272 {
273   GObjectClass *object_class;
274   GtkWidgetClass *widget_class;
275
276   object_class = (GObjectClass *)klass;
277   widget_class = (GtkWidgetClass *)klass;
278
279   object_class->set_property = gtk_about_dialog_set_property;
280   object_class->get_property = gtk_about_dialog_get_property;
281
282   object_class->finalize = gtk_about_dialog_finalize;
283
284   widget_class->show = gtk_about_dialog_show;
285
286   /**
287    * GtkAboutDialog:program-name:
288    *
289    * The name of the program.
290    * If this is not set, it defaults to g_get_application_name().
291    *
292    * Since: 2.12
293    */
294   g_object_class_install_property (object_class,
295                                    PROP_NAME,
296                                    g_param_spec_string ("program-name",
297                                                         P_("Program name"),
298                                                         P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
299                                                         NULL,
300                                                         GTK_PARAM_READWRITE));
301
302   /**
303    * GtkAboutDialog:version:
304    *
305    * The version of the program.
306    *
307    * Since: 2.6
308    */
309   g_object_class_install_property (object_class,
310                                    PROP_VERSION,
311                                    g_param_spec_string ("version",
312                                                         P_("Program version"),
313                                                         P_("The version of the program"),
314                                                         NULL,
315                                                         GTK_PARAM_READWRITE));
316
317   /**
318    * GtkAboutDialog:copyright:
319    *
320    * Copyright information for the program.
321    *
322    * Since: 2.6
323    */
324   g_object_class_install_property (object_class,
325                                    PROP_COPYRIGHT,
326                                    g_param_spec_string ("copyright",
327                                                         P_("Copyright string"),
328                                                         P_("Copyright information for the program"),
329                                                         NULL,
330                                                         GTK_PARAM_READWRITE));
331         
332
333   /**
334    * GtkAboutDialog:comments:
335    *
336    * Comments about the program. This string is displayed in a label
337    * in the main dialog, thus it should be a short explanation of
338    * the main purpose of the program, not a detailed list of features.
339    *
340    * Since: 2.6
341    */
342   g_object_class_install_property (object_class,
343                                    PROP_COMMENTS,
344                                    g_param_spec_string ("comments",
345                                                         P_("Comments string"),
346                                                         P_("Comments about the program"),
347                                                         NULL,
348                                                         GTK_PARAM_READWRITE));
349
350   /**
351    * GtkAboutDialog:license:
352    *
353    * The license of the program. This string is displayed in a
354    * text view in a secondary dialog, therefore it is fine to use
355    * a long multi-paragraph text. Note that the text is only wrapped
356    * in the text view if the "wrap-license" property is set to %TRUE;
357    * otherwise the text itself must contain the intended linebreaks.
358    *
359    * Since: 2.6
360    */
361   g_object_class_install_property (object_class,
362                                    PROP_LICENSE,
363                                    g_param_spec_string ("license",
364                                                         _("License"),
365                                                         _("The license of the program"),
366                                                         NULL,
367                                                         GTK_PARAM_READWRITE));
368
369   /**
370    * GtkAboutDialog:website:
371    *
372    * The URL for the link to the website of the program.
373    * This should be a string starting with "http://.
374    *
375    * Since: 2.6
376    */
377   g_object_class_install_property (object_class,
378                                    PROP_WEBSITE,
379                                    g_param_spec_string ("website",
380                                                         P_("Website URL"),
381                                                         P_("The URL for the link to the website of the program"),
382                                                         NULL,
383                                                         GTK_PARAM_READWRITE));
384
385   /**
386    * GtkAboutDialog:website-label:
387    *
388    * The label for the link to the website of the program. If this is not set,
389    * it defaults to the URL specified in the #GtkAboutDialog:website property.
390    *
391    * Since: 2.6
392    */
393   g_object_class_install_property (object_class,
394                                    PROP_WEBSITE_LABEL,
395                                    g_param_spec_string ("website-label",
396                                                         P_("Website label"),
397                                                         P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
398                                                         NULL,
399                                                         GTK_PARAM_READWRITE));
400
401   /**
402    * GtkAboutDialog:authors:
403    *
404    * The authors of the program, as a %NULL-terminated array of strings.
405    * Each string may contain email addresses and URLs, which will be displayed
406    * as links, see the introduction for more details.
407    *
408    * Since: 2.6
409    */
410   g_object_class_install_property (object_class,
411                                    PROP_AUTHORS,
412                                    g_param_spec_boxed ("authors",
413                                                        P_("Authors"),
414                                                        P_("List of authors of the program"),
415                                                        G_TYPE_STRV,
416                                                        GTK_PARAM_READWRITE));
417
418   /**
419    * GtkAboutDialog:documenters:
420    *
421    * The people documenting the program, as a %NULL-terminated array of strings.
422    * Each string may contain email addresses and URLs, which will be displayed
423    * as links, see the introduction for more details.
424    *
425    * Since: 2.6
426    */
427   g_object_class_install_property (object_class,
428                                    PROP_DOCUMENTERS,
429                                    g_param_spec_boxed ("documenters",
430                                                        P_("Documenters"),
431                                                        P_("List of people documenting the program"),
432                                                        G_TYPE_STRV,
433                                                        GTK_PARAM_READWRITE));
434
435   /**
436    * GtkAboutDialog:artists:
437    *
438    * The people who contributed artwork to the program, as a %NULL-terminated
439    * array of strings. Each string may contain email addresses and URLs, which
440    * will be displayed as links, see the introduction for more details.
441    *
442    * Since: 2.6
443    */
444   g_object_class_install_property (object_class,
445                                    PROP_ARTISTS,
446                                    g_param_spec_boxed ("artists",
447                                                        P_("Artists"),
448                                                        P_("List of people who have contributed artwork to the program"),
449                                                        G_TYPE_STRV,
450                                                        GTK_PARAM_READWRITE));
451
452
453   /**
454    * GtkAboutDialog:translator-credits:
455    *
456    * Credits to the translators. This string should be marked as translatable.
457    * The string may contain email addresses and URLs, which will be displayed
458    * as links, see the introduction for more details.
459    *
460    * Since: 2.6
461    */
462   g_object_class_install_property (object_class,
463                                    PROP_TRANSLATOR_CREDITS,
464                                    g_param_spec_string ("translator-credits",
465                                                         P_("Translator credits"),
466                                                         P_("Credits to the translators. This string should be marked as translatable"),
467                                                         NULL,
468                                                         GTK_PARAM_READWRITE));
469         
470   /**
471    * GtkAboutDialog:logo:
472    *
473    * A logo for the about box. If this is not set, it defaults to
474    * gtk_window_get_default_icon_list().
475    *
476    * Since: 2.6
477    */
478   g_object_class_install_property (object_class,
479                                    PROP_LOGO,
480                                    g_param_spec_object ("logo",
481                                                         P_("Logo"),
482                                                         P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
483                                                         GDK_TYPE_PIXBUF,
484                                                         GTK_PARAM_READWRITE));
485
486   /**
487    * GtkAboutDialog:logo-icon-name:
488    *
489    * A named icon to use as the logo for the about box. This property
490    * overrides the #GtkAboutDialog:logo property.
491    *
492    * Since: 2.6
493    */
494   g_object_class_install_property (object_class,
495                                    PROP_LOGO_ICON_NAME,
496                                    g_param_spec_string ("logo-icon-name",
497                                                         P_("Logo Icon Name"),
498                                                         P_("A named icon to use as the logo for the about box."),
499                                                         NULL,
500                                                         GTK_PARAM_READWRITE));
501   /**
502    * GtkAboutDialog:wrap-license:
503    *
504    * Whether to wrap the text in the license dialog.
505    *
506    * Since: 2.8
507    */
508   g_object_class_install_property (object_class,
509                                    PROP_WRAP_LICENSE,
510                                    g_param_spec_boolean ("wrap-license",
511                                                          P_("Wrap license"),
512                                                          P_("Whether to wrap the license text."),
513                                                          FALSE,
514                                                          GTK_PARAM_READWRITE));
515
516
517   g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
518 }
519
520 static gboolean
521 website_clicked (GtkLabel       *label,
522                  const gchar    *uri,
523                  GtkAboutDialog *about)
524 {
525   GtkAboutDialogActivateLinkFunc url_hook;
526   gpointer url_hook_data;
527
528   if (activate_url_hook_set)
529     {
530       url_hook = activate_url_hook;
531       url_hook_data = activate_url_hook_data;
532     }
533   else
534     {
535       url_hook = default_url_hook;
536       url_hook_data = NULL;
537     }
538
539   url_hook (about, uri, url_hook_data);
540
541   return TRUE;
542 }
543
544 static void
545 gtk_about_dialog_init (GtkAboutDialog *about)
546 {
547   GtkDialog *dialog = GTK_DIALOG (about);
548   GtkAboutDialogPrivate *priv;
549   GtkWidget *vbox, *hbox, *button, *close_button, *image;
550
551   /* Data */
552   priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
553   about->priv = priv;
554
555   priv->name = NULL;
556   priv->version = NULL;
557   priv->copyright = NULL;
558   priv->comments = NULL;
559   priv->website_url = NULL;
560   priv->website_text = NULL;
561   priv->translator_credits = NULL;
562   priv->license = NULL;
563   priv->authors = NULL;
564   priv->documenters = NULL;
565   priv->artists = NULL;
566
567   priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
568   priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
569   priv->hovering_over_link = FALSE;
570   priv->wrap_license = FALSE;
571
572   gtk_dialog_set_has_separator (dialog, FALSE);
573   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
574   gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
575   gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
576
577   /* Widgets */
578   gtk_widget_push_composite_child ();
579
580   vbox = gtk_vbox_new (FALSE, 8);
581   gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
582   gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
583
584   priv->logo_image = gtk_image_new ();
585   gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
586
587   priv->name_label = gtk_label_new (NULL);
588   gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
589   gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
590   gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
591
592   priv->comments_label = gtk_label_new (NULL);
593   gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
594   gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
595   gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
596   gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
597
598   priv->copyright_label = gtk_label_new (NULL);
599   gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
600   gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
601   gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
602
603   hbox = gtk_hbox_new (TRUE, 0);
604   gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
605
606   priv->website_label = button = gtk_label_new ("");
607   gtk_widget_set_no_show_all (button, TRUE);
608   gtk_label_set_selectable (GTK_LABEL (button), TRUE);
609   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
610   g_signal_connect (button, "activate-link",
611                     G_CALLBACK (website_clicked), about);
612
613   gtk_widget_show (vbox);
614   gtk_widget_show (priv->logo_image);
615   gtk_widget_show (priv->name_label);
616   gtk_widget_show (hbox);
617
618   /* Add the close button */
619   close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
620                                         GTK_RESPONSE_CANCEL);
621   gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
622
623   /* Add the credits button */
624   button = gtk_button_new_with_mnemonic (_("C_redits"));
625   gtk_widget_set_can_default (button, TRUE);
626   image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
627   gtk_button_set_image (GTK_BUTTON (button), image);
628   gtk_widget_set_no_show_all (button, TRUE);
629   gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area),
630                     button, FALSE, TRUE, 0);
631   gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
632   g_signal_connect (button, "clicked",
633                     G_CALLBACK (display_credits_dialog), about);
634   priv->credits_button = button;
635   priv->credits_dialog = NULL;
636
637   /* Add the license button */
638   button = gtk_button_new_from_stock (_("_License"));
639   gtk_widget_set_can_default (button, TRUE);
640   gtk_widget_set_no_show_all (button, TRUE);
641   gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area),
642                     button, FALSE, TRUE, 0);
643   gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
644   g_signal_connect (button, "clicked",
645                     G_CALLBACK (display_license_dialog), about);
646   priv->license_button = button;
647   priv->license_dialog = NULL;
648
649   gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
650
651   gtk_widget_pop_composite_child ();
652
653   gtk_widget_grab_default (close_button);
654   gtk_widget_grab_focus (close_button);
655
656   /* force defaults */
657   gtk_about_dialog_set_program_name (about, NULL);
658   gtk_about_dialog_set_logo (about, NULL);
659 }
660
661 static void
662 gtk_about_dialog_finalize (GObject *object)
663 {
664   GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
665   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
666
667   g_free (priv->name);
668   g_free (priv->version);
669   g_free (priv->copyright);
670   g_free (priv->comments);
671   g_free (priv->license);
672   g_free (priv->website_url);
673   g_free (priv->website_text);
674   g_free (priv->translator_credits);
675
676   g_strfreev (priv->authors);
677   g_strfreev (priv->documenters);
678   g_strfreev (priv->artists);
679
680   g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
681   g_slist_free (priv->visited_links);
682
683   gdk_cursor_unref (priv->hand_cursor);
684   gdk_cursor_unref (priv->regular_cursor);
685
686   G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
687 }
688
689 static void
690 gtk_about_dialog_set_property (GObject      *object,
691                                guint         prop_id,
692                                const GValue *value,
693                                GParamSpec   *pspec)
694 {
695   GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
696   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
697
698   switch (prop_id)
699     {
700     case PROP_NAME:
701       gtk_about_dialog_set_program_name (about, g_value_get_string (value));
702       break;
703     case PROP_VERSION:
704       gtk_about_dialog_set_version (about, g_value_get_string (value));
705       break;
706     case PROP_COMMENTS:
707       gtk_about_dialog_set_comments (about, g_value_get_string (value));
708       break;
709     case PROP_WEBSITE:
710       gtk_about_dialog_set_website (about, g_value_get_string (value));
711       break;
712     case PROP_WEBSITE_LABEL:
713       gtk_about_dialog_set_website_label (about, g_value_get_string (value));
714       break;
715     case PROP_LICENSE:
716       gtk_about_dialog_set_license (about, g_value_get_string (value));
717       break;
718     case PROP_COPYRIGHT:
719       gtk_about_dialog_set_copyright (about, g_value_get_string (value));
720       break;
721     case PROP_LOGO:
722       gtk_about_dialog_set_logo (about, g_value_get_object (value));
723       break;
724     case PROP_AUTHORS:
725       gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
726       break;
727     case PROP_DOCUMENTERS:
728       gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
729       break;
730     case PROP_ARTISTS:
731       gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
732       break;
733     case PROP_TRANSLATOR_CREDITS:
734       gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
735       break;
736     case PROP_LOGO_ICON_NAME:
737       gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
738       break;
739     case PROP_WRAP_LICENSE:
740       priv->wrap_license = g_value_get_boolean (value);
741       break;
742     default:
743       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
744       break;
745     }
746 }
747
748 static void
749 gtk_about_dialog_get_property (GObject    *object,
750                                guint       prop_id,
751                                GValue     *value,
752                                GParamSpec *pspec)
753 {
754   GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
755   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
756         
757   switch (prop_id) 
758     {
759     case PROP_NAME:
760       g_value_set_string (value, priv->name);
761       break;
762     case PROP_VERSION:
763       g_value_set_string (value, priv->version);
764       break;
765     case PROP_COPYRIGHT:
766       g_value_set_string (value, priv->copyright);
767       break;
768     case PROP_COMMENTS:
769       g_value_set_string (value, priv->comments);
770       break;
771     case PROP_WEBSITE:
772       g_value_set_string (value, priv->website_url);
773       break;
774     case PROP_WEBSITE_LABEL:
775       g_value_set_string (value, priv->website_text);
776       break;
777     case PROP_LICENSE:
778       g_value_set_string (value, priv->license);
779       break;
780     case PROP_TRANSLATOR_CREDITS:
781       g_value_set_string (value, priv->translator_credits);
782       break;
783     case PROP_AUTHORS:
784       g_value_set_boxed (value, priv->authors);
785       break;
786     case PROP_DOCUMENTERS:
787       g_value_set_boxed (value, priv->documenters);
788       break;
789     case PROP_ARTISTS:
790       g_value_set_boxed (value, priv->artists);
791       break;
792     case PROP_LOGO:
793       if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
794         g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
795       else
796         g_value_set_object (value, NULL);
797       break;
798     case PROP_LOGO_ICON_NAME:
799       if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
800         {
801           const gchar *icon_name;
802
803           gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
804           g_value_set_string (value, icon_name);
805         }
806       else
807         g_value_set_string (value, NULL);
808       break;
809     case PROP_WRAP_LICENSE:
810       g_value_set_boolean (value, priv->wrap_license);
811       break;
812     default:
813       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
814       break;
815     }
816 }
817
818 static void
819 update_website (GtkAboutDialog *about)
820 {
821   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
822
823   gtk_widget_show (priv->website_label);
824
825   if (priv->website_url && (!activate_url_hook_set || activate_url_hook != NULL))
826     {
827       gchar *markup;
828
829       if (priv->website_text)
830         {
831           gchar *escaped;
832
833           escaped = g_markup_escape_text (priv->website_text, -1);
834           markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
835                                     priv->website_url, escaped);
836           g_free (escaped);
837         }
838       else
839         {
840           markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
841                                     priv->website_url, priv->website_url);
842         }
843
844       gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
845       g_free (markup);
846     }
847   else
848     {
849       if (priv->website_url)
850         gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
851       else if (priv->website_text)
852         gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
853       else
854         gtk_widget_hide (priv->website_label);
855     }
856 }
857
858 static void
859 gtk_about_dialog_show (GtkWidget *widget)
860 {
861   update_website (GTK_ABOUT_DIALOG (widget));
862
863   GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
864 }
865
866 /**
867  * gtk_about_dialog_get_program_name:
868  * @about: a #GtkAboutDialog
869  *
870  * Returns the program name displayed in the about dialog.
871  *
872  * Return value: The program name. The string is owned by the about
873  *  dialog and must not be modified.
874  *
875  * Since: 2.12
876  */
877 G_CONST_RETURN gchar *
878 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
879 {
880   GtkAboutDialogPrivate *priv;
881
882   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
883
884   priv = (GtkAboutDialogPrivate *)about->priv;
885
886   return priv->name;
887 }
888
889 static void
890 update_name_version (GtkAboutDialog *about)
891 {
892   GtkAboutDialogPrivate *priv;
893   gchar *title_string, *name_string;
894
895   priv = (GtkAboutDialogPrivate *)about->priv;
896
897   title_string = g_strdup_printf (_("About %s"), priv->name);
898   gtk_window_set_title (GTK_WINDOW (about), title_string);
899   g_free (title_string);
900
901   if (priv->version != NULL)
902     name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
903                                              priv->name, priv->version);
904   else
905     name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
906                                            priv->name);
907
908   gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
909
910   g_free (name_string);
911 }
912
913 /**
914  * gtk_about_dialog_set_program_name:
915  * @about: a #GtkAboutDialog
916  * @name: the program name
917  *
918  * Sets the name to display in the about dialog.
919  * If this is not set, it defaults to g_get_application_name().
920  *
921  * Since: 2.12
922  */
923 void
924 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
925                                    const gchar    *name)
926 {
927   GtkAboutDialogPrivate *priv;
928   gchar *tmp;
929
930   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
931
932   priv = (GtkAboutDialogPrivate *)about->priv;
933   tmp = priv->name;
934   priv->name = g_strdup (name ? name : g_get_application_name ());
935   g_free (tmp);
936
937   update_name_version (about);
938
939   g_object_notify (G_OBJECT (about), "program-name");
940 }
941
942
943 /**
944  * gtk_about_dialog_get_version:
945  * @about: a #GtkAboutDialog
946  *
947  * Returns the version string.
948  *
949  * Return value: The version string. The string is owned by the about
950  *  dialog and must not be modified.
951  *
952  * Since: 2.6
953  */
954 G_CONST_RETURN gchar *
955 gtk_about_dialog_get_version (GtkAboutDialog *about)
956 {
957   GtkAboutDialogPrivate *priv;
958
959   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
960
961   priv = (GtkAboutDialogPrivate *)about->priv;
962
963   return priv->version;
964 }
965
966 /**
967  * gtk_about_dialog_set_version:
968  * @about: a #GtkAboutDialog
969  * @version: (allow-none): the version string
970  *
971  * Sets the version string to display in the about dialog.
972  *
973  * Since: 2.6
974  */
975 void
976 gtk_about_dialog_set_version (GtkAboutDialog *about,
977                               const gchar    *version)
978 {
979   GtkAboutDialogPrivate *priv;
980   gchar *tmp;
981
982   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
983
984   priv = (GtkAboutDialogPrivate *)about->priv;
985   
986   tmp = priv->version;
987   priv->version = g_strdup (version);
988   g_free (tmp);
989
990   update_name_version (about);
991
992   g_object_notify (G_OBJECT (about), "version");
993 }
994
995 /**
996  * gtk_about_dialog_get_copyright:
997  * @about: a #GtkAboutDialog
998  *
999  * Returns the copyright string.
1000  *
1001  * Return value: The copyright string. The string is owned by the about
1002  *  dialog and must not be modified.
1003  *
1004  * Since: 2.6
1005  */
1006 G_CONST_RETURN gchar *
1007 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1008 {
1009   GtkAboutDialogPrivate *priv;
1010
1011   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1012
1013   priv = (GtkAboutDialogPrivate *)about->priv;
1014
1015   return priv->copyright;
1016 }
1017
1018 /**
1019  * gtk_about_dialog_set_copyright:
1020  * @about: a #GtkAboutDialog
1021  * @copyright: (allow-none) the copyright string
1022  *
1023  * Sets the copyright string to display in the about dialog.
1024  * This should be a short string of one or two lines.
1025  *
1026  * Since: 2.6
1027  */
1028 void
1029 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1030                                 const gchar    *copyright)
1031 {
1032   GtkAboutDialogPrivate *priv;
1033   gchar *copyright_string, *tmp;
1034
1035   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1036
1037   priv = (GtkAboutDialogPrivate *)about->priv;
1038
1039   tmp = priv->copyright;
1040   priv->copyright = g_strdup (copyright);
1041   g_free (tmp);
1042
1043   if (priv->copyright != NULL)
1044     {
1045       copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1046                                                   priv->copyright);
1047       gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1048       g_free (copyright_string);
1049
1050       gtk_widget_show (priv->copyright_label);
1051     }
1052   else
1053     gtk_widget_hide (priv->copyright_label);
1054
1055   g_object_notify (G_OBJECT (about), "copyright");
1056 }
1057
1058 /**
1059  * gtk_about_dialog_get_comments:
1060  * @about: a #GtkAboutDialog
1061  *
1062  * Returns the comments string.
1063  *
1064  * Return value: The comments. The string is owned by the about
1065  *  dialog and must not be modified.
1066  *
1067  * Since: 2.6
1068  */
1069 G_CONST_RETURN gchar *
1070 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1071 {
1072   GtkAboutDialogPrivate *priv;
1073
1074   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1075
1076   priv = (GtkAboutDialogPrivate *)about->priv;
1077
1078   return priv->comments;
1079 }
1080
1081 /**
1082  * gtk_about_dialog_set_comments:
1083  * @about: a #GtkAboutDialog
1084  * @comments: (allow-none): a comments string
1085  *
1086  * Sets the comments string to display in the about dialog.
1087  * This should be a short string of one or two lines.
1088  *
1089  * Since: 2.6
1090  */
1091 void
1092 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1093                                const gchar    *comments)
1094 {
1095   GtkAboutDialogPrivate *priv;
1096   gchar *tmp;
1097
1098   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1099
1100   priv = (GtkAboutDialogPrivate *)about->priv;
1101
1102   tmp = priv->comments;
1103   if (comments)
1104     {
1105       priv->comments = g_strdup (comments);
1106       gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1107       gtk_widget_show (priv->comments_label);
1108     }
1109   else
1110     {
1111       priv->comments = NULL;
1112       gtk_widget_hide (priv->comments_label);
1113     }
1114   g_free (tmp);
1115
1116   g_object_notify (G_OBJECT (about), "comments");
1117 }
1118
1119 /**
1120  * gtk_about_dialog_get_license:
1121  * @about: a #GtkAboutDialog
1122  *
1123  * Returns the license information.
1124  *
1125  * Return value: The license information. The string is owned by the about
1126  *  dialog and must not be modified.
1127  *
1128  * Since: 2.6
1129  */
1130 G_CONST_RETURN gchar *
1131 gtk_about_dialog_get_license (GtkAboutDialog *about)
1132 {
1133   GtkAboutDialogPrivate *priv;
1134
1135   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1136
1137   priv = (GtkAboutDialogPrivate *)about->priv;
1138
1139   return priv->license;
1140 }
1141
1142 /**
1143  * gtk_about_dialog_set_license:
1144  * @about: a #GtkAboutDialog
1145  * @license: (allow-none): the license information or %NULL
1146  *
1147  * Sets the license information to be displayed in the secondary
1148  * license dialog. If @license is %NULL, the license button is
1149  * hidden.
1150  *
1151  * Since: 2.6
1152  */
1153 void
1154 gtk_about_dialog_set_license (GtkAboutDialog *about,
1155                               const gchar    *license)
1156 {
1157   GtkAboutDialogPrivate *priv;
1158   gchar *tmp;
1159
1160   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1161
1162   priv = (GtkAboutDialogPrivate *)about->priv;
1163
1164   tmp = priv->license;
1165   if (license)
1166     {
1167       priv->license = g_strdup (license);
1168       gtk_widget_show (priv->license_button);
1169     }
1170   else
1171     {
1172       priv->license = NULL;
1173       gtk_widget_hide (priv->license_button);
1174     }
1175   g_free (tmp);
1176
1177   g_object_notify (G_OBJECT (about), "license");
1178 }
1179
1180 /**
1181  * gtk_about_dialog_get_wrap_license:
1182  * @about: a #GtkAboutDialog
1183  *
1184  * Returns whether the license text in @about is
1185  * automatically wrapped.
1186  *
1187  * Returns: %TRUE if the license text is wrapped
1188  *
1189  * Since: 2.8
1190  */
1191 gboolean
1192 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1193 {
1194   GtkAboutDialogPrivate *priv;
1195
1196   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1197
1198   priv = (GtkAboutDialogPrivate *)about->priv;
1199
1200   return priv->wrap_license;
1201 }
1202
1203 /**
1204  * gtk_about_dialog_set_wrap_license:
1205  * @about: a #GtkAboutDialog
1206  * @wrap_license: whether to wrap the license
1207  *
1208  * Sets whether the license text in @about is
1209  * automatically wrapped.
1210  *
1211  * Since: 2.8
1212  */
1213 void
1214 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1215                                    gboolean        wrap_license)
1216 {
1217   GtkAboutDialogPrivate *priv;
1218
1219   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1220
1221   priv = (GtkAboutDialogPrivate *)about->priv;
1222
1223   wrap_license = wrap_license != FALSE;
1224
1225   if (priv->wrap_license != wrap_license)
1226     {
1227        priv->wrap_license = wrap_license;
1228
1229        g_object_notify (G_OBJECT (about), "wrap-license");
1230     }
1231 }
1232
1233 /**
1234  * gtk_about_dialog_get_website:
1235  * @about: a #GtkAboutDialog
1236  *
1237  * Returns the website URL.
1238  *
1239  * Return value: The website URL. The string is owned by the about
1240  *  dialog and must not be modified.
1241  *
1242  * Since: 2.6
1243  */
1244 G_CONST_RETURN gchar *
1245 gtk_about_dialog_get_website (GtkAboutDialog *about)
1246 {
1247   GtkAboutDialogPrivate *priv;
1248
1249   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1250
1251   priv = (GtkAboutDialogPrivate *)about->priv;
1252
1253   return priv->website_url;
1254 }
1255
1256 /**
1257  * gtk_about_dialog_set_website:
1258  * @about: a #GtkAboutDialog
1259  * @website: (allow-none): a URL string starting with "http://"
1260  *
1261  * Sets the URL to use for the website link.
1262  *
1263  * Note that that the hook functions need to be set up
1264  * before calling this function.
1265  *
1266  * Since: 2.6
1267  */
1268 void
1269 gtk_about_dialog_set_website (GtkAboutDialog *about,
1270                               const gchar    *website)
1271 {
1272   GtkAboutDialogPrivate *priv;
1273   gchar *tmp;
1274
1275   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1276
1277   priv = (GtkAboutDialogPrivate *)about->priv;
1278
1279   tmp = priv->website_url;
1280   priv->website_url = g_strdup (website);
1281   g_free (tmp);
1282
1283   update_website (about);
1284
1285   g_object_notify (G_OBJECT (about), "website");
1286 }
1287
1288 /**
1289  * gtk_about_dialog_get_website_label:
1290  * @about: a #GtkAboutDialog
1291  *
1292  * Returns the label used for the website link.
1293  *
1294  * Return value: The label used for the website link. The string is
1295  *     owned by the about dialog and must not be modified.
1296  *
1297  * Since: 2.6
1298  */
1299 G_CONST_RETURN gchar *
1300 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1301 {
1302   GtkAboutDialogPrivate *priv;
1303
1304   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1305
1306   priv = (GtkAboutDialogPrivate *)about->priv;
1307
1308   return priv->website_text;
1309 }
1310
1311 /**
1312  * gtk_about_dialog_set_website_label:
1313  * @about: a #GtkAboutDialog
1314  * @website_label: the label used for the website link
1315  *
1316  * Sets the label to be used for the website link.
1317  * It defaults to the website URL.
1318  *
1319  * Since: 2.6
1320  */
1321 void
1322 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1323                                     const gchar    *website_label)
1324 {
1325   GtkAboutDialogPrivate *priv;
1326   gchar *tmp;
1327
1328   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1329
1330   priv = (GtkAboutDialogPrivate *)about->priv;
1331
1332   tmp = priv->website_text;
1333   priv->website_text = g_strdup (website_label);
1334   g_free (tmp);
1335
1336   update_website (about);
1337
1338   g_object_notify (G_OBJECT (about), "website-label");
1339 }
1340
1341 /**
1342  * gtk_about_dialog_get_authors:
1343  * @about: a #GtkAboutDialog
1344  *
1345  * Returns the string which are displayed in the authors tab
1346  * of the secondary credits dialog.
1347  *
1348  * Return value: A %NULL-terminated string array containing
1349  *  the authors. The array is owned by the about dialog
1350  *  and must not be modified.
1351  *
1352  * Since: 2.6
1353  */
1354 G_CONST_RETURN gchar * G_CONST_RETURN *
1355 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1356 {
1357   GtkAboutDialogPrivate *priv;
1358
1359   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1360
1361   priv = (GtkAboutDialogPrivate *)about->priv;
1362
1363   return (const gchar * const *) priv->authors;
1364 }
1365
1366 static void
1367 update_credits_button_visibility (GtkAboutDialog *about)
1368 {
1369   GtkAboutDialogPrivate *priv = about->priv;
1370   gboolean show;
1371
1372   show = priv->authors != NULL ||
1373          priv->documenters != NULL ||
1374          priv->artists != NULL ||
1375          (priv->translator_credits != NULL &&
1376           strcmp (priv->translator_credits, "translator_credits") &&
1377           strcmp (priv->translator_credits, "translator-credits"));
1378   if (show)
1379     gtk_widget_show (priv->credits_button);
1380   else
1381     gtk_widget_hide (priv->credits_button);
1382 }
1383
1384 /**
1385  * gtk_about_dialog_set_authors:
1386  * @about: a #GtkAboutDialog
1387  * @authors: a %NULL-terminated array of strings
1388  *
1389  * Sets the strings which are displayed in the authors tab
1390  * of the secondary credits dialog.
1391  *
1392  * Since: 2.6
1393  */
1394 void
1395 gtk_about_dialog_set_authors (GtkAboutDialog  *about,
1396                               const gchar    **authors)
1397 {
1398   GtkAboutDialogPrivate *priv;
1399   gchar **tmp;
1400
1401   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1402
1403   priv = (GtkAboutDialogPrivate *)about->priv;
1404
1405   tmp = priv->authors;
1406   priv->authors = g_strdupv ((gchar **)authors);
1407   g_strfreev (tmp);
1408
1409   update_credits_button_visibility (about);
1410
1411   g_object_notify (G_OBJECT (about), "authors");
1412 }
1413
1414 /**
1415  * gtk_about_dialog_get_documenters:
1416  * @about: a #GtkAboutDialog
1417  *
1418  * Returns the string which are displayed in the documenters
1419  * tab of the secondary credits dialog.
1420  *
1421  * Return value: A %NULL-terminated string array containing
1422  *  the documenters. The array is owned by the about dialog
1423  *  and must not be modified.
1424  *
1425  * Since: 2.6
1426  */
1427 G_CONST_RETURN gchar * G_CONST_RETURN *
1428 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1429 {
1430   GtkAboutDialogPrivate *priv;
1431
1432   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1433
1434   priv = (GtkAboutDialogPrivate *)about->priv;
1435
1436   return (const gchar * const *)priv->documenters;
1437 }
1438
1439 /**
1440  * gtk_about_dialog_set_documenters:
1441  * @about: a #GtkAboutDialog
1442  * @documenters: a %NULL-terminated array of strings
1443  *
1444  * Sets the strings which are displayed in the documenters tab
1445  * of the secondary credits dialog.
1446  *
1447  * Since: 2.6
1448  */
1449 void
1450 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1451                                   const gchar   **documenters)
1452 {
1453   GtkAboutDialogPrivate *priv;
1454   gchar **tmp;
1455
1456   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1457
1458   priv = (GtkAboutDialogPrivate *)about->priv;
1459
1460   tmp = priv->documenters;
1461   priv->documenters = g_strdupv ((gchar **)documenters);
1462   g_strfreev (tmp);
1463
1464   update_credits_button_visibility (about);
1465
1466   g_object_notify (G_OBJECT (about), "documenters");
1467 }
1468
1469 /**
1470  * gtk_about_dialog_get_artists:
1471  * @about: a #GtkAboutDialog
1472  *
1473  * Returns the string which are displayed in the artists tab
1474  * of the secondary credits dialog.
1475  *
1476  * Return value: A %NULL-terminated string array containing
1477  *  the artists. The array is owned by the about dialog
1478  *  and must not be modified.
1479  *
1480  * Since: 2.6
1481  */
1482 G_CONST_RETURN gchar * G_CONST_RETURN *
1483 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1484 {
1485   GtkAboutDialogPrivate *priv;
1486
1487   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1488
1489   priv = (GtkAboutDialogPrivate *)about->priv;
1490
1491   return (const gchar * const *)priv->artists;
1492 }
1493
1494 /**
1495  * gtk_about_dialog_set_artists:
1496  * @about: a #GtkAboutDialog
1497  * @artists: a %NULL-terminated array of strings
1498  *
1499  * Sets the strings which are displayed in the artists tab
1500  * of the secondary credits dialog.
1501  *
1502  * Since: 2.6
1503  */
1504 void
1505 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1506                               const gchar   **artists)
1507 {
1508   GtkAboutDialogPrivate *priv;
1509   gchar **tmp;
1510
1511   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1512
1513   priv = (GtkAboutDialogPrivate *)about->priv;
1514
1515   tmp = priv->artists;
1516   priv->artists = g_strdupv ((gchar **)artists);
1517   g_strfreev (tmp);
1518
1519   update_credits_button_visibility (about);
1520
1521   g_object_notify (G_OBJECT (about), "artists");
1522 }
1523
1524 /**
1525  * gtk_about_dialog_get_translator_credits:
1526  * @about: a #GtkAboutDialog
1527  *
1528  * Returns the translator credits string which is displayed
1529  * in the translators tab of the secondary credits dialog.
1530  *
1531  * Return value: The translator credits string. The string is
1532  *   owned by the about dialog and must not be modified.
1533  *
1534  * Since: 2.6
1535  */
1536 G_CONST_RETURN gchar *
1537 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1538 {
1539   GtkAboutDialogPrivate *priv;
1540
1541   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1542
1543   priv = (GtkAboutDialogPrivate *)about->priv;
1544
1545   return priv->translator_credits;
1546 }
1547
1548 /**
1549  * gtk_about_dialog_set_translator_credits:
1550  * @about: a #GtkAboutDialog
1551  * @translator_credits: (allow-none): the translator credits
1552  *
1553  * Sets the translator credits string which is displayed in
1554  * the translators tab of the secondary credits dialog.
1555  *
1556  * The intended use for this string is to display the translator
1557  * of the language which is currently used in the user interface.
1558  * Using gettext(), a simple way to achieve that is to mark the
1559  * string for translation:
1560  * |[
1561  *  gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1562  * ]|
1563  * It is a good idea to use the customary msgid "translator-credits" for this
1564  * purpose, since translators will already know the purpose of that msgid, and
1565  * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1566  * and hide the tab.
1567  *
1568  * Since: 2.6
1569  */
1570 void
1571 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1572                                          const gchar    *translator_credits)
1573 {
1574   GtkAboutDialogPrivate *priv;
1575   gchar *tmp;
1576
1577   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1578
1579   priv = (GtkAboutDialogPrivate *)about->priv;
1580
1581   tmp = priv->translator_credits;
1582   priv->translator_credits = g_strdup (translator_credits);
1583   g_free (tmp);
1584
1585   update_credits_button_visibility (about);
1586
1587   g_object_notify (G_OBJECT (about), "translator-credits");
1588 }
1589
1590 /**
1591  * gtk_about_dialog_get_logo:
1592  * @about: a #GtkAboutDialog
1593  *
1594  * Returns the pixbuf displayed as logo in the about dialog.
1595  *
1596  * Return value: the pixbuf displayed as logo. The pixbuf is
1597  *   owned by the about dialog. If you want to keep a reference
1598  *   to it, you have to call g_object_ref() on it.
1599  *
1600  * Since: 2.6
1601  */
1602 GdkPixbuf *
1603 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1604 {
1605   GtkAboutDialogPrivate *priv;
1606
1607   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1608
1609   priv = (GtkAboutDialogPrivate *)about->priv;
1610
1611   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1612     return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1613   else
1614     return NULL;
1615 }
1616
1617 static GtkIconSet *
1618 icon_set_new_from_pixbufs (GList *pixbufs)
1619 {
1620   GtkIconSet *icon_set = gtk_icon_set_new ();
1621
1622   for (; pixbufs; pixbufs = pixbufs->next)
1623     {
1624       GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1625
1626       GtkIconSource *icon_source = gtk_icon_source_new ();
1627       gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1628       gtk_icon_set_add_source (icon_set, icon_source);
1629       gtk_icon_source_free (icon_source);
1630     }
1631
1632   return icon_set;
1633 }
1634
1635 /**
1636  * gtk_about_dialog_set_logo:
1637  * @about: a #GtkAboutDialog
1638  * @logo: (allow-none): a #GdkPixbuf, or %NULL
1639  *
1640  * Sets the pixbuf to be displayed as logo in the about dialog.
1641  * If it is %NULL, the default window icon set with
1642  * gtk_window_set_default_icon() will be used.
1643  *
1644  * Since: 2.6
1645  */
1646 void
1647 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1648                            GdkPixbuf      *logo)
1649 {
1650   GtkAboutDialogPrivate *priv;
1651
1652   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1653
1654   priv = (GtkAboutDialogPrivate *)about->priv;
1655
1656   g_object_freeze_notify (G_OBJECT (about));
1657
1658   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1659     g_object_notify (G_OBJECT (about), "logo-icon-name");
1660
1661   if (logo != NULL)
1662     gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1663   else
1664     {
1665       GList *pixbufs = gtk_window_get_default_icon_list ();
1666
1667       if (pixbufs != NULL)
1668         {
1669           GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1670
1671           gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1672                                        icon_set, GTK_ICON_SIZE_DIALOG);
1673
1674           gtk_icon_set_unref (icon_set);
1675           g_list_free (pixbufs);
1676         }
1677     }
1678
1679   g_object_notify (G_OBJECT (about), "logo");
1680
1681   g_object_thaw_notify (G_OBJECT (about));
1682 }
1683
1684 /**
1685  * gtk_about_dialog_get_logo_icon_name:
1686  * @about: a #GtkAboutDialog
1687  *
1688  * Returns the icon name displayed as logo in the about dialog.
1689  *
1690  * Return value: the icon name displayed as logo. The string is
1691  *   owned by the dialog. If you want to keep a reference
1692  *   to it, you have to call g_strdup() on it.
1693  *
1694  * Since: 2.6
1695  */
1696 G_CONST_RETURN gchar *
1697 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1698 {
1699   GtkAboutDialogPrivate *priv;
1700   const gchar *icon_name = NULL;
1701
1702   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1703
1704   priv = (GtkAboutDialogPrivate *)about->priv;
1705
1706   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1707     gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1708
1709   return icon_name;
1710 }
1711
1712 /**
1713  * gtk_about_dialog_set_logo_icon_name:
1714  * @about: a #GtkAboutDialog
1715  * @icon_name: (allow-none): an icon name, or %NULL
1716  *
1717  * Sets the pixbuf to be displayed as logo in the about dialog.
1718  * If it is %NULL, the default window icon set with
1719  * gtk_window_set_default_icon() will be used.
1720  *
1721  * Since: 2.6
1722  */
1723 void
1724 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1725                                      const gchar    *icon_name)
1726 {
1727   GtkAboutDialogPrivate *priv;
1728
1729   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1730
1731   priv = (GtkAboutDialogPrivate *)about->priv;
1732
1733   g_object_freeze_notify (G_OBJECT (about));
1734
1735   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1736     g_object_notify (G_OBJECT (about), "logo");
1737
1738   gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1739                                 GTK_ICON_SIZE_DIALOG);
1740   g_object_notify (G_OBJECT (about), "logo-icon-name");
1741
1742   g_object_thaw_notify (G_OBJECT (about));
1743 }
1744
1745 static void
1746 follow_if_link (GtkAboutDialog *about,
1747                 GtkTextView    *text_view,
1748                 GtkTextIter    *iter)
1749 {
1750   GSList *tags = NULL, *tagp = NULL;
1751   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
1752   gchar *url = NULL;
1753   GtkAboutDialogActivateLinkFunc email_hook, url_hook;
1754   gpointer email_hook_data, url_hook_data;
1755
1756   if (activate_email_hook_set)
1757     {
1758       email_hook = activate_email_hook;
1759       email_hook_data = activate_email_hook_data;
1760     }
1761   else
1762     {
1763       email_hook = default_email_hook;
1764       email_hook_data = NULL;
1765     }
1766
1767   if (activate_url_hook_set)
1768     {
1769       url_hook = activate_url_hook;
1770       url_hook_data = activate_url_hook_data;
1771     }
1772   else
1773     {
1774       url_hook = default_url_hook;
1775       url_hook_data = NULL;
1776     }
1777
1778   tags = gtk_text_iter_get_tags (iter);
1779   for (tagp = tags; tagp != NULL && !url; tagp = tagp->next)
1780     {
1781       GtkTextTag *tag = tagp->data;
1782
1783       if (email_hook != NULL)
1784         {
1785           url = g_object_get_data (G_OBJECT (tag), "email");
1786           if (url)
1787             email_hook (about, url, email_hook_data);
1788         }
1789
1790       if (!url && url_hook != NULL)
1791         {
1792           url = g_object_get_data (G_OBJECT (tag), "url");
1793           if (url)
1794             url_hook (about, url, url_hook_data);
1795         }
1796
1797       if (url && !g_slist_find_custom (priv->visited_links, url, (GCompareFunc)strcmp))
1798         {
1799           GdkColor *style_visited_link_color;
1800           GdkColor color;
1801
1802           gtk_widget_ensure_style (GTK_WIDGET (about));
1803           gtk_widget_style_get (GTK_WIDGET (about),
1804                                 "visited-link-color", &style_visited_link_color,
1805                                 NULL);
1806           if (style_visited_link_color)
1807             {
1808               color = *style_visited_link_color;
1809               gdk_color_free (style_visited_link_color);
1810             }
1811           else
1812             color = default_visited_link_color;
1813
1814           g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1815
1816           priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (url));
1817         }
1818     }
1819
1820   if (tags)
1821     g_slist_free (tags);
1822 }
1823
1824 static gboolean
1825 text_view_key_press_event (GtkWidget      *text_view,
1826                            GdkEventKey    *event,
1827                            GtkAboutDialog *about)
1828 {
1829   GtkTextIter iter;
1830   GtkTextBuffer *buffer;
1831
1832   switch (event->keyval)
1833     {
1834       case GDK_Return:
1835       case GDK_ISO_Enter:
1836       case GDK_KP_Enter:
1837         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1838         gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1839                                           gtk_text_buffer_get_insert (buffer));
1840         follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1841         break;
1842
1843       default:
1844         break;
1845     }
1846
1847   return FALSE;
1848 }
1849
1850 static gboolean
1851 text_view_event_after (GtkWidget      *text_view,
1852                        GdkEvent       *event,
1853                        GtkAboutDialog *about)
1854 {
1855   GtkTextIter start, end, iter;
1856   GtkTextBuffer *buffer;
1857   GdkEventButton *button_event;
1858   gint x, y;
1859
1860   if (event->type != GDK_BUTTON_RELEASE)
1861     return FALSE;
1862
1863   button_event = (GdkEventButton *)event;
1864
1865   if (button_event->button != 1)
1866     return FALSE;
1867
1868   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1869
1870   /* we shouldn't follow a link if the user has selected something */
1871   gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1872   if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1873     return FALSE;
1874
1875   gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1876                                          GTK_TEXT_WINDOW_WIDGET,
1877                                          button_event->x, button_event->y, &x, &y);
1878
1879   gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1880
1881   follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1882
1883   return FALSE;
1884 }
1885
1886 static void
1887 set_cursor_if_appropriate (GtkAboutDialog *about,
1888                            GtkTextView    *text_view,
1889                            gint            x,
1890                            gint            y)
1891 {
1892   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
1893   GSList *tags = NULL, *tagp = NULL;
1894   GtkTextIter iter;
1895   gboolean hovering_over_link = FALSE;
1896
1897   gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1898
1899   tags = gtk_text_iter_get_tags (&iter);
1900   for (tagp = tags;  tagp != NULL;  tagp = tagp->next)
1901     {
1902       GtkTextTag *tag = tagp->data;
1903       gchar *email = g_object_get_data (G_OBJECT (tag), "email");
1904       gchar *url = g_object_get_data (G_OBJECT (tag), "url");
1905
1906       if (email != NULL || url != NULL)
1907         {
1908           hovering_over_link = TRUE;
1909           break;
1910         }
1911     }
1912
1913   if (hovering_over_link != priv->hovering_over_link)
1914     {
1915       priv->hovering_over_link = hovering_over_link;
1916
1917       if (hovering_over_link)
1918         gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->hand_cursor);
1919       else
1920         gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->regular_cursor);
1921     }
1922
1923   if (tags)
1924     g_slist_free (tags);
1925 }
1926
1927 static gboolean
1928 text_view_motion_notify_event (GtkWidget *text_view,
1929                                GdkEventMotion *event,
1930                                GtkAboutDialog *about)
1931 {
1932   gint x, y;
1933
1934   gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1935                                          GTK_TEXT_WINDOW_WIDGET,
1936                                          event->x, event->y, &x, &y);
1937
1938   set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), x, y);
1939
1940   gdk_event_request_motions (event);
1941
1942   return FALSE;
1943 }
1944
1945
1946 static gboolean
1947 text_view_visibility_notify_event (GtkWidget          *text_view,
1948                                    GdkEventVisibility *event,
1949                                    GtkAboutDialog     *about)
1950 {
1951   gint wx, wy, bx, by;
1952
1953   gdk_window_get_pointer (text_view->window, &wx, &wy, NULL);
1954
1955   gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1956                                          GTK_TEXT_WINDOW_WIDGET,
1957                                          wx, wy, &bx, &by);
1958
1959   set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), bx, by);
1960
1961   return FALSE;
1962 }
1963
1964 static GtkWidget *
1965 text_view_new (GtkAboutDialog  *about,
1966                GtkWidget       *dialog,
1967                gchar          **strings,
1968                GtkWrapMode      wrap_mode)
1969 {
1970   gchar **p;
1971   gchar *q0, *q1, *q2, *r1, *r2;
1972   GtkWidget *view;
1973   GtkTextView *text_view;
1974   GtkTextBuffer *buffer;
1975   gboolean linkify_email, linkify_urls;
1976   GdkColor *style_link_color;
1977   GdkColor *style_visited_link_color;
1978   GdkColor color;
1979   GdkColor link_color;
1980   GdkColor visited_link_color;
1981
1982   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
1983
1984   linkify_email = (!activate_email_hook_set || activate_email_hook != NULL);
1985   linkify_urls = (!activate_url_hook_set || activate_url_hook != NULL);
1986
1987   gtk_widget_ensure_style (GTK_WIDGET (about));
1988   gtk_widget_style_get (GTK_WIDGET (about),
1989                         "link-color", &style_link_color,
1990                         "visited-link-color", &style_visited_link_color,
1991                         NULL);
1992   if (style_link_color)
1993     {
1994       link_color = *style_link_color;
1995       gdk_color_free (style_link_color);
1996     }
1997   else
1998     link_color = default_link_color;
1999
2000   if (style_visited_link_color)
2001     {
2002       visited_link_color = *style_visited_link_color;
2003       gdk_color_free (style_visited_link_color);
2004     }
2005   else
2006     visited_link_color = default_visited_link_color;
2007
2008   view = gtk_text_view_new ();
2009   text_view = GTK_TEXT_VIEW (view);
2010   buffer = gtk_text_view_get_buffer (text_view);
2011   gtk_text_view_set_cursor_visible (text_view, FALSE);
2012   gtk_text_view_set_editable (text_view, FALSE);
2013   gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2014
2015   gtk_text_view_set_left_margin (text_view, 8);
2016   gtk_text_view_set_right_margin (text_view, 8);
2017
2018   g_signal_connect (view, "key-press-event",
2019                     G_CALLBACK (text_view_key_press_event), about);
2020   g_signal_connect (view, "event-after",
2021                     G_CALLBACK (text_view_event_after), about);
2022   g_signal_connect (view, "motion-notify-event",
2023                     G_CALLBACK (text_view_motion_notify_event), about);
2024   g_signal_connect (view, "visibility-notify-event",
2025                     G_CALLBACK (text_view_visibility_notify_event), about);
2026
2027   if (strings == NULL)
2028     {
2029       gtk_widget_hide (view);
2030       return view;
2031     }
2032
2033   for (p = strings; *p; p++)
2034     {
2035       q0  = *p;
2036       while (*q0)
2037         {
2038           q1 = linkify_email ? strchr (q0, '<') : NULL;
2039           q2 = q1 ? strchr (q1, '>') : NULL;
2040           r1 = linkify_urls ? strstr (q0, "http://") : NULL;
2041           if (r1)
2042             {
2043               r2 = strpbrk (r1, " \n\t");
2044               if (!r2)
2045                 r2 = strchr (r1, '\0');
2046             }
2047           else
2048             r2 = NULL;
2049
2050           if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2051             {
2052               q1 = r1;
2053               q2 = r2;
2054             }
2055
2056           if (q1 && q2)
2057             {
2058               GtkTextIter end;
2059               gchar *link;
2060               const gchar *link_type;
2061               GtkTextTag *tag;
2062
2063               if (*q1 == '<')
2064                 {
2065                   gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
2066                   gtk_text_buffer_get_end_iter (buffer, &end);
2067                   q1++;
2068                   link_type = I_("email");
2069                 }
2070               else
2071                 {
2072                   gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2073                   gtk_text_buffer_get_end_iter (buffer, &end);
2074                   link_type = I_("url");
2075                 }
2076
2077               q0 = q2;
2078
2079               link = g_strndup (q1, q2 - q1);
2080
2081               if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2082                 color = visited_link_color;
2083               else
2084                 color = link_color;
2085
2086               tag = gtk_text_buffer_create_tag (buffer, NULL,
2087                                                 "foreground-gdk", &color,
2088                                                 "underline", PANGO_UNDERLINE_SINGLE,
2089                                                 NULL);
2090               g_object_set_data_full (G_OBJECT (tag), link_type, g_strdup (link), g_free);
2091               gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2092
2093               g_free (link);
2094             }
2095           else
2096             {
2097               gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2098               break;
2099             }
2100         }
2101
2102       if (p[1])
2103         gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2104     }
2105
2106   gtk_widget_show (view);
2107   return view;
2108 }
2109
2110 static void
2111 add_credits_page (GtkAboutDialog *about,
2112                   GtkWidget      *credits_dialog,
2113                   GtkWidget      *notebook,
2114                   gchar          *title,
2115                   gchar         **people)
2116 {
2117   GtkWidget *sw, *view;
2118
2119   view = text_view_new (about, credits_dialog, people, GTK_WRAP_NONE);
2120
2121   sw = gtk_scrolled_window_new (NULL, NULL);
2122   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2123                                        GTK_SHADOW_IN);
2124   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2125                                   GTK_POLICY_AUTOMATIC,
2126                                   GTK_POLICY_AUTOMATIC);
2127   gtk_container_add (GTK_CONTAINER (sw), view);
2128
2129   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
2130                             sw, gtk_label_new (title));
2131 }
2132
2133 static void
2134 display_credits_dialog (GtkWidget *button,
2135                         gpointer   data)
2136 {
2137   GtkAboutDialog *about = (GtkAboutDialog *)data;
2138   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
2139   GtkWidget *dialog, *notebook;
2140   GtkDialog *credits_dialog;
2141
2142   if (priv->credits_dialog != NULL)
2143     {
2144       gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2145       return;
2146     }
2147
2148   dialog = gtk_dialog_new_with_buttons (_("Credits"),
2149                                         GTK_WINDOW (about),
2150                                         GTK_DIALOG_DESTROY_WITH_PARENT,
2151                                         GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2152                                         NULL);
2153   credits_dialog = GTK_DIALOG (dialog);
2154   gtk_dialog_set_has_separator (credits_dialog, FALSE);
2155   gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2156   gtk_box_set_spacing (GTK_BOX (credits_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2157   gtk_container_set_border_width (GTK_CONTAINER (credits_dialog->action_area), 5);
2158
2159   priv->credits_dialog = dialog;
2160   gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2161   gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2162
2163   gtk_window_set_modal (GTK_WINDOW (dialog),
2164                         gtk_window_get_modal (GTK_WINDOW (about)));
2165
2166   g_signal_connect (dialog, "response",
2167                     G_CALLBACK (gtk_widget_destroy), dialog);
2168   g_signal_connect (dialog, "destroy",
2169                     G_CALLBACK (gtk_widget_destroyed),
2170                     &(priv->credits_dialog));
2171
2172   notebook = gtk_notebook_new ();
2173   gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2174   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, TRUE, 0);
2175
2176   if (priv->authors != NULL)
2177     add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2178
2179   if (priv->documenters != NULL)
2180     add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2181
2182   /* Don't show an untranslated gettext msgid */
2183   if (priv->translator_credits != NULL &&
2184       strcmp (priv->translator_credits, "translator_credits") != 0 &&
2185       strcmp (priv->translator_credits, "translator-credits") != 0)
2186     {
2187       gchar *translators[2];
2188
2189       translators[0] = priv->translator_credits;
2190       translators[1] = NULL;
2191
2192       add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2193     }
2194
2195   if (priv->artists != NULL)
2196     add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2197
2198   gtk_widget_show_all (dialog);
2199 }
2200
2201 static void
2202 set_policy (GtkWidget *sw)
2203 {
2204   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2205                                   GTK_POLICY_AUTOMATIC,
2206                                   GTK_POLICY_AUTOMATIC);
2207 }
2208
2209 static void
2210 display_license_dialog (GtkWidget *button,
2211                         gpointer   data)
2212 {
2213   GtkAboutDialog *about = (GtkAboutDialog *)data;
2214   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
2215   GtkWidget *dialog, *view, *sw;
2216   GtkDialog *licence_dialog;
2217   gchar *strings[2];
2218
2219   if (priv->license_dialog != NULL)
2220     {
2221       gtk_window_present (GTK_WINDOW (priv->license_dialog));
2222       return;
2223     }
2224
2225   dialog = gtk_dialog_new_with_buttons (_("License"),
2226                                         GTK_WINDOW (about),
2227                                         GTK_DIALOG_DESTROY_WITH_PARENT,
2228                                         GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2229                                         NULL);
2230   licence_dialog = GTK_DIALOG (dialog);
2231   gtk_dialog_set_has_separator (licence_dialog, FALSE);
2232   gtk_container_set_border_width (GTK_CONTAINER (licence_dialog), 5);
2233   gtk_box_set_spacing (GTK_BOX (licence_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2234   gtk_container_set_border_width (GTK_CONTAINER (licence_dialog->action_area), 5);
2235
2236   priv->license_dialog = dialog;
2237   gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2238   gtk_dialog_set_default_response (licence_dialog, GTK_RESPONSE_CANCEL);
2239
2240   gtk_window_set_modal (GTK_WINDOW (dialog),
2241                         gtk_window_get_modal (GTK_WINDOW (about)));
2242
2243   g_signal_connect (dialog, "response",
2244                     G_CALLBACK (gtk_widget_destroy), dialog);
2245   g_signal_connect (dialog, "destroy",
2246                     G_CALLBACK (gtk_widget_destroyed),
2247                     &(priv->license_dialog));
2248
2249   sw = gtk_scrolled_window_new (NULL, NULL);
2250   gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2251   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2252                                        GTK_SHADOW_IN);
2253   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2254                                   GTK_POLICY_NEVER,
2255                                   GTK_POLICY_AUTOMATIC);
2256   g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2257   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), sw, TRUE, TRUE, 0);
2258
2259   strings[0] = priv->license;
2260   strings[1] = NULL;
2261   view = text_view_new (about, dialog, strings,
2262                         priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2263
2264   gtk_container_add (GTK_CONTAINER (sw), view);
2265
2266   gtk_widget_show_all (dialog);
2267 }
2268
2269 /**
2270  * gtk_about_dialog_new:
2271  *
2272  * Creates a new #GtkAboutDialog.
2273  *
2274  * Returns: a newly created #GtkAboutDialog
2275  *
2276  * Since: 2.6
2277  */
2278 GtkWidget *
2279 gtk_about_dialog_new (void)
2280 {
2281   GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2282
2283   return GTK_WIDGET (dialog);
2284 }
2285
2286 /**
2287  * gtk_about_dialog_set_email_hook:
2288  * @func: a function to call when an email link is activated.
2289  * @data: data to pass to @func
2290  * @destroy: #GDestroyNotify for @data
2291  *
2292  * Installs a global function to be called whenever the user activates an
2293  * email link in an about dialog.
2294  *
2295  * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2296  * deactivate it, you can pass %NULL for @func.
2297  *
2298  * Return value: the previous email hook.
2299  *
2300  * Since: 2.6
2301  */
2302 GtkAboutDialogActivateLinkFunc
2303 gtk_about_dialog_set_email_hook (GtkAboutDialogActivateLinkFunc func,
2304                                  gpointer                       data,
2305                                  GDestroyNotify                 destroy)
2306 {
2307   GtkAboutDialogActivateLinkFunc old;
2308
2309   if (activate_email_hook_destroy != NULL)
2310     (* activate_email_hook_destroy) (activate_email_hook_data);
2311
2312   old = activate_email_hook;
2313
2314   activate_email_hook_set = TRUE;
2315   activate_email_hook = func;
2316   activate_email_hook_data = data;
2317   activate_email_hook_destroy = destroy;
2318
2319   return old;
2320 }
2321
2322 /**
2323  * gtk_about_dialog_set_url_hook:
2324  * @func: a function to call when a URL link is activated.
2325  * @data: data to pass to @func
2326  * @destroy: #GDestroyNotify for @data
2327  *
2328  * Installs a global function to be called whenever the user activates a
2329  * URL link in an about dialog.
2330  *
2331  * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2332  * deactivate it, you can pass %NULL for @func.
2333  *
2334  * Return value: the previous URL hook.
2335  *
2336  * Since: 2.6
2337  */
2338 GtkAboutDialogActivateLinkFunc
2339 gtk_about_dialog_set_url_hook (GtkAboutDialogActivateLinkFunc func,
2340                                gpointer                       data,
2341                                GDestroyNotify                 destroy)
2342 {
2343   GtkAboutDialogActivateLinkFunc old;
2344
2345   if (activate_url_hook_destroy != NULL)
2346     (* activate_url_hook_destroy) (activate_url_hook_data);
2347
2348   old = activate_url_hook;
2349
2350   activate_url_hook_set = TRUE;
2351   activate_url_hook = func;
2352   activate_url_hook_data = data;
2353   activate_url_hook_destroy = destroy;
2354
2355   return old;
2356 }
2357
2358 static void
2359 close_cb (GtkAboutDialog *about)
2360 {
2361   GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
2362
2363   if (priv->license_dialog != NULL)
2364     {
2365       gtk_widget_destroy (priv->license_dialog);
2366       priv->license_dialog = NULL;
2367     }
2368
2369   if (priv->credits_dialog != NULL)
2370     {
2371       gtk_widget_destroy (priv->credits_dialog);
2372       priv->credits_dialog = NULL;
2373     }
2374
2375   gtk_widget_hide (GTK_WIDGET (about));
2376
2377 }
2378
2379 /**
2380  * gtk_show_about_dialog:
2381  * @parent: (allow-none): transient parent, or %NULL for none
2382  * @first_property_name: the name of the first property
2383  * @Varargs: value of first property, followed by more properties, %NULL-terminated
2384  *
2385  * This is a convenience function for showing an application's about box.
2386  * The constructed dialog is associated with the parent window and
2387  * reused for future invocations of this function.
2388  *
2389  * Since: 2.6
2390  */
2391 void
2392 gtk_show_about_dialog (GtkWindow   *parent,
2393                        const gchar *first_property_name,
2394                        ...)
2395 {
2396   static GtkWidget *global_about_dialog = NULL;
2397   GtkWidget *dialog = NULL;
2398   va_list var_args;
2399
2400   if (parent)
2401     dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2402   else
2403     dialog = global_about_dialog;
2404
2405   if (!dialog)
2406     {
2407       dialog = gtk_about_dialog_new ();
2408
2409       g_object_ref_sink (dialog);
2410
2411       g_signal_connect (dialog, "delete-event",
2412                         G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2413
2414       /* Close dialog on user response */
2415       g_signal_connect (dialog, "response",
2416                         G_CALLBACK (close_cb), NULL);
2417
2418       va_start (var_args, first_property_name);
2419       g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2420       va_end (var_args);
2421
2422       if (parent)
2423         {
2424           gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2425           gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2426           g_object_set_data_full (G_OBJECT (parent),
2427                                   I_("gtk-about-dialog"),
2428                                   dialog, g_object_unref);
2429         }
2430       else
2431         global_about_dialog = dialog;
2432
2433     }
2434
2435   gtk_window_present (GTK_WINDOW (dialog));
2436 }
2437
2438 #define __GTK_ABOUT_DIALOG_C__
2439 #include "gtkaliasdef.c"