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