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>
96 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
97 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
99 /* Translators: this is the license preamble; the string at the end
100 * contains the URL of the license.
102 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit <a href=\"%s\">%s</a>");
104 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
105 static const gchar *gtk_license_urls[] = {
109 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
110 "http://www.gnu.org/licenses/gpl.html",
112 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
113 "http://www.gnu.org/licenses/lgpl.html",
115 "http://opensource.org/licenses/bsd-license.php",
116 "http://opensource.org/licenses/mit-license.php",
118 "http://opensource.org/licenses/artistic-license-2.0.php"
121 struct _GtkAboutDialogPrivate
129 gchar *translator_credits;
140 GtkWidget *logo_image;
141 GtkWidget *name_label;
142 GtkWidget *version_label;
143 GtkWidget *comments_label;
144 GtkWidget *copyright_label;
145 GtkWidget *license_label;
146 GtkWidget *website_label;
148 GtkWidget *credits_button;
149 GtkWidget *license_button;
151 GdkCursor *hand_cursor;
152 GdkCursor *regular_cursor;
154 GSList *visited_links;
156 GtkLicense license_type;
158 guint hovering_over_link : 1;
159 guint wrap_license : 1;
162 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
177 PROP_TRANSLATOR_CREDITS,
185 static void gtk_about_dialog_finalize (GObject *object);
186 static void gtk_about_dialog_get_property (GObject *object,
190 static void gtk_about_dialog_set_property (GObject *object,
194 static void gtk_about_dialog_show (GtkWidget *widge);
195 static void update_name_version (GtkAboutDialog *about);
196 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
197 static void follow_if_link (GtkAboutDialog *about,
198 GtkTextView *text_view,
200 static void set_cursor_if_appropriate (GtkAboutDialog *about,
201 GtkTextView *text_view,
205 static void display_credits_page (GtkWidget *button,
207 static void display_license_page (GtkWidget *button,
209 static void close_cb (GtkAboutDialog *about);
210 static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
218 static guint signals[LAST_SIGNAL] = { 0 };
220 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
224 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
226 GObjectClass *object_class;
227 GtkWidgetClass *widget_class;
229 object_class = (GObjectClass *)klass;
230 widget_class = (GtkWidgetClass *)klass;
232 object_class->set_property = gtk_about_dialog_set_property;
233 object_class->get_property = gtk_about_dialog_get_property;
235 object_class->finalize = gtk_about_dialog_finalize;
237 widget_class->show = gtk_about_dialog_show;
239 klass->activate_link = gtk_about_dialog_activate_link;
242 * GtkAboutDialog::activate-link:
243 * @label: The object on which the signal was emitted
244 * @uri: the URI that is activated
246 * The signal which gets emitted to activate a URI.
247 * Applications may connect to it to override the default behaviour,
248 * which is to call gtk_show_uri().
250 * Returns: %TRUE if the link has been activated
254 signals[ACTIVATE_LINK] =
255 g_signal_new ("activate-link",
256 G_TYPE_FROM_CLASS (object_class),
258 G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
259 _gtk_boolean_handled_accumulator, NULL,
260 _gtk_marshal_BOOLEAN__STRING,
261 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
264 * GtkAboutDialog:program-name:
266 * The name of the program.
267 * If this is not set, it defaults to g_get_application_name().
271 g_object_class_install_property (object_class,
273 g_param_spec_string ("program-name",
275 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
277 GTK_PARAM_READWRITE));
280 * GtkAboutDialog:version:
282 * The version of the program.
286 g_object_class_install_property (object_class,
288 g_param_spec_string ("version",
289 P_("Program version"),
290 P_("The version of the program"),
292 GTK_PARAM_READWRITE));
295 * GtkAboutDialog:copyright:
297 * Copyright information for the program.
301 g_object_class_install_property (object_class,
303 g_param_spec_string ("copyright",
304 P_("Copyright string"),
305 P_("Copyright information for the program"),
307 GTK_PARAM_READWRITE));
311 * GtkAboutDialog:comments:
313 * Comments about the program. This string is displayed in a label
314 * in the main dialog, thus it should be a short explanation of
315 * the main purpose of the program, not a detailed list of features.
319 g_object_class_install_property (object_class,
321 g_param_spec_string ("comments",
322 P_("Comments string"),
323 P_("Comments about the program"),
325 GTK_PARAM_READWRITE));
328 * GtkAboutDialog:license:
330 * The license of the program. This string is displayed in a
331 * text view in a secondary dialog, therefore it is fine to use
332 * a long multi-paragraph text. Note that the text is only wrapped
333 * in the text view if the "wrap-license" property is set to %TRUE;
334 * otherwise the text itself must contain the intended linebreaks.
335 * When setting this property to a non-%NULL value, the
336 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
341 g_object_class_install_property (object_class,
343 g_param_spec_string ("license",
345 _("The license of the program"),
347 GTK_PARAM_READWRITE));
350 * GtkAboutDialog:license-type:
352 * The license of the program, as a value of the %GtkLicense enumeration.
354 * The #GtkAboutDialog will automatically fill out a standard disclaimer
355 * and link the user to the appropriate online resource for the license
358 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
359 * specified in the #GtkAboutDialog:website property.
361 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
362 * #GtkAboutDialog:license property are used.
364 * For any other #GtkLicense value, the contents of the
365 * #GtkAboutDialog:license property are also set by this property as
370 g_object_class_install_property (object_class,
372 g_param_spec_enum ("license-type",
374 P_("The license type of the program"),
377 GTK_PARAM_READWRITE));
380 * GtkAboutDialog:website:
382 * The URL for the link to the website of the program.
383 * This should be a string starting with "http://.
387 g_object_class_install_property (object_class,
389 g_param_spec_string ("website",
391 P_("The URL for the link to the website of the program"),
393 GTK_PARAM_READWRITE));
396 * GtkAboutDialog:website-label:
398 * The label for the link to the website of the program.
402 g_object_class_install_property (object_class,
404 g_param_spec_string ("website-label",
406 P_("The label for the link to the website of the program"),
408 GTK_PARAM_READWRITE));
411 * GtkAboutDialog:authors:
413 * The authors of the program, as a %NULL-terminated array of strings.
414 * Each string may contain email addresses and URLs, which will be displayed
415 * as links, see the introduction for more details.
419 g_object_class_install_property (object_class,
421 g_param_spec_boxed ("authors",
423 P_("List of authors of the program"),
425 GTK_PARAM_READWRITE));
428 * GtkAboutDialog:documenters:
430 * The people documenting the program, as a %NULL-terminated array of strings.
431 * Each string may contain email addresses and URLs, which will be displayed
432 * as links, see the introduction for more details.
436 g_object_class_install_property (object_class,
438 g_param_spec_boxed ("documenters",
440 P_("List of people documenting the program"),
442 GTK_PARAM_READWRITE));
445 * GtkAboutDialog:artists:
447 * The people who contributed artwork to the program, as a %NULL-terminated
448 * array of strings. Each string may contain email addresses and URLs, which
449 * will be displayed as links, see the introduction for more details.
453 g_object_class_install_property (object_class,
455 g_param_spec_boxed ("artists",
457 P_("List of people who have contributed artwork to the program"),
459 GTK_PARAM_READWRITE));
463 * GtkAboutDialog:translator-credits:
465 * Credits to the translators. This string should be marked as translatable.
466 * The string may contain email addresses and URLs, which will be displayed
467 * as links, see the introduction for more details.
471 g_object_class_install_property (object_class,
472 PROP_TRANSLATOR_CREDITS,
473 g_param_spec_string ("translator-credits",
474 P_("Translator credits"),
475 P_("Credits to the translators. This string should be marked as translatable"),
477 GTK_PARAM_READWRITE));
480 * GtkAboutDialog:logo:
482 * A logo for the about box. If this is not set, it defaults to
483 * gtk_window_get_default_icon_list().
487 g_object_class_install_property (object_class,
489 g_param_spec_object ("logo",
491 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
493 GTK_PARAM_READWRITE));
496 * GtkAboutDialog:logo-icon-name:
498 * A named icon to use as the logo for the about box. This property
499 * overrides the #GtkAboutDialog:logo property.
503 g_object_class_install_property (object_class,
505 g_param_spec_string ("logo-icon-name",
506 P_("Logo Icon Name"),
507 P_("A named icon to use as the logo for the about box."),
509 GTK_PARAM_READWRITE));
511 * GtkAboutDialog:wrap-license:
513 * Whether to wrap the text in the license dialog.
517 g_object_class_install_property (object_class,
519 g_param_spec_boolean ("wrap-license",
521 P_("Whether to wrap the license text."),
523 GTK_PARAM_READWRITE));
526 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
530 emit_activate_link (GtkAboutDialog *about,
533 gboolean handled = FALSE;
535 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
541 update_license_button_visibility (GtkAboutDialog *about)
543 GtkAboutDialogPrivate *priv = about->priv;
545 if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL)
546 gtk_widget_show (priv->license_button);
548 gtk_widget_hide (priv->license_button);
552 update_credits_button_visibility (GtkAboutDialog *about)
554 GtkAboutDialogPrivate *priv = about->priv;
557 show = (priv->authors != NULL ||
558 priv->documenters != NULL ||
559 priv->artists != NULL ||
560 (priv->translator_credits != NULL &&
561 strcmp (priv->translator_credits, "translator_credits") &&
562 strcmp (priv->translator_credits, "translator-credits")));
564 gtk_widget_show (priv->credits_button);
566 gtk_widget_hide (priv->credits_button);
570 switch_page (GtkAboutDialog *about,
573 GtkAboutDialogPrivate *priv = about->priv;
575 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page);
579 display_main_page (GtkButton *button,
582 GtkAboutDialog *about = (GtkAboutDialog *)data;
584 switch_page (about, 0);
588 credits_button_clicked (GtkButton *button,
591 GtkAboutDialog *about = (GtkAboutDialog *)data;
592 GtkAboutDialogPrivate *priv = about->priv;
595 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
599 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
600 display_credits_page (NULL, data);
604 display_main_page (NULL, data);
609 license_button_clicked (GtkButton *button,
612 GtkAboutDialog *about = (GtkAboutDialog *)data;
613 GtkAboutDialogPrivate *priv = about->priv;
616 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
620 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
621 display_license_page (NULL, data);
625 display_main_page (NULL, data);
629 gtk_about_dialog_init (GtkAboutDialog *about)
631 GtkDialog *dialog = GTK_DIALOG (about);
632 GtkAboutDialogPrivate *priv;
633 GtkWidget *vbox, *page_vbox, *hbox, *button, *close_button, *image;
634 GtkWidget *content_area, *action_area;
637 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
641 priv->version = NULL;
642 priv->copyright = NULL;
643 priv->comments = NULL;
644 priv->website_url = NULL;
645 priv->website_text = NULL;
646 priv->translator_credits = NULL;
647 priv->license = NULL;
648 priv->authors = NULL;
649 priv->documenters = NULL;
650 priv->artists = NULL;
652 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
653 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
654 priv->hovering_over_link = FALSE;
655 priv->wrap_license = FALSE;
657 priv->license_type = GTK_LICENSE_UNKNOWN;
659 content_area = gtk_dialog_get_content_area (dialog);
660 action_area = gtk_dialog_get_action_area (dialog);
662 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
663 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
664 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
667 gtk_widget_push_composite_child ();
669 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
670 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
671 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
673 priv->logo_image = gtk_image_new ();
674 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
676 priv->name_label = gtk_label_new (NULL);
677 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
678 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
679 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
681 priv->notebook = gtk_notebook_new ();
682 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
683 gtk_widget_set_size_request (priv->notebook, 400, 100);
685 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
686 gtk_widget_show (page_vbox);
687 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
688 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
689 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
691 priv->version_label = gtk_label_new (NULL);
692 gtk_label_set_selectable (GTK_LABEL (priv->version_label), TRUE);
693 gtk_label_set_justify (GTK_LABEL (priv->version_label), GTK_JUSTIFY_CENTER);
694 gtk_box_pack_start (GTK_BOX (page_vbox), priv->version_label, FALSE, FALSE, 0);
696 priv->comments_label = gtk_label_new (NULL);
697 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
698 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
699 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
700 gtk_box_pack_start (GTK_BOX (page_vbox), priv->comments_label, FALSE, FALSE, 0);
702 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
703 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
704 gtk_box_pack_start (GTK_BOX (page_vbox), hbox, FALSE, FALSE, 0);
706 priv->website_label = button = gtk_label_new ("");
707 gtk_widget_set_no_show_all (button, TRUE);
708 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
709 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
710 g_signal_connect_swapped (button, "activate-link",
711 G_CALLBACK (emit_activate_link), about);
713 priv->license_label = gtk_label_new (NULL);
714 gtk_label_set_use_markup (GTK_LABEL (priv->license_label), TRUE);
715 gtk_label_set_selectable (GTK_LABEL (priv->license_label), TRUE);
716 gtk_label_set_justify (GTK_LABEL (priv->license_label), GTK_JUSTIFY_CENTER);
717 gtk_box_pack_end (GTK_BOX (page_vbox), priv->license_label, FALSE, FALSE, 0);
718 gtk_label_set_line_wrap (GTK_LABEL (priv->license_label), TRUE);
720 priv->copyright_label = gtk_label_new (NULL);
721 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
722 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
723 gtk_box_pack_end (GTK_BOX (page_vbox), priv->copyright_label, FALSE, FALSE, 0);
725 gtk_widget_show (vbox);
726 gtk_widget_show (priv->notebook);
727 gtk_widget_show (priv->logo_image);
728 gtk_widget_show (priv->name_label);
729 gtk_widget_show (hbox);
731 /* Add the close button */
732 close_button = gtk_dialog_add_button (GTK_DIALOG (about),
733 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL);
734 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
736 /* Add the credits button */
737 button = gtk_toggle_button_new_with_mnemonic (_("C_redits"));
738 gtk_widget_set_can_default (button, TRUE);
739 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
740 gtk_button_set_image (GTK_BUTTON (button), image);
741 gtk_widget_set_no_show_all (button, TRUE);
742 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
743 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
744 g_signal_connect (button, "clicked",
745 G_CALLBACK (credits_button_clicked), about);
746 priv->credits_button = button;
747 priv->credits_page = 0;
749 /* Add the license button */
750 button = gtk_toggle_button_new_with_mnemonic (_("_License"));
751 gtk_widget_set_can_default (button, TRUE);
752 gtk_widget_set_no_show_all (button, TRUE);
753 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
754 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
755 g_signal_connect (button, "clicked",
756 G_CALLBACK (license_button_clicked), about);
757 priv->license_button = button;
758 priv->license_page = 0;
760 switch_page (about, 0);
762 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
764 gtk_widget_pop_composite_child ();
766 gtk_widget_grab_default (close_button);
767 gtk_widget_grab_focus (close_button);
770 gtk_about_dialog_set_program_name (about, NULL);
771 gtk_about_dialog_set_logo (about, NULL);
775 gtk_about_dialog_finalize (GObject *object)
777 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
778 GtkAboutDialogPrivate *priv = about->priv;
781 g_free (priv->version);
782 g_free (priv->copyright);
783 g_free (priv->comments);
784 g_free (priv->license);
785 g_free (priv->website_url);
786 g_free (priv->website_text);
787 g_free (priv->translator_credits);
789 g_strfreev (priv->authors);
790 g_strfreev (priv->documenters);
791 g_strfreev (priv->artists);
793 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
794 g_slist_free (priv->visited_links);
796 g_object_unref (priv->hand_cursor);
797 g_object_unref (priv->regular_cursor);
799 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
803 gtk_about_dialog_set_property (GObject *object,
808 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
809 GtkAboutDialogPrivate *priv = about->priv;
814 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
817 gtk_about_dialog_set_version (about, g_value_get_string (value));
820 gtk_about_dialog_set_comments (about, g_value_get_string (value));
823 gtk_about_dialog_set_website (about, g_value_get_string (value));
825 case PROP_WEBSITE_LABEL:
826 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
829 gtk_about_dialog_set_license (about, g_value_get_string (value));
831 case PROP_LICENSE_TYPE:
832 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
835 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
838 gtk_about_dialog_set_logo (about, g_value_get_object (value));
841 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
843 case PROP_DOCUMENTERS:
844 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
847 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
849 case PROP_TRANSLATOR_CREDITS:
850 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
852 case PROP_LOGO_ICON_NAME:
853 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
855 case PROP_WRAP_LICENSE:
856 priv->wrap_license = g_value_get_boolean (value);
859 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
865 gtk_about_dialog_get_property (GObject *object,
870 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
871 GtkAboutDialogPrivate *priv = about->priv;
876 g_value_set_string (value, priv->name);
879 g_value_set_string (value, priv->version);
882 g_value_set_string (value, priv->copyright);
885 g_value_set_string (value, priv->comments);
888 g_value_set_string (value, priv->website_url);
890 case PROP_WEBSITE_LABEL:
891 g_value_set_string (value, priv->website_text);
894 g_value_set_string (value, priv->license);
896 case PROP_LICENSE_TYPE:
897 g_value_set_enum (value, priv->license_type);
899 case PROP_TRANSLATOR_CREDITS:
900 g_value_set_string (value, priv->translator_credits);
903 g_value_set_boxed (value, priv->authors);
905 case PROP_DOCUMENTERS:
906 g_value_set_boxed (value, priv->documenters);
909 g_value_set_boxed (value, priv->artists);
912 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
913 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
915 g_value_set_object (value, NULL);
917 case PROP_LOGO_ICON_NAME:
918 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
920 const gchar *icon_name;
922 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
923 g_value_set_string (value, icon_name);
926 g_value_set_string (value, NULL);
928 case PROP_WRAP_LICENSE:
929 g_value_set_boolean (value, priv->wrap_license);
932 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
938 gtk_about_dialog_activate_link (GtkAboutDialog *about,
942 GError *error = NULL;
944 screen = gtk_widget_get_screen (GTK_WIDGET (about));
946 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
950 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
951 GTK_DIALOG_DESTROY_WITH_PARENT |
955 "%s", _("Could not show link"));
956 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
957 "%s", error->message);
958 g_error_free (error);
960 g_signal_connect (dialog, "response",
961 G_CALLBACK (gtk_widget_destroy), NULL);
963 gtk_window_present (GTK_WINDOW (dialog));
970 update_website (GtkAboutDialog *about)
972 GtkAboutDialogPrivate *priv = about->priv;
974 gtk_widget_show (priv->website_label);
976 if (priv->website_url)
980 if (priv->website_text)
984 escaped = g_markup_escape_text (priv->website_text, -1);
985 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
986 priv->website_url, escaped);
991 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
992 priv->website_url, _("Homepage"));
995 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
1000 if (priv->website_text)
1001 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
1003 gtk_widget_hide (priv->website_label);
1008 gtk_about_dialog_show (GtkWidget *widget)
1010 update_website (GTK_ABOUT_DIALOG (widget));
1012 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
1016 * gtk_about_dialog_get_program_name:
1017 * @about: a #GtkAboutDialog
1019 * Returns the program name displayed in the about dialog.
1021 * Return value: The program name. The string is owned by the about
1022 * dialog and must not be modified.
1027 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
1029 GtkAboutDialogPrivate *priv;
1031 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1039 update_name_version (GtkAboutDialog *about)
1041 GtkAboutDialogPrivate *priv;
1042 gchar *title_string, *name_string;
1046 title_string = g_strdup_printf (_("About %s"), priv->name);
1047 gtk_window_set_title (GTK_WINDOW (about), title_string);
1048 g_free (title_string);
1050 if (priv->version != NULL)
1052 gtk_label_set_markup (GTK_LABEL (priv->version_label), priv->version);
1053 gtk_widget_show (priv->version_label);
1056 gtk_widget_hide (priv->version_label);
1058 name_string = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
1060 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
1061 g_free (name_string);
1065 * gtk_about_dialog_set_program_name:
1066 * @about: a #GtkAboutDialog
1067 * @name: the program name
1069 * Sets the name to display in the about dialog.
1070 * If this is not set, it defaults to g_get_application_name().
1075 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
1078 GtkAboutDialogPrivate *priv;
1081 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1086 priv->name = g_strdup (name ? name : g_get_application_name ());
1089 update_name_version (about);
1091 g_object_notify (G_OBJECT (about), "program-name");
1096 * gtk_about_dialog_get_version:
1097 * @about: a #GtkAboutDialog
1099 * Returns the version string.
1101 * Return value: The version string. The string is owned by the about
1102 * dialog and must not be modified.
1107 gtk_about_dialog_get_version (GtkAboutDialog *about)
1109 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1111 return about->priv->version;
1115 * gtk_about_dialog_set_version:
1116 * @about: a #GtkAboutDialog
1117 * @version: (allow-none): the version string
1119 * Sets the version string to display in the about dialog.
1124 gtk_about_dialog_set_version (GtkAboutDialog *about,
1125 const gchar *version)
1127 GtkAboutDialogPrivate *priv;
1130 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1134 tmp = priv->version;
1135 priv->version = g_strdup (version);
1138 update_name_version (about);
1140 g_object_notify (G_OBJECT (about), "version");
1144 * gtk_about_dialog_get_copyright:
1145 * @about: a #GtkAboutDialog
1147 * Returns the copyright string.
1149 * Return value: The copyright string. The string is owned by the about
1150 * dialog and must not be modified.
1155 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1157 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1159 return about->priv->copyright;
1163 * gtk_about_dialog_set_copyright:
1164 * @about: a #GtkAboutDialog
1165 * @copyright: (allow-none) the copyright string
1167 * Sets the copyright string to display in the about dialog.
1168 * This should be a short string of one or two lines.
1173 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1174 const gchar *copyright)
1176 GtkAboutDialogPrivate *priv;
1177 gchar *copyright_string, *tmp;
1179 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1183 tmp = priv->copyright;
1184 priv->copyright = g_strdup (copyright);
1187 if (priv->copyright != NULL)
1189 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1191 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1192 g_free (copyright_string);
1194 gtk_widget_show (priv->copyright_label);
1197 gtk_widget_hide (priv->copyright_label);
1199 g_object_notify (G_OBJECT (about), "copyright");
1203 * gtk_about_dialog_get_comments:
1204 * @about: a #GtkAboutDialog
1206 * Returns the comments string.
1208 * Return value: The comments. The string is owned by the about
1209 * dialog and must not be modified.
1214 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1216 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1218 return about->priv->comments;
1222 * gtk_about_dialog_set_comments:
1223 * @about: a #GtkAboutDialog
1224 * @comments: (allow-none): a comments string
1226 * Sets the comments string to display in the about dialog.
1227 * This should be a short string of one or two lines.
1232 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1233 const gchar *comments)
1235 GtkAboutDialogPrivate *priv;
1238 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1242 tmp = priv->comments;
1245 priv->comments = g_strdup (comments);
1246 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1247 gtk_widget_show (priv->comments_label);
1251 priv->comments = NULL;
1252 gtk_widget_hide (priv->comments_label);
1256 g_object_notify (G_OBJECT (about), "comments");
1260 * gtk_about_dialog_get_license:
1261 * @about: a #GtkAboutDialog
1263 * Returns the license information.
1265 * Return value: The license information. The string is owned by the about
1266 * dialog and must not be modified.
1271 gtk_about_dialog_get_license (GtkAboutDialog *about)
1273 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1275 return about->priv->license;
1279 * gtk_about_dialog_set_license:
1280 * @about: a #GtkAboutDialog
1281 * @license: (allow-none): the license information or %NULL
1283 * Sets the license information to be displayed in the secondary
1284 * license dialog. If @license is %NULL, the license button is
1290 gtk_about_dialog_set_license (GtkAboutDialog *about,
1291 const gchar *license)
1293 GtkAboutDialogPrivate *priv;
1296 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1300 tmp = priv->license;
1303 priv->license = g_strdup (license);
1304 priv->license_type = GTK_LICENSE_CUSTOM;
1308 priv->license = NULL;
1309 priv->license_type = GTK_LICENSE_UNKNOWN;
1313 gtk_widget_hide (priv->license_label);
1315 update_license_button_visibility (about);
1317 g_object_notify (G_OBJECT (about), "license");
1318 g_object_notify (G_OBJECT (about), "license-type");
1322 * gtk_about_dialog_get_wrap_license:
1323 * @about: a #GtkAboutDialog
1325 * Returns whether the license text in @about is
1326 * automatically wrapped.
1328 * Returns: %TRUE if the license text is wrapped
1333 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1335 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1337 return about->priv->wrap_license;
1341 * gtk_about_dialog_set_wrap_license:
1342 * @about: a #GtkAboutDialog
1343 * @wrap_license: whether to wrap the license
1345 * Sets whether the license text in @about is
1346 * automatically wrapped.
1351 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1352 gboolean wrap_license)
1354 GtkAboutDialogPrivate *priv;
1356 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1360 wrap_license = wrap_license != FALSE;
1362 if (priv->wrap_license != wrap_license)
1364 priv->wrap_license = wrap_license;
1366 g_object_notify (G_OBJECT (about), "wrap-license");
1371 * gtk_about_dialog_get_website:
1372 * @about: a #GtkAboutDialog
1374 * Returns the website URL.
1376 * Return value: The website URL. The string is owned by the about
1377 * dialog and must not be modified.
1382 gtk_about_dialog_get_website (GtkAboutDialog *about)
1384 GtkAboutDialogPrivate *priv;
1386 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1390 return priv->website_url;
1394 * gtk_about_dialog_set_website:
1395 * @about: a #GtkAboutDialog
1396 * @website: (allow-none): a URL string starting with "http://"
1398 * Sets the URL to use for the website link.
1403 gtk_about_dialog_set_website (GtkAboutDialog *about,
1404 const gchar *website)
1406 GtkAboutDialogPrivate *priv;
1409 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1413 tmp = priv->website_url;
1414 priv->website_url = g_strdup (website);
1417 update_website (about);
1419 g_object_notify (G_OBJECT (about), "website");
1423 * gtk_about_dialog_get_website_label:
1424 * @about: a #GtkAboutDialog
1426 * Returns the label used for the website link.
1428 * Return value: The label used for the website link. The string is
1429 * owned by the about dialog and must not be modified.
1434 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1436 GtkAboutDialogPrivate *priv;
1438 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1442 return priv->website_text;
1446 * gtk_about_dialog_set_website_label:
1447 * @about: a #GtkAboutDialog
1448 * @website_label: the label used for the website link
1450 * Sets the label to be used for the website link.
1455 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1456 const gchar *website_label)
1458 GtkAboutDialogPrivate *priv;
1461 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1465 tmp = priv->website_text;
1466 priv->website_text = g_strdup (website_label);
1469 update_website (about);
1471 g_object_notify (G_OBJECT (about), "website-label");
1475 * gtk_about_dialog_get_authors:
1476 * @about: a #GtkAboutDialog
1478 * Returns the string which are displayed in the authors tab
1479 * of the secondary credits dialog.
1481 * Return value: (array zero-terminated=1) (transfer none): A
1482 * %NULL-terminated string array containing the authors. The array is
1483 * owned by the about dialog and must not be modified.
1487 const gchar * const *
1488 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1490 GtkAboutDialogPrivate *priv;
1492 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1496 return (const gchar * const *) priv->authors;
1500 * gtk_about_dialog_set_authors:
1501 * @about: a #GtkAboutDialog
1502 * @authors: (array zero-terminated=1): a %NULL-terminated array of strings
1504 * Sets the strings which are displayed in the authors tab
1505 * of the secondary credits dialog.
1510 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1511 const gchar **authors)
1513 GtkAboutDialogPrivate *priv;
1516 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1520 tmp = priv->authors;
1521 priv->authors = g_strdupv ((gchar **)authors);
1524 update_credits_button_visibility (about);
1526 g_object_notify (G_OBJECT (about), "authors");
1530 * gtk_about_dialog_get_documenters:
1531 * @about: a #GtkAboutDialog
1533 * Returns the string which are displayed in the documenters
1534 * tab of the secondary credits dialog.
1536 * Return value: (array zero-terminated=1) (transfer none): A
1537 * %NULL-terminated string array containing the documenters. The
1538 * array is owned by the about dialog and must not be modified.
1542 const gchar * const *
1543 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1545 GtkAboutDialogPrivate *priv;
1547 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1551 return (const gchar * const *)priv->documenters;
1555 * gtk_about_dialog_set_documenters:
1556 * @about: a #GtkAboutDialog
1557 * @documenters: (array zero-terminated=1): a %NULL-terminated array of strings
1559 * Sets the strings which are displayed in the documenters tab
1560 * of the secondary credits dialog.
1565 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1566 const gchar **documenters)
1568 GtkAboutDialogPrivate *priv;
1571 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1575 tmp = priv->documenters;
1576 priv->documenters = g_strdupv ((gchar **)documenters);
1579 update_credits_button_visibility (about);
1581 g_object_notify (G_OBJECT (about), "documenters");
1585 * gtk_about_dialog_get_artists:
1586 * @about: a #GtkAboutDialog
1588 * Returns the string which are displayed in the artists tab
1589 * of the secondary credits dialog.
1591 * Return value: (array zero-terminated=1) (transfer none): A
1592 * %NULL-terminated string array containing the artists. The array is
1593 * owned by the about dialog and must not be modified.
1597 const gchar * const *
1598 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1600 GtkAboutDialogPrivate *priv;
1602 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1606 return (const gchar * const *)priv->artists;
1610 * gtk_about_dialog_set_artists:
1611 * @about: a #GtkAboutDialog
1612 * @artists: (array zero-terminated=1): a %NULL-terminated array of strings
1614 * Sets the strings which are displayed in the artists tab
1615 * of the secondary credits dialog.
1620 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1621 const gchar **artists)
1623 GtkAboutDialogPrivate *priv;
1626 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1630 tmp = priv->artists;
1631 priv->artists = g_strdupv ((gchar **)artists);
1634 update_credits_button_visibility (about);
1636 g_object_notify (G_OBJECT (about), "artists");
1640 * gtk_about_dialog_get_translator_credits:
1641 * @about: a #GtkAboutDialog
1643 * Returns the translator credits string which is displayed
1644 * in the translators tab of the secondary credits dialog.
1646 * Return value: The translator credits string. The string is
1647 * owned by the about dialog and must not be modified.
1652 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1654 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1656 return about->priv->translator_credits;
1660 * gtk_about_dialog_set_translator_credits:
1661 * @about: a #GtkAboutDialog
1662 * @translator_credits: (allow-none): the translator credits
1664 * Sets the translator credits string which is displayed in
1665 * the translators tab of the secondary credits dialog.
1667 * The intended use for this string is to display the translator
1668 * of the language which is currently used in the user interface.
1669 * Using gettext(), a simple way to achieve that is to mark the
1670 * string for translation:
1672 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1674 * It is a good idea to use the customary msgid "translator-credits" for this
1675 * purpose, since translators will already know the purpose of that msgid, and
1676 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1682 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1683 const gchar *translator_credits)
1685 GtkAboutDialogPrivate *priv;
1688 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1692 tmp = priv->translator_credits;
1693 priv->translator_credits = g_strdup (translator_credits);
1696 update_credits_button_visibility (about);
1698 g_object_notify (G_OBJECT (about), "translator-credits");
1702 * gtk_about_dialog_get_logo:
1703 * @about: a #GtkAboutDialog
1705 * Returns the pixbuf displayed as logo in the about dialog.
1707 * Return value: (transfer none): the pixbuf displayed as logo. The
1708 * pixbuf is owned by the about dialog. If you want to keep a
1709 * reference to it, you have to call g_object_ref() on it.
1714 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1716 GtkAboutDialogPrivate *priv;
1718 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1722 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1723 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1729 icon_set_new_from_pixbufs (GList *pixbufs)
1731 GtkIconSet *icon_set = gtk_icon_set_new ();
1733 for (; pixbufs; pixbufs = pixbufs->next)
1735 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1737 GtkIconSource *icon_source = gtk_icon_source_new ();
1738 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1739 gtk_icon_set_add_source (icon_set, icon_source);
1740 gtk_icon_source_free (icon_source);
1747 * gtk_about_dialog_set_logo:
1748 * @about: a #GtkAboutDialog
1749 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1751 * Sets the pixbuf to be displayed as logo in the about dialog.
1752 * If it is %NULL, the default window icon set with
1753 * gtk_window_set_default_icon() will be used.
1758 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1761 GtkAboutDialogPrivate *priv;
1763 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1767 g_object_freeze_notify (G_OBJECT (about));
1769 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1770 g_object_notify (G_OBJECT (about), "logo-icon-name");
1773 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1776 GList *pixbufs = gtk_window_get_default_icon_list ();
1778 if (pixbufs != NULL)
1780 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1782 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1783 icon_set, GTK_ICON_SIZE_DIALOG);
1785 gtk_icon_set_unref (icon_set);
1786 g_list_free (pixbufs);
1790 g_object_notify (G_OBJECT (about), "logo");
1792 g_object_thaw_notify (G_OBJECT (about));
1796 * gtk_about_dialog_get_logo_icon_name:
1797 * @about: a #GtkAboutDialog
1799 * Returns the icon name displayed as logo in the about dialog.
1801 * Return value: the icon name displayed as logo. The string is
1802 * owned by the dialog. If you want to keep a reference
1803 * to it, you have to call g_strdup() on it.
1808 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1810 GtkAboutDialogPrivate *priv;
1811 const gchar *icon_name = NULL;
1813 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1817 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1818 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1824 * gtk_about_dialog_set_logo_icon_name:
1825 * @about: a #GtkAboutDialog
1826 * @icon_name: (allow-none): an icon name, or %NULL
1828 * Sets the pixbuf to be displayed as logo in the about dialog.
1829 * If it is %NULL, the default window icon set with
1830 * gtk_window_set_default_icon() will be used.
1835 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1836 const gchar *icon_name)
1838 GtkAboutDialogPrivate *priv;
1840 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1844 g_object_freeze_notify (G_OBJECT (about));
1846 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1847 g_object_notify (G_OBJECT (about), "logo");
1849 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1850 GTK_ICON_SIZE_DIALOG);
1851 g_object_notify (G_OBJECT (about), "logo-icon-name");
1853 g_object_thaw_notify (G_OBJECT (about));
1857 follow_if_link (GtkAboutDialog *about,
1858 GtkTextView *text_view,
1861 GSList *tags = NULL, *tagp = NULL;
1862 GtkAboutDialogPrivate *priv = about->priv;
1865 tags = gtk_text_iter_get_tags (iter);
1866 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1868 GtkTextTag *tag = tagp->data;
1870 uri = g_object_get_data (G_OBJECT (tag), "uri");
1872 emit_activate_link (about, uri);
1874 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1876 GdkColor *style_visited_link_color;
1879 gtk_widget_style_get (GTK_WIDGET (about),
1880 "visited-link-color", &style_visited_link_color,
1882 if (style_visited_link_color)
1884 color = *style_visited_link_color;
1885 gdk_color_free (style_visited_link_color);
1888 color = default_visited_link_color;
1890 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1892 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1897 g_slist_free (tags);
1901 text_view_key_press_event (GtkWidget *text_view,
1903 GtkAboutDialog *about)
1906 GtkTextBuffer *buffer;
1908 switch (event->keyval)
1910 case GDK_KEY_Return:
1911 case GDK_KEY_ISO_Enter:
1912 case GDK_KEY_KP_Enter:
1913 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1914 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1915 gtk_text_buffer_get_insert (buffer));
1916 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1927 text_view_event_after (GtkWidget *text_view,
1929 GtkAboutDialog *about)
1931 GtkTextIter start, end, iter;
1932 GtkTextBuffer *buffer;
1933 GdkEventButton *button_event;
1936 if (event->type != GDK_BUTTON_RELEASE)
1939 button_event = (GdkEventButton *)event;
1941 if (button_event->button != 1)
1944 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1946 /* we shouldn't follow a link if the user has selected something */
1947 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1948 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1951 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1952 GTK_TEXT_WINDOW_WIDGET,
1953 button_event->x, button_event->y, &x, &y);
1955 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1957 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1963 set_cursor_if_appropriate (GtkAboutDialog *about,
1964 GtkTextView *text_view,
1969 GtkAboutDialogPrivate *priv = about->priv;
1970 GSList *tags = NULL, *tagp = NULL;
1972 gboolean hovering_over_link = FALSE;
1974 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1976 tags = gtk_text_iter_get_tags (&iter);
1977 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1979 GtkTextTag *tag = tagp->data;
1980 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1984 hovering_over_link = TRUE;
1989 if (hovering_over_link != priv->hovering_over_link)
1991 priv->hovering_over_link = hovering_over_link;
1993 if (hovering_over_link)
1994 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1996 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
2000 g_slist_free (tags);
2004 text_view_motion_notify_event (GtkWidget *text_view,
2005 GdkEventMotion *event,
2006 GtkAboutDialog *about)
2010 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2011 GTK_TEXT_WINDOW_WIDGET,
2012 event->x, event->y, &x, &y);
2014 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
2016 gdk_event_request_motions (event);
2023 text_view_visibility_notify_event (GtkWidget *text_view,
2024 GdkEventVisibility *event,
2025 GtkAboutDialog *about)
2027 GdkDeviceManager *device_manager;
2028 GdkDisplay *display;
2030 gint wx, wy, bx, by;
2032 display = gdk_window_get_display (event->window);
2033 device_manager = gdk_display_get_device_manager (display);
2034 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2036 for (d = devices; d; d = d->next)
2038 GdkDevice *dev = d->data;
2040 if (gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD)
2043 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
2046 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2047 GTK_TEXT_WINDOW_WIDGET,
2050 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
2053 g_list_free (devices);
2059 text_view_new (GtkAboutDialog *about,
2061 GtkWrapMode wrap_mode)
2064 gchar *q0, *q1, *q2, *r1, *r2;
2066 GtkTextView *text_view;
2067 GtkTextBuffer *buffer;
2068 GdkColor *style_link_color;
2069 GdkColor *style_visited_link_color;
2071 GdkColor link_color;
2072 GdkColor visited_link_color;
2074 PangoFontDescription *font_desc;
2075 GtkAboutDialogPrivate *priv = about->priv;
2076 GtkStyleContext *context;
2077 GtkStateFlags state;
2079 gtk_widget_style_get (GTK_WIDGET (about),
2080 "link-color", &style_link_color,
2081 "visited-link-color", &style_visited_link_color,
2083 if (style_link_color)
2085 link_color = *style_link_color;
2086 gdk_color_free (style_link_color);
2089 link_color = default_link_color;
2091 if (style_visited_link_color)
2093 visited_link_color = *style_visited_link_color;
2094 gdk_color_free (style_visited_link_color);
2097 visited_link_color = default_visited_link_color;
2099 view = gtk_text_view_new ();
2100 text_view = GTK_TEXT_VIEW (view);
2101 buffer = gtk_text_view_get_buffer (text_view);
2102 gtk_text_view_set_cursor_visible (text_view, FALSE);
2103 gtk_text_view_set_editable (text_view, FALSE);
2104 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2106 context = gtk_widget_get_style_context (view);
2107 state = gtk_widget_get_state_flags (view);
2109 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
2110 font_desc = pango_font_description_new ();
2111 pango_font_description_set_size (font_desc, size * PANGO_SCALE_SMALL);
2112 gtk_widget_modify_font (view, font_desc);
2113 pango_font_description_free (font_desc);
2115 gtk_text_view_set_left_margin (text_view, 8);
2116 gtk_text_view_set_right_margin (text_view, 8);
2118 g_signal_connect (view, "key-press-event",
2119 G_CALLBACK (text_view_key_press_event), about);
2120 g_signal_connect (view, "event-after",
2121 G_CALLBACK (text_view_event_after), about);
2122 g_signal_connect (view, "motion-notify-event",
2123 G_CALLBACK (text_view_motion_notify_event), about);
2124 g_signal_connect (view, "visibility-notify-event",
2125 G_CALLBACK (text_view_visibility_notify_event), about);
2127 if (strings == NULL)
2129 gtk_widget_hide (view);
2133 for (p = strings; *p; p++)
2138 q1 = strchr (q0, '<');
2139 q2 = q1 ? strchr (q1, '>') : NULL;
2140 r1 = strstr (q0, "http://");
2143 r2 = strpbrk (r1, " \n\t");
2145 r2 = strchr (r1, '\0');
2150 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2161 const gchar *link_type;
2166 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0 + 1);
2167 gtk_text_buffer_get_end_iter (buffer, &end);
2169 link_type = "email";
2173 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2174 gtk_text_buffer_get_end_iter (buffer, &end);
2180 link = g_strndup (q1, q2 - q1);
2182 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2183 color = visited_link_color;
2187 tag = gtk_text_buffer_create_tag (buffer, NULL,
2188 "foreground-gdk", &color,
2189 "underline", PANGO_UNDERLINE_SINGLE,
2191 if (strcmp (link_type, "email") == 0)
2195 escaped = g_uri_escape_string (link, NULL, FALSE);
2196 uri = g_strconcat ("mailto:", escaped, NULL);
2201 uri = g_strdup (link);
2203 g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
2204 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2210 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2216 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2219 gtk_widget_show (view);
2224 add_credits_section (GtkAboutDialog *about,
2233 gchar *q0, *q1, *q2, *r1, *r2;
2238 markup = g_strdup_printf ("<span size=\"small\">%s</span>", title);
2239 label = gtk_label_new (markup);
2240 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2242 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
2243 gtk_grid_attach (grid, label, 0, *row, 1, 1);
2245 for (p = people; *p; p++)
2249 str = g_string_new ("<span size=\"small\">");
2254 q1 = strchr (q0, '<');
2255 q2 = q1 ? strchr (q1, '>') : NULL;
2256 r1 = strstr (q0, "http://");
2259 r2 = strpbrk (r1, " \n\t");
2261 r2 = strchr (r1, '\0');
2266 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2271 else if (q1 && (q1[1] == 'a' || q1[1] == 'A') && q1[2] == ' ')
2273 /* if it is a <a> link leave it for the label to parse */
2288 text = g_strstrip (g_strndup (q0, q1 - q0));
2289 name = g_markup_escape_text (text, -1);
2291 link = g_strndup (q1, q2 - q1);
2293 escaped = g_uri_escape_string (link, NULL, FALSE);
2294 g_string_append_printf (str,
2295 "<a href=\"mailto:%s\">%s</a>",
2297 name[0] ? name : link);
2306 text = g_strstrip (g_strndup (q0, q1 - q0));
2307 name = g_markup_escape_text (text, -1);
2308 link = g_strndup (q1, q2 - q1);
2309 g_string_append_printf (str,
2310 "<a href=\"%s\">%s</a>",
2312 name[0] ? name : link);
2322 g_string_append (str, q0);
2326 g_string_append (str, "</span>");
2328 label = gtk_label_new (str->str);
2329 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2330 g_string_free (str, TRUE);
2331 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2332 gtk_grid_attach (grid, label, 1, *row, 1, 1);
2336 /* skip one at the end */
2341 create_credits_page (GtkAboutDialog *about)
2343 GtkAboutDialogPrivate *priv = about->priv;
2344 GtkWidget *page_vbox;
2349 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2350 gtk_widget_show (page_vbox);
2351 priv->credits_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2353 sw = gtk_scrolled_window_new (NULL, NULL);
2354 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
2355 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2357 GTK_POLICY_AUTOMATIC);
2358 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2360 grid = gtk_grid_new ();
2361 gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
2362 gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
2363 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2364 gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
2365 gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
2366 gtk_widget_set_valign (grid, GTK_ALIGN_START);
2367 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), grid);
2369 if (priv->authors != NULL)
2370 add_credits_section (about, GTK_GRID (grid), &row, _("Created by"), priv->authors);
2372 if (priv->documenters != NULL)
2373 add_credits_section (about, GTK_GRID (grid), &row, _("Documented by"), priv->documenters);
2375 /* Don't show an untranslated gettext msgid */
2376 if (priv->translator_credits != NULL &&
2377 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2378 strcmp (priv->translator_credits, "translator-credits") != 0)
2380 gchar **translators;
2382 translators = g_strsplit (priv->translator_credits, "\n", 0);
2383 add_credits_section (about, GTK_GRID (grid), &row, _("Translated by"), translators);
2384 g_strfreev (translators);
2387 if (priv->artists != NULL)
2388 add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
2390 gtk_widget_show_all (sw);
2394 display_credits_page (GtkWidget *button,
2397 GtkAboutDialog *about = (GtkAboutDialog *)data;
2398 GtkAboutDialogPrivate *priv = about->priv;
2400 if (priv->credits_page == 0)
2401 create_credits_page (about);
2403 switch_page (about, priv->credits_page);
2407 create_license_page (GtkAboutDialog *about)
2409 GtkAboutDialogPrivate *priv = about->priv;
2410 GtkWidget *page_vbox;
2415 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2416 priv->license_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2418 sw = gtk_scrolled_window_new (NULL, NULL);
2419 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2420 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
2421 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2422 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
2423 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2425 strings[0] = priv->license;
2427 view = text_view_new (about, strings,
2428 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2430 gtk_container_add (GTK_CONTAINER (sw), view);
2432 gtk_widget_show_all (page_vbox);
2436 display_license_page (GtkWidget *button,
2439 GtkAboutDialog *about = (GtkAboutDialog *)data;
2440 GtkAboutDialogPrivate *priv = about->priv;
2442 if (priv->license_page == 0)
2443 create_license_page (about);
2445 switch_page (about, priv->license_page);
2449 * gtk_about_dialog_new:
2451 * Creates a new #GtkAboutDialog.
2453 * Returns: a newly created #GtkAboutDialog
2458 gtk_about_dialog_new (void)
2460 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2462 return GTK_WIDGET (dialog);
2466 close_cb (GtkAboutDialog *about)
2468 GtkAboutDialogPrivate *priv = about->priv;
2470 switch_page (about, 0);
2471 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
2472 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
2473 gtk_widget_hide (GTK_WIDGET (about));
2477 * gtk_show_about_dialog:
2478 * @parent: (allow-none): transient parent, or %NULL for none
2479 * @first_property_name: the name of the first property
2480 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2482 * This is a convenience function for showing an application's about box.
2483 * The constructed dialog is associated with the parent window and
2484 * reused for future invocations of this function.
2489 gtk_show_about_dialog (GtkWindow *parent,
2490 const gchar *first_property_name,
2493 static GtkWidget *global_about_dialog = NULL;
2494 GtkWidget *dialog = NULL;
2498 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2500 dialog = global_about_dialog;
2504 dialog = gtk_about_dialog_new ();
2506 g_object_ref_sink (dialog);
2508 g_signal_connect (dialog, "delete-event",
2509 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2511 /* Close dialog on user response */
2512 g_signal_connect (dialog, "response",
2513 G_CALLBACK (close_cb), NULL);
2515 va_start (var_args, first_property_name);
2516 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2521 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2522 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2523 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2524 g_object_set_data_full (G_OBJECT (parent),
2525 I_("gtk-about-dialog"),
2526 dialog, g_object_unref);
2529 global_about_dialog = dialog;
2533 gtk_window_present (GTK_WINDOW (dialog));
2537 * gtk_about_dialog_set_license_type:
2538 * @about: a #GtkAboutDialog
2539 * @license_type: the type of license
2541 * Sets the license of the application showing the @about dialog from a
2542 * list of known licenses.
2544 * This function overrides the license set using
2545 * gtk_about_dialog_set_license().
2550 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2551 GtkLicense license_type)
2553 GtkAboutDialogPrivate *priv;
2555 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2556 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2557 license_type <= GTK_LICENSE_ARTISTIC);
2561 if (priv->license_type != license_type)
2563 g_object_freeze_notify (G_OBJECT (about));
2565 priv->license_type = license_type;
2567 /* custom licenses use the contents of the :license property */
2568 if (priv->license_type != GTK_LICENSE_CUSTOM)
2571 gchar *license_string;
2574 url = gtk_license_urls[priv->license_type];
2576 url = priv->website_url;
2578 str = g_string_sized_new (256);
2579 g_string_append_printf (str, _(gtk_license_preamble), url, url);
2581 g_free (priv->license);
2582 priv->license = g_string_free (str, FALSE);
2583 priv->wrap_license = TRUE;
2585 license_string = g_strdup_printf ("<span size=\"small\">%s</span>",
2587 gtk_label_set_markup (GTK_LABEL (priv->license_label), license_string);
2588 g_free (license_string);
2589 gtk_widget_show (priv->license_label);
2591 update_license_button_visibility (about);
2593 g_object_notify (G_OBJECT (about), "wrap-license");
2594 g_object_notify (G_OBJECT (about), "license");
2598 gtk_widget_show (priv->license_label);
2601 g_object_notify (G_OBJECT (about), "license-type");
2603 g_object_thaw_notify (G_OBJECT (about));
2608 * gtk_about_dialog_get_license_type:
2609 * @about: a #GtkAboutDialog
2611 * Retrieves the license set using gtk_about_dialog_set_license_type()
2613 * Return value: a #GtkLicense value
2618 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2620 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2622 return about->priv->license_type;