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