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