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"
52 #include "gtkmainprivate.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"
125 struct _GtkAboutDialogPrivate
133 gchar *translator_credits;
144 GtkWidget *logo_image;
145 GtkWidget *name_label;
146 GtkWidget *version_label;
147 GtkWidget *comments_label;
148 GtkWidget *copyright_label;
149 GtkWidget *license_label;
150 GtkWidget *website_label;
152 GtkWidget *credits_button;
153 GtkWidget *license_button;
155 GdkCursor *hand_cursor;
156 GdkCursor *regular_cursor;
158 GSList *visited_links;
160 GtkLicense license_type;
162 guint hovering_over_link : 1;
163 guint wrap_license : 1;
166 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
181 PROP_TRANSLATOR_CREDITS,
189 static void gtk_about_dialog_finalize (GObject *object);
190 static void gtk_about_dialog_get_property (GObject *object,
194 static void gtk_about_dialog_set_property (GObject *object,
198 static void gtk_about_dialog_show (GtkWidget *widge);
199 static void update_name_version (GtkAboutDialog *about);
200 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
201 static void follow_if_link (GtkAboutDialog *about,
202 GtkTextView *text_view,
204 static void set_cursor_if_appropriate (GtkAboutDialog *about,
205 GtkTextView *text_view,
209 static void display_credits_page (GtkWidget *button,
211 static void display_license_page (GtkWidget *button,
213 static void close_cb (GtkAboutDialog *about);
214 static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
222 static guint signals[LAST_SIGNAL] = { 0 };
224 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
228 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
230 GObjectClass *object_class;
231 GtkWidgetClass *widget_class;
233 object_class = (GObjectClass *)klass;
234 widget_class = (GtkWidgetClass *)klass;
236 object_class->set_property = gtk_about_dialog_set_property;
237 object_class->get_property = gtk_about_dialog_get_property;
239 object_class->finalize = gtk_about_dialog_finalize;
241 widget_class->show = gtk_about_dialog_show;
243 klass->activate_link = gtk_about_dialog_activate_link;
246 * GtkAboutDialog::activate-link:
247 * @label: The object on which the signal was emitted
248 * @uri: the URI that is activated
250 * The signal which gets emitted to activate a URI.
251 * Applications may connect to it to override the default behaviour,
252 * which is to call gtk_show_uri().
254 * Returns: %TRUE if the link has been activated
258 signals[ACTIVATE_LINK] =
259 g_signal_new ("activate-link",
260 G_TYPE_FROM_CLASS (object_class),
262 G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
263 _gtk_boolean_handled_accumulator, NULL,
264 _gtk_marshal_BOOLEAN__STRING,
265 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
268 * GtkAboutDialog:program-name:
270 * The name of the program.
271 * If this is not set, it defaults to g_get_application_name().
275 g_object_class_install_property (object_class,
277 g_param_spec_string ("program-name",
279 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
281 GTK_PARAM_READWRITE));
284 * GtkAboutDialog:version:
286 * The version of the program.
290 g_object_class_install_property (object_class,
292 g_param_spec_string ("version",
293 P_("Program version"),
294 P_("The version of the program"),
296 GTK_PARAM_READWRITE));
299 * GtkAboutDialog:copyright:
301 * Copyright information for the program.
305 g_object_class_install_property (object_class,
307 g_param_spec_string ("copyright",
308 P_("Copyright string"),
309 P_("Copyright information for the program"),
311 GTK_PARAM_READWRITE));
315 * GtkAboutDialog:comments:
317 * Comments about the program. This string is displayed in a label
318 * in the main dialog, thus it should be a short explanation of
319 * the main purpose of the program, not a detailed list of features.
323 g_object_class_install_property (object_class,
325 g_param_spec_string ("comments",
326 P_("Comments string"),
327 P_("Comments about the program"),
329 GTK_PARAM_READWRITE));
332 * GtkAboutDialog:license:
334 * The license of the program. This string is displayed in a
335 * text view in a secondary dialog, therefore it is fine to use
336 * a long multi-paragraph text. Note that the text is only wrapped
337 * in the text view if the "wrap-license" property is set to %TRUE;
338 * otherwise the text itself must contain the intended linebreaks.
339 * When setting this property to a non-%NULL value, the
340 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
345 g_object_class_install_property (object_class,
347 g_param_spec_string ("license",
349 _("The license of the program"),
351 GTK_PARAM_READWRITE));
354 * GtkAboutDialog:license-type:
356 * The license of the program, as a value of the %GtkLicense enumeration.
358 * The #GtkAboutDialog will automatically fill out a standard disclaimer
359 * and link the user to the appropriate online resource for the license
362 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
363 * specified in the #GtkAboutDialog:website property.
365 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
366 * #GtkAboutDialog:license property are used.
368 * For any other #GtkLicense value, the contents of the
369 * #GtkAboutDialog:license property are also set by this property as
374 g_object_class_install_property (object_class,
376 g_param_spec_enum ("license-type",
378 P_("The license type of the program"),
381 GTK_PARAM_READWRITE));
384 * GtkAboutDialog:website:
386 * The URL for the link to the website of the program.
387 * This should be a string starting with "http://.
391 g_object_class_install_property (object_class,
393 g_param_spec_string ("website",
395 P_("The URL for the link to the website of the program"),
397 GTK_PARAM_READWRITE));
400 * GtkAboutDialog:website-label:
402 * The label for the link to the website of the program.
406 g_object_class_install_property (object_class,
408 g_param_spec_string ("website-label",
410 P_("The label for the link to the website of the program"),
412 GTK_PARAM_READWRITE));
415 * GtkAboutDialog:authors:
417 * The authors of the program, as a %NULL-terminated array of strings.
418 * Each string may contain email addresses and URLs, which will be displayed
419 * as links, see the introduction for more details.
423 g_object_class_install_property (object_class,
425 g_param_spec_boxed ("authors",
427 P_("List of authors of the program"),
429 GTK_PARAM_READWRITE));
432 * GtkAboutDialog:documenters:
434 * The people documenting the program, as a %NULL-terminated array of strings.
435 * Each string may contain email addresses and URLs, which will be displayed
436 * as links, see the introduction for more details.
440 g_object_class_install_property (object_class,
442 g_param_spec_boxed ("documenters",
444 P_("List of people documenting the program"),
446 GTK_PARAM_READWRITE));
449 * GtkAboutDialog:artists:
451 * The people who contributed artwork to the program, as a %NULL-terminated
452 * array of strings. Each string may contain email addresses and URLs, which
453 * will be displayed as links, see the introduction for more details.
457 g_object_class_install_property (object_class,
459 g_param_spec_boxed ("artists",
461 P_("List of people who have contributed artwork to the program"),
463 GTK_PARAM_READWRITE));
467 * GtkAboutDialog:translator-credits:
469 * Credits to the translators. This string should be marked as translatable.
470 * The string may contain email addresses and URLs, which will be displayed
471 * as links, see the introduction for more details.
475 g_object_class_install_property (object_class,
476 PROP_TRANSLATOR_CREDITS,
477 g_param_spec_string ("translator-credits",
478 P_("Translator credits"),
479 P_("Credits to the translators. This string should be marked as translatable"),
481 GTK_PARAM_READWRITE));
484 * GtkAboutDialog:logo:
486 * A logo for the about box. If this is not set, it defaults to
487 * gtk_window_get_default_icon_list().
491 g_object_class_install_property (object_class,
493 g_param_spec_object ("logo",
495 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
497 GTK_PARAM_READWRITE));
500 * GtkAboutDialog:logo-icon-name:
502 * A named icon to use as the logo for the about box. This property
503 * overrides the #GtkAboutDialog:logo property.
507 g_object_class_install_property (object_class,
509 g_param_spec_string ("logo-icon-name",
510 P_("Logo Icon Name"),
511 P_("A named icon to use as the logo for the about box."),
513 GTK_PARAM_READWRITE));
515 * GtkAboutDialog:wrap-license:
517 * Whether to wrap the text in the license dialog.
521 g_object_class_install_property (object_class,
523 g_param_spec_boolean ("wrap-license",
525 P_("Whether to wrap the license text."),
527 GTK_PARAM_READWRITE));
530 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
534 emit_activate_link (GtkAboutDialog *about,
537 gboolean handled = FALSE;
539 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
545 update_license_button_visibility (GtkAboutDialog *about)
547 GtkAboutDialogPrivate *priv = about->priv;
549 if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL)
550 gtk_widget_show (priv->license_button);
552 gtk_widget_hide (priv->license_button);
556 update_credits_button_visibility (GtkAboutDialog *about)
558 GtkAboutDialogPrivate *priv = about->priv;
561 show = (priv->authors != NULL ||
562 priv->documenters != NULL ||
563 priv->artists != NULL ||
564 (priv->translator_credits != NULL &&
565 strcmp (priv->translator_credits, "translator_credits") &&
566 strcmp (priv->translator_credits, "translator-credits")));
568 gtk_widget_show (priv->credits_button);
570 gtk_widget_hide (priv->credits_button);
574 switch_page (GtkAboutDialog *about,
577 GtkAboutDialogPrivate *priv = about->priv;
579 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page);
583 display_main_page (GtkButton *button,
586 GtkAboutDialog *about = (GtkAboutDialog *)data;
588 switch_page (about, 0);
592 credits_button_clicked (GtkButton *button,
595 GtkAboutDialog *about = (GtkAboutDialog *)data;
596 GtkAboutDialogPrivate *priv = about->priv;
599 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
603 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
604 display_credits_page (NULL, data);
608 display_main_page (NULL, data);
613 license_button_clicked (GtkButton *button,
616 GtkAboutDialog *about = (GtkAboutDialog *)data;
617 GtkAboutDialogPrivate *priv = about->priv;
620 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
624 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
625 display_license_page (NULL, data);
629 display_main_page (NULL, data);
633 gtk_about_dialog_init (GtkAboutDialog *about)
635 GtkDialog *dialog = GTK_DIALOG (about);
636 GtkAboutDialogPrivate *priv;
637 GtkWidget *vbox, *page_vbox, *hbox, *button, *close_button, *image;
638 GtkWidget *content_area, *action_area;
641 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
645 priv->version = NULL;
646 priv->copyright = NULL;
647 priv->comments = NULL;
648 priv->website_url = NULL;
649 priv->website_text = NULL;
650 priv->translator_credits = NULL;
651 priv->license = NULL;
652 priv->authors = NULL;
653 priv->documenters = NULL;
654 priv->artists = NULL;
656 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
657 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
658 priv->hovering_over_link = FALSE;
659 priv->wrap_license = FALSE;
661 priv->license_type = GTK_LICENSE_UNKNOWN;
663 content_area = gtk_dialog_get_content_area (dialog);
664 action_area = gtk_dialog_get_action_area (dialog);
666 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
667 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
668 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
671 gtk_widget_push_composite_child ();
673 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
674 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
675 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
677 priv->logo_image = gtk_image_new ();
678 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
680 priv->name_label = gtk_label_new (NULL);
681 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
682 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
683 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
685 priv->notebook = gtk_notebook_new ();
686 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
687 gtk_widget_set_size_request (priv->notebook, 400, 100);
689 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
690 gtk_widget_show (page_vbox);
691 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
692 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
693 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
695 priv->version_label = gtk_label_new (NULL);
696 gtk_label_set_selectable (GTK_LABEL (priv->version_label), TRUE);
697 gtk_label_set_justify (GTK_LABEL (priv->version_label), GTK_JUSTIFY_CENTER);
698 gtk_box_pack_start (GTK_BOX (page_vbox), priv->version_label, FALSE, FALSE, 0);
700 priv->comments_label = gtk_label_new (NULL);
701 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
702 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
703 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
704 gtk_box_pack_start (GTK_BOX (page_vbox), priv->comments_label, FALSE, FALSE, 0);
706 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
707 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
708 gtk_box_pack_start (GTK_BOX (page_vbox), hbox, FALSE, FALSE, 0);
710 priv->website_label = button = gtk_label_new ("");
711 gtk_widget_set_no_show_all (button, TRUE);
712 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
713 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
714 g_signal_connect_swapped (button, "activate-link",
715 G_CALLBACK (emit_activate_link), about);
717 priv->license_label = gtk_label_new (NULL);
718 gtk_label_set_use_markup (GTK_LABEL (priv->license_label), TRUE);
719 gtk_label_set_selectable (GTK_LABEL (priv->license_label), TRUE);
720 gtk_label_set_justify (GTK_LABEL (priv->license_label), GTK_JUSTIFY_CENTER);
721 gtk_box_pack_end (GTK_BOX (page_vbox), priv->license_label, FALSE, FALSE, 0);
722 gtk_label_set_line_wrap (GTK_LABEL (priv->license_label), TRUE);
724 priv->copyright_label = gtk_label_new (NULL);
725 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
726 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
727 gtk_box_pack_end (GTK_BOX (page_vbox), priv->copyright_label, FALSE, FALSE, 0);
729 gtk_widget_show (vbox);
730 gtk_widget_show (priv->notebook);
731 gtk_widget_show (priv->logo_image);
732 gtk_widget_show (priv->name_label);
733 gtk_widget_show (hbox);
735 /* Add the close button */
736 close_button = gtk_dialog_add_button (GTK_DIALOG (about),
737 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL);
738 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
740 /* Add the credits button */
741 button = gtk_toggle_button_new_with_mnemonic (_("C_redits"));
742 gtk_widget_set_can_default (button, TRUE);
743 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
744 gtk_button_set_image (GTK_BUTTON (button), image);
745 gtk_widget_set_no_show_all (button, TRUE);
746 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
747 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
748 g_signal_connect (button, "clicked",
749 G_CALLBACK (credits_button_clicked), about);
750 priv->credits_button = button;
751 priv->credits_page = 0;
753 /* Add the license button */
754 button = gtk_toggle_button_new_with_mnemonic (_("_License"));
755 gtk_widget_set_can_default (button, TRUE);
756 gtk_widget_set_no_show_all (button, TRUE);
757 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
758 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
759 g_signal_connect (button, "clicked",
760 G_CALLBACK (license_button_clicked), about);
761 priv->license_button = button;
762 priv->license_page = 0;
764 switch_page (about, 0);
766 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
768 gtk_widget_pop_composite_child ();
770 gtk_widget_grab_default (close_button);
771 gtk_widget_grab_focus (close_button);
774 gtk_about_dialog_set_program_name (about, NULL);
775 gtk_about_dialog_set_logo (about, NULL);
779 gtk_about_dialog_finalize (GObject *object)
781 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
782 GtkAboutDialogPrivate *priv = about->priv;
785 g_free (priv->version);
786 g_free (priv->copyright);
787 g_free (priv->comments);
788 g_free (priv->license);
789 g_free (priv->website_url);
790 g_free (priv->website_text);
791 g_free (priv->translator_credits);
793 g_strfreev (priv->authors);
794 g_strfreev (priv->documenters);
795 g_strfreev (priv->artists);
797 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
798 g_slist_free (priv->visited_links);
800 g_object_unref (priv->hand_cursor);
801 g_object_unref (priv->regular_cursor);
803 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
807 gtk_about_dialog_set_property (GObject *object,
812 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
813 GtkAboutDialogPrivate *priv = about->priv;
818 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
821 gtk_about_dialog_set_version (about, g_value_get_string (value));
824 gtk_about_dialog_set_comments (about, g_value_get_string (value));
827 gtk_about_dialog_set_website (about, g_value_get_string (value));
829 case PROP_WEBSITE_LABEL:
830 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
833 gtk_about_dialog_set_license (about, g_value_get_string (value));
835 case PROP_LICENSE_TYPE:
836 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
839 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
842 gtk_about_dialog_set_logo (about, g_value_get_object (value));
845 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
847 case PROP_DOCUMENTERS:
848 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
851 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
853 case PROP_TRANSLATOR_CREDITS:
854 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
856 case PROP_LOGO_ICON_NAME:
857 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
859 case PROP_WRAP_LICENSE:
860 priv->wrap_license = g_value_get_boolean (value);
863 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
869 gtk_about_dialog_get_property (GObject *object,
874 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
875 GtkAboutDialogPrivate *priv = about->priv;
880 g_value_set_string (value, priv->name);
883 g_value_set_string (value, priv->version);
886 g_value_set_string (value, priv->copyright);
889 g_value_set_string (value, priv->comments);
892 g_value_set_string (value, priv->website_url);
894 case PROP_WEBSITE_LABEL:
895 g_value_set_string (value, priv->website_text);
898 g_value_set_string (value, priv->license);
900 case PROP_LICENSE_TYPE:
901 g_value_set_enum (value, priv->license_type);
903 case PROP_TRANSLATOR_CREDITS:
904 g_value_set_string (value, priv->translator_credits);
907 g_value_set_boxed (value, priv->authors);
909 case PROP_DOCUMENTERS:
910 g_value_set_boxed (value, priv->documenters);
913 g_value_set_boxed (value, priv->artists);
916 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
917 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
919 g_value_set_object (value, NULL);
921 case PROP_LOGO_ICON_NAME:
922 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
924 const gchar *icon_name;
926 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
927 g_value_set_string (value, icon_name);
930 g_value_set_string (value, NULL);
932 case PROP_WRAP_LICENSE:
933 g_value_set_boolean (value, priv->wrap_license);
936 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
942 gtk_about_dialog_activate_link (GtkAboutDialog *about,
946 GError *error = NULL;
948 screen = gtk_widget_get_screen (GTK_WIDGET (about));
950 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
954 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
955 GTK_DIALOG_DESTROY_WITH_PARENT |
959 "%s", _("Could not show link"));
960 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
961 "%s", error->message);
962 g_error_free (error);
964 g_signal_connect (dialog, "response",
965 G_CALLBACK (gtk_widget_destroy), NULL);
967 gtk_window_present (GTK_WINDOW (dialog));
974 update_website (GtkAboutDialog *about)
976 GtkAboutDialogPrivate *priv = about->priv;
978 gtk_widget_show (priv->website_label);
980 if (priv->website_url)
984 if (priv->website_text)
988 escaped = g_markup_escape_text (priv->website_text, -1);
989 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
990 priv->website_url, escaped);
995 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
996 priv->website_url, _("Homepage"));
999 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
1004 if (priv->website_text)
1005 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
1007 gtk_widget_hide (priv->website_label);
1012 gtk_about_dialog_show (GtkWidget *widget)
1014 update_website (GTK_ABOUT_DIALOG (widget));
1016 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
1020 * gtk_about_dialog_get_program_name:
1021 * @about: a #GtkAboutDialog
1023 * Returns the program name displayed in the about dialog.
1025 * Return value: The program name. The string is owned by the about
1026 * dialog and must not be modified.
1031 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
1033 GtkAboutDialogPrivate *priv;
1035 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1043 update_name_version (GtkAboutDialog *about)
1045 GtkAboutDialogPrivate *priv;
1046 gchar *title_string, *name_string;
1050 title_string = g_strdup_printf (_("About %s"), priv->name);
1051 gtk_window_set_title (GTK_WINDOW (about), title_string);
1052 g_free (title_string);
1054 if (priv->version != NULL)
1056 gtk_label_set_markup (GTK_LABEL (priv->version_label), priv->version);
1057 gtk_widget_show (priv->version_label);
1060 gtk_widget_hide (priv->version_label);
1062 name_string = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
1064 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
1065 g_free (name_string);
1069 * gtk_about_dialog_set_program_name:
1070 * @about: a #GtkAboutDialog
1071 * @name: the program name
1073 * Sets the name to display in the about dialog.
1074 * If this is not set, it defaults to g_get_application_name().
1079 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
1082 GtkAboutDialogPrivate *priv;
1085 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1090 priv->name = g_strdup (name ? name : g_get_application_name ());
1093 update_name_version (about);
1095 g_object_notify (G_OBJECT (about), "program-name");
1100 * gtk_about_dialog_get_version:
1101 * @about: a #GtkAboutDialog
1103 * Returns the version string.
1105 * Return value: The version string. The string is owned by the about
1106 * dialog and must not be modified.
1111 gtk_about_dialog_get_version (GtkAboutDialog *about)
1113 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1115 return about->priv->version;
1119 * gtk_about_dialog_set_version:
1120 * @about: a #GtkAboutDialog
1121 * @version: (allow-none): the version string
1123 * Sets the version string to display in the about dialog.
1128 gtk_about_dialog_set_version (GtkAboutDialog *about,
1129 const gchar *version)
1131 GtkAboutDialogPrivate *priv;
1134 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1138 tmp = priv->version;
1139 priv->version = g_strdup (version);
1142 update_name_version (about);
1144 g_object_notify (G_OBJECT (about), "version");
1148 * gtk_about_dialog_get_copyright:
1149 * @about: a #GtkAboutDialog
1151 * Returns the copyright string.
1153 * Return value: The copyright string. The string is owned by the about
1154 * dialog and must not be modified.
1159 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1161 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1163 return about->priv->copyright;
1167 * gtk_about_dialog_set_copyright:
1168 * @about: a #GtkAboutDialog
1169 * @copyright: (allow-none) the copyright string
1171 * Sets the copyright string to display in the about dialog.
1172 * This should be a short string of one or two lines.
1177 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1178 const gchar *copyright)
1180 GtkAboutDialogPrivate *priv;
1181 gchar *copyright_string, *tmp;
1183 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1187 tmp = priv->copyright;
1188 priv->copyright = g_strdup (copyright);
1191 if (priv->copyright != NULL)
1193 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1195 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1196 g_free (copyright_string);
1198 gtk_widget_show (priv->copyright_label);
1201 gtk_widget_hide (priv->copyright_label);
1203 g_object_notify (G_OBJECT (about), "copyright");
1207 * gtk_about_dialog_get_comments:
1208 * @about: a #GtkAboutDialog
1210 * Returns the comments string.
1212 * Return value: The comments. The string is owned by the about
1213 * dialog and must not be modified.
1218 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1220 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1222 return about->priv->comments;
1226 * gtk_about_dialog_set_comments:
1227 * @about: a #GtkAboutDialog
1228 * @comments: (allow-none): a comments string
1230 * Sets the comments string to display in the about dialog.
1231 * This should be a short string of one or two lines.
1236 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1237 const gchar *comments)
1239 GtkAboutDialogPrivate *priv;
1242 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1246 tmp = priv->comments;
1249 priv->comments = g_strdup (comments);
1250 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1251 gtk_widget_show (priv->comments_label);
1255 priv->comments = NULL;
1256 gtk_widget_hide (priv->comments_label);
1260 g_object_notify (G_OBJECT (about), "comments");
1264 * gtk_about_dialog_get_license:
1265 * @about: a #GtkAboutDialog
1267 * Returns the license information.
1269 * Return value: The license information. The string is owned by the about
1270 * dialog and must not be modified.
1275 gtk_about_dialog_get_license (GtkAboutDialog *about)
1277 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1279 return about->priv->license;
1283 * gtk_about_dialog_set_license:
1284 * @about: a #GtkAboutDialog
1285 * @license: (allow-none): the license information or %NULL
1287 * Sets the license information to be displayed in the secondary
1288 * license dialog. If @license is %NULL, the license button is
1294 gtk_about_dialog_set_license (GtkAboutDialog *about,
1295 const gchar *license)
1297 GtkAboutDialogPrivate *priv;
1300 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1304 tmp = priv->license;
1307 priv->license = g_strdup (license);
1308 priv->license_type = GTK_LICENSE_CUSTOM;
1312 priv->license = NULL;
1313 priv->license_type = GTK_LICENSE_UNKNOWN;
1317 gtk_widget_hide (priv->license_label);
1319 update_license_button_visibility (about);
1321 g_object_notify (G_OBJECT (about), "license");
1322 g_object_notify (G_OBJECT (about), "license-type");
1326 * gtk_about_dialog_get_wrap_license:
1327 * @about: a #GtkAboutDialog
1329 * Returns whether the license text in @about is
1330 * automatically wrapped.
1332 * Returns: %TRUE if the license text is wrapped
1337 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1339 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1341 return about->priv->wrap_license;
1345 * gtk_about_dialog_set_wrap_license:
1346 * @about: a #GtkAboutDialog
1347 * @wrap_license: whether to wrap the license
1349 * Sets whether the license text in @about is
1350 * automatically wrapped.
1355 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1356 gboolean wrap_license)
1358 GtkAboutDialogPrivate *priv;
1360 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1364 wrap_license = wrap_license != FALSE;
1366 if (priv->wrap_license != wrap_license)
1368 priv->wrap_license = wrap_license;
1370 g_object_notify (G_OBJECT (about), "wrap-license");
1375 * gtk_about_dialog_get_website:
1376 * @about: a #GtkAboutDialog
1378 * Returns the website URL.
1380 * Return value: The website URL. The string is owned by the about
1381 * dialog and must not be modified.
1386 gtk_about_dialog_get_website (GtkAboutDialog *about)
1388 GtkAboutDialogPrivate *priv;
1390 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1394 return priv->website_url;
1398 * gtk_about_dialog_set_website:
1399 * @about: a #GtkAboutDialog
1400 * @website: (allow-none): a URL string starting with "http://"
1402 * Sets the URL to use for the website link.
1407 gtk_about_dialog_set_website (GtkAboutDialog *about,
1408 const gchar *website)
1410 GtkAboutDialogPrivate *priv;
1413 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1417 tmp = priv->website_url;
1418 priv->website_url = g_strdup (website);
1421 update_website (about);
1423 g_object_notify (G_OBJECT (about), "website");
1427 * gtk_about_dialog_get_website_label:
1428 * @about: a #GtkAboutDialog
1430 * Returns the label used for the website link.
1432 * Return value: The label used for the website link. The string is
1433 * owned by the about dialog and must not be modified.
1438 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1440 GtkAboutDialogPrivate *priv;
1442 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1446 return priv->website_text;
1450 * gtk_about_dialog_set_website_label:
1451 * @about: a #GtkAboutDialog
1452 * @website_label: the label used for the website link
1454 * Sets the label to be used for the website link.
1459 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1460 const gchar *website_label)
1462 GtkAboutDialogPrivate *priv;
1465 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1469 tmp = priv->website_text;
1470 priv->website_text = g_strdup (website_label);
1473 update_website (about);
1475 g_object_notify (G_OBJECT (about), "website-label");
1479 * gtk_about_dialog_get_authors:
1480 * @about: a #GtkAboutDialog
1482 * Returns the string which are displayed in the authors tab
1483 * of the secondary credits dialog.
1485 * Return value: (array zero-terminated=1) (transfer none): A
1486 * %NULL-terminated string array containing the authors. The array is
1487 * owned by the about dialog and must not be modified.
1491 const gchar * const *
1492 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1494 GtkAboutDialogPrivate *priv;
1496 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1500 return (const gchar * const *) priv->authors;
1504 * gtk_about_dialog_set_authors:
1505 * @about: a #GtkAboutDialog
1506 * @authors: (array zero-terminated=1): a %NULL-terminated array of strings
1508 * Sets the strings which are displayed in the authors tab
1509 * of the secondary credits dialog.
1514 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1515 const gchar **authors)
1517 GtkAboutDialogPrivate *priv;
1520 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1524 tmp = priv->authors;
1525 priv->authors = g_strdupv ((gchar **)authors);
1528 update_credits_button_visibility (about);
1530 g_object_notify (G_OBJECT (about), "authors");
1534 * gtk_about_dialog_get_documenters:
1535 * @about: a #GtkAboutDialog
1537 * Returns the string which are displayed in the documenters
1538 * tab of the secondary credits dialog.
1540 * Return value: (array zero-terminated=1) (transfer none): A
1541 * %NULL-terminated string array containing the documenters. The
1542 * array is owned by the about dialog and must not be modified.
1546 const gchar * const *
1547 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1549 GtkAboutDialogPrivate *priv;
1551 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1555 return (const gchar * const *)priv->documenters;
1559 * gtk_about_dialog_set_documenters:
1560 * @about: a #GtkAboutDialog
1561 * @documenters: (array zero-terminated=1): a %NULL-terminated array of strings
1563 * Sets the strings which are displayed in the documenters tab
1564 * of the secondary credits dialog.
1569 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1570 const gchar **documenters)
1572 GtkAboutDialogPrivate *priv;
1575 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1579 tmp = priv->documenters;
1580 priv->documenters = g_strdupv ((gchar **)documenters);
1583 update_credits_button_visibility (about);
1585 g_object_notify (G_OBJECT (about), "documenters");
1589 * gtk_about_dialog_get_artists:
1590 * @about: a #GtkAboutDialog
1592 * Returns the string which are displayed in the artists tab
1593 * of the secondary credits dialog.
1595 * Return value: (array zero-terminated=1) (transfer none): A
1596 * %NULL-terminated string array containing the artists. The array is
1597 * owned by the about dialog and must not be modified.
1601 const gchar * const *
1602 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1604 GtkAboutDialogPrivate *priv;
1606 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1610 return (const gchar * const *)priv->artists;
1614 * gtk_about_dialog_set_artists:
1615 * @about: a #GtkAboutDialog
1616 * @artists: (array zero-terminated=1): a %NULL-terminated array of strings
1618 * Sets the strings which are displayed in the artists tab
1619 * of the secondary credits dialog.
1624 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1625 const gchar **artists)
1627 GtkAboutDialogPrivate *priv;
1630 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1634 tmp = priv->artists;
1635 priv->artists = g_strdupv ((gchar **)artists);
1638 update_credits_button_visibility (about);
1640 g_object_notify (G_OBJECT (about), "artists");
1644 * gtk_about_dialog_get_translator_credits:
1645 * @about: a #GtkAboutDialog
1647 * Returns the translator credits string which is displayed
1648 * in the translators tab of the secondary credits dialog.
1650 * Return value: The translator credits string. The string is
1651 * owned by the about dialog and must not be modified.
1656 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1658 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1660 return about->priv->translator_credits;
1664 * gtk_about_dialog_set_translator_credits:
1665 * @about: a #GtkAboutDialog
1666 * @translator_credits: (allow-none): the translator credits
1668 * Sets the translator credits string which is displayed in
1669 * the translators tab of the secondary credits dialog.
1671 * The intended use for this string is to display the translator
1672 * of the language which is currently used in the user interface.
1673 * Using gettext(), a simple way to achieve that is to mark the
1674 * string for translation:
1676 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1678 * It is a good idea to use the customary msgid "translator-credits" for this
1679 * purpose, since translators will already know the purpose of that msgid, and
1680 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1686 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1687 const gchar *translator_credits)
1689 GtkAboutDialogPrivate *priv;
1692 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1696 tmp = priv->translator_credits;
1697 priv->translator_credits = g_strdup (translator_credits);
1700 update_credits_button_visibility (about);
1702 g_object_notify (G_OBJECT (about), "translator-credits");
1706 * gtk_about_dialog_get_logo:
1707 * @about: a #GtkAboutDialog
1709 * Returns the pixbuf displayed as logo in the about dialog.
1711 * Return value: (transfer none): the pixbuf displayed as logo. The
1712 * pixbuf is owned by the about dialog. If you want to keep a
1713 * reference to it, you have to call g_object_ref() on it.
1718 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1720 GtkAboutDialogPrivate *priv;
1722 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1726 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1727 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1733 icon_set_new_from_pixbufs (GList *pixbufs)
1735 GtkIconSet *icon_set = gtk_icon_set_new ();
1737 for (; pixbufs; pixbufs = pixbufs->next)
1739 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1741 GtkIconSource *icon_source = gtk_icon_source_new ();
1742 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1743 gtk_icon_set_add_source (icon_set, icon_source);
1744 gtk_icon_source_free (icon_source);
1751 * gtk_about_dialog_set_logo:
1752 * @about: a #GtkAboutDialog
1753 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1755 * Sets the pixbuf to be displayed as logo in the about dialog.
1756 * If it is %NULL, the default window icon set with
1757 * gtk_window_set_default_icon() will be used.
1762 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1765 GtkAboutDialogPrivate *priv;
1767 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1771 g_object_freeze_notify (G_OBJECT (about));
1773 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1774 g_object_notify (G_OBJECT (about), "logo-icon-name");
1777 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1780 GList *pixbufs = gtk_window_get_default_icon_list ();
1782 if (pixbufs != NULL)
1784 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1786 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1787 icon_set, GTK_ICON_SIZE_DIALOG);
1789 gtk_icon_set_unref (icon_set);
1790 g_list_free (pixbufs);
1794 g_object_notify (G_OBJECT (about), "logo");
1796 g_object_thaw_notify (G_OBJECT (about));
1800 * gtk_about_dialog_get_logo_icon_name:
1801 * @about: a #GtkAboutDialog
1803 * Returns the icon name displayed as logo in the about dialog.
1805 * Return value: the icon name displayed as logo. The string is
1806 * owned by the dialog. If you want to keep a reference
1807 * to it, you have to call g_strdup() on it.
1812 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1814 GtkAboutDialogPrivate *priv;
1815 const gchar *icon_name = NULL;
1817 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1821 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1822 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1828 * gtk_about_dialog_set_logo_icon_name:
1829 * @about: a #GtkAboutDialog
1830 * @icon_name: (allow-none): an icon name, or %NULL
1832 * Sets the pixbuf to be displayed as logo in the about dialog.
1833 * If it is %NULL, the default window icon set with
1834 * gtk_window_set_default_icon() will be used.
1839 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1840 const gchar *icon_name)
1842 GtkAboutDialogPrivate *priv;
1844 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1848 g_object_freeze_notify (G_OBJECT (about));
1850 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1851 g_object_notify (G_OBJECT (about), "logo");
1853 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1854 GTK_ICON_SIZE_DIALOG);
1855 g_object_notify (G_OBJECT (about), "logo-icon-name");
1857 g_object_thaw_notify (G_OBJECT (about));
1861 follow_if_link (GtkAboutDialog *about,
1862 GtkTextView *text_view,
1865 GSList *tags = NULL, *tagp = NULL;
1866 GtkAboutDialogPrivate *priv = about->priv;
1869 tags = gtk_text_iter_get_tags (iter);
1870 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1872 GtkTextTag *tag = tagp->data;
1874 uri = g_object_get_data (G_OBJECT (tag), "uri");
1876 emit_activate_link (about, uri);
1878 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1880 GdkColor *style_visited_link_color;
1883 gtk_widget_style_get (GTK_WIDGET (about),
1884 "visited-link-color", &style_visited_link_color,
1886 if (style_visited_link_color)
1888 color = *style_visited_link_color;
1889 gdk_color_free (style_visited_link_color);
1892 color = default_visited_link_color;
1894 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1896 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1901 g_slist_free (tags);
1905 text_view_key_press_event (GtkWidget *text_view,
1907 GtkAboutDialog *about)
1910 GtkTextBuffer *buffer;
1912 switch (event->keyval)
1914 case GDK_KEY_Return:
1915 case GDK_KEY_ISO_Enter:
1916 case GDK_KEY_KP_Enter:
1917 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1918 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1919 gtk_text_buffer_get_insert (buffer));
1920 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1931 text_view_event_after (GtkWidget *text_view,
1933 GtkAboutDialog *about)
1935 GtkTextIter start, end, iter;
1936 GtkTextBuffer *buffer;
1937 GdkEventButton *button_event;
1940 if (event->type != GDK_BUTTON_RELEASE)
1943 button_event = (GdkEventButton *)event;
1945 if (button_event->button != 1)
1948 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1950 /* we shouldn't follow a link if the user has selected something */
1951 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1952 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1955 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1956 GTK_TEXT_WINDOW_WIDGET,
1957 button_event->x, button_event->y, &x, &y);
1959 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1961 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1967 set_cursor_if_appropriate (GtkAboutDialog *about,
1968 GtkTextView *text_view,
1973 GtkAboutDialogPrivate *priv = about->priv;
1974 GSList *tags = NULL, *tagp = NULL;
1976 gboolean hovering_over_link = FALSE;
1978 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1980 tags = gtk_text_iter_get_tags (&iter);
1981 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1983 GtkTextTag *tag = tagp->data;
1984 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1988 hovering_over_link = TRUE;
1993 if (hovering_over_link != priv->hovering_over_link)
1995 priv->hovering_over_link = hovering_over_link;
1997 if (hovering_over_link)
1998 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
2000 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
2004 g_slist_free (tags);
2008 text_view_motion_notify_event (GtkWidget *text_view,
2009 GdkEventMotion *event,
2010 GtkAboutDialog *about)
2014 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2015 GTK_TEXT_WINDOW_WIDGET,
2016 event->x, event->y, &x, &y);
2018 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
2020 gdk_event_request_motions (event);
2027 text_view_visibility_notify_event (GtkWidget *text_view,
2028 GdkEventVisibility *event,
2029 GtkAboutDialog *about)
2031 GdkDeviceManager *device_manager;
2032 GdkDisplay *display;
2034 gint wx, wy, bx, by;
2036 display = gdk_window_get_display (event->window);
2037 device_manager = gdk_display_get_device_manager (display);
2038 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2040 for (d = devices; d; d = d->next)
2042 GdkDevice *dev = d->data;
2044 if (gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD)
2047 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
2050 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2051 GTK_TEXT_WINDOW_WIDGET,
2054 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
2057 g_list_free (devices);
2063 text_view_new (GtkAboutDialog *about,
2065 GtkWrapMode wrap_mode)
2068 gchar *q0, *q1, *q2, *r1, *r2;
2070 GtkTextView *text_view;
2071 GtkTextBuffer *buffer;
2072 GdkColor *style_link_color;
2073 GdkColor *style_visited_link_color;
2075 GdkColor link_color;
2076 GdkColor visited_link_color;
2078 PangoFontDescription *font_desc;
2079 GtkAboutDialogPrivate *priv = about->priv;
2080 GtkStyleContext *context;
2081 GtkStateFlags state;
2083 gtk_widget_style_get (GTK_WIDGET (about),
2084 "link-color", &style_link_color,
2085 "visited-link-color", &style_visited_link_color,
2087 if (style_link_color)
2089 link_color = *style_link_color;
2090 gdk_color_free (style_link_color);
2093 link_color = default_link_color;
2095 if (style_visited_link_color)
2097 visited_link_color = *style_visited_link_color;
2098 gdk_color_free (style_visited_link_color);
2101 visited_link_color = default_visited_link_color;
2103 view = gtk_text_view_new ();
2104 text_view = GTK_TEXT_VIEW (view);
2105 buffer = gtk_text_view_get_buffer (text_view);
2106 gtk_text_view_set_cursor_visible (text_view, FALSE);
2107 gtk_text_view_set_editable (text_view, FALSE);
2108 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2110 context = gtk_widget_get_style_context (view);
2111 state = gtk_widget_get_state_flags (view);
2113 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
2114 font_desc = pango_font_description_new ();
2115 pango_font_description_set_size (font_desc, size * PANGO_SCALE_SMALL);
2116 gtk_widget_modify_font (view, font_desc);
2117 pango_font_description_free (font_desc);
2119 gtk_text_view_set_left_margin (text_view, 8);
2120 gtk_text_view_set_right_margin (text_view, 8);
2122 g_signal_connect (view, "key-press-event",
2123 G_CALLBACK (text_view_key_press_event), about);
2124 g_signal_connect (view, "event-after",
2125 G_CALLBACK (text_view_event_after), about);
2126 g_signal_connect (view, "motion-notify-event",
2127 G_CALLBACK (text_view_motion_notify_event), about);
2128 g_signal_connect (view, "visibility-notify-event",
2129 G_CALLBACK (text_view_visibility_notify_event), about);
2131 if (strings == NULL)
2133 gtk_widget_hide (view);
2137 for (p = strings; *p; p++)
2142 q1 = strchr (q0, '<');
2143 q2 = q1 ? strchr (q1, '>') : NULL;
2144 r1 = strstr (q0, "http://");
2147 r2 = strpbrk (r1, " \n\t");
2149 r2 = strchr (r1, '\0');
2154 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2165 const gchar *link_type;
2170 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0 + 1);
2171 gtk_text_buffer_get_end_iter (buffer, &end);
2173 link_type = "email";
2177 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2178 gtk_text_buffer_get_end_iter (buffer, &end);
2184 link = g_strndup (q1, q2 - q1);
2186 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2187 color = visited_link_color;
2191 tag = gtk_text_buffer_create_tag (buffer, NULL,
2192 "foreground-gdk", &color,
2193 "underline", PANGO_UNDERLINE_SINGLE,
2195 if (strcmp (link_type, "email") == 0)
2199 escaped = g_uri_escape_string (link, NULL, FALSE);
2200 uri = g_strconcat ("mailto:", escaped, NULL);
2205 uri = g_strdup (link);
2207 g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
2208 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2214 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2220 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2223 gtk_widget_show (view);
2228 add_credits_section (GtkAboutDialog *about,
2237 gchar *q0, *q1, *q2, *r1, *r2;
2242 markup = g_strdup_printf ("<span size=\"small\">%s</span>", title);
2243 label = gtk_label_new (markup);
2244 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2246 gtk_widget_set_halign (label, GTK_ALIGN_END);
2247 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
2248 gtk_grid_attach (grid, label, 0, *row, 1, 1);
2250 for (p = people; *p; p++)
2254 str = g_string_new ("<span size=\"small\">");
2259 q1 = strchr (q0, '<');
2260 q2 = q1 ? strchr (q1, '>') : NULL;
2261 r1 = strstr (q0, "http://");
2264 r2 = strpbrk (r1, " \n\t");
2266 r2 = strchr (r1, '\0');
2271 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2276 else if (q1 && (q1[1] == 'a' || q1[1] == 'A') && q1[2] == ' ')
2278 /* if it is a <a> link leave it for the label to parse */
2293 text = g_strstrip (g_strndup (q0, q1 - q0));
2294 name = g_markup_escape_text (text, -1);
2296 link = g_strndup (q1, q2 - q1);
2298 escaped = g_uri_escape_string (link, NULL, FALSE);
2299 g_string_append_printf (str,
2300 "<a href=\"mailto:%s\">%s</a>",
2302 name[0] ? name : link);
2311 text = g_strstrip (g_strndup (q0, q1 - q0));
2312 name = g_markup_escape_text (text, -1);
2313 link = g_strndup (q1, q2 - q1);
2314 g_string_append_printf (str,
2315 "<a href=\"%s\">%s</a>",
2317 name[0] ? name : link);
2327 g_string_append (str, q0);
2331 g_string_append (str, "</span>");
2333 label = gtk_label_new (str->str);
2334 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2335 g_string_free (str, TRUE);
2336 gtk_widget_set_halign (label, GTK_ALIGN_START);
2337 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
2338 gtk_grid_attach (grid, label, 1, *row, 1, 1);
2342 /* skip one at the end */
2347 create_credits_page (GtkAboutDialog *about)
2349 GtkAboutDialogPrivate *priv = about->priv;
2350 GtkWidget *page_vbox;
2355 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2356 gtk_widget_show (page_vbox);
2357 priv->credits_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2359 sw = gtk_scrolled_window_new (NULL, NULL);
2360 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
2361 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2363 GTK_POLICY_AUTOMATIC);
2364 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2366 grid = gtk_grid_new ();
2367 gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
2368 gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
2369 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2370 gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
2371 gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
2372 gtk_widget_set_valign (grid, GTK_ALIGN_START);
2373 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), grid);
2375 if (priv->authors != NULL)
2376 add_credits_section (about, GTK_GRID (grid), &row, _("Created by"), priv->authors);
2378 if (priv->documenters != NULL)
2379 add_credits_section (about, GTK_GRID (grid), &row, _("Documented by"), priv->documenters);
2381 /* Don't show an untranslated gettext msgid */
2382 if (priv->translator_credits != NULL &&
2383 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2384 strcmp (priv->translator_credits, "translator-credits") != 0)
2386 gchar **translators;
2388 translators = g_strsplit (priv->translator_credits, "\n", 0);
2389 add_credits_section (about, GTK_GRID (grid), &row, _("Translated by"), translators);
2390 g_strfreev (translators);
2393 if (priv->artists != NULL)
2394 add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
2396 gtk_widget_show_all (sw);
2400 display_credits_page (GtkWidget *button,
2403 GtkAboutDialog *about = (GtkAboutDialog *)data;
2404 GtkAboutDialogPrivate *priv = about->priv;
2406 if (priv->credits_page == 0)
2407 create_credits_page (about);
2409 switch_page (about, priv->credits_page);
2413 create_license_page (GtkAboutDialog *about)
2415 GtkAboutDialogPrivate *priv = about->priv;
2416 GtkWidget *page_vbox;
2421 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2422 priv->license_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2424 sw = gtk_scrolled_window_new (NULL, NULL);
2425 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2426 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
2427 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2428 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
2429 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2431 strings[0] = priv->license;
2433 view = text_view_new (about, strings,
2434 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2436 gtk_container_add (GTK_CONTAINER (sw), view);
2438 gtk_widget_show_all (page_vbox);
2442 display_license_page (GtkWidget *button,
2445 GtkAboutDialog *about = (GtkAboutDialog *)data;
2446 GtkAboutDialogPrivate *priv = about->priv;
2448 if (priv->license_page == 0)
2449 create_license_page (about);
2451 switch_page (about, priv->license_page);
2455 * gtk_about_dialog_new:
2457 * Creates a new #GtkAboutDialog.
2459 * Returns: a newly created #GtkAboutDialog
2464 gtk_about_dialog_new (void)
2466 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2468 return GTK_WIDGET (dialog);
2472 close_cb (GtkAboutDialog *about)
2474 GtkAboutDialogPrivate *priv = about->priv;
2476 switch_page (about, 0);
2477 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
2478 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
2479 gtk_widget_hide (GTK_WIDGET (about));
2483 * gtk_show_about_dialog:
2484 * @parent: (allow-none): transient parent, or %NULL for none
2485 * @first_property_name: the name of the first property
2486 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2488 * This is a convenience function for showing an application's about box.
2489 * The constructed dialog is associated with the parent window and
2490 * reused for future invocations of this function.
2495 gtk_show_about_dialog (GtkWindow *parent,
2496 const gchar *first_property_name,
2499 static GtkWidget *global_about_dialog = NULL;
2500 GtkWidget *dialog = NULL;
2504 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2506 dialog = global_about_dialog;
2510 dialog = gtk_about_dialog_new ();
2512 g_object_ref_sink (dialog);
2514 g_signal_connect (dialog, "delete-event",
2515 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2517 /* Close dialog on user response */
2518 g_signal_connect (dialog, "response",
2519 G_CALLBACK (close_cb), NULL);
2521 va_start (var_args, first_property_name);
2522 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2527 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2528 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2529 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2530 g_object_set_data_full (G_OBJECT (parent),
2531 I_("gtk-about-dialog"),
2532 dialog, g_object_unref);
2535 global_about_dialog = dialog;
2539 gtk_window_present (GTK_WINDOW (dialog));
2543 * gtk_about_dialog_set_license_type:
2544 * @about: a #GtkAboutDialog
2545 * @license_type: the type of license
2547 * Sets the license of the application showing the @about dialog from a
2548 * list of known licenses.
2550 * This function overrides the license set using
2551 * gtk_about_dialog_set_license().
2556 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2557 GtkLicense license_type)
2559 GtkAboutDialogPrivate *priv;
2561 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2562 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2563 license_type <= GTK_LICENSE_ARTISTIC);
2567 if (priv->license_type != license_type)
2569 g_object_freeze_notify (G_OBJECT (about));
2571 priv->license_type = license_type;
2573 /* custom licenses use the contents of the :license property */
2574 if (priv->license_type != GTK_LICENSE_CUSTOM)
2577 gchar *license_string;
2580 url = gtk_license_urls[priv->license_type];
2582 url = priv->website_url;
2584 str = g_string_sized_new (256);
2585 g_string_append_printf (str, _(gtk_license_preamble), url, url);
2587 g_free (priv->license);
2588 priv->license = g_string_free (str, FALSE);
2589 priv->wrap_license = TRUE;
2591 license_string = g_strdup_printf ("<span size=\"small\">%s</span>",
2593 gtk_label_set_markup (GTK_LABEL (priv->license_label), license_string);
2594 g_free (license_string);
2595 gtk_widget_show (priv->license_label);
2597 update_license_button_visibility (about);
2599 g_object_notify (G_OBJECT (about), "wrap-license");
2600 g_object_notify (G_OBJECT (about), "license");
2604 gtk_widget_show (priv->license_label);
2607 g_object_notify (G_OBJECT (about), "license-type");
2609 g_object_thaw_notify (G_OBJECT (about));
2614 * gtk_about_dialog_get_license_type:
2615 * @about: a #GtkAboutDialog
2617 * Retrieves the license set using gtk_about_dialog_set_license_type()
2619 * Return value: a #GtkLicense value
2624 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2626 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2628 return about->priv->license_type;