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 <gdk/gdkkeysyms.h>
37 #include "gtkaboutdialog.h"
38 #include "gtkbutton.h"
40 #include "gtkdialog.h"
44 #include "gtklinkbutton.h"
45 #include "gtkmarshalers.h"
46 #include "gtknotebook.h"
47 #include "gtkscrolledwindow.h"
49 #include "gtktextview.h"
51 #include "gtkiconfactory.h"
54 #include "gtkmessagedialog.h"
55 #include "gtkprivate.h"
60 * SECTION:gtkaboutdialog
61 * @Short_description: Display information about an application
62 * @Title: GtkAboutDialog
63 * @See_also:#GTK_STOCK_ABOUT
65 * The #GtkAboutDialog offers a simple way to display information about
66 * a program like its logo, name, copyright, website and license. It is
67 * also possible to give credits to the authors, documenters, translators
68 * and artists who have worked on the program. An about dialog is typically
69 * opened when the user selects the <literal>About</literal> option from
70 * the <literal>Help</literal> menu. All parts of the dialog are optional.
72 * About dialog often contain links and email addresses. #GtkAboutDialog
73 * supports this by offering global hooks, which are called when the user
74 * clicks on a link or email address, see gtk_about_dialog_set_email_hook()
75 * and gtk_about_dialog_set_url_hook(). Email addresses in the
76 * authors, documenters and artists properties are recognized by looking for
77 * <literal><user@<!-- -->host></literal>, URLs are
78 * recognized by looking for <literal>http://url</literal>, with
79 * <literal>url</literal> extending to the next space, tab or line break.
81 * <para id="gtk-about-dialog-hook-setup">
82 * Since 2.18 #GtkAboutDialog provides default website and email hooks that
86 * If you want provide your own hooks overriding the default ones, it is
87 * important to do so before setting the website and email URL properties,
89 * <informalexample><programlisting>
90 * gtk_about_dialog_set_url_hook (GTK_ABOUT_DIALOG (dialog), launch_url, NULL, NULL);
91 * gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), app_url);
92 * </programlisting></informalexample>
93 * To disable the default hooks, you can pass %NULL as the hook func. Then,
94 * the #GtkAboutDialog widget will not display the website or the
95 * email addresses as clickable.
97 * To make constructing a #GtkAboutDialog as convenient as possible, you can
98 * use the function gtk_show_about_dialog() which constructs and shows a dialog
99 * and keeps it around so that it can be shown again.
101 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
102 * on the dialog window (where %s is replaced by the name of the
103 * application, but in order to ensure proper translation of the title,
104 * applications should set the title property explicitly when constructing
105 * a #GtkAboutDialog, as shown in the following example:
106 * <informalexample><programlisting>
107 * gtk_show_about_dialog (NULL,
108 * "program-name", "ExampleCode",
109 * "logo", example_logo,
110 * "title" _("About ExampleCode"),
112 * </programlisting></informalexample>
113 * Note that prior to GTK+ 2.12, the #GtkAboutDialog:program-name property
114 * was called "name". This was changed to avoid the conflict with the
115 * #GtkWidget:name property.
118 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
119 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
121 /* Translators: this is the license preamble; the string at the end
122 * contains the URL of the license.
124 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit %s");
126 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
127 static const gchar *gtk_license_urls[] = {
131 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
132 "http://www.gnu.org/licenses/gpl.html",
134 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
135 "http://www.gnu.org/licenses/lgpl.html",
137 "http://opensource.org/licenses/bsd-license.php",
138 "http://opensource.org/licenses/mit-license.php",
140 "http://opensource.org/licenses/artistic-license-2.0.php"
143 struct _GtkAboutDialogPrivate
151 gchar *translator_credits;
158 GtkWidget *logo_image;
159 GtkWidget *name_label;
160 GtkWidget *comments_label;
161 GtkWidget *copyright_label;
162 GtkWidget *website_label;
164 GtkWidget *credits_button;
165 GtkWidget *credits_dialog;
166 GtkWidget *license_button;
167 GtkWidget *license_dialog;
169 GdkCursor *hand_cursor;
170 GdkCursor *regular_cursor;
172 GSList *visited_links;
174 GtkLicense license_type;
176 guint hovering_over_link : 1;
177 guint wrap_license : 1;
180 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
195 PROP_TRANSLATOR_CREDITS,
203 static void gtk_about_dialog_finalize (GObject *object);
204 static void gtk_about_dialog_get_property (GObject *object,
208 static void gtk_about_dialog_set_property (GObject *object,
212 static void gtk_about_dialog_show (GtkWidget *widge);
213 static void update_name_version (GtkAboutDialog *about);
214 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
215 static void follow_if_link (GtkAboutDialog *about,
216 GtkTextView *text_view,
218 static void set_cursor_if_appropriate (GtkAboutDialog *about,
219 GtkTextView *text_view,
223 static void display_credits_dialog (GtkWidget *button,
225 static void display_license_dialog (GtkWidget *button,
227 static void close_cb (GtkAboutDialog *about);
228 static void default_url_hook (GtkAboutDialog *about,
231 static void default_email_hook (GtkAboutDialog *about,
232 const gchar *email_address,
235 static gboolean activate_email_hook_set = FALSE;
236 static GtkAboutDialogActivateLinkFunc activate_email_hook = NULL;
237 static gpointer activate_email_hook_data = NULL;
238 static GDestroyNotify activate_email_hook_destroy = NULL;
240 static gboolean activate_url_hook_set = FALSE;
241 static GtkAboutDialogActivateLinkFunc activate_url_hook = NULL;
242 static gpointer activate_url_hook_data = NULL;
243 static GDestroyNotify activate_url_hook_destroy = NULL;
246 default_url_hook (GtkAboutDialog *about,
251 GError *error = NULL;
253 screen = gtk_widget_get_screen (GTK_WIDGET (about));
255 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
259 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
260 GTK_DIALOG_DESTROY_WITH_PARENT |
264 "%s", _("Could not show link"));
265 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
266 "%s", error->message);
267 g_error_free (error);
269 g_signal_connect (dialog, "response",
270 G_CALLBACK (gtk_widget_destroy), NULL);
272 gtk_window_present (GTK_WINDOW (dialog));
277 default_email_hook (GtkAboutDialog *about,
278 const gchar *email_address,
283 escaped = g_uri_escape_string (email_address, NULL, FALSE);
284 uri = g_strdup_printf ("mailto:%s", escaped);
287 default_url_hook (about, uri, user_data);
291 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
294 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
296 GObjectClass *object_class;
297 GtkWidgetClass *widget_class;
299 object_class = (GObjectClass *)klass;
300 widget_class = (GtkWidgetClass *)klass;
302 object_class->set_property = gtk_about_dialog_set_property;
303 object_class->get_property = gtk_about_dialog_get_property;
305 object_class->finalize = gtk_about_dialog_finalize;
307 widget_class->show = gtk_about_dialog_show;
310 * GtkAboutDialog:program-name:
312 * The name of the program.
313 * If this is not set, it defaults to g_get_application_name().
317 g_object_class_install_property (object_class,
319 g_param_spec_string ("program-name",
321 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
323 GTK_PARAM_READWRITE));
326 * GtkAboutDialog:version:
328 * The version of the program.
332 g_object_class_install_property (object_class,
334 g_param_spec_string ("version",
335 P_("Program version"),
336 P_("The version of the program"),
338 GTK_PARAM_READWRITE));
341 * GtkAboutDialog:copyright:
343 * Copyright information for the program.
347 g_object_class_install_property (object_class,
349 g_param_spec_string ("copyright",
350 P_("Copyright string"),
351 P_("Copyright information for the program"),
353 GTK_PARAM_READWRITE));
357 * GtkAboutDialog:comments:
359 * Comments about the program. This string is displayed in a label
360 * in the main dialog, thus it should be a short explanation of
361 * the main purpose of the program, not a detailed list of features.
365 g_object_class_install_property (object_class,
367 g_param_spec_string ("comments",
368 P_("Comments string"),
369 P_("Comments about the program"),
371 GTK_PARAM_READWRITE));
374 * GtkAboutDialog:license:
376 * The license of the program. This string is displayed in a
377 * text view in a secondary dialog, therefore it is fine to use
378 * a long multi-paragraph text. Note that the text is only wrapped
379 * in the text view if the "wrap-license" property is set to %TRUE;
380 * otherwise the text itself must contain the intended linebreaks.
381 * When setting this property to a non-%NULL value, the
382 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
387 g_object_class_install_property (object_class,
389 g_param_spec_string ("license",
391 _("The license of the program"),
393 GTK_PARAM_READWRITE));
396 * GtkAboutDialog:license-type:
398 * The license of the program, as a value of the %GtkLicense enumeration.
400 * The #GtkAboutDialog will automatically fill out a standard disclaimer
401 * and link the user to the appropriate online resource for the license
404 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
405 * specified in the #GtkAboutDialog:website property.
407 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
408 * #GtkAboutDialog:license property are used.
410 * For any other #GtkLicense value, the contents of the
411 * #GtkAboutDialog:license property are also set by this property as
416 g_object_class_install_property (object_class,
418 g_param_spec_enum ("license-type",
420 P_("The license type of the program"),
423 GTK_PARAM_READWRITE));
426 * GtkAboutDialog:website:
428 * The URL for the link to the website of the program.
429 * This should be a string starting with "http://.
433 g_object_class_install_property (object_class,
435 g_param_spec_string ("website",
437 P_("The URL for the link to the website of the program"),
439 GTK_PARAM_READWRITE));
442 * GtkAboutDialog:website-label:
444 * The label for the link to the website of the program. If this is not set,
445 * it defaults to the URL specified in the #GtkAboutDialog:website property.
449 g_object_class_install_property (object_class,
451 g_param_spec_string ("website-label",
453 P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
455 GTK_PARAM_READWRITE));
458 * GtkAboutDialog:authors:
460 * The authors of the program, as a %NULL-terminated array of strings.
461 * Each string may contain email addresses and URLs, which will be displayed
462 * as links, see the introduction for more details.
466 g_object_class_install_property (object_class,
468 g_param_spec_boxed ("authors",
470 P_("List of authors of the program"),
472 GTK_PARAM_READWRITE));
475 * GtkAboutDialog:documenters:
477 * The people documenting the program, as a %NULL-terminated array of strings.
478 * Each string may contain email addresses and URLs, which will be displayed
479 * as links, see the introduction for more details.
483 g_object_class_install_property (object_class,
485 g_param_spec_boxed ("documenters",
487 P_("List of people documenting the program"),
489 GTK_PARAM_READWRITE));
492 * GtkAboutDialog:artists:
494 * The people who contributed artwork to the program, as a %NULL-terminated
495 * array of strings. Each string may contain email addresses and URLs, which
496 * will be displayed as links, see the introduction for more details.
500 g_object_class_install_property (object_class,
502 g_param_spec_boxed ("artists",
504 P_("List of people who have contributed artwork to the program"),
506 GTK_PARAM_READWRITE));
510 * GtkAboutDialog:translator-credits:
512 * Credits to the translators. This string should be marked as translatable.
513 * The string may contain email addresses and URLs, which will be displayed
514 * as links, see the introduction for more details.
518 g_object_class_install_property (object_class,
519 PROP_TRANSLATOR_CREDITS,
520 g_param_spec_string ("translator-credits",
521 P_("Translator credits"),
522 P_("Credits to the translators. This string should be marked as translatable"),
524 GTK_PARAM_READWRITE));
527 * GtkAboutDialog:logo:
529 * A logo for the about box. If this is not set, it defaults to
530 * gtk_window_get_default_icon_list().
534 g_object_class_install_property (object_class,
536 g_param_spec_object ("logo",
538 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
540 GTK_PARAM_READWRITE));
543 * GtkAboutDialog:logo-icon-name:
545 * A named icon to use as the logo for the about box. This property
546 * overrides the #GtkAboutDialog:logo property.
550 g_object_class_install_property (object_class,
552 g_param_spec_string ("logo-icon-name",
553 P_("Logo Icon Name"),
554 P_("A named icon to use as the logo for the about box."),
556 GTK_PARAM_READWRITE));
558 * GtkAboutDialog:wrap-license:
560 * Whether to wrap the text in the license dialog.
564 g_object_class_install_property (object_class,
566 g_param_spec_boolean ("wrap-license",
568 P_("Whether to wrap the license text."),
570 GTK_PARAM_READWRITE));
573 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
577 website_clicked (GtkLabel *label,
579 GtkAboutDialog *about)
581 GtkAboutDialogActivateLinkFunc url_hook;
582 gpointer url_hook_data;
584 if (activate_url_hook_set)
586 url_hook = activate_url_hook;
587 url_hook_data = activate_url_hook_data;
591 url_hook = default_url_hook;
592 url_hook_data = NULL;
595 url_hook (about, uri, url_hook_data);
601 gtk_about_dialog_init (GtkAboutDialog *about)
603 GtkDialog *dialog = GTK_DIALOG (about);
604 GtkAboutDialogPrivate *priv;
605 GtkWidget *vbox, *hbox, *button, *close_button, *image;
606 GtkWidget *content_area, *action_area;
609 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
613 priv->version = NULL;
614 priv->copyright = NULL;
615 priv->comments = NULL;
616 priv->website_url = NULL;
617 priv->website_text = NULL;
618 priv->translator_credits = NULL;
619 priv->license = NULL;
620 priv->authors = NULL;
621 priv->documenters = NULL;
622 priv->artists = NULL;
624 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
625 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
626 priv->hovering_over_link = FALSE;
627 priv->wrap_license = FALSE;
629 priv->license_type = GTK_LICENSE_UNKNOWN;
631 content_area = gtk_dialog_get_content_area (dialog);
632 action_area = gtk_dialog_get_action_area (dialog);
634 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
635 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
636 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
639 gtk_widget_push_composite_child ();
641 vbox = gtk_vbox_new (FALSE, 8);
642 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
643 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
645 priv->logo_image = gtk_image_new ();
646 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
648 priv->name_label = gtk_label_new (NULL);
649 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
650 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
651 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
653 priv->comments_label = gtk_label_new (NULL);
654 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
655 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
656 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
657 gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
659 priv->copyright_label = gtk_label_new (NULL);
660 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
661 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
662 gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
664 hbox = gtk_hbox_new (TRUE, 0);
665 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
667 priv->website_label = button = gtk_label_new ("");
668 gtk_widget_set_no_show_all (button, TRUE);
669 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
670 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
671 g_signal_connect (button, "activate-link",
672 G_CALLBACK (website_clicked), about);
674 gtk_widget_show (vbox);
675 gtk_widget_show (priv->logo_image);
676 gtk_widget_show (priv->name_label);
677 gtk_widget_show (hbox);
679 /* Add the close button */
680 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
681 GTK_RESPONSE_CANCEL);
682 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
684 /* Add the credits button */
685 button = gtk_button_new_with_mnemonic (_("C_redits"));
686 gtk_widget_set_can_default (button, TRUE);
687 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
688 gtk_button_set_image (GTK_BUTTON (button), image);
689 gtk_widget_set_no_show_all (button, TRUE);
690 gtk_box_pack_end (GTK_BOX (action_area),
691 button, FALSE, TRUE, 0);
692 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
693 g_signal_connect (button, "clicked",
694 G_CALLBACK (display_credits_dialog), about);
695 priv->credits_button = button;
696 priv->credits_dialog = NULL;
698 /* Add the license button */
699 button = gtk_button_new_from_stock (_("_License"));
700 gtk_widget_set_can_default (button, TRUE);
701 gtk_widget_set_no_show_all (button, TRUE);
702 gtk_box_pack_end (GTK_BOX (action_area),
703 button, FALSE, TRUE, 0);
704 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
705 g_signal_connect (button, "clicked",
706 G_CALLBACK (display_license_dialog), about);
707 priv->license_button = button;
708 priv->license_dialog = NULL;
710 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
712 gtk_widget_pop_composite_child ();
714 gtk_widget_grab_default (close_button);
715 gtk_widget_grab_focus (close_button);
718 gtk_about_dialog_set_program_name (about, NULL);
719 gtk_about_dialog_set_logo (about, NULL);
723 gtk_about_dialog_finalize (GObject *object)
725 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
726 GtkAboutDialogPrivate *priv = about->priv;
729 g_free (priv->version);
730 g_free (priv->copyright);
731 g_free (priv->comments);
732 g_free (priv->license);
733 g_free (priv->website_url);
734 g_free (priv->website_text);
735 g_free (priv->translator_credits);
737 g_strfreev (priv->authors);
738 g_strfreev (priv->documenters);
739 g_strfreev (priv->artists);
741 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
742 g_slist_free (priv->visited_links);
744 gdk_cursor_unref (priv->hand_cursor);
745 gdk_cursor_unref (priv->regular_cursor);
747 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
751 gtk_about_dialog_set_property (GObject *object,
756 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
757 GtkAboutDialogPrivate *priv = about->priv;
762 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
765 gtk_about_dialog_set_version (about, g_value_get_string (value));
768 gtk_about_dialog_set_comments (about, g_value_get_string (value));
771 gtk_about_dialog_set_website (about, g_value_get_string (value));
773 case PROP_WEBSITE_LABEL:
774 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
777 gtk_about_dialog_set_license (about, g_value_get_string (value));
779 case PROP_LICENSE_TYPE:
780 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
783 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
786 gtk_about_dialog_set_logo (about, g_value_get_object (value));
789 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
791 case PROP_DOCUMENTERS:
792 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
795 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
797 case PROP_TRANSLATOR_CREDITS:
798 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
800 case PROP_LOGO_ICON_NAME:
801 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
803 case PROP_WRAP_LICENSE:
804 priv->wrap_license = g_value_get_boolean (value);
807 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
813 gtk_about_dialog_get_property (GObject *object,
818 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
819 GtkAboutDialogPrivate *priv = about->priv;
824 g_value_set_string (value, priv->name);
827 g_value_set_string (value, priv->version);
830 g_value_set_string (value, priv->copyright);
833 g_value_set_string (value, priv->comments);
836 g_value_set_string (value, priv->website_url);
838 case PROP_WEBSITE_LABEL:
839 g_value_set_string (value, priv->website_text);
842 g_value_set_string (value, priv->license);
844 case PROP_LICENSE_TYPE:
845 g_value_set_enum (value, priv->license_type);
847 case PROP_TRANSLATOR_CREDITS:
848 g_value_set_string (value, priv->translator_credits);
851 g_value_set_boxed (value, priv->authors);
853 case PROP_DOCUMENTERS:
854 g_value_set_boxed (value, priv->documenters);
857 g_value_set_boxed (value, priv->artists);
860 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
861 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
863 g_value_set_object (value, NULL);
865 case PROP_LOGO_ICON_NAME:
866 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
868 const gchar *icon_name;
870 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
871 g_value_set_string (value, icon_name);
874 g_value_set_string (value, NULL);
876 case PROP_WRAP_LICENSE:
877 g_value_set_boolean (value, priv->wrap_license);
880 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
886 update_website (GtkAboutDialog *about)
888 GtkAboutDialogPrivate *priv = about->priv;
890 gtk_widget_show (priv->website_label);
892 if (priv->website_url && (!activate_url_hook_set || activate_url_hook != NULL))
896 if (priv->website_text)
900 escaped = g_markup_escape_text (priv->website_text, -1);
901 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
902 priv->website_url, escaped);
907 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
908 priv->website_url, priv->website_url);
911 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
916 if (priv->website_url)
917 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
918 else if (priv->website_text)
919 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
921 gtk_widget_hide (priv->website_label);
926 gtk_about_dialog_show (GtkWidget *widget)
928 update_website (GTK_ABOUT_DIALOG (widget));
930 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
934 * gtk_about_dialog_get_program_name:
935 * @about: a #GtkAboutDialog
937 * Returns the program name displayed in the about dialog.
939 * Return value: The program name. The string is owned by the about
940 * dialog and must not be modified.
944 G_CONST_RETURN gchar *
945 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
947 GtkAboutDialogPrivate *priv;
949 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
957 update_name_version (GtkAboutDialog *about)
959 GtkAboutDialogPrivate *priv;
960 gchar *title_string, *name_string;
964 title_string = g_strdup_printf (_("About %s"), priv->name);
965 gtk_window_set_title (GTK_WINDOW (about), title_string);
966 g_free (title_string);
968 if (priv->version != NULL)
969 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
970 priv->name, priv->version);
972 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
975 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
977 g_free (name_string);
981 * gtk_about_dialog_set_program_name:
982 * @about: a #GtkAboutDialog
983 * @name: the program name
985 * Sets the name to display in the about dialog.
986 * If this is not set, it defaults to g_get_application_name().
991 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
994 GtkAboutDialogPrivate *priv;
997 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1002 priv->name = g_strdup (name ? name : g_get_application_name ());
1005 update_name_version (about);
1007 g_object_notify (G_OBJECT (about), "program-name");
1012 * gtk_about_dialog_get_version:
1013 * @about: a #GtkAboutDialog
1015 * Returns the version string.
1017 * Return value: The version string. The string is owned by the about
1018 * dialog and must not be modified.
1022 G_CONST_RETURN gchar *
1023 gtk_about_dialog_get_version (GtkAboutDialog *about)
1025 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1027 return about->priv->version;
1031 * gtk_about_dialog_set_version:
1032 * @about: a #GtkAboutDialog
1033 * @version: (allow-none): the version string
1035 * Sets the version string to display in the about dialog.
1040 gtk_about_dialog_set_version (GtkAboutDialog *about,
1041 const gchar *version)
1043 GtkAboutDialogPrivate *priv;
1046 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1050 tmp = priv->version;
1051 priv->version = g_strdup (version);
1054 update_name_version (about);
1056 g_object_notify (G_OBJECT (about), "version");
1060 * gtk_about_dialog_get_copyright:
1061 * @about: a #GtkAboutDialog
1063 * Returns the copyright string.
1065 * Return value: The copyright string. The string is owned by the about
1066 * dialog and must not be modified.
1070 G_CONST_RETURN gchar *
1071 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1073 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1075 return about->priv->copyright;
1079 * gtk_about_dialog_set_copyright:
1080 * @about: a #GtkAboutDialog
1081 * @copyright: (allow-none) the copyright string
1083 * Sets the copyright string to display in the about dialog.
1084 * This should be a short string of one or two lines.
1089 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1090 const gchar *copyright)
1092 GtkAboutDialogPrivate *priv;
1093 gchar *copyright_string, *tmp;
1095 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1099 tmp = priv->copyright;
1100 priv->copyright = g_strdup (copyright);
1103 if (priv->copyright != NULL)
1105 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1107 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1108 g_free (copyright_string);
1110 gtk_widget_show (priv->copyright_label);
1113 gtk_widget_hide (priv->copyright_label);
1115 g_object_notify (G_OBJECT (about), "copyright");
1119 * gtk_about_dialog_get_comments:
1120 * @about: a #GtkAboutDialog
1122 * Returns the comments string.
1124 * Return value: The comments. The string is owned by the about
1125 * dialog and must not be modified.
1129 G_CONST_RETURN gchar *
1130 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1132 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1134 return about->priv->comments;
1138 * gtk_about_dialog_set_comments:
1139 * @about: a #GtkAboutDialog
1140 * @comments: (allow-none): a comments string
1142 * Sets the comments string to display in the about dialog.
1143 * This should be a short string of one or two lines.
1148 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1149 const gchar *comments)
1151 GtkAboutDialogPrivate *priv;
1154 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1158 tmp = priv->comments;
1161 priv->comments = g_strdup (comments);
1162 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1163 gtk_widget_show (priv->comments_label);
1167 priv->comments = NULL;
1168 gtk_widget_hide (priv->comments_label);
1172 g_object_notify (G_OBJECT (about), "comments");
1176 * gtk_about_dialog_get_license:
1177 * @about: a #GtkAboutDialog
1179 * Returns the license information.
1181 * Return value: The license information. The string is owned by the about
1182 * dialog and must not be modified.
1186 G_CONST_RETURN gchar *
1187 gtk_about_dialog_get_license (GtkAboutDialog *about)
1189 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1191 return about->priv->license;
1195 * gtk_about_dialog_set_license:
1196 * @about: a #GtkAboutDialog
1197 * @license: (allow-none): the license information or %NULL
1199 * Sets the license information to be displayed in the secondary
1200 * license dialog. If @license is %NULL, the license button is
1206 gtk_about_dialog_set_license (GtkAboutDialog *about,
1207 const gchar *license)
1209 GtkAboutDialogPrivate *priv;
1212 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1216 tmp = priv->license;
1219 priv->license = g_strdup (license);
1220 priv->license_type = GTK_LICENSE_CUSTOM;
1221 gtk_widget_show (priv->license_button);
1225 priv->license = NULL;
1226 priv->license_type = GTK_LICENSE_UNKNOWN;
1227 gtk_widget_hide (priv->license_button);
1231 g_object_notify (G_OBJECT (about), "license");
1232 g_object_notify (G_OBJECT (about), "license-type");
1236 * gtk_about_dialog_get_wrap_license:
1237 * @about: a #GtkAboutDialog
1239 * Returns whether the license text in @about is
1240 * automatically wrapped.
1242 * Returns: %TRUE if the license text is wrapped
1247 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1249 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1251 return about->priv->wrap_license;
1255 * gtk_about_dialog_set_wrap_license:
1256 * @about: a #GtkAboutDialog
1257 * @wrap_license: whether to wrap the license
1259 * Sets whether the license text in @about is
1260 * automatically wrapped.
1265 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1266 gboolean wrap_license)
1268 GtkAboutDialogPrivate *priv;
1270 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1274 wrap_license = wrap_license != FALSE;
1276 if (priv->wrap_license != wrap_license)
1278 priv->wrap_license = wrap_license;
1280 g_object_notify (G_OBJECT (about), "wrap-license");
1285 * gtk_about_dialog_get_website:
1286 * @about: a #GtkAboutDialog
1288 * Returns the website URL.
1290 * Return value: The website URL. The string is owned by the about
1291 * dialog and must not be modified.
1295 G_CONST_RETURN gchar *
1296 gtk_about_dialog_get_website (GtkAboutDialog *about)
1298 GtkAboutDialogPrivate *priv;
1300 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1304 return priv->website_url;
1308 * gtk_about_dialog_set_website:
1309 * @about: a #GtkAboutDialog
1310 * @website: (allow-none): a URL string starting with "http://"
1312 * Sets the URL to use for the website link.
1314 * Note that that the hook functions need to be set up
1315 * before calling this function.
1320 gtk_about_dialog_set_website (GtkAboutDialog *about,
1321 const gchar *website)
1323 GtkAboutDialogPrivate *priv;
1326 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1330 tmp = priv->website_url;
1331 priv->website_url = g_strdup (website);
1334 update_website (about);
1336 g_object_notify (G_OBJECT (about), "website");
1340 * gtk_about_dialog_get_website_label:
1341 * @about: a #GtkAboutDialog
1343 * Returns the label used for the website link.
1345 * Return value: The label used for the website link. The string is
1346 * owned by the about dialog and must not be modified.
1350 G_CONST_RETURN gchar *
1351 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1353 GtkAboutDialogPrivate *priv;
1355 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1359 return priv->website_text;
1363 * gtk_about_dialog_set_website_label:
1364 * @about: a #GtkAboutDialog
1365 * @website_label: the label used for the website link
1367 * Sets the label to be used for the website link.
1368 * It defaults to the website URL.
1373 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1374 const gchar *website_label)
1376 GtkAboutDialogPrivate *priv;
1379 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1383 tmp = priv->website_text;
1384 priv->website_text = g_strdup (website_label);
1387 update_website (about);
1389 g_object_notify (G_OBJECT (about), "website-label");
1393 * gtk_about_dialog_get_authors:
1394 * @about: a #GtkAboutDialog
1396 * Returns the string which are displayed in the authors tab
1397 * of the secondary credits dialog.
1399 * Return value: A %NULL-terminated string array containing
1400 * the authors. The array is owned by the about dialog
1401 * and must not be modified.
1405 G_CONST_RETURN gchar * G_CONST_RETURN *
1406 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1408 GtkAboutDialogPrivate *priv;
1410 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1414 return (const gchar * const *) priv->authors;
1418 update_credits_button_visibility (GtkAboutDialog *about)
1420 GtkAboutDialogPrivate *priv = about->priv;
1423 show = priv->authors != NULL ||
1424 priv->documenters != NULL ||
1425 priv->artists != NULL ||
1426 (priv->translator_credits != NULL &&
1427 strcmp (priv->translator_credits, "translator_credits") &&
1428 strcmp (priv->translator_credits, "translator-credits"));
1430 gtk_widget_show (priv->credits_button);
1432 gtk_widget_hide (priv->credits_button);
1436 * gtk_about_dialog_set_authors:
1437 * @about: a #GtkAboutDialog
1438 * @authors: a %NULL-terminated array of strings
1440 * Sets the strings which are displayed in the authors tab
1441 * of the secondary credits dialog.
1446 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1447 const gchar **authors)
1449 GtkAboutDialogPrivate *priv;
1452 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1456 tmp = priv->authors;
1457 priv->authors = g_strdupv ((gchar **)authors);
1460 update_credits_button_visibility (about);
1462 g_object_notify (G_OBJECT (about), "authors");
1466 * gtk_about_dialog_get_documenters:
1467 * @about: a #GtkAboutDialog
1469 * Returns the string which are displayed in the documenters
1470 * tab of the secondary credits dialog.
1472 * Return value: A %NULL-terminated string array containing
1473 * the documenters. The array is owned by the about dialog
1474 * and must not be modified.
1478 G_CONST_RETURN gchar * G_CONST_RETURN *
1479 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1481 GtkAboutDialogPrivate *priv;
1483 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1487 return (const gchar * const *)priv->documenters;
1491 * gtk_about_dialog_set_documenters:
1492 * @about: a #GtkAboutDialog
1493 * @documenters: a %NULL-terminated array of strings
1495 * Sets the strings which are displayed in the documenters tab
1496 * of the secondary credits dialog.
1501 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1502 const gchar **documenters)
1504 GtkAboutDialogPrivate *priv;
1507 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1511 tmp = priv->documenters;
1512 priv->documenters = g_strdupv ((gchar **)documenters);
1515 update_credits_button_visibility (about);
1517 g_object_notify (G_OBJECT (about), "documenters");
1521 * gtk_about_dialog_get_artists:
1522 * @about: a #GtkAboutDialog
1524 * Returns the string which are displayed in the artists tab
1525 * of the secondary credits dialog.
1527 * Return value: A %NULL-terminated string array containing
1528 * the artists. The array is owned by the about dialog
1529 * and must not be modified.
1533 G_CONST_RETURN gchar * G_CONST_RETURN *
1534 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1536 GtkAboutDialogPrivate *priv;
1538 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1542 return (const gchar * const *)priv->artists;
1546 * gtk_about_dialog_set_artists:
1547 * @about: a #GtkAboutDialog
1548 * @artists: a %NULL-terminated array of strings
1550 * Sets the strings which are displayed in the artists tab
1551 * of the secondary credits dialog.
1556 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1557 const gchar **artists)
1559 GtkAboutDialogPrivate *priv;
1562 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1566 tmp = priv->artists;
1567 priv->artists = g_strdupv ((gchar **)artists);
1570 update_credits_button_visibility (about);
1572 g_object_notify (G_OBJECT (about), "artists");
1576 * gtk_about_dialog_get_translator_credits:
1577 * @about: a #GtkAboutDialog
1579 * Returns the translator credits string which is displayed
1580 * in the translators tab of the secondary credits dialog.
1582 * Return value: The translator credits string. The string is
1583 * owned by the about dialog and must not be modified.
1587 G_CONST_RETURN gchar *
1588 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1590 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1592 return about->priv->translator_credits;
1596 * gtk_about_dialog_set_translator_credits:
1597 * @about: a #GtkAboutDialog
1598 * @translator_credits: (allow-none): the translator credits
1600 * Sets the translator credits string which is displayed in
1601 * the translators tab of the secondary credits dialog.
1603 * The intended use for this string is to display the translator
1604 * of the language which is currently used in the user interface.
1605 * Using gettext(), a simple way to achieve that is to mark the
1606 * string for translation:
1608 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1610 * It is a good idea to use the customary msgid "translator-credits" for this
1611 * purpose, since translators will already know the purpose of that msgid, and
1612 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1618 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1619 const gchar *translator_credits)
1621 GtkAboutDialogPrivate *priv;
1624 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1628 tmp = priv->translator_credits;
1629 priv->translator_credits = g_strdup (translator_credits);
1632 update_credits_button_visibility (about);
1634 g_object_notify (G_OBJECT (about), "translator-credits");
1638 * gtk_about_dialog_get_logo:
1639 * @about: a #GtkAboutDialog
1641 * Returns the pixbuf displayed as logo in the about dialog.
1643 * Return value: the pixbuf displayed as logo. The pixbuf is
1644 * owned by the about dialog. If you want to keep a reference
1645 * to it, you have to call g_object_ref() on it.
1650 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1652 GtkAboutDialogPrivate *priv;
1654 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1658 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1659 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1665 icon_set_new_from_pixbufs (GList *pixbufs)
1667 GtkIconSet *icon_set = gtk_icon_set_new ();
1669 for (; pixbufs; pixbufs = pixbufs->next)
1671 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1673 GtkIconSource *icon_source = gtk_icon_source_new ();
1674 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1675 gtk_icon_set_add_source (icon_set, icon_source);
1676 gtk_icon_source_free (icon_source);
1683 * gtk_about_dialog_set_logo:
1684 * @about: a #GtkAboutDialog
1685 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1687 * Sets the pixbuf to be displayed as logo in the about dialog.
1688 * If it is %NULL, the default window icon set with
1689 * gtk_window_set_default_icon() will be used.
1694 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1697 GtkAboutDialogPrivate *priv;
1699 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1703 g_object_freeze_notify (G_OBJECT (about));
1705 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1706 g_object_notify (G_OBJECT (about), "logo-icon-name");
1709 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1712 GList *pixbufs = gtk_window_get_default_icon_list ();
1714 if (pixbufs != NULL)
1716 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1718 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1719 icon_set, GTK_ICON_SIZE_DIALOG);
1721 gtk_icon_set_unref (icon_set);
1722 g_list_free (pixbufs);
1726 g_object_notify (G_OBJECT (about), "logo");
1728 g_object_thaw_notify (G_OBJECT (about));
1732 * gtk_about_dialog_get_logo_icon_name:
1733 * @about: a #GtkAboutDialog
1735 * Returns the icon name displayed as logo in the about dialog.
1737 * Return value: the icon name displayed as logo. The string is
1738 * owned by the dialog. If you want to keep a reference
1739 * to it, you have to call g_strdup() on it.
1743 G_CONST_RETURN gchar *
1744 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1746 GtkAboutDialogPrivate *priv;
1747 const gchar *icon_name = NULL;
1749 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1753 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1754 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1760 * gtk_about_dialog_set_logo_icon_name:
1761 * @about: a #GtkAboutDialog
1762 * @icon_name: (allow-none): an icon name, or %NULL
1764 * Sets the pixbuf to be displayed as logo in the about dialog.
1765 * If it is %NULL, the default window icon set with
1766 * gtk_window_set_default_icon() will be used.
1771 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1772 const gchar *icon_name)
1774 GtkAboutDialogPrivate *priv;
1776 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1780 g_object_freeze_notify (G_OBJECT (about));
1782 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1783 g_object_notify (G_OBJECT (about), "logo");
1785 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1786 GTK_ICON_SIZE_DIALOG);
1787 g_object_notify (G_OBJECT (about), "logo-icon-name");
1789 g_object_thaw_notify (G_OBJECT (about));
1793 follow_if_link (GtkAboutDialog *about,
1794 GtkTextView *text_view,
1797 GSList *tags = NULL, *tagp = NULL;
1798 GtkAboutDialogPrivate *priv = about->priv;
1800 GtkAboutDialogActivateLinkFunc email_hook, url_hook;
1801 gpointer email_hook_data, url_hook_data;
1803 if (activate_email_hook_set)
1805 email_hook = activate_email_hook;
1806 email_hook_data = activate_email_hook_data;
1810 email_hook = default_email_hook;
1811 email_hook_data = NULL;
1814 if (activate_url_hook_set)
1816 url_hook = activate_url_hook;
1817 url_hook_data = activate_url_hook_data;
1821 url_hook = default_url_hook;
1822 url_hook_data = NULL;
1825 tags = gtk_text_iter_get_tags (iter);
1826 for (tagp = tags; tagp != NULL && !url; tagp = tagp->next)
1828 GtkTextTag *tag = tagp->data;
1830 if (email_hook != NULL)
1832 url = g_object_get_data (G_OBJECT (tag), "email");
1834 email_hook (about, url, email_hook_data);
1837 if (!url && url_hook != NULL)
1839 url = g_object_get_data (G_OBJECT (tag), "url");
1841 url_hook (about, url, url_hook_data);
1844 if (url && !g_slist_find_custom (priv->visited_links, url, (GCompareFunc)strcmp))
1846 GdkColor *style_visited_link_color;
1849 gtk_widget_ensure_style (GTK_WIDGET (about));
1850 gtk_widget_style_get (GTK_WIDGET (about),
1851 "visited-link-color", &style_visited_link_color,
1853 if (style_visited_link_color)
1855 color = *style_visited_link_color;
1856 gdk_color_free (style_visited_link_color);
1859 color = default_visited_link_color;
1861 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1863 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (url));
1868 g_slist_free (tags);
1872 text_view_key_press_event (GtkWidget *text_view,
1874 GtkAboutDialog *about)
1877 GtkTextBuffer *buffer;
1879 switch (event->keyval)
1884 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1885 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1886 gtk_text_buffer_get_insert (buffer));
1887 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1898 text_view_event_after (GtkWidget *text_view,
1900 GtkAboutDialog *about)
1902 GtkTextIter start, end, iter;
1903 GtkTextBuffer *buffer;
1904 GdkEventButton *button_event;
1907 if (event->type != GDK_BUTTON_RELEASE)
1910 button_event = (GdkEventButton *)event;
1912 if (button_event->button != 1)
1915 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1917 /* we shouldn't follow a link if the user has selected something */
1918 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1919 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1922 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1923 GTK_TEXT_WINDOW_WIDGET,
1924 button_event->x, button_event->y, &x, &y);
1926 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1928 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1934 set_cursor_if_appropriate (GtkAboutDialog *about,
1935 GtkTextView *text_view,
1940 GtkAboutDialogPrivate *priv = about->priv;
1941 GSList *tags = NULL, *tagp = NULL;
1943 gboolean hovering_over_link = FALSE;
1945 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1947 tags = gtk_text_iter_get_tags (&iter);
1948 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1950 GtkTextTag *tag = tagp->data;
1951 gchar *email = g_object_get_data (G_OBJECT (tag), "email");
1952 gchar *url = g_object_get_data (G_OBJECT (tag), "url");
1954 if (email != NULL || url != NULL)
1956 hovering_over_link = TRUE;
1961 if (hovering_over_link != priv->hovering_over_link)
1963 priv->hovering_over_link = hovering_over_link;
1965 if (hovering_over_link)
1966 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1968 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
1972 g_slist_free (tags);
1976 text_view_motion_notify_event (GtkWidget *text_view,
1977 GdkEventMotion *event,
1978 GtkAboutDialog *about)
1982 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1983 GTK_TEXT_WINDOW_WIDGET,
1984 event->x, event->y, &x, &y);
1986 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
1988 gdk_event_request_motions (event);
1995 text_view_visibility_notify_event (GtkWidget *text_view,
1996 GdkEventVisibility *event,
1997 GtkAboutDialog *about)
1999 GdkDeviceManager *device_manager;
2000 GdkDisplay *display;
2002 gint wx, wy, bx, by;
2004 display = gdk_drawable_get_display (event->window);
2005 device_manager = gdk_display_get_device_manager (display);
2006 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2008 for (d = devices; d; d = d->next)
2010 GdkDevice *dev = d->data;
2012 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
2015 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2016 GTK_TEXT_WINDOW_WIDGET,
2019 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
2026 text_view_new (GtkAboutDialog *about,
2029 GtkWrapMode wrap_mode)
2032 gchar *q0, *q1, *q2, *r1, *r2;
2034 GtkTextView *text_view;
2035 GtkTextBuffer *buffer;
2036 gboolean linkify_email, linkify_urls;
2037 GdkColor *style_link_color;
2038 GdkColor *style_visited_link_color;
2040 GdkColor link_color;
2041 GdkColor visited_link_color;
2043 GtkAboutDialogPrivate *priv = about->priv;
2045 linkify_email = (!activate_email_hook_set || activate_email_hook != NULL);
2046 linkify_urls = (!activate_url_hook_set || activate_url_hook != NULL);
2048 gtk_widget_ensure_style (GTK_WIDGET (about));
2049 gtk_widget_style_get (GTK_WIDGET (about),
2050 "link-color", &style_link_color,
2051 "visited-link-color", &style_visited_link_color,
2053 if (style_link_color)
2055 link_color = *style_link_color;
2056 gdk_color_free (style_link_color);
2059 link_color = default_link_color;
2061 if (style_visited_link_color)
2063 visited_link_color = *style_visited_link_color;
2064 gdk_color_free (style_visited_link_color);
2067 visited_link_color = default_visited_link_color;
2069 view = gtk_text_view_new ();
2070 text_view = GTK_TEXT_VIEW (view);
2071 buffer = gtk_text_view_get_buffer (text_view);
2072 gtk_text_view_set_cursor_visible (text_view, FALSE);
2073 gtk_text_view_set_editable (text_view, FALSE);
2074 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2076 gtk_text_view_set_left_margin (text_view, 8);
2077 gtk_text_view_set_right_margin (text_view, 8);
2079 g_signal_connect (view, "key-press-event",
2080 G_CALLBACK (text_view_key_press_event), about);
2081 g_signal_connect (view, "event-after",
2082 G_CALLBACK (text_view_event_after), about);
2083 g_signal_connect (view, "motion-notify-event",
2084 G_CALLBACK (text_view_motion_notify_event), about);
2085 g_signal_connect (view, "visibility-notify-event",
2086 G_CALLBACK (text_view_visibility_notify_event), about);
2088 if (strings == NULL)
2090 gtk_widget_hide (view);
2094 for (p = strings; *p; p++)
2099 q1 = linkify_email ? strchr (q0, '<') : NULL;
2100 q2 = q1 ? strchr (q1, '>') : NULL;
2101 r1 = linkify_urls ? strstr (q0, "http://") : NULL;
2104 r2 = strpbrk (r1, " \n\t");
2106 r2 = strchr (r1, '\0');
2111 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2121 const gchar *link_type;
2126 gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
2127 gtk_text_buffer_get_end_iter (buffer, &end);
2129 link_type = I_("email");
2133 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2134 gtk_text_buffer_get_end_iter (buffer, &end);
2135 link_type = I_("url");
2140 link = g_strndup (q1, q2 - q1);
2142 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2143 color = visited_link_color;
2147 tag = gtk_text_buffer_create_tag (buffer, NULL,
2148 "foreground-gdk", &color,
2149 "underline", PANGO_UNDERLINE_SINGLE,
2151 g_object_set_data_full (G_OBJECT (tag), link_type, g_strdup (link), g_free);
2152 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2158 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2164 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2167 gtk_widget_show (view);
2172 add_credits_page (GtkAboutDialog *about,
2173 GtkWidget *credits_dialog,
2174 GtkWidget *notebook,
2178 GtkWidget *sw, *view;
2180 view = text_view_new (about, credits_dialog, people, GTK_WRAP_NONE);
2182 sw = gtk_scrolled_window_new (NULL, NULL);
2183 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2185 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2186 GTK_POLICY_AUTOMATIC,
2187 GTK_POLICY_AUTOMATIC);
2188 gtk_container_add (GTK_CONTAINER (sw), view);
2190 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
2191 sw, gtk_label_new (title));
2195 display_credits_dialog (GtkWidget *button,
2198 GtkAboutDialog *about = (GtkAboutDialog *)data;
2199 GtkAboutDialogPrivate *priv = about->priv;
2200 GtkWidget *dialog, *notebook;
2201 GtkDialog *credits_dialog;
2202 GtkWidget *content_area;
2203 GtkWidget *action_area;
2205 if (priv->credits_dialog != NULL)
2207 gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2211 dialog = gtk_dialog_new_with_buttons (_("Credits"),
2213 GTK_DIALOG_DESTROY_WITH_PARENT,
2214 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2216 credits_dialog = GTK_DIALOG (dialog);
2218 content_area = gtk_dialog_get_content_area (credits_dialog);
2219 action_area = gtk_dialog_get_action_area (credits_dialog);
2221 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2222 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2223 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2225 priv->credits_dialog = dialog;
2226 gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2227 gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2229 gtk_window_set_modal (GTK_WINDOW (dialog),
2230 gtk_window_get_modal (GTK_WINDOW (about)));
2232 g_signal_connect (dialog, "response",
2233 G_CALLBACK (gtk_widget_destroy), dialog);
2234 g_signal_connect (dialog, "destroy",
2235 G_CALLBACK (gtk_widget_destroyed),
2236 &(priv->credits_dialog));
2238 notebook = gtk_notebook_new ();
2239 gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2240 gtk_box_pack_start (GTK_BOX (content_area), notebook, TRUE, TRUE, 0);
2242 if (priv->authors != NULL)
2243 add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2245 if (priv->documenters != NULL)
2246 add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2248 /* Don't show an untranslated gettext msgid */
2249 if (priv->translator_credits != NULL &&
2250 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2251 strcmp (priv->translator_credits, "translator-credits") != 0)
2253 gchar *translators[2];
2255 translators[0] = priv->translator_credits;
2256 translators[1] = NULL;
2258 add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2261 if (priv->artists != NULL)
2262 add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2264 gtk_widget_show_all (dialog);
2268 set_policy (GtkWidget *sw)
2270 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2271 GTK_POLICY_AUTOMATIC,
2272 GTK_POLICY_AUTOMATIC);
2276 display_license_dialog (GtkWidget *button,
2279 GtkAboutDialog *about = (GtkAboutDialog *)data;
2280 GtkAboutDialogPrivate *priv = about->priv;
2281 GtkWidget *dialog, *view, *sw;
2282 GtkDialog *license_dialog;
2283 GtkWidget *content_area;
2284 GtkWidget *action_area;
2287 if (priv->license_dialog != NULL)
2289 gtk_window_present (GTK_WINDOW (priv->license_dialog));
2293 dialog = gtk_dialog_new_with_buttons (_("License"),
2295 GTK_DIALOG_DESTROY_WITH_PARENT,
2296 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2298 license_dialog = GTK_DIALOG (dialog);
2300 content_area = gtk_dialog_get_content_area (license_dialog);
2301 action_area = gtk_dialog_get_action_area (license_dialog);
2303 gtk_container_set_border_width (GTK_CONTAINER (license_dialog), 5);
2304 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2305 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2307 priv->license_dialog = dialog;
2308 gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2309 gtk_dialog_set_default_response (license_dialog, GTK_RESPONSE_CANCEL);
2311 gtk_window_set_modal (GTK_WINDOW (dialog),
2312 gtk_window_get_modal (GTK_WINDOW (about)));
2314 g_signal_connect (dialog, "response",
2315 G_CALLBACK (gtk_widget_destroy), dialog);
2316 g_signal_connect (dialog, "destroy",
2317 G_CALLBACK (gtk_widget_destroyed),
2318 &(priv->license_dialog));
2320 sw = gtk_scrolled_window_new (NULL, NULL);
2321 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2322 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2324 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2326 GTK_POLICY_AUTOMATIC);
2327 g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2328 gtk_box_pack_start (GTK_BOX (content_area), sw, TRUE, TRUE, 0);
2330 strings[0] = priv->license;
2332 view = text_view_new (about, dialog, strings,
2333 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2335 gtk_container_add (GTK_CONTAINER (sw), view);
2337 gtk_widget_show_all (dialog);
2341 * gtk_about_dialog_new:
2343 * Creates a new #GtkAboutDialog.
2345 * Returns: a newly created #GtkAboutDialog
2350 gtk_about_dialog_new (void)
2352 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2354 return GTK_WIDGET (dialog);
2358 * gtk_about_dialog_set_email_hook:
2359 * @func: a function to call when an email link is activated.
2360 * @data: data to pass to @func
2361 * @destroy: #GDestroyNotify for @data
2363 * Installs a global function to be called whenever the user activates an
2364 * email link in an about dialog.
2366 * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2367 * deactivate it, you can pass %NULL for @func.
2369 * Return value: the previous email hook.
2373 GtkAboutDialogActivateLinkFunc
2374 gtk_about_dialog_set_email_hook (GtkAboutDialogActivateLinkFunc func,
2376 GDestroyNotify destroy)
2378 GtkAboutDialogActivateLinkFunc old;
2380 if (activate_email_hook_destroy != NULL)
2381 (* activate_email_hook_destroy) (activate_email_hook_data);
2383 old = activate_email_hook;
2385 activate_email_hook_set = TRUE;
2386 activate_email_hook = func;
2387 activate_email_hook_data = data;
2388 activate_email_hook_destroy = destroy;
2394 * gtk_about_dialog_set_url_hook:
2395 * @func: a function to call when a URL link is activated.
2396 * @data: data to pass to @func
2397 * @destroy: #GDestroyNotify for @data
2399 * Installs a global function to be called whenever the user activates a
2400 * URL link in an about dialog.
2402 * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2403 * deactivate it, you can pass %NULL for @func.
2405 * Return value: the previous URL hook.
2409 GtkAboutDialogActivateLinkFunc
2410 gtk_about_dialog_set_url_hook (GtkAboutDialogActivateLinkFunc func,
2412 GDestroyNotify destroy)
2414 GtkAboutDialogActivateLinkFunc old;
2416 if (activate_url_hook_destroy != NULL)
2417 (* activate_url_hook_destroy) (activate_url_hook_data);
2419 old = activate_url_hook;
2421 activate_url_hook_set = TRUE;
2422 activate_url_hook = func;
2423 activate_url_hook_data = data;
2424 activate_url_hook_destroy = destroy;
2430 close_cb (GtkAboutDialog *about)
2432 GtkAboutDialogPrivate *priv = about->priv;
2434 if (priv->license_dialog != NULL)
2436 gtk_widget_destroy (priv->license_dialog);
2437 priv->license_dialog = NULL;
2440 if (priv->credits_dialog != NULL)
2442 gtk_widget_destroy (priv->credits_dialog);
2443 priv->credits_dialog = NULL;
2446 gtk_widget_hide (GTK_WIDGET (about));
2451 * gtk_show_about_dialog:
2452 * @parent: (allow-none): transient parent, or %NULL for none
2453 * @first_property_name: the name of the first property
2454 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2456 * This is a convenience function for showing an application's about box.
2457 * The constructed dialog is associated with the parent window and
2458 * reused for future invocations of this function.
2463 gtk_show_about_dialog (GtkWindow *parent,
2464 const gchar *first_property_name,
2467 static GtkWidget *global_about_dialog = NULL;
2468 GtkWidget *dialog = NULL;
2472 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2474 dialog = global_about_dialog;
2478 dialog = gtk_about_dialog_new ();
2480 g_object_ref_sink (dialog);
2482 g_signal_connect (dialog, "delete-event",
2483 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2485 /* Close dialog on user response */
2486 g_signal_connect (dialog, "response",
2487 G_CALLBACK (close_cb), NULL);
2489 va_start (var_args, first_property_name);
2490 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2495 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2496 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2497 g_object_set_data_full (G_OBJECT (parent),
2498 I_("gtk-about-dialog"),
2499 dialog, g_object_unref);
2502 global_about_dialog = dialog;
2506 gtk_window_present (GTK_WINDOW (dialog));
2510 * gtk_about_dialog_set_license_type:
2511 * @about: a #GtkAboutDialog
2512 * @license_type: the type of license
2514 * Sets the license of the application showing the @about dialog from a
2515 * list of known licenses.
2517 * This function overrides the license set using
2518 * gtk_about_dialog_set_license().
2523 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2524 GtkLicense license_type)
2526 GtkAboutDialogPrivate *priv;
2528 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2529 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2530 license_type <= GTK_LICENSE_ARTISTIC);
2534 if (priv->license_type != license_type)
2536 g_object_freeze_notify (G_OBJECT (about));
2538 priv->license_type = license_type;
2540 /* custom licenses use the contents of the :license property */
2541 if (priv->license_type != GTK_LICENSE_CUSTOM)
2546 url = gtk_license_urls[priv->license_type];
2548 url = priv->website_url;
2550 /* compose the new license string as:
2553 * <copyright line 1>\n
2555 * <copyright line n>\n
2557 * license preamble + URL
2560 str = g_string_sized_new (256);
2561 g_string_append (str, priv->name);
2562 g_string_append (str, "\n");
2563 g_string_append (str, priv->copyright);
2564 g_string_append (str, "\n\n");
2565 g_string_append_printf (str, _(gtk_license_preamble), url);
2567 g_free (priv->license);
2568 priv->license = g_string_free (str, FALSE);
2569 priv->wrap_license = TRUE;
2570 gtk_widget_show (priv->license_button);
2572 g_object_notify (G_OBJECT (about), "wrap-license");
2573 g_object_notify (G_OBJECT (about), "license");
2576 g_object_notify (G_OBJECT (about), "license-type");
2578 g_object_thaw_notify (G_OBJECT (about));
2583 * gtk_about_dialog_get_license_type:
2584 * @about: a #GtkAboutDialog
2586 * Retrieves the license set using gtk_about_dialog_set_license_type()
2588 * Return value: a #GtkLicense value
2593 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2595 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2597 return about->priv->license_type;