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