]> Pileus Git - ~andy/gtk/blob - gtk/gtkaboutdialog.c
gtk: gdk_drawable_get_display() => gdk_window_get_display()
[~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_vbox_new (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_hbox_new (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  * Note that that the hook functions need to be set up
1283  * before calling this function.
1284  *
1285  * Since: 2.6
1286  */
1287 void
1288 gtk_about_dialog_set_website (GtkAboutDialog *about,
1289                               const gchar    *website)
1290 {
1291   GtkAboutDialogPrivate *priv;
1292   gchar *tmp;
1293
1294   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1295
1296   priv = about->priv;
1297
1298   tmp = priv->website_url;
1299   priv->website_url = g_strdup (website);
1300   g_free (tmp);
1301
1302   update_website (about);
1303
1304   g_object_notify (G_OBJECT (about), "website");
1305 }
1306
1307 /**
1308  * gtk_about_dialog_get_website_label:
1309  * @about: a #GtkAboutDialog
1310  *
1311  * Returns the label used for the website link.
1312  *
1313  * Return value: The label used for the website link. The string is
1314  *     owned by the about dialog and must not be modified.
1315  *
1316  * Since: 2.6
1317  */
1318 G_CONST_RETURN gchar *
1319 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1320 {
1321   GtkAboutDialogPrivate *priv;
1322
1323   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1324
1325   priv = about->priv;
1326
1327   return priv->website_text;
1328 }
1329
1330 /**
1331  * gtk_about_dialog_set_website_label:
1332  * @about: a #GtkAboutDialog
1333  * @website_label: the label used for the website link
1334  *
1335  * Sets the label to be used for the website link.
1336  * It defaults to the website URL.
1337  *
1338  * Since: 2.6
1339  */
1340 void
1341 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1342                                     const gchar    *website_label)
1343 {
1344   GtkAboutDialogPrivate *priv;
1345   gchar *tmp;
1346
1347   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1348
1349   priv = about->priv;
1350
1351   tmp = priv->website_text;
1352   priv->website_text = g_strdup (website_label);
1353   g_free (tmp);
1354
1355   update_website (about);
1356
1357   g_object_notify (G_OBJECT (about), "website-label");
1358 }
1359
1360 /**
1361  * gtk_about_dialog_get_authors:
1362  * @about: a #GtkAboutDialog
1363  *
1364  * Returns the string which are displayed in the authors tab
1365  * of the secondary credits dialog.
1366  *
1367  * Return value: A %NULL-terminated string array containing
1368  *  the authors. The array is owned by the about dialog
1369  *  and must not be modified.
1370  *
1371  * Since: 2.6
1372  */
1373 G_CONST_RETURN gchar * G_CONST_RETURN *
1374 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1375 {
1376   GtkAboutDialogPrivate *priv;
1377
1378   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1379
1380   priv = about->priv;
1381
1382   return (const gchar * const *) priv->authors;
1383 }
1384
1385 static void
1386 update_credits_button_visibility (GtkAboutDialog *about)
1387 {
1388   GtkAboutDialogPrivate *priv = about->priv;
1389   gboolean show;
1390
1391   show = priv->authors != NULL ||
1392          priv->documenters != NULL ||
1393          priv->artists != NULL ||
1394          (priv->translator_credits != NULL &&
1395           strcmp (priv->translator_credits, "translator_credits") &&
1396           strcmp (priv->translator_credits, "translator-credits"));
1397   if (show)
1398     gtk_widget_show (priv->credits_button);
1399   else
1400     gtk_widget_hide (priv->credits_button);
1401 }
1402
1403 /**
1404  * gtk_about_dialog_set_authors:
1405  * @about: a #GtkAboutDialog
1406  * @authors: a %NULL-terminated array of strings
1407  *
1408  * Sets the strings which are displayed in the authors tab
1409  * of the secondary credits dialog.
1410  *
1411  * Since: 2.6
1412  */
1413 void
1414 gtk_about_dialog_set_authors (GtkAboutDialog  *about,
1415                               const gchar    **authors)
1416 {
1417   GtkAboutDialogPrivate *priv;
1418   gchar **tmp;
1419
1420   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1421
1422   priv = about->priv;
1423
1424   tmp = priv->authors;
1425   priv->authors = g_strdupv ((gchar **)authors);
1426   g_strfreev (tmp);
1427
1428   update_credits_button_visibility (about);
1429
1430   g_object_notify (G_OBJECT (about), "authors");
1431 }
1432
1433 /**
1434  * gtk_about_dialog_get_documenters:
1435  * @about: a #GtkAboutDialog
1436  *
1437  * Returns the string which are displayed in the documenters
1438  * tab of the secondary credits dialog.
1439  *
1440  * Return value: A %NULL-terminated string array containing
1441  *  the documenters. The array is owned by the about dialog
1442  *  and must not be modified.
1443  *
1444  * Since: 2.6
1445  */
1446 G_CONST_RETURN gchar * G_CONST_RETURN *
1447 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1448 {
1449   GtkAboutDialogPrivate *priv;
1450
1451   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1452
1453   priv = about->priv;
1454
1455   return (const gchar * const *)priv->documenters;
1456 }
1457
1458 /**
1459  * gtk_about_dialog_set_documenters:
1460  * @about: a #GtkAboutDialog
1461  * @documenters: a %NULL-terminated array of strings
1462  *
1463  * Sets the strings which are displayed in the documenters tab
1464  * of the secondary credits dialog.
1465  *
1466  * Since: 2.6
1467  */
1468 void
1469 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1470                                   const gchar   **documenters)
1471 {
1472   GtkAboutDialogPrivate *priv;
1473   gchar **tmp;
1474
1475   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1476
1477   priv = about->priv;
1478
1479   tmp = priv->documenters;
1480   priv->documenters = g_strdupv ((gchar **)documenters);
1481   g_strfreev (tmp);
1482
1483   update_credits_button_visibility (about);
1484
1485   g_object_notify (G_OBJECT (about), "documenters");
1486 }
1487
1488 /**
1489  * gtk_about_dialog_get_artists:
1490  * @about: a #GtkAboutDialog
1491  *
1492  * Returns the string which are displayed in the artists tab
1493  * of the secondary credits dialog.
1494  *
1495  * Return value: A %NULL-terminated string array containing
1496  *  the artists. The array is owned by the about dialog
1497  *  and must not be modified.
1498  *
1499  * Since: 2.6
1500  */
1501 G_CONST_RETURN gchar * G_CONST_RETURN *
1502 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1503 {
1504   GtkAboutDialogPrivate *priv;
1505
1506   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1507
1508   priv = about->priv;
1509
1510   return (const gchar * const *)priv->artists;
1511 }
1512
1513 /**
1514  * gtk_about_dialog_set_artists:
1515  * @about: a #GtkAboutDialog
1516  * @artists: a %NULL-terminated array of strings
1517  *
1518  * Sets the strings which are displayed in the artists tab
1519  * of the secondary credits dialog.
1520  *
1521  * Since: 2.6
1522  */
1523 void
1524 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1525                               const gchar   **artists)
1526 {
1527   GtkAboutDialogPrivate *priv;
1528   gchar **tmp;
1529
1530   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1531
1532   priv = about->priv;
1533
1534   tmp = priv->artists;
1535   priv->artists = g_strdupv ((gchar **)artists);
1536   g_strfreev (tmp);
1537
1538   update_credits_button_visibility (about);
1539
1540   g_object_notify (G_OBJECT (about), "artists");
1541 }
1542
1543 /**
1544  * gtk_about_dialog_get_translator_credits:
1545  * @about: a #GtkAboutDialog
1546  *
1547  * Returns the translator credits string which is displayed
1548  * in the translators tab of the secondary credits dialog.
1549  *
1550  * Return value: The translator credits string. The string is
1551  *   owned by the about dialog and must not be modified.
1552  *
1553  * Since: 2.6
1554  */
1555 G_CONST_RETURN gchar *
1556 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1557 {
1558   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1559
1560   return about->priv->translator_credits;
1561 }
1562
1563 /**
1564  * gtk_about_dialog_set_translator_credits:
1565  * @about: a #GtkAboutDialog
1566  * @translator_credits: (allow-none): the translator credits
1567  *
1568  * Sets the translator credits string which is displayed in
1569  * the translators tab of the secondary credits dialog.
1570  *
1571  * The intended use for this string is to display the translator
1572  * of the language which is currently used in the user interface.
1573  * Using gettext(), a simple way to achieve that is to mark the
1574  * string for translation:
1575  * |[
1576  *  gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1577  * ]|
1578  * It is a good idea to use the customary msgid "translator-credits" for this
1579  * purpose, since translators will already know the purpose of that msgid, and
1580  * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1581  * and hide the tab.
1582  *
1583  * Since: 2.6
1584  */
1585 void
1586 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1587                                          const gchar    *translator_credits)
1588 {
1589   GtkAboutDialogPrivate *priv;
1590   gchar *tmp;
1591
1592   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1593
1594   priv = about->priv;
1595
1596   tmp = priv->translator_credits;
1597   priv->translator_credits = g_strdup (translator_credits);
1598   g_free (tmp);
1599
1600   update_credits_button_visibility (about);
1601
1602   g_object_notify (G_OBJECT (about), "translator-credits");
1603 }
1604
1605 /**
1606  * gtk_about_dialog_get_logo:
1607  * @about: a #GtkAboutDialog
1608  *
1609  * Returns the pixbuf displayed as logo in the about dialog.
1610  *
1611  * Return value: the pixbuf displayed as logo. The pixbuf is
1612  *   owned by the about dialog. If you want to keep a reference
1613  *   to it, you have to call g_object_ref() on it.
1614  *
1615  * Since: 2.6
1616  */
1617 GdkPixbuf *
1618 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1619 {
1620   GtkAboutDialogPrivate *priv;
1621
1622   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1623
1624   priv = about->priv;
1625
1626   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1627     return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1628   else
1629     return NULL;
1630 }
1631
1632 static GtkIconSet *
1633 icon_set_new_from_pixbufs (GList *pixbufs)
1634 {
1635   GtkIconSet *icon_set = gtk_icon_set_new ();
1636
1637   for (; pixbufs; pixbufs = pixbufs->next)
1638     {
1639       GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1640
1641       GtkIconSource *icon_source = gtk_icon_source_new ();
1642       gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1643       gtk_icon_set_add_source (icon_set, icon_source);
1644       gtk_icon_source_free (icon_source);
1645     }
1646
1647   return icon_set;
1648 }
1649
1650 /**
1651  * gtk_about_dialog_set_logo:
1652  * @about: a #GtkAboutDialog
1653  * @logo: (allow-none): a #GdkPixbuf, or %NULL
1654  *
1655  * Sets the pixbuf to be displayed as logo in the about dialog.
1656  * If it is %NULL, the default window icon set with
1657  * gtk_window_set_default_icon() will be used.
1658  *
1659  * Since: 2.6
1660  */
1661 void
1662 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1663                            GdkPixbuf      *logo)
1664 {
1665   GtkAboutDialogPrivate *priv;
1666
1667   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1668
1669   priv = about->priv;
1670
1671   g_object_freeze_notify (G_OBJECT (about));
1672
1673   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1674     g_object_notify (G_OBJECT (about), "logo-icon-name");
1675
1676   if (logo != NULL)
1677     gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1678   else
1679     {
1680       GList *pixbufs = gtk_window_get_default_icon_list ();
1681
1682       if (pixbufs != NULL)
1683         {
1684           GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1685
1686           gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1687                                        icon_set, GTK_ICON_SIZE_DIALOG);
1688
1689           gtk_icon_set_unref (icon_set);
1690           g_list_free (pixbufs);
1691         }
1692     }
1693
1694   g_object_notify (G_OBJECT (about), "logo");
1695
1696   g_object_thaw_notify (G_OBJECT (about));
1697 }
1698
1699 /**
1700  * gtk_about_dialog_get_logo_icon_name:
1701  * @about: a #GtkAboutDialog
1702  *
1703  * Returns the icon name displayed as logo in the about dialog.
1704  *
1705  * Return value: the icon name displayed as logo. The string is
1706  *   owned by the dialog. If you want to keep a reference
1707  *   to it, you have to call g_strdup() on it.
1708  *
1709  * Since: 2.6
1710  */
1711 G_CONST_RETURN gchar *
1712 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1713 {
1714   GtkAboutDialogPrivate *priv;
1715   const gchar *icon_name = NULL;
1716
1717   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1718
1719   priv = about->priv;
1720
1721   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1722     gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1723
1724   return icon_name;
1725 }
1726
1727 /**
1728  * gtk_about_dialog_set_logo_icon_name:
1729  * @about: a #GtkAboutDialog
1730  * @icon_name: (allow-none): an icon name, or %NULL
1731  *
1732  * Sets the pixbuf to be displayed as logo in the about dialog.
1733  * If it is %NULL, the default window icon set with
1734  * gtk_window_set_default_icon() will be used.
1735  *
1736  * Since: 2.6
1737  */
1738 void
1739 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1740                                      const gchar    *icon_name)
1741 {
1742   GtkAboutDialogPrivate *priv;
1743
1744   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1745
1746   priv = about->priv;
1747
1748   g_object_freeze_notify (G_OBJECT (about));
1749
1750   if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1751     g_object_notify (G_OBJECT (about), "logo");
1752
1753   gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1754                                 GTK_ICON_SIZE_DIALOG);
1755   g_object_notify (G_OBJECT (about), "logo-icon-name");
1756
1757   g_object_thaw_notify (G_OBJECT (about));
1758 }
1759
1760 static void
1761 follow_if_link (GtkAboutDialog *about,
1762                 GtkTextView    *text_view,
1763                 GtkTextIter    *iter)
1764 {
1765   GSList *tags = NULL, *tagp = NULL;
1766   GtkAboutDialogPrivate *priv = about->priv;
1767   gchar *uri = NULL;
1768
1769   tags = gtk_text_iter_get_tags (iter);
1770   for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1771     {
1772       GtkTextTag *tag = tagp->data;
1773
1774       uri = g_object_get_data (G_OBJECT (tag), "uri");
1775       if (uri)
1776         emit_activate_link (about, uri);
1777
1778       if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1779         {
1780           GdkColor *style_visited_link_color;
1781           GdkColor color;
1782
1783           gtk_widget_ensure_style (GTK_WIDGET (about));
1784           gtk_widget_style_get (GTK_WIDGET (about),
1785                                 "visited-link-color", &style_visited_link_color,
1786                                 NULL);
1787           if (style_visited_link_color)
1788             {
1789               color = *style_visited_link_color;
1790               gdk_color_free (style_visited_link_color);
1791             }
1792           else
1793             color = default_visited_link_color;
1794
1795           g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1796
1797           priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1798         }
1799     }
1800
1801   if (tags)
1802     g_slist_free (tags);
1803 }
1804
1805 static gboolean
1806 text_view_key_press_event (GtkWidget      *text_view,
1807                            GdkEventKey    *event,
1808                            GtkAboutDialog *about)
1809 {
1810   GtkTextIter iter;
1811   GtkTextBuffer *buffer;
1812
1813   switch (event->keyval)
1814     {
1815       case GDK_KEY_Return:
1816       case GDK_KEY_ISO_Enter:
1817       case GDK_KEY_KP_Enter:
1818         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1819         gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1820                                           gtk_text_buffer_get_insert (buffer));
1821         follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1822         break;
1823
1824       default:
1825         break;
1826     }
1827
1828   return FALSE;
1829 }
1830
1831 static gboolean
1832 text_view_event_after (GtkWidget      *text_view,
1833                        GdkEvent       *event,
1834                        GtkAboutDialog *about)
1835 {
1836   GtkTextIter start, end, iter;
1837   GtkTextBuffer *buffer;
1838   GdkEventButton *button_event;
1839   gint x, y;
1840
1841   if (event->type != GDK_BUTTON_RELEASE)
1842     return FALSE;
1843
1844   button_event = (GdkEventButton *)event;
1845
1846   if (button_event->button != 1)
1847     return FALSE;
1848
1849   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1850
1851   /* we shouldn't follow a link if the user has selected something */
1852   gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1853   if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1854     return FALSE;
1855
1856   gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1857                                          GTK_TEXT_WINDOW_WIDGET,
1858                                          button_event->x, button_event->y, &x, &y);
1859
1860   gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1861
1862   follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1863
1864   return FALSE;
1865 }
1866
1867 static void
1868 set_cursor_if_appropriate (GtkAboutDialog *about,
1869                            GtkTextView    *text_view,
1870                            GdkDevice      *device,
1871                            gint            x,
1872                            gint            y)
1873 {
1874   GtkAboutDialogPrivate *priv = about->priv;
1875   GSList *tags = NULL, *tagp = NULL;
1876   GtkTextIter iter;
1877   gboolean hovering_over_link = FALSE;
1878
1879   gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1880
1881   tags = gtk_text_iter_get_tags (&iter);
1882   for (tagp = tags;  tagp != NULL;  tagp = tagp->next)
1883     {
1884       GtkTextTag *tag = tagp->data;
1885       gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1886
1887       if (uri != NULL)
1888         {
1889           hovering_over_link = TRUE;
1890           break;
1891         }
1892     }
1893
1894   if (hovering_over_link != priv->hovering_over_link)
1895     {
1896       priv->hovering_over_link = hovering_over_link;
1897
1898       if (hovering_over_link)
1899         gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1900       else
1901         gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
1902     }
1903
1904   if (tags)
1905     g_slist_free (tags);
1906 }
1907
1908 static gboolean
1909 text_view_motion_notify_event (GtkWidget *text_view,
1910                                GdkEventMotion *event,
1911                                GtkAboutDialog *about)
1912 {
1913   gint x, y;
1914
1915   gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1916                                          GTK_TEXT_WINDOW_WIDGET,
1917                                          event->x, event->y, &x, &y);
1918
1919   set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
1920
1921   gdk_event_request_motions (event);
1922
1923   return FALSE;
1924 }
1925
1926
1927 static gboolean
1928 text_view_visibility_notify_event (GtkWidget          *text_view,
1929                                    GdkEventVisibility *event,
1930                                    GtkAboutDialog     *about)
1931 {
1932   GdkDeviceManager *device_manager;
1933   GdkDisplay *display;
1934   GList *devices, *d;
1935   gint wx, wy, bx, by;
1936
1937   display = gdk_window_get_display (event->window);
1938   device_manager = gdk_display_get_device_manager (display);
1939   devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1940
1941   for (d = devices; d; d = d->next)
1942     {
1943       GdkDevice *dev = d->data;
1944
1945       gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
1946                                       &wx, &wy, NULL);
1947
1948       gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1949                                              GTK_TEXT_WINDOW_WIDGET,
1950                                              wx, wy, &bx, &by);
1951
1952       set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
1953     }
1954
1955   return FALSE;
1956 }
1957
1958 static GtkWidget *
1959 text_view_new (GtkAboutDialog  *about,
1960                GtkWidget       *dialog,
1961                gchar          **strings,
1962                GtkWrapMode      wrap_mode)
1963 {
1964   gchar **p;
1965   gchar *q0, *q1, *q2, *r1, *r2;
1966   GtkWidget *view;
1967   GtkTextView *text_view;
1968   GtkTextBuffer *buffer;
1969   GdkColor *style_link_color;
1970   GdkColor *style_visited_link_color;
1971   GdkColor color;
1972   GdkColor link_color;
1973   GdkColor visited_link_color;
1974
1975   GtkAboutDialogPrivate *priv = about->priv;
1976
1977   gtk_widget_ensure_style (GTK_WIDGET (about));
1978   gtk_widget_style_get (GTK_WIDGET (about),
1979                         "link-color", &style_link_color,
1980                         "visited-link-color", &style_visited_link_color,
1981                         NULL);
1982   if (style_link_color)
1983     {
1984       link_color = *style_link_color;
1985       gdk_color_free (style_link_color);
1986     }
1987   else
1988     link_color = default_link_color;
1989
1990   if (style_visited_link_color)
1991     {
1992       visited_link_color = *style_visited_link_color;
1993       gdk_color_free (style_visited_link_color);
1994     }
1995   else
1996     visited_link_color = default_visited_link_color;
1997
1998   view = gtk_text_view_new ();
1999   text_view = GTK_TEXT_VIEW (view);
2000   buffer = gtk_text_view_get_buffer (text_view);
2001   gtk_text_view_set_cursor_visible (text_view, FALSE);
2002   gtk_text_view_set_editable (text_view, FALSE);
2003   gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2004
2005   gtk_text_view_set_left_margin (text_view, 8);
2006   gtk_text_view_set_right_margin (text_view, 8);
2007
2008   g_signal_connect (view, "key-press-event",
2009                     G_CALLBACK (text_view_key_press_event), about);
2010   g_signal_connect (view, "event-after",
2011                     G_CALLBACK (text_view_event_after), about);
2012   g_signal_connect (view, "motion-notify-event",
2013                     G_CALLBACK (text_view_motion_notify_event), about);
2014   g_signal_connect (view, "visibility-notify-event",
2015                     G_CALLBACK (text_view_visibility_notify_event), about);
2016
2017   if (strings == NULL)
2018     {
2019       gtk_widget_hide (view);
2020       return view;
2021     }
2022
2023   for (p = strings; *p; p++)
2024     {
2025       q0  = *p;
2026       while (*q0)
2027         {
2028           q1 = strchr (q0, '<');
2029           q2 = q1 ? strchr (q1, '>') : NULL;
2030           r1 = strstr (q0, "http://");
2031           if (r1)
2032             {
2033               r2 = strpbrk (r1, " \n\t");
2034               if (!r2)
2035                 r2 = strchr (r1, '\0');
2036             }
2037           else
2038             r2 = NULL;
2039
2040           if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2041             {
2042               q1 = r1;
2043               q2 = r2;
2044             }
2045
2046           if (q1 && q2)
2047             {
2048               GtkTextIter end;
2049               gchar *link;
2050               gchar *uri;
2051               const gchar *link_type;
2052               GtkTextTag *tag;
2053
2054               if (*q1 == '<')
2055                 {
2056                   gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
2057                   gtk_text_buffer_get_end_iter (buffer, &end);
2058                   q1++;
2059                   link_type = "email";
2060                 }
2061               else
2062                 {
2063                   gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2064                   gtk_text_buffer_get_end_iter (buffer, &end);
2065                   link_type = "uri";
2066                 }
2067
2068               q0 = q2;
2069
2070               link = g_strndup (q1, q2 - q1);
2071
2072               if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2073                 color = visited_link_color;
2074               else
2075                 color = link_color;
2076
2077               tag = gtk_text_buffer_create_tag (buffer, NULL,
2078                                                 "foreground-gdk", &color,
2079                                                 "underline", PANGO_UNDERLINE_SINGLE,
2080                                                 NULL);
2081               if (strcmp (link_type, "email") == 0)
2082                 {
2083                   gchar *escaped;
2084
2085                   escaped = g_uri_escape_string (link, NULL, FALSE);
2086                   uri = g_strconcat ("mailto:", escaped, NULL);
2087                   g_free (escaped);
2088                 }
2089               else
2090                 {
2091                   uri = g_strdup (link);
2092                 }
2093               g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
2094               gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2095
2096               g_free (link);
2097             }
2098           else
2099             {
2100               gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2101               break;
2102             }
2103         }
2104
2105       if (p[1])
2106         gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2107     }
2108
2109   gtk_widget_show (view);
2110   return view;
2111 }
2112
2113 static void
2114 add_credits_page (GtkAboutDialog *about,
2115                   GtkWidget      *credits_dialog,
2116                   GtkWidget      *notebook,
2117                   gchar          *title,
2118                   gchar         **people)
2119 {
2120   GtkWidget *sw, *view;
2121
2122   view = text_view_new (about, credits_dialog, people, GTK_WRAP_NONE);
2123
2124   sw = gtk_scrolled_window_new (NULL, NULL);
2125   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2126                                        GTK_SHADOW_IN);
2127   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2128                                   GTK_POLICY_AUTOMATIC,
2129                                   GTK_POLICY_AUTOMATIC);
2130   gtk_container_add (GTK_CONTAINER (sw), view);
2131
2132   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
2133                             sw, gtk_label_new (title));
2134 }
2135
2136 static void
2137 display_credits_dialog (GtkWidget *button,
2138                         gpointer   data)
2139 {
2140   GtkAboutDialog *about = (GtkAboutDialog *)data;
2141   GtkAboutDialogPrivate *priv = about->priv;
2142   GtkWidget *dialog, *notebook;
2143   GtkDialog *credits_dialog;
2144   GtkWidget *content_area;
2145   GtkWidget *action_area;
2146
2147   if (priv->credits_dialog != NULL)
2148     {
2149       gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2150       return;
2151     }
2152
2153   dialog = gtk_dialog_new_with_buttons (_("Credits"),
2154                                         GTK_WINDOW (about),
2155                                         GTK_DIALOG_DESTROY_WITH_PARENT,
2156                                         GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2157                                         NULL);
2158   credits_dialog = GTK_DIALOG (dialog);
2159
2160   content_area = gtk_dialog_get_content_area (credits_dialog);
2161   action_area = gtk_dialog_get_action_area (credits_dialog);
2162
2163   gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2164   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2165   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2166
2167   priv->credits_dialog = dialog;
2168   gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2169   gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2170
2171   gtk_window_set_modal (GTK_WINDOW (dialog),
2172                         gtk_window_get_modal (GTK_WINDOW (about)));
2173
2174   g_signal_connect (dialog, "response",
2175                     G_CALLBACK (gtk_widget_destroy), dialog);
2176   g_signal_connect (dialog, "destroy",
2177                     G_CALLBACK (gtk_widget_destroyed),
2178                     &(priv->credits_dialog));
2179
2180   notebook = gtk_notebook_new ();
2181   gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2182   gtk_box_pack_start (GTK_BOX (content_area), notebook, TRUE, TRUE, 0);
2183
2184   if (priv->authors != NULL)
2185     add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2186
2187   if (priv->documenters != NULL)
2188     add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2189
2190   /* Don't show an untranslated gettext msgid */
2191   if (priv->translator_credits != NULL &&
2192       strcmp (priv->translator_credits, "translator_credits") != 0 &&
2193       strcmp (priv->translator_credits, "translator-credits") != 0)
2194     {
2195       gchar *translators[2];
2196
2197       translators[0] = priv->translator_credits;
2198       translators[1] = NULL;
2199
2200       add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2201     }
2202
2203   if (priv->artists != NULL)
2204     add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2205
2206   gtk_widget_show_all (dialog);
2207 }
2208
2209 static void
2210 set_policy (GtkWidget *sw)
2211 {
2212   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2213                                   GTK_POLICY_AUTOMATIC,
2214                                   GTK_POLICY_AUTOMATIC);
2215 }
2216
2217 static void
2218 display_license_dialog (GtkWidget *button,
2219                         gpointer   data)
2220 {
2221   GtkAboutDialog *about = (GtkAboutDialog *)data;
2222   GtkAboutDialogPrivate *priv = about->priv;
2223   GtkWidget *dialog, *view, *sw;
2224   GtkDialog *license_dialog;
2225   GtkWidget *content_area;
2226   GtkWidget *action_area;
2227   gchar *strings[2];
2228
2229   if (priv->license_dialog != NULL)
2230     {
2231       gtk_window_present (GTK_WINDOW (priv->license_dialog));
2232       return;
2233     }
2234
2235   dialog = gtk_dialog_new_with_buttons (_("License"),
2236                                         GTK_WINDOW (about),
2237                                         GTK_DIALOG_DESTROY_WITH_PARENT,
2238                                         GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2239                                         NULL);
2240   license_dialog = GTK_DIALOG (dialog);
2241
2242   content_area = gtk_dialog_get_content_area (license_dialog);
2243   action_area = gtk_dialog_get_action_area (license_dialog);
2244
2245   gtk_container_set_border_width (GTK_CONTAINER (license_dialog), 5);
2246   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2247   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2248
2249   priv->license_dialog = dialog;
2250   gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2251   gtk_dialog_set_default_response (license_dialog, GTK_RESPONSE_CANCEL);
2252
2253   gtk_window_set_modal (GTK_WINDOW (dialog),
2254                         gtk_window_get_modal (GTK_WINDOW (about)));
2255
2256   g_signal_connect (dialog, "response",
2257                     G_CALLBACK (gtk_widget_destroy), dialog);
2258   g_signal_connect (dialog, "destroy",
2259                     G_CALLBACK (gtk_widget_destroyed),
2260                     &(priv->license_dialog));
2261
2262   sw = gtk_scrolled_window_new (NULL, NULL);
2263   gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2264   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2265                                        GTK_SHADOW_IN);
2266   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2267                                   GTK_POLICY_NEVER,
2268                                   GTK_POLICY_AUTOMATIC);
2269   g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2270   gtk_box_pack_start (GTK_BOX (content_area), sw, TRUE, TRUE, 0);
2271
2272   strings[0] = priv->license;
2273   strings[1] = NULL;
2274   view = text_view_new (about, dialog, strings,
2275                         priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2276
2277   gtk_container_add (GTK_CONTAINER (sw), view);
2278
2279   gtk_widget_show_all (dialog);
2280 }
2281
2282 /**
2283  * gtk_about_dialog_new:
2284  *
2285  * Creates a new #GtkAboutDialog.
2286  *
2287  * Returns: a newly created #GtkAboutDialog
2288  *
2289  * Since: 2.6
2290  */
2291 GtkWidget *
2292 gtk_about_dialog_new (void)
2293 {
2294   GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2295
2296   return GTK_WIDGET (dialog);
2297 }
2298
2299 static void
2300 close_cb (GtkAboutDialog *about)
2301 {
2302   GtkAboutDialogPrivate *priv = about->priv;
2303
2304   if (priv->license_dialog != NULL)
2305     {
2306       gtk_widget_destroy (priv->license_dialog);
2307       priv->license_dialog = NULL;
2308     }
2309
2310   if (priv->credits_dialog != NULL)
2311     {
2312       gtk_widget_destroy (priv->credits_dialog);
2313       priv->credits_dialog = NULL;
2314     }
2315
2316   gtk_widget_hide (GTK_WIDGET (about));
2317
2318 }
2319
2320 /**
2321  * gtk_show_about_dialog:
2322  * @parent: (allow-none): transient parent, or %NULL for none
2323  * @first_property_name: the name of the first property
2324  * @Varargs: value of first property, followed by more properties, %NULL-terminated
2325  *
2326  * This is a convenience function for showing an application's about box.
2327  * The constructed dialog is associated with the parent window and
2328  * reused for future invocations of this function.
2329  *
2330  * Since: 2.6
2331  */
2332 void
2333 gtk_show_about_dialog (GtkWindow   *parent,
2334                        const gchar *first_property_name,
2335                        ...)
2336 {
2337   static GtkWidget *global_about_dialog = NULL;
2338   GtkWidget *dialog = NULL;
2339   va_list var_args;
2340
2341   if (parent)
2342     dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2343   else
2344     dialog = global_about_dialog;
2345
2346   if (!dialog)
2347     {
2348       dialog = gtk_about_dialog_new ();
2349
2350       g_object_ref_sink (dialog);
2351
2352       g_signal_connect (dialog, "delete-event",
2353                         G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2354
2355       /* Close dialog on user response */
2356       g_signal_connect (dialog, "response",
2357                         G_CALLBACK (close_cb), NULL);
2358
2359       va_start (var_args, first_property_name);
2360       g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2361       va_end (var_args);
2362
2363       if (parent)
2364         {
2365           gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2366           gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2367           g_object_set_data_full (G_OBJECT (parent),
2368                                   I_("gtk-about-dialog"),
2369                                   dialog, g_object_unref);
2370         }
2371       else
2372         global_about_dialog = dialog;
2373
2374     }
2375
2376   gtk_window_present (GTK_WINDOW (dialog));
2377 }
2378
2379 /**
2380  * gtk_about_dialog_set_license_type:
2381  * @about: a #GtkAboutDialog
2382  * @license_type: the type of license
2383  *
2384  * Sets the license of the application showing the @about dialog from a
2385  * list of known licenses.
2386  *
2387  * This function overrides the license set using
2388  * gtk_about_dialog_set_license().
2389  *
2390  * Since: 3.0
2391  */
2392 void
2393 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2394                                    GtkLicense      license_type)
2395 {
2396   GtkAboutDialogPrivate *priv;
2397
2398   g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2399   g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2400                     license_type <= GTK_LICENSE_ARTISTIC);
2401
2402   priv = about->priv;
2403
2404   if (priv->license_type != license_type)
2405     {
2406       g_object_freeze_notify (G_OBJECT (about));
2407
2408       priv->license_type = license_type;
2409
2410       /* custom licenses use the contents of the :license property */
2411       if (priv->license_type != GTK_LICENSE_CUSTOM)
2412         {
2413           const gchar *url;
2414           GString *str;
2415
2416           url = gtk_license_urls[priv->license_type];
2417           if (url == NULL)
2418             url = priv->website_url;
2419
2420           /* compose the new license string as:
2421            *
2422            *   <program-name>\n
2423            *   <copyright line 1>\n
2424            *   ...
2425            *   <copyright line n>\n
2426            *   \n
2427            *   license preamble + URL
2428            *
2429            */
2430           str = g_string_sized_new (256);
2431           g_string_append (str, priv->name);
2432           g_string_append (str, "\n");
2433           g_string_append (str, priv->copyright);
2434           g_string_append (str, "\n\n");
2435           g_string_append_printf (str, _(gtk_license_preamble), url);
2436
2437           g_free (priv->license);
2438           priv->license = g_string_free (str, FALSE);
2439           priv->wrap_license = TRUE;
2440           gtk_widget_show (priv->license_button);
2441
2442           g_object_notify (G_OBJECT (about), "wrap-license");
2443           g_object_notify (G_OBJECT (about), "license");
2444         }
2445
2446       g_object_notify (G_OBJECT (about), "license-type");
2447
2448       g_object_thaw_notify (G_OBJECT (about));
2449     }
2450 }
2451
2452 /**
2453  * gtk_about_dialog_get_license_type:
2454  * @about: a #GtkAboutDialog
2455  *
2456  * Retrieves the license set using gtk_about_dialog_set_license_type()
2457  *
2458  * Return value: a #GtkLicense value
2459  *
2460  * Since: 3.0
2461  */
2462 GtkLicense
2463 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2464 {
2465   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2466
2467   return about->priv->license_type;
2468 }