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