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