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>
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.
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.
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.
23 * Author: Anders Carlsson <andersca@gnome.org>
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/.
35 #include "gtkaboutdialog.h"
36 #include "gtkbutton.h"
38 #include "gtkdialog.h"
43 #include "gtklinkbutton.h"
44 #include "gtkmarshalers.h"
45 #include "gtknotebook.h"
46 #include "gtkorientable.h"
47 #include "gtkscrolledwindow.h"
49 #include "gtktextview.h"
50 #include "gtkiconfactory.h"
53 #include "gtkmessagedialog.h"
54 #include "gtktogglebutton.h"
55 #include "gtktypebuiltins.h"
56 #include "gtkprivate.h"
61 * SECTION:gtkaboutdialog
62 * @Short_description: Display information about an application
63 * @Title: GtkAboutDialog
64 * @See_also: #GTK_STOCK_ABOUT
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.
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.
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.
82 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
83 * on the dialog window (where %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"),
93 * </programlisting></informalexample>
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.
100 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
101 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
103 /* Translators: this is the license preamble; the string at the end
104 * contains the URL of the license.
106 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit <a href=\"%s\">%s</a>");
108 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
109 static const gchar *gtk_license_urls[] = {
113 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
114 "http://www.gnu.org/licenses/gpl.html",
116 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
117 "http://www.gnu.org/licenses/lgpl.html",
119 "http://opensource.org/licenses/bsd-license.php",
120 "http://opensource.org/licenses/mit-license.php",
122 "http://opensource.org/licenses/artistic-license-2.0.php"
131 struct _GtkAboutDialogPrivate
139 gchar *translator_credits;
147 GSList *credit_sections;
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;
161 GtkWidget *credits_button;
162 GtkWidget *license_button;
164 GdkCursor *hand_cursor;
165 GdkCursor *regular_cursor;
167 GSList *visited_links;
169 GtkLicense license_type;
171 guint hovering_over_link : 1;
172 guint wrap_license : 1;
177 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
192 PROP_TRANSLATOR_CREDITS,
200 static void gtk_about_dialog_finalize (GObject *object);
201 static void gtk_about_dialog_get_property (GObject *object,
205 static void gtk_about_dialog_set_property (GObject *object,
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,
215 static void set_cursor_if_appropriate (GtkAboutDialog *about,
216 GtkTextView *text_view,
220 static void display_credits_page (GtkWidget *button,
222 static void display_license_page (GtkWidget *button,
224 static void close_cb (GtkAboutDialog *about);
225 static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
233 static guint signals[LAST_SIGNAL] = { 0 };
235 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
239 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
241 GObjectClass *object_class;
242 GtkWidgetClass *widget_class;
244 object_class = (GObjectClass *)klass;
245 widget_class = (GtkWidgetClass *)klass;
247 object_class->set_property = gtk_about_dialog_set_property;
248 object_class->get_property = gtk_about_dialog_get_property;
250 object_class->finalize = gtk_about_dialog_finalize;
252 widget_class->show = gtk_about_dialog_show;
254 klass->activate_link = gtk_about_dialog_activate_link;
257 * GtkAboutDialog::activate-link:
258 * @label: The object on which the signal was emitted
259 * @uri: the URI that is activated
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().
265 * Returns: %TRUE if the link has been activated
269 signals[ACTIVATE_LINK] =
270 g_signal_new ("activate-link",
271 G_TYPE_FROM_CLASS (object_class),
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);
279 * GtkAboutDialog:program-name:
281 * The name of the program.
282 * If this is not set, it defaults to g_get_application_name().
286 g_object_class_install_property (object_class,
288 g_param_spec_string ("program-name",
290 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
292 GTK_PARAM_READWRITE));
295 * GtkAboutDialog:version:
297 * The version of the program.
301 g_object_class_install_property (object_class,
303 g_param_spec_string ("version",
304 P_("Program version"),
305 P_("The version of the program"),
307 GTK_PARAM_READWRITE));
310 * GtkAboutDialog:copyright:
312 * Copyright information for the program.
316 g_object_class_install_property (object_class,
318 g_param_spec_string ("copyright",
319 P_("Copyright string"),
320 P_("Copyright information for the program"),
322 GTK_PARAM_READWRITE));
326 * GtkAboutDialog:comments:
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.
334 g_object_class_install_property (object_class,
336 g_param_spec_string ("comments",
337 P_("Comments string"),
338 P_("Comments about the program"),
340 GTK_PARAM_READWRITE));
343 * GtkAboutDialog:license:
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
356 g_object_class_install_property (object_class,
358 g_param_spec_string ("license",
360 _("The license of the program"),
362 GTK_PARAM_READWRITE));
365 * GtkAboutDialog:license-type:
367 * The license of the program, as a value of the %GtkLicense enumeration.
369 * The #GtkAboutDialog will automatically fill out a standard disclaimer
370 * and link the user to the appropriate online resource for the license
373 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
374 * specified in the #GtkAboutDialog:website property.
376 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
377 * #GtkAboutDialog:license property are used.
379 * For any other #GtkLicense value, the contents of the
380 * #GtkAboutDialog:license property are also set by this property as
385 g_object_class_install_property (object_class,
387 g_param_spec_enum ("license-type",
389 P_("The license type of the program"),
392 GTK_PARAM_READWRITE));
395 * GtkAboutDialog:website:
397 * The URL for the link to the website of the program.
398 * This should be a string starting with "http://.
402 g_object_class_install_property (object_class,
404 g_param_spec_string ("website",
406 P_("The URL for the link to the website of the program"),
408 GTK_PARAM_READWRITE));
411 * GtkAboutDialog:website-label:
413 * The label for the link to the website of the program.
417 g_object_class_install_property (object_class,
419 g_param_spec_string ("website-label",
421 P_("The label for the link to the website of the program"),
423 GTK_PARAM_READWRITE));
426 * GtkAboutDialog:authors:
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.
434 g_object_class_install_property (object_class,
436 g_param_spec_boxed ("authors",
438 P_("List of authors of the program"),
440 GTK_PARAM_READWRITE));
443 * GtkAboutDialog:documenters:
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.
451 g_object_class_install_property (object_class,
453 g_param_spec_boxed ("documenters",
455 P_("List of people documenting the program"),
457 GTK_PARAM_READWRITE));
460 * GtkAboutDialog:artists:
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.
468 g_object_class_install_property (object_class,
470 g_param_spec_boxed ("artists",
472 P_("List of people who have contributed artwork to the program"),
474 GTK_PARAM_READWRITE));
478 * GtkAboutDialog:translator-credits:
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.
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"),
492 GTK_PARAM_READWRITE));
495 * GtkAboutDialog:logo:
497 * A logo for the about box. If this is not set, it defaults to
498 * gtk_window_get_default_icon_list().
502 g_object_class_install_property (object_class,
504 g_param_spec_object ("logo",
506 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
508 GTK_PARAM_READWRITE));
511 * GtkAboutDialog:logo-icon-name:
513 * A named icon to use as the logo for the about box. This property
514 * overrides the #GtkAboutDialog:logo property.
518 g_object_class_install_property (object_class,
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."),
524 GTK_PARAM_READWRITE));
526 * GtkAboutDialog:wrap-license:
528 * Whether to wrap the text in the license dialog.
532 g_object_class_install_property (object_class,
534 g_param_spec_boolean ("wrap-license",
536 P_("Whether to wrap the license text."),
538 GTK_PARAM_READWRITE));
541 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
545 emit_activate_link (GtkAboutDialog *about,
548 gboolean handled = FALSE;
550 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
556 update_license_button_visibility (GtkAboutDialog *about)
558 GtkAboutDialogPrivate *priv = about->priv;
560 if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL)
561 gtk_widget_show (priv->license_button);
563 gtk_widget_hide (priv->license_button);
567 update_credits_button_visibility (GtkAboutDialog *about)
569 GtkAboutDialogPrivate *priv = about->priv;
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")));
580 gtk_widget_show (priv->credits_button);
582 gtk_widget_hide (priv->credits_button);
586 switch_page (GtkAboutDialog *about,
589 GtkAboutDialogPrivate *priv = about->priv;
591 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page);
595 display_main_page (GtkButton *button,
598 GtkAboutDialog *about = (GtkAboutDialog *)data;
600 switch_page (about, 0);
604 credits_button_clicked (GtkButton *button,
607 GtkAboutDialog *about = (GtkAboutDialog *)data;
608 GtkAboutDialogPrivate *priv = about->priv;
611 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
615 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
616 display_credits_page (NULL, data);
620 display_main_page (NULL, data);
625 license_button_clicked (GtkButton *button,
628 GtkAboutDialog *about = (GtkAboutDialog *)data;
629 GtkAboutDialogPrivate *priv = about->priv;
632 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
636 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
637 display_license_page (NULL, data);
641 display_main_page (NULL, data);
645 gtk_about_dialog_init (GtkAboutDialog *about)
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;
653 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
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;
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;
673 priv->license_type = GTK_LICENSE_UNKNOWN;
675 content_area = gtk_dialog_get_content_area (dialog);
676 action_area = gtk_dialog_get_action_area (dialog);
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);
683 gtk_widget_push_composite_child ();
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);
689 priv->logo_image = gtk_image_new ();
690 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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;
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;
776 switch_page (about, 0);
778 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
780 gtk_widget_pop_composite_child ();
782 gtk_widget_grab_default (close_button);
783 gtk_widget_grab_focus (close_button);
786 gtk_about_dialog_set_program_name (about, NULL);
787 gtk_about_dialog_set_logo (about, NULL);
791 destroy_credit_section (gpointer data)
793 CreditSection *cs = data;
794 g_free (cs->heading);
795 g_strfreev (cs->people);
796 g_slice_free (CreditSection, data);
800 gtk_about_dialog_finalize (GObject *object)
802 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
803 GtkAboutDialogPrivate *priv = about->priv;
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);
814 g_strfreev (priv->authors);
815 g_strfreev (priv->documenters);
816 g_strfreev (priv->artists);
818 g_slist_free_full (priv->credit_sections, destroy_credit_section);
820 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
821 g_slist_free (priv->visited_links);
823 g_object_unref (priv->hand_cursor);
824 g_object_unref (priv->regular_cursor);
826 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
830 gtk_about_dialog_set_property (GObject *object,
835 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
836 GtkAboutDialogPrivate *priv = about->priv;
841 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
844 gtk_about_dialog_set_version (about, g_value_get_string (value));
847 gtk_about_dialog_set_comments (about, g_value_get_string (value));
850 gtk_about_dialog_set_website (about, g_value_get_string (value));
852 case PROP_WEBSITE_LABEL:
853 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
856 gtk_about_dialog_set_license (about, g_value_get_string (value));
858 case PROP_LICENSE_TYPE:
859 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
862 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
865 gtk_about_dialog_set_logo (about, g_value_get_object (value));
868 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
870 case PROP_DOCUMENTERS:
871 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
874 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
876 case PROP_TRANSLATOR_CREDITS:
877 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
879 case PROP_LOGO_ICON_NAME:
880 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
882 case PROP_WRAP_LICENSE:
883 priv->wrap_license = g_value_get_boolean (value);
886 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
892 gtk_about_dialog_get_property (GObject *object,
897 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
898 GtkAboutDialogPrivate *priv = about->priv;
903 g_value_set_string (value, priv->name);
906 g_value_set_string (value, priv->version);
909 g_value_set_string (value, priv->copyright);
912 g_value_set_string (value, priv->comments);
915 g_value_set_string (value, priv->website_url);
917 case PROP_WEBSITE_LABEL:
918 g_value_set_string (value, priv->website_text);
921 g_value_set_string (value, priv->license);
923 case PROP_LICENSE_TYPE:
924 g_value_set_enum (value, priv->license_type);
926 case PROP_TRANSLATOR_CREDITS:
927 g_value_set_string (value, priv->translator_credits);
930 g_value_set_boxed (value, priv->authors);
932 case PROP_DOCUMENTERS:
933 g_value_set_boxed (value, priv->documenters);
936 g_value_set_boxed (value, priv->artists);
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)));
942 g_value_set_object (value, NULL);
944 case PROP_LOGO_ICON_NAME:
945 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
947 const gchar *icon_name;
949 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
950 g_value_set_string (value, icon_name);
953 g_value_set_string (value, NULL);
955 case PROP_WRAP_LICENSE:
956 g_value_set_boolean (value, priv->wrap_license);
959 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
965 gtk_about_dialog_activate_link (GtkAboutDialog *about,
969 GError *error = NULL;
971 screen = gtk_widget_get_screen (GTK_WIDGET (about));
973 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
977 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
978 GTK_DIALOG_DESTROY_WITH_PARENT |
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);
987 g_signal_connect (dialog, "response",
988 G_CALLBACK (gtk_widget_destroy), NULL);
990 gtk_window_present (GTK_WINDOW (dialog));
997 update_website (GtkAboutDialog *about)
999 GtkAboutDialogPrivate *priv = about->priv;
1001 gtk_widget_show (priv->website_label);
1003 if (priv->website_url)
1007 if (priv->website_text)
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);
1018 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
1019 priv->website_url, _("Homepage"));
1022 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
1027 if (priv->website_text)
1028 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
1030 gtk_widget_hide (priv->website_label);
1035 gtk_about_dialog_show (GtkWidget *widget)
1037 update_website (GTK_ABOUT_DIALOG (widget));
1039 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
1043 * gtk_about_dialog_get_program_name:
1044 * @about: a #GtkAboutDialog
1046 * Returns the program name displayed in the about dialog.
1048 * Return value: The program name. The string is owned by the about
1049 * dialog and must not be modified.
1054 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
1056 GtkAboutDialogPrivate *priv;
1058 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1066 update_name_version (GtkAboutDialog *about)
1068 GtkAboutDialogPrivate *priv;
1069 gchar *title_string, *name_string;
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);
1077 if (priv->version != NULL)
1079 gtk_label_set_markup (GTK_LABEL (priv->version_label), priv->version);
1080 gtk_widget_show (priv->version_label);
1083 gtk_widget_hide (priv->version_label);
1085 name_string = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
1087 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
1088 g_free (name_string);
1092 * gtk_about_dialog_set_program_name:
1093 * @about: a #GtkAboutDialog
1094 * @name: the program name
1096 * Sets the name to display in the about dialog.
1097 * If this is not set, it defaults to g_get_application_name().
1102 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
1105 GtkAboutDialogPrivate *priv;
1108 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1113 priv->name = g_strdup (name ? name : g_get_application_name ());
1116 update_name_version (about);
1118 g_object_notify (G_OBJECT (about), "program-name");
1123 * gtk_about_dialog_get_version:
1124 * @about: a #GtkAboutDialog
1126 * Returns the version string.
1128 * Return value: The version string. The string is owned by the about
1129 * dialog and must not be modified.
1134 gtk_about_dialog_get_version (GtkAboutDialog *about)
1136 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1138 return about->priv->version;
1142 * gtk_about_dialog_set_version:
1143 * @about: a #GtkAboutDialog
1144 * @version: (allow-none): the version string
1146 * Sets the version string to display in the about dialog.
1151 gtk_about_dialog_set_version (GtkAboutDialog *about,
1152 const gchar *version)
1154 GtkAboutDialogPrivate *priv;
1157 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1161 tmp = priv->version;
1162 priv->version = g_strdup (version);
1165 update_name_version (about);
1167 g_object_notify (G_OBJECT (about), "version");
1171 * gtk_about_dialog_get_copyright:
1172 * @about: a #GtkAboutDialog
1174 * Returns the copyright string.
1176 * Return value: The copyright string. The string is owned by the about
1177 * dialog and must not be modified.
1182 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1184 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1186 return about->priv->copyright;
1190 * gtk_about_dialog_set_copyright:
1191 * @about: a #GtkAboutDialog
1192 * @copyright: (allow-none) the copyright string
1194 * Sets the copyright string to display in the about dialog.
1195 * This should be a short string of one or two lines.
1200 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1201 const gchar *copyright)
1203 GtkAboutDialogPrivate *priv;
1204 gchar *copyright_string, *tmp;
1206 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1210 tmp = priv->copyright;
1211 priv->copyright = g_strdup (copyright);
1214 if (priv->copyright != NULL)
1216 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1218 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1219 g_free (copyright_string);
1221 gtk_widget_show (priv->copyright_label);
1224 gtk_widget_hide (priv->copyright_label);
1226 g_object_notify (G_OBJECT (about), "copyright");
1230 * gtk_about_dialog_get_comments:
1231 * @about: a #GtkAboutDialog
1233 * Returns the comments string.
1235 * Return value: The comments. The string is owned by the about
1236 * dialog and must not be modified.
1241 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1243 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1245 return about->priv->comments;
1249 * gtk_about_dialog_set_comments:
1250 * @about: a #GtkAboutDialog
1251 * @comments: (allow-none): a comments string
1253 * Sets the comments string to display in the about dialog.
1254 * This should be a short string of one or two lines.
1259 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1260 const gchar *comments)
1262 GtkAboutDialogPrivate *priv;
1265 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1269 tmp = priv->comments;
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);
1278 priv->comments = NULL;
1279 gtk_widget_hide (priv->comments_label);
1283 g_object_notify (G_OBJECT (about), "comments");
1287 * gtk_about_dialog_get_license:
1288 * @about: a #GtkAboutDialog
1290 * Returns the license information.
1292 * Return value: The license information. The string is owned by the about
1293 * dialog and must not be modified.
1298 gtk_about_dialog_get_license (GtkAboutDialog *about)
1300 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1302 return about->priv->license;
1306 * gtk_about_dialog_set_license:
1307 * @about: a #GtkAboutDialog
1308 * @license: (allow-none): the license information or %NULL
1310 * Sets the license information to be displayed in the secondary
1311 * license dialog. If @license is %NULL, the license button is
1317 gtk_about_dialog_set_license (GtkAboutDialog *about,
1318 const gchar *license)
1320 GtkAboutDialogPrivate *priv;
1323 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1327 tmp = priv->license;
1330 priv->license = g_strdup (license);
1331 priv->license_type = GTK_LICENSE_CUSTOM;
1335 priv->license = NULL;
1336 priv->license_type = GTK_LICENSE_UNKNOWN;
1340 gtk_widget_hide (priv->license_label);
1342 update_license_button_visibility (about);
1344 g_object_notify (G_OBJECT (about), "license");
1345 g_object_notify (G_OBJECT (about), "license-type");
1349 * gtk_about_dialog_get_wrap_license:
1350 * @about: a #GtkAboutDialog
1352 * Returns whether the license text in @about is
1353 * automatically wrapped.
1355 * Returns: %TRUE if the license text is wrapped
1360 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1362 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1364 return about->priv->wrap_license;
1368 * gtk_about_dialog_set_wrap_license:
1369 * @about: a #GtkAboutDialog
1370 * @wrap_license: whether to wrap the license
1372 * Sets whether the license text in @about is
1373 * automatically wrapped.
1378 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1379 gboolean wrap_license)
1381 GtkAboutDialogPrivate *priv;
1383 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1387 wrap_license = wrap_license != FALSE;
1389 if (priv->wrap_license != wrap_license)
1391 priv->wrap_license = wrap_license;
1393 g_object_notify (G_OBJECT (about), "wrap-license");
1398 * gtk_about_dialog_get_website:
1399 * @about: a #GtkAboutDialog
1401 * Returns the website URL.
1403 * Return value: The website URL. The string is owned by the about
1404 * dialog and must not be modified.
1409 gtk_about_dialog_get_website (GtkAboutDialog *about)
1411 GtkAboutDialogPrivate *priv;
1413 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1417 return priv->website_url;
1421 * gtk_about_dialog_set_website:
1422 * @about: a #GtkAboutDialog
1423 * @website: (allow-none): a URL string starting with "http://"
1425 * Sets the URL to use for the website link.
1430 gtk_about_dialog_set_website (GtkAboutDialog *about,
1431 const gchar *website)
1433 GtkAboutDialogPrivate *priv;
1436 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1440 tmp = priv->website_url;
1441 priv->website_url = g_strdup (website);
1444 update_website (about);
1446 g_object_notify (G_OBJECT (about), "website");
1450 * gtk_about_dialog_get_website_label:
1451 * @about: a #GtkAboutDialog
1453 * Returns the label used for the website link.
1455 * Return value: The label used for the website link. The string is
1456 * owned by the about dialog and must not be modified.
1461 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1463 GtkAboutDialogPrivate *priv;
1465 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1469 return priv->website_text;
1473 * gtk_about_dialog_set_website_label:
1474 * @about: a #GtkAboutDialog
1475 * @website_label: the label used for the website link
1477 * Sets the label to be used for the website link.
1482 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1483 const gchar *website_label)
1485 GtkAboutDialogPrivate *priv;
1488 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1492 tmp = priv->website_text;
1493 priv->website_text = g_strdup (website_label);
1496 update_website (about);
1498 g_object_notify (G_OBJECT (about), "website-label");
1502 * gtk_about_dialog_get_authors:
1503 * @about: a #GtkAboutDialog
1505 * Returns the string which are displayed in the authors tab
1506 * of the secondary credits dialog.
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.
1514 const gchar * const *
1515 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1517 GtkAboutDialogPrivate *priv;
1519 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1523 return (const gchar * const *) priv->authors;
1527 * gtk_about_dialog_set_authors:
1528 * @about: a #GtkAboutDialog
1529 * @authors: (array zero-terminated=1): a %NULL-terminated array of strings
1531 * Sets the strings which are displayed in the authors tab
1532 * of the secondary credits dialog.
1537 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1538 const gchar **authors)
1540 GtkAboutDialogPrivate *priv;
1543 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1547 tmp = priv->authors;
1548 priv->authors = g_strdupv ((gchar **)authors);
1551 update_credits_button_visibility (about);
1553 g_object_notify (G_OBJECT (about), "authors");
1557 * gtk_about_dialog_get_documenters:
1558 * @about: a #GtkAboutDialog
1560 * Returns the string which are displayed in the documenters
1561 * tab of the secondary credits dialog.
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.
1569 const gchar * const *
1570 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1572 GtkAboutDialogPrivate *priv;
1574 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1578 return (const gchar * const *)priv->documenters;
1582 * gtk_about_dialog_set_documenters:
1583 * @about: a #GtkAboutDialog
1584 * @documenters: (array zero-terminated=1): a %NULL-terminated array of strings
1586 * Sets the strings which are displayed in the documenters tab
1587 * of the secondary credits dialog.
1592 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1593 const gchar **documenters)
1595 GtkAboutDialogPrivate *priv;
1598 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1602 tmp = priv->documenters;
1603 priv->documenters = g_strdupv ((gchar **)documenters);
1606 update_credits_button_visibility (about);
1608 g_object_notify (G_OBJECT (about), "documenters");
1612 * gtk_about_dialog_get_artists:
1613 * @about: a #GtkAboutDialog
1615 * Returns the string which are displayed in the artists tab
1616 * of the secondary credits dialog.
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.
1624 const gchar * const *
1625 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1627 GtkAboutDialogPrivate *priv;
1629 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1633 return (const gchar * const *)priv->artists;
1637 * gtk_about_dialog_set_artists:
1638 * @about: a #GtkAboutDialog
1639 * @artists: (array zero-terminated=1): a %NULL-terminated array of strings
1641 * Sets the strings which are displayed in the artists tab
1642 * of the secondary credits dialog.
1647 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1648 const gchar **artists)
1650 GtkAboutDialogPrivate *priv;
1653 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1657 tmp = priv->artists;
1658 priv->artists = g_strdupv ((gchar **)artists);
1661 update_credits_button_visibility (about);
1663 g_object_notify (G_OBJECT (about), "artists");
1667 * gtk_about_dialog_get_translator_credits:
1668 * @about: a #GtkAboutDialog
1670 * Returns the translator credits string which is displayed
1671 * in the translators tab of the secondary credits dialog.
1673 * Return value: The translator credits string. The string is
1674 * owned by the about dialog and must not be modified.
1679 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1681 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1683 return about->priv->translator_credits;
1687 * gtk_about_dialog_set_translator_credits:
1688 * @about: a #GtkAboutDialog
1689 * @translator_credits: (allow-none): the translator credits
1691 * Sets the translator credits string which is displayed in
1692 * the translators tab of the secondary credits dialog.
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:
1699 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
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
1709 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1710 const gchar *translator_credits)
1712 GtkAboutDialogPrivate *priv;
1715 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1719 tmp = priv->translator_credits;
1720 priv->translator_credits = g_strdup (translator_credits);
1723 update_credits_button_visibility (about);
1725 g_object_notify (G_OBJECT (about), "translator-credits");
1729 * gtk_about_dialog_get_logo:
1730 * @about: a #GtkAboutDialog
1732 * Returns the pixbuf displayed as logo in the about dialog.
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.
1741 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1743 GtkAboutDialogPrivate *priv;
1745 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
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));
1756 icon_set_new_from_pixbufs (GList *pixbufs)
1758 GtkIconSet *icon_set = gtk_icon_set_new ();
1760 for (; pixbufs; pixbufs = pixbufs->next)
1762 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
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);
1774 * gtk_about_dialog_set_logo:
1775 * @about: a #GtkAboutDialog
1776 * @logo: (allow-none): a #GdkPixbuf, or %NULL
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.
1785 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1788 GtkAboutDialogPrivate *priv;
1790 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1794 g_object_freeze_notify (G_OBJECT (about));
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");
1800 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1803 GList *pixbufs = gtk_window_get_default_icon_list ();
1805 if (pixbufs != NULL)
1807 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1809 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1810 icon_set, GTK_ICON_SIZE_DIALOG);
1812 gtk_icon_set_unref (icon_set);
1813 g_list_free (pixbufs);
1817 g_object_notify (G_OBJECT (about), "logo");
1819 g_object_thaw_notify (G_OBJECT (about));
1823 * gtk_about_dialog_get_logo_icon_name:
1824 * @about: a #GtkAboutDialog
1826 * Returns the icon name displayed as logo in the about dialog.
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.
1835 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1837 GtkAboutDialogPrivate *priv;
1838 const gchar *icon_name = NULL;
1840 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
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);
1851 * gtk_about_dialog_set_logo_icon_name:
1852 * @about: a #GtkAboutDialog
1853 * @icon_name: (allow-none): an icon name, or %NULL
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.
1862 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1863 const gchar *icon_name)
1865 GtkAboutDialogPrivate *priv;
1867 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1871 g_object_freeze_notify (G_OBJECT (about));
1873 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1874 g_object_notify (G_OBJECT (about), "logo");
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");
1880 g_object_thaw_notify (G_OBJECT (about));
1884 follow_if_link (GtkAboutDialog *about,
1885 GtkTextView *text_view,
1888 GSList *tags = NULL, *tagp = NULL;
1889 GtkAboutDialogPrivate *priv = about->priv;
1892 tags = gtk_text_iter_get_tags (iter);
1893 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1895 GtkTextTag *tag = tagp->data;
1897 uri = g_object_get_data (G_OBJECT (tag), "uri");
1899 emit_activate_link (about, uri);
1901 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1903 GdkColor *style_visited_link_color;
1906 gtk_widget_style_get (GTK_WIDGET (about),
1907 "visited-link-color", &style_visited_link_color,
1909 if (style_visited_link_color)
1911 color = *style_visited_link_color;
1912 gdk_color_free (style_visited_link_color);
1915 color = default_visited_link_color;
1917 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1919 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1924 g_slist_free (tags);
1928 text_view_key_press_event (GtkWidget *text_view,
1930 GtkAboutDialog *about)
1933 GtkTextBuffer *buffer;
1935 switch (event->keyval)
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);
1954 text_view_event_after (GtkWidget *text_view,
1956 GtkAboutDialog *about)
1958 GtkTextIter start, end, iter;
1959 GtkTextBuffer *buffer;
1960 GdkEventButton *button_event;
1963 if (event->type != GDK_BUTTON_RELEASE)
1966 button_event = (GdkEventButton *)event;
1968 if (button_event->button != GDK_BUTTON_PRIMARY)
1971 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
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))
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);
1982 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1984 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1990 set_cursor_if_appropriate (GtkAboutDialog *about,
1991 GtkTextView *text_view,
1996 GtkAboutDialogPrivate *priv = about->priv;
1997 GSList *tags = NULL, *tagp = NULL;
1999 gboolean hovering_over_link = FALSE;
2001 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
2003 tags = gtk_text_iter_get_tags (&iter);
2004 for (tagp = tags; tagp != NULL; tagp = tagp->next)
2006 GtkTextTag *tag = tagp->data;
2007 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
2011 hovering_over_link = TRUE;
2016 if (hovering_over_link != priv->hovering_over_link)
2018 priv->hovering_over_link = hovering_over_link;
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);
2023 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
2027 g_slist_free (tags);
2031 text_view_motion_notify_event (GtkWidget *text_view,
2032 GdkEventMotion *event,
2033 GtkAboutDialog *about)
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);
2041 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
2043 gdk_event_request_motions (event);
2050 text_view_visibility_notify_event (GtkWidget *text_view,
2051 GdkEventVisibility *event,
2052 GtkAboutDialog *about)
2054 GdkDeviceManager *device_manager;
2055 GdkDisplay *display;
2057 gint wx, wy, bx, by;
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);
2063 for (d = devices; d; d = d->next)
2065 GdkDevice *dev = d->data;
2067 if (gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD)
2070 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
2073 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2074 GTK_TEXT_WINDOW_WIDGET,
2077 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
2080 g_list_free (devices);
2086 text_view_new (GtkAboutDialog *about,
2088 GtkWrapMode wrap_mode)
2091 gchar *q0, *q1, *q2, *r1, *r2;
2093 GtkTextView *text_view;
2094 GtkTextBuffer *buffer;
2095 GdkColor *style_link_color;
2096 GdkColor *style_visited_link_color;
2098 GdkColor link_color;
2099 GdkColor visited_link_color;
2101 PangoFontDescription *font_desc;
2102 GtkAboutDialogPrivate *priv = about->priv;
2103 GtkStyleContext *context;
2104 GtkStateFlags state;
2106 gtk_widget_style_get (GTK_WIDGET (about),
2107 "link-color", &style_link_color,
2108 "visited-link-color", &style_visited_link_color,
2110 if (style_link_color)
2112 link_color = *style_link_color;
2113 gdk_color_free (style_link_color);
2116 link_color = default_link_color;
2118 if (style_visited_link_color)
2120 visited_link_color = *style_visited_link_color;
2121 gdk_color_free (style_visited_link_color);
2124 visited_link_color = default_visited_link_color;
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);
2133 context = gtk_widget_get_style_context (view);
2134 state = gtk_widget_get_state_flags (view);
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);
2142 gtk_text_view_set_left_margin (text_view, 8);
2143 gtk_text_view_set_right_margin (text_view, 8);
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);
2154 if (strings == NULL)
2156 gtk_widget_hide (view);
2160 for (p = strings; *p; p++)
2165 q1 = strchr (q0, '<');
2166 q2 = q1 ? strchr (q1, '>') : NULL;
2167 r1 = strstr (q0, "http://");
2170 r2 = strpbrk (r1, " \n\t");
2172 r2 = strchr (r1, '\0');
2177 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2188 const gchar *link_type;
2193 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0 + 1);
2194 gtk_text_buffer_get_end_iter (buffer, &end);
2196 link_type = "email";
2200 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2201 gtk_text_buffer_get_end_iter (buffer, &end);
2207 link = g_strndup (q1, q2 - q1);
2209 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2210 color = visited_link_color;
2214 tag = gtk_text_buffer_create_tag (buffer, NULL,
2215 "foreground-gdk", &color,
2216 "underline", PANGO_UNDERLINE_SINGLE,
2218 if (strcmp (link_type, "email") == 0)
2222 escaped = g_uri_escape_string (link, NULL, FALSE);
2223 uri = g_strconcat ("mailto:", escaped, NULL);
2228 uri = g_strdup (link);
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);
2237 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2243 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2246 gtk_widget_show (view);
2251 add_credits_section (GtkAboutDialog *about,
2260 gchar *q0, *q1, *q2, *r1, *r2;
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);
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);
2273 for (p = people; *p; p++)
2277 str = g_string_new ("<span size=\"small\">");
2282 q1 = strchr (q0, '<');
2283 q2 = q1 ? strchr (q1, '>') : NULL;
2284 r1 = strstr (q0, "http://");
2287 r2 = strpbrk (r1, " \n\t");
2289 r2 = strchr (r1, '\0');
2294 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2299 else if (q1 && (q1[1] == 'a' || q1[1] == 'A') && q1[2] == ' ')
2301 /* if it is a <a> link leave it for the label to parse */
2316 text = g_strstrip (g_strndup (q0, q1 - q0));
2317 name = g_markup_escape_text (text, -1);
2319 link = g_strndup (q1, q2 - q1);
2321 escaped = g_uri_escape_string (link, NULL, FALSE);
2322 g_string_append_printf (str,
2323 "<a href=\"mailto:%s\">%s</a>",
2325 name[0] ? name : link);
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>",
2340 name[0] ? name : link);
2350 g_string_append (str, q0);
2354 g_string_append (str, "</span>");
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);
2365 /* skip one at the end */
2370 create_credits_page (GtkAboutDialog *about)
2372 GtkAboutDialogPrivate *priv = about->priv;
2373 GtkWidget *page_vbox;
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);
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),
2386 GTK_POLICY_AUTOMATIC);
2387 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
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);
2398 if (priv->authors != NULL)
2399 add_credits_section (about, GTK_GRID (grid), &row, _("Created by"), priv->authors);
2401 if (priv->documenters != NULL)
2402 add_credits_section (about, GTK_GRID (grid), &row, _("Documented by"), priv->documenters);
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)
2409 gchar **translators;
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);
2416 if (priv->artists != NULL)
2417 add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
2419 if (priv->credit_sections != NULL)
2422 for (cs = priv->credit_sections; cs != NULL; cs = cs->next)
2424 CreditSection *section = cs->data;
2425 add_credits_section (about, GTK_GRID (grid), &row, section->heading, section->people);
2429 gtk_widget_show_all (sw);
2433 display_credits_page (GtkWidget *button,
2436 GtkAboutDialog *about = (GtkAboutDialog *)data;
2437 GtkAboutDialogPrivate *priv = about->priv;
2439 if (priv->credits_page == 0)
2440 create_credits_page (about);
2442 switch_page (about, priv->credits_page);
2446 create_license_page (GtkAboutDialog *about)
2448 GtkAboutDialogPrivate *priv = about->priv;
2449 GtkWidget *page_vbox;
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);
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);
2464 strings[0] = priv->license;
2466 view = text_view_new (about, strings,
2467 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2469 gtk_container_add (GTK_CONTAINER (sw), view);
2471 gtk_widget_show_all (page_vbox);
2475 display_license_page (GtkWidget *button,
2478 GtkAboutDialog *about = (GtkAboutDialog *)data;
2479 GtkAboutDialogPrivate *priv = about->priv;
2481 if (priv->license_page == 0)
2482 create_license_page (about);
2484 switch_page (about, priv->license_page);
2488 * gtk_about_dialog_new:
2490 * Creates a new #GtkAboutDialog.
2492 * Returns: a newly created #GtkAboutDialog
2497 gtk_about_dialog_new (void)
2499 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2501 return GTK_WIDGET (dialog);
2505 close_cb (GtkAboutDialog *about)
2507 GtkAboutDialogPrivate *priv = about->priv;
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));
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
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.
2528 gtk_show_about_dialog (GtkWindow *parent,
2529 const gchar *first_property_name,
2532 static GtkWidget *global_about_dialog = NULL;
2533 GtkWidget *dialog = NULL;
2537 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2539 dialog = global_about_dialog;
2543 dialog = gtk_about_dialog_new ();
2545 g_object_ref_sink (dialog);
2547 g_signal_connect (dialog, "delete-event",
2548 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2550 /* Close dialog on user response */
2551 g_signal_connect (dialog, "response",
2552 G_CALLBACK (close_cb), NULL);
2554 va_start (var_args, first_property_name);
2555 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
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);
2568 global_about_dialog = dialog;
2572 gtk_window_present (GTK_WINDOW (dialog));
2576 * gtk_about_dialog_set_license_type:
2577 * @about: a #GtkAboutDialog
2578 * @license_type: the type of license
2580 * Sets the license of the application showing the @about dialog from a
2581 * list of known licenses.
2583 * This function overrides the license set using
2584 * gtk_about_dialog_set_license().
2589 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2590 GtkLicense license_type)
2592 GtkAboutDialogPrivate *priv;
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);
2600 if (priv->license_type != license_type)
2602 g_object_freeze_notify (G_OBJECT (about));
2604 priv->license_type = license_type;
2606 /* custom licenses use the contents of the :license property */
2607 if (priv->license_type != GTK_LICENSE_CUSTOM)
2610 gchar *license_string;
2613 url = gtk_license_urls[priv->license_type];
2615 url = priv->website_url;
2617 str = g_string_sized_new (256);
2618 g_string_append_printf (str, _(gtk_license_preamble), url, url);
2620 g_free (priv->license);
2621 priv->license = g_string_free (str, FALSE);
2622 priv->wrap_license = TRUE;
2624 license_string = g_strdup_printf ("<span size=\"small\">%s</span>",
2626 gtk_label_set_markup (GTK_LABEL (priv->license_label), license_string);
2627 g_free (license_string);
2628 gtk_widget_show (priv->license_label);
2630 update_license_button_visibility (about);
2632 g_object_notify (G_OBJECT (about), "wrap-license");
2633 g_object_notify (G_OBJECT (about), "license");
2637 gtk_widget_show (priv->license_label);
2640 g_object_notify (G_OBJECT (about), "license-type");
2642 g_object_thaw_notify (G_OBJECT (about));
2647 * gtk_about_dialog_get_license_type:
2648 * @about: a #GtkAboutDialog
2650 * Retrieves the license set using gtk_about_dialog_set_license_type()
2652 * Return value: a #GtkLicense value
2657 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2659 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2661 return about->priv->license_type;
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
2670 * Creates a new section in the Credits page.
2675 gtk_about_dialog_add_credit_section (GtkAboutDialog *about,
2676 const gchar *section_name,
2677 const gchar **people)
2679 GtkAboutDialogPrivate *priv;
2680 CreditSection *new_entry;
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);
2688 new_entry = g_slice_new (CreditSection);
2689 new_entry->heading = g_strdup ((gchar *)section_name);
2690 new_entry->people = g_strdupv ((gchar **)people);
2692 priv->credit_sections = g_slist_append (priv->credit_sections, new_entry);
2693 update_credits_button_visibility (about);