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_dialog_set_has_separator (dialog, FALSE);
635 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
636 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
637 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
640 gtk_widget_push_composite_child ();
642 vbox = gtk_vbox_new (FALSE, 8);
643 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
644 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
646 priv->logo_image = gtk_image_new ();
647 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
649 priv->name_label = gtk_label_new (NULL);
650 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
651 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
652 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
654 priv->comments_label = gtk_label_new (NULL);
655 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
656 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
657 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
658 gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
660 priv->copyright_label = gtk_label_new (NULL);
661 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
662 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
663 gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
665 hbox = gtk_hbox_new (TRUE, 0);
666 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
668 priv->website_label = button = gtk_label_new ("");
669 gtk_widget_set_no_show_all (button, TRUE);
670 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
671 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
672 g_signal_connect (button, "activate-link",
673 G_CALLBACK (website_clicked), about);
675 gtk_widget_show (vbox);
676 gtk_widget_show (priv->logo_image);
677 gtk_widget_show (priv->name_label);
678 gtk_widget_show (hbox);
680 /* Add the close button */
681 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
682 GTK_RESPONSE_CANCEL);
683 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
685 /* Add the credits button */
686 button = gtk_button_new_with_mnemonic (_("C_redits"));
687 gtk_widget_set_can_default (button, TRUE);
688 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
689 gtk_button_set_image (GTK_BUTTON (button), image);
690 gtk_widget_set_no_show_all (button, TRUE);
691 gtk_box_pack_end (GTK_BOX (action_area),
692 button, FALSE, TRUE, 0);
693 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
694 g_signal_connect (button, "clicked",
695 G_CALLBACK (display_credits_dialog), about);
696 priv->credits_button = button;
697 priv->credits_dialog = NULL;
699 /* Add the license button */
700 button = gtk_button_new_from_stock (_("_License"));
701 gtk_widget_set_can_default (button, TRUE);
702 gtk_widget_set_no_show_all (button, TRUE);
703 gtk_box_pack_end (GTK_BOX (action_area),
704 button, FALSE, TRUE, 0);
705 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
706 g_signal_connect (button, "clicked",
707 G_CALLBACK (display_license_dialog), about);
708 priv->license_button = button;
709 priv->license_dialog = NULL;
711 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
713 gtk_widget_pop_composite_child ();
715 gtk_widget_grab_default (close_button);
716 gtk_widget_grab_focus (close_button);
719 gtk_about_dialog_set_program_name (about, NULL);
720 gtk_about_dialog_set_logo (about, NULL);
724 gtk_about_dialog_finalize (GObject *object)
726 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
727 GtkAboutDialogPrivate *priv = about->priv;
730 g_free (priv->version);
731 g_free (priv->copyright);
732 g_free (priv->comments);
733 g_free (priv->license);
734 g_free (priv->website_url);
735 g_free (priv->website_text);
736 g_free (priv->translator_credits);
738 g_strfreev (priv->authors);
739 g_strfreev (priv->documenters);
740 g_strfreev (priv->artists);
742 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
743 g_slist_free (priv->visited_links);
745 gdk_cursor_unref (priv->hand_cursor);
746 gdk_cursor_unref (priv->regular_cursor);
748 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
752 gtk_about_dialog_set_property (GObject *object,
757 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
758 GtkAboutDialogPrivate *priv = about->priv;
763 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
766 gtk_about_dialog_set_version (about, g_value_get_string (value));
769 gtk_about_dialog_set_comments (about, g_value_get_string (value));
772 gtk_about_dialog_set_website (about, g_value_get_string (value));
774 case PROP_WEBSITE_LABEL:
775 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
778 gtk_about_dialog_set_license (about, g_value_get_string (value));
780 case PROP_LICENSE_TYPE:
781 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
784 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
787 gtk_about_dialog_set_logo (about, g_value_get_object (value));
790 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
792 case PROP_DOCUMENTERS:
793 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
796 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
798 case PROP_TRANSLATOR_CREDITS:
799 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
801 case PROP_LOGO_ICON_NAME:
802 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
804 case PROP_WRAP_LICENSE:
805 priv->wrap_license = g_value_get_boolean (value);
808 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
814 gtk_about_dialog_get_property (GObject *object,
819 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
820 GtkAboutDialogPrivate *priv = about->priv;
825 g_value_set_string (value, priv->name);
828 g_value_set_string (value, priv->version);
831 g_value_set_string (value, priv->copyright);
834 g_value_set_string (value, priv->comments);
837 g_value_set_string (value, priv->website_url);
839 case PROP_WEBSITE_LABEL:
840 g_value_set_string (value, priv->website_text);
843 g_value_set_string (value, priv->license);
845 case PROP_LICENSE_TYPE:
846 g_value_set_enum (value, priv->license_type);
848 case PROP_TRANSLATOR_CREDITS:
849 g_value_set_string (value, priv->translator_credits);
852 g_value_set_boxed (value, priv->authors);
854 case PROP_DOCUMENTERS:
855 g_value_set_boxed (value, priv->documenters);
858 g_value_set_boxed (value, priv->artists);
861 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
862 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
864 g_value_set_object (value, NULL);
866 case PROP_LOGO_ICON_NAME:
867 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
869 const gchar *icon_name;
871 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
872 g_value_set_string (value, icon_name);
875 g_value_set_string (value, NULL);
877 case PROP_WRAP_LICENSE:
878 g_value_set_boolean (value, priv->wrap_license);
881 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
887 update_website (GtkAboutDialog *about)
889 GtkAboutDialogPrivate *priv = about->priv;
891 gtk_widget_show (priv->website_label);
893 if (priv->website_url && (!activate_url_hook_set || activate_url_hook != NULL))
897 if (priv->website_text)
901 escaped = g_markup_escape_text (priv->website_text, -1);
902 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
903 priv->website_url, escaped);
908 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
909 priv->website_url, priv->website_url);
912 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
917 if (priv->website_url)
918 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
919 else if (priv->website_text)
920 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
922 gtk_widget_hide (priv->website_label);
927 gtk_about_dialog_show (GtkWidget *widget)
929 update_website (GTK_ABOUT_DIALOG (widget));
931 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
935 * gtk_about_dialog_get_program_name:
936 * @about: a #GtkAboutDialog
938 * Returns the program name displayed in the about dialog.
940 * Return value: The program name. The string is owned by the about
941 * dialog and must not be modified.
945 G_CONST_RETURN gchar *
946 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
948 GtkAboutDialogPrivate *priv;
950 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
958 update_name_version (GtkAboutDialog *about)
960 GtkAboutDialogPrivate *priv;
961 gchar *title_string, *name_string;
965 title_string = g_strdup_printf (_("About %s"), priv->name);
966 gtk_window_set_title (GTK_WINDOW (about), title_string);
967 g_free (title_string);
969 if (priv->version != NULL)
970 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
971 priv->name, priv->version);
973 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
976 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
978 g_free (name_string);
982 * gtk_about_dialog_set_program_name:
983 * @about: a #GtkAboutDialog
984 * @name: the program name
986 * Sets the name to display in the about dialog.
987 * If this is not set, it defaults to g_get_application_name().
992 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
995 GtkAboutDialogPrivate *priv;
998 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1003 priv->name = g_strdup (name ? name : g_get_application_name ());
1006 update_name_version (about);
1008 g_object_notify (G_OBJECT (about), "program-name");
1013 * gtk_about_dialog_get_version:
1014 * @about: a #GtkAboutDialog
1016 * Returns the version string.
1018 * Return value: The version string. The string is owned by the about
1019 * dialog and must not be modified.
1023 G_CONST_RETURN gchar *
1024 gtk_about_dialog_get_version (GtkAboutDialog *about)
1026 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1028 return about->priv->version;
1032 * gtk_about_dialog_set_version:
1033 * @about: a #GtkAboutDialog
1034 * @version: (allow-none): the version string
1036 * Sets the version string to display in the about dialog.
1041 gtk_about_dialog_set_version (GtkAboutDialog *about,
1042 const gchar *version)
1044 GtkAboutDialogPrivate *priv;
1047 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1051 tmp = priv->version;
1052 priv->version = g_strdup (version);
1055 update_name_version (about);
1057 g_object_notify (G_OBJECT (about), "version");
1061 * gtk_about_dialog_get_copyright:
1062 * @about: a #GtkAboutDialog
1064 * Returns the copyright string.
1066 * Return value: The copyright string. The string is owned by the about
1067 * dialog and must not be modified.
1071 G_CONST_RETURN gchar *
1072 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1074 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1076 return about->priv->copyright;
1080 * gtk_about_dialog_set_copyright:
1081 * @about: a #GtkAboutDialog
1082 * @copyright: (allow-none) the copyright string
1084 * Sets the copyright string to display in the about dialog.
1085 * This should be a short string of one or two lines.
1090 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1091 const gchar *copyright)
1093 GtkAboutDialogPrivate *priv;
1094 gchar *copyright_string, *tmp;
1096 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1100 tmp = priv->copyright;
1101 priv->copyright = g_strdup (copyright);
1104 if (priv->copyright != NULL)
1106 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1108 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1109 g_free (copyright_string);
1111 gtk_widget_show (priv->copyright_label);
1114 gtk_widget_hide (priv->copyright_label);
1116 g_object_notify (G_OBJECT (about), "copyright");
1120 * gtk_about_dialog_get_comments:
1121 * @about: a #GtkAboutDialog
1123 * Returns the comments string.
1125 * Return value: The comments. The string is owned by the about
1126 * dialog and must not be modified.
1130 G_CONST_RETURN gchar *
1131 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1133 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1135 return about->priv->comments;
1139 * gtk_about_dialog_set_comments:
1140 * @about: a #GtkAboutDialog
1141 * @comments: (allow-none): a comments string
1143 * Sets the comments string to display in the about dialog.
1144 * This should be a short string of one or two lines.
1149 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1150 const gchar *comments)
1152 GtkAboutDialogPrivate *priv;
1155 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1159 tmp = priv->comments;
1162 priv->comments = g_strdup (comments);
1163 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1164 gtk_widget_show (priv->comments_label);
1168 priv->comments = NULL;
1169 gtk_widget_hide (priv->comments_label);
1173 g_object_notify (G_OBJECT (about), "comments");
1177 * gtk_about_dialog_get_license:
1178 * @about: a #GtkAboutDialog
1180 * Returns the license information.
1182 * Return value: The license information. The string is owned by the about
1183 * dialog and must not be modified.
1187 G_CONST_RETURN gchar *
1188 gtk_about_dialog_get_license (GtkAboutDialog *about)
1190 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1192 return about->priv->license;
1196 * gtk_about_dialog_set_license:
1197 * @about: a #GtkAboutDialog
1198 * @license: (allow-none): the license information or %NULL
1200 * Sets the license information to be displayed in the secondary
1201 * license dialog. If @license is %NULL, the license button is
1207 gtk_about_dialog_set_license (GtkAboutDialog *about,
1208 const gchar *license)
1210 GtkAboutDialogPrivate *priv;
1213 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1217 tmp = priv->license;
1220 priv->license = g_strdup (license);
1221 priv->license_type = GTK_LICENSE_CUSTOM;
1222 gtk_widget_show (priv->license_button);
1226 priv->license = NULL;
1227 priv->license_type = GTK_LICENSE_UNKNOWN;
1228 gtk_widget_hide (priv->license_button);
1232 g_object_notify (G_OBJECT (about), "license");
1233 g_object_notify (G_OBJECT (about), "license-type");
1237 * gtk_about_dialog_get_wrap_license:
1238 * @about: a #GtkAboutDialog
1240 * Returns whether the license text in @about is
1241 * automatically wrapped.
1243 * Returns: %TRUE if the license text is wrapped
1248 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1250 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1252 return about->priv->wrap_license;
1256 * gtk_about_dialog_set_wrap_license:
1257 * @about: a #GtkAboutDialog
1258 * @wrap_license: whether to wrap the license
1260 * Sets whether the license text in @about is
1261 * automatically wrapped.
1266 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1267 gboolean wrap_license)
1269 GtkAboutDialogPrivate *priv;
1271 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1275 wrap_license = wrap_license != FALSE;
1277 if (priv->wrap_license != wrap_license)
1279 priv->wrap_license = wrap_license;
1281 g_object_notify (G_OBJECT (about), "wrap-license");
1286 * gtk_about_dialog_get_website:
1287 * @about: a #GtkAboutDialog
1289 * Returns the website URL.
1291 * Return value: The website URL. The string is owned by the about
1292 * dialog and must not be modified.
1296 G_CONST_RETURN gchar *
1297 gtk_about_dialog_get_website (GtkAboutDialog *about)
1299 GtkAboutDialogPrivate *priv;
1301 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1305 return priv->website_url;
1309 * gtk_about_dialog_set_website:
1310 * @about: a #GtkAboutDialog
1311 * @website: (allow-none): a URL string starting with "http://"
1313 * Sets the URL to use for the website link.
1315 * Note that that the hook functions need to be set up
1316 * before calling this function.
1321 gtk_about_dialog_set_website (GtkAboutDialog *about,
1322 const gchar *website)
1324 GtkAboutDialogPrivate *priv;
1327 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1331 tmp = priv->website_url;
1332 priv->website_url = g_strdup (website);
1335 update_website (about);
1337 g_object_notify (G_OBJECT (about), "website");
1341 * gtk_about_dialog_get_website_label:
1342 * @about: a #GtkAboutDialog
1344 * Returns the label used for the website link.
1346 * Return value: The label used for the website link. The string is
1347 * owned by the about dialog and must not be modified.
1351 G_CONST_RETURN gchar *
1352 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1354 GtkAboutDialogPrivate *priv;
1356 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1360 return priv->website_text;
1364 * gtk_about_dialog_set_website_label:
1365 * @about: a #GtkAboutDialog
1366 * @website_label: the label used for the website link
1368 * Sets the label to be used for the website link.
1369 * It defaults to the website URL.
1374 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1375 const gchar *website_label)
1377 GtkAboutDialogPrivate *priv;
1380 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1384 tmp = priv->website_text;
1385 priv->website_text = g_strdup (website_label);
1388 update_website (about);
1390 g_object_notify (G_OBJECT (about), "website-label");
1394 * gtk_about_dialog_get_authors:
1395 * @about: a #GtkAboutDialog
1397 * Returns the string which are displayed in the authors tab
1398 * of the secondary credits dialog.
1400 * Return value: A %NULL-terminated string array containing
1401 * the authors. The array is owned by the about dialog
1402 * and must not be modified.
1406 G_CONST_RETURN gchar * G_CONST_RETURN *
1407 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1409 GtkAboutDialogPrivate *priv;
1411 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1415 return (const gchar * const *) priv->authors;
1419 update_credits_button_visibility (GtkAboutDialog *about)
1421 GtkAboutDialogPrivate *priv = about->priv;
1424 show = priv->authors != NULL ||
1425 priv->documenters != NULL ||
1426 priv->artists != NULL ||
1427 (priv->translator_credits != NULL &&
1428 strcmp (priv->translator_credits, "translator_credits") &&
1429 strcmp (priv->translator_credits, "translator-credits"));
1431 gtk_widget_show (priv->credits_button);
1433 gtk_widget_hide (priv->credits_button);
1437 * gtk_about_dialog_set_authors:
1438 * @about: a #GtkAboutDialog
1439 * @authors: a %NULL-terminated array of strings
1441 * Sets the strings which are displayed in the authors tab
1442 * of the secondary credits dialog.
1447 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1448 const gchar **authors)
1450 GtkAboutDialogPrivate *priv;
1453 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1457 tmp = priv->authors;
1458 priv->authors = g_strdupv ((gchar **)authors);
1461 update_credits_button_visibility (about);
1463 g_object_notify (G_OBJECT (about), "authors");
1467 * gtk_about_dialog_get_documenters:
1468 * @about: a #GtkAboutDialog
1470 * Returns the string which are displayed in the documenters
1471 * tab of the secondary credits dialog.
1473 * Return value: A %NULL-terminated string array containing
1474 * the documenters. The array is owned by the about dialog
1475 * and must not be modified.
1479 G_CONST_RETURN gchar * G_CONST_RETURN *
1480 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1482 GtkAboutDialogPrivate *priv;
1484 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1488 return (const gchar * const *)priv->documenters;
1492 * gtk_about_dialog_set_documenters:
1493 * @about: a #GtkAboutDialog
1494 * @documenters: a %NULL-terminated array of strings
1496 * Sets the strings which are displayed in the documenters tab
1497 * of the secondary credits dialog.
1502 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1503 const gchar **documenters)
1505 GtkAboutDialogPrivate *priv;
1508 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1512 tmp = priv->documenters;
1513 priv->documenters = g_strdupv ((gchar **)documenters);
1516 update_credits_button_visibility (about);
1518 g_object_notify (G_OBJECT (about), "documenters");
1522 * gtk_about_dialog_get_artists:
1523 * @about: a #GtkAboutDialog
1525 * Returns the string which are displayed in the artists tab
1526 * of the secondary credits dialog.
1528 * Return value: A %NULL-terminated string array containing
1529 * the artists. The array is owned by the about dialog
1530 * and must not be modified.
1534 G_CONST_RETURN gchar * G_CONST_RETURN *
1535 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1537 GtkAboutDialogPrivate *priv;
1539 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1543 return (const gchar * const *)priv->artists;
1547 * gtk_about_dialog_set_artists:
1548 * @about: a #GtkAboutDialog
1549 * @artists: a %NULL-terminated array of strings
1551 * Sets the strings which are displayed in the artists tab
1552 * of the secondary credits dialog.
1557 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1558 const gchar **artists)
1560 GtkAboutDialogPrivate *priv;
1563 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1567 tmp = priv->artists;
1568 priv->artists = g_strdupv ((gchar **)artists);
1571 update_credits_button_visibility (about);
1573 g_object_notify (G_OBJECT (about), "artists");
1577 * gtk_about_dialog_get_translator_credits:
1578 * @about: a #GtkAboutDialog
1580 * Returns the translator credits string which is displayed
1581 * in the translators tab of the secondary credits dialog.
1583 * Return value: The translator credits string. The string is
1584 * owned by the about dialog and must not be modified.
1588 G_CONST_RETURN gchar *
1589 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1591 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1593 return about->priv->translator_credits;
1597 * gtk_about_dialog_set_translator_credits:
1598 * @about: a #GtkAboutDialog
1599 * @translator_credits: (allow-none): the translator credits
1601 * Sets the translator credits string which is displayed in
1602 * the translators tab of the secondary credits dialog.
1604 * The intended use for this string is to display the translator
1605 * of the language which is currently used in the user interface.
1606 * Using gettext(), a simple way to achieve that is to mark the
1607 * string for translation:
1609 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1611 * It is a good idea to use the customary msgid "translator-credits" for this
1612 * purpose, since translators will already know the purpose of that msgid, and
1613 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1619 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1620 const gchar *translator_credits)
1622 GtkAboutDialogPrivate *priv;
1625 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1629 tmp = priv->translator_credits;
1630 priv->translator_credits = g_strdup (translator_credits);
1633 update_credits_button_visibility (about);
1635 g_object_notify (G_OBJECT (about), "translator-credits");
1639 * gtk_about_dialog_get_logo:
1640 * @about: a #GtkAboutDialog
1642 * Returns the pixbuf displayed as logo in the about dialog.
1644 * Return value: the pixbuf displayed as logo. The pixbuf is
1645 * owned by the about dialog. If you want to keep a reference
1646 * to it, you have to call g_object_ref() on it.
1651 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1653 GtkAboutDialogPrivate *priv;
1655 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1659 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1660 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1666 icon_set_new_from_pixbufs (GList *pixbufs)
1668 GtkIconSet *icon_set = gtk_icon_set_new ();
1670 for (; pixbufs; pixbufs = pixbufs->next)
1672 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1674 GtkIconSource *icon_source = gtk_icon_source_new ();
1675 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1676 gtk_icon_set_add_source (icon_set, icon_source);
1677 gtk_icon_source_free (icon_source);
1684 * gtk_about_dialog_set_logo:
1685 * @about: a #GtkAboutDialog
1686 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1688 * Sets the pixbuf to be displayed as logo in the about dialog.
1689 * If it is %NULL, the default window icon set with
1690 * gtk_window_set_default_icon() will be used.
1695 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1698 GtkAboutDialogPrivate *priv;
1700 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1704 g_object_freeze_notify (G_OBJECT (about));
1706 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1707 g_object_notify (G_OBJECT (about), "logo-icon-name");
1710 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1713 GList *pixbufs = gtk_window_get_default_icon_list ();
1715 if (pixbufs != NULL)
1717 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1719 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1720 icon_set, GTK_ICON_SIZE_DIALOG);
1722 gtk_icon_set_unref (icon_set);
1723 g_list_free (pixbufs);
1727 g_object_notify (G_OBJECT (about), "logo");
1729 g_object_thaw_notify (G_OBJECT (about));
1733 * gtk_about_dialog_get_logo_icon_name:
1734 * @about: a #GtkAboutDialog
1736 * Returns the icon name displayed as logo in the about dialog.
1738 * Return value: the icon name displayed as logo. The string is
1739 * owned by the dialog. If you want to keep a reference
1740 * to it, you have to call g_strdup() on it.
1744 G_CONST_RETURN gchar *
1745 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1747 GtkAboutDialogPrivate *priv;
1748 const gchar *icon_name = NULL;
1750 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1754 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1755 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1761 * gtk_about_dialog_set_logo_icon_name:
1762 * @about: a #GtkAboutDialog
1763 * @icon_name: (allow-none): an icon name, or %NULL
1765 * Sets the pixbuf to be displayed as logo in the about dialog.
1766 * If it is %NULL, the default window icon set with
1767 * gtk_window_set_default_icon() will be used.
1772 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1773 const gchar *icon_name)
1775 GtkAboutDialogPrivate *priv;
1777 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1781 g_object_freeze_notify (G_OBJECT (about));
1783 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1784 g_object_notify (G_OBJECT (about), "logo");
1786 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1787 GTK_ICON_SIZE_DIALOG);
1788 g_object_notify (G_OBJECT (about), "logo-icon-name");
1790 g_object_thaw_notify (G_OBJECT (about));
1794 follow_if_link (GtkAboutDialog *about,
1795 GtkTextView *text_view,
1798 GSList *tags = NULL, *tagp = NULL;
1799 GtkAboutDialogPrivate *priv = about->priv;
1801 GtkAboutDialogActivateLinkFunc email_hook, url_hook;
1802 gpointer email_hook_data, url_hook_data;
1804 if (activate_email_hook_set)
1806 email_hook = activate_email_hook;
1807 email_hook_data = activate_email_hook_data;
1811 email_hook = default_email_hook;
1812 email_hook_data = NULL;
1815 if (activate_url_hook_set)
1817 url_hook = activate_url_hook;
1818 url_hook_data = activate_url_hook_data;
1822 url_hook = default_url_hook;
1823 url_hook_data = NULL;
1826 tags = gtk_text_iter_get_tags (iter);
1827 for (tagp = tags; tagp != NULL && !url; tagp = tagp->next)
1829 GtkTextTag *tag = tagp->data;
1831 if (email_hook != NULL)
1833 url = g_object_get_data (G_OBJECT (tag), "email");
1835 email_hook (about, url, email_hook_data);
1838 if (!url && url_hook != NULL)
1840 url = g_object_get_data (G_OBJECT (tag), "url");
1842 url_hook (about, url, url_hook_data);
1845 if (url && !g_slist_find_custom (priv->visited_links, url, (GCompareFunc)strcmp))
1847 GdkColor *style_visited_link_color;
1850 gtk_widget_ensure_style (GTK_WIDGET (about));
1851 gtk_widget_style_get (GTK_WIDGET (about),
1852 "visited-link-color", &style_visited_link_color,
1854 if (style_visited_link_color)
1856 color = *style_visited_link_color;
1857 gdk_color_free (style_visited_link_color);
1860 color = default_visited_link_color;
1862 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1864 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (url));
1869 g_slist_free (tags);
1873 text_view_key_press_event (GtkWidget *text_view,
1875 GtkAboutDialog *about)
1878 GtkTextBuffer *buffer;
1880 switch (event->keyval)
1885 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1886 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1887 gtk_text_buffer_get_insert (buffer));
1888 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1899 text_view_event_after (GtkWidget *text_view,
1901 GtkAboutDialog *about)
1903 GtkTextIter start, end, iter;
1904 GtkTextBuffer *buffer;
1905 GdkEventButton *button_event;
1908 if (event->type != GDK_BUTTON_RELEASE)
1911 button_event = (GdkEventButton *)event;
1913 if (button_event->button != 1)
1916 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1918 /* we shouldn't follow a link if the user has selected something */
1919 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1920 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1923 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1924 GTK_TEXT_WINDOW_WIDGET,
1925 button_event->x, button_event->y, &x, &y);
1927 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1929 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1935 set_cursor_if_appropriate (GtkAboutDialog *about,
1936 GtkTextView *text_view,
1941 GtkAboutDialogPrivate *priv = about->priv;
1942 GSList *tags = NULL, *tagp = NULL;
1944 gboolean hovering_over_link = FALSE;
1946 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1948 tags = gtk_text_iter_get_tags (&iter);
1949 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1951 GtkTextTag *tag = tagp->data;
1952 gchar *email = g_object_get_data (G_OBJECT (tag), "email");
1953 gchar *url = g_object_get_data (G_OBJECT (tag), "url");
1955 if (email != NULL || url != NULL)
1957 hovering_over_link = TRUE;
1962 if (hovering_over_link != priv->hovering_over_link)
1964 priv->hovering_over_link = hovering_over_link;
1966 if (hovering_over_link)
1967 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1969 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
1973 g_slist_free (tags);
1977 text_view_motion_notify_event (GtkWidget *text_view,
1978 GdkEventMotion *event,
1979 GtkAboutDialog *about)
1983 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1984 GTK_TEXT_WINDOW_WIDGET,
1985 event->x, event->y, &x, &y);
1987 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
1989 gdk_event_request_motions (event);
1996 text_view_visibility_notify_event (GtkWidget *text_view,
1997 GdkEventVisibility *event,
1998 GtkAboutDialog *about)
2000 GdkDeviceManager *device_manager;
2001 GdkDisplay *display;
2003 gint wx, wy, bx, by;
2005 display = gdk_drawable_get_display (event->window);
2006 device_manager = gdk_display_get_device_manager (display);
2007 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2009 for (d = devices; d; d = d->next)
2011 GdkDevice *dev = d->data;
2013 gdk_window_get_device_position (text_view->window, dev, &wx, &wy, NULL);
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_dialog_set_has_separator (credits_dialog, FALSE);
2222 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2223 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2224 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2226 priv->credits_dialog = dialog;
2227 gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2228 gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2230 gtk_window_set_modal (GTK_WINDOW (dialog),
2231 gtk_window_get_modal (GTK_WINDOW (about)));
2233 g_signal_connect (dialog, "response",
2234 G_CALLBACK (gtk_widget_destroy), dialog);
2235 g_signal_connect (dialog, "destroy",
2236 G_CALLBACK (gtk_widget_destroyed),
2237 &(priv->credits_dialog));
2239 notebook = gtk_notebook_new ();
2240 gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2241 gtk_box_pack_start (GTK_BOX (content_area), notebook, TRUE, TRUE, 0);
2243 if (priv->authors != NULL)
2244 add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2246 if (priv->documenters != NULL)
2247 add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2249 /* Don't show an untranslated gettext msgid */
2250 if (priv->translator_credits != NULL &&
2251 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2252 strcmp (priv->translator_credits, "translator-credits") != 0)
2254 gchar *translators[2];
2256 translators[0] = priv->translator_credits;
2257 translators[1] = NULL;
2259 add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2262 if (priv->artists != NULL)
2263 add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2265 gtk_widget_show_all (dialog);
2269 set_policy (GtkWidget *sw)
2271 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2272 GTK_POLICY_AUTOMATIC,
2273 GTK_POLICY_AUTOMATIC);
2277 display_license_dialog (GtkWidget *button,
2280 GtkAboutDialog *about = (GtkAboutDialog *)data;
2281 GtkAboutDialogPrivate *priv = about->priv;
2282 GtkWidget *dialog, *view, *sw;
2283 GtkDialog *license_dialog;
2284 GtkWidget *content_area;
2285 GtkWidget *action_area;
2288 if (priv->license_dialog != NULL)
2290 gtk_window_present (GTK_WINDOW (priv->license_dialog));
2294 dialog = gtk_dialog_new_with_buttons (_("License"),
2296 GTK_DIALOG_DESTROY_WITH_PARENT,
2297 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2299 license_dialog = GTK_DIALOG (dialog);
2301 content_area = gtk_dialog_get_content_area (license_dialog);
2302 action_area = gtk_dialog_get_action_area (license_dialog);
2304 gtk_dialog_set_has_separator (license_dialog, FALSE);
2305 gtk_container_set_border_width (GTK_CONTAINER (license_dialog), 5);
2306 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2307 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2309 priv->license_dialog = dialog;
2310 gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2311 gtk_dialog_set_default_response (license_dialog, GTK_RESPONSE_CANCEL);
2313 gtk_window_set_modal (GTK_WINDOW (dialog),
2314 gtk_window_get_modal (GTK_WINDOW (about)));
2316 g_signal_connect (dialog, "response",
2317 G_CALLBACK (gtk_widget_destroy), dialog);
2318 g_signal_connect (dialog, "destroy",
2319 G_CALLBACK (gtk_widget_destroyed),
2320 &(priv->license_dialog));
2322 sw = gtk_scrolled_window_new (NULL, NULL);
2323 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2324 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2326 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2328 GTK_POLICY_AUTOMATIC);
2329 g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2330 gtk_box_pack_start (GTK_BOX (content_area), sw, TRUE, TRUE, 0);
2332 strings[0] = priv->license;
2334 view = text_view_new (about, dialog, strings,
2335 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2337 gtk_container_add (GTK_CONTAINER (sw), view);
2339 gtk_widget_show_all (dialog);
2343 * gtk_about_dialog_new:
2345 * Creates a new #GtkAboutDialog.
2347 * Returns: a newly created #GtkAboutDialog
2352 gtk_about_dialog_new (void)
2354 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2356 return GTK_WIDGET (dialog);
2360 * gtk_about_dialog_set_email_hook:
2361 * @func: a function to call when an email link is activated.
2362 * @data: data to pass to @func
2363 * @destroy: #GDestroyNotify for @data
2365 * Installs a global function to be called whenever the user activates an
2366 * email link in an about dialog.
2368 * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2369 * deactivate it, you can pass %NULL for @func.
2371 * Return value: the previous email hook.
2375 GtkAboutDialogActivateLinkFunc
2376 gtk_about_dialog_set_email_hook (GtkAboutDialogActivateLinkFunc func,
2378 GDestroyNotify destroy)
2380 GtkAboutDialogActivateLinkFunc old;
2382 if (activate_email_hook_destroy != NULL)
2383 (* activate_email_hook_destroy) (activate_email_hook_data);
2385 old = activate_email_hook;
2387 activate_email_hook_set = TRUE;
2388 activate_email_hook = func;
2389 activate_email_hook_data = data;
2390 activate_email_hook_destroy = destroy;
2396 * gtk_about_dialog_set_url_hook:
2397 * @func: a function to call when a URL link is activated.
2398 * @data: data to pass to @func
2399 * @destroy: #GDestroyNotify for @data
2401 * Installs a global function to be called whenever the user activates a
2402 * URL link in an about dialog.
2404 * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2405 * deactivate it, you can pass %NULL for @func.
2407 * Return value: the previous URL hook.
2411 GtkAboutDialogActivateLinkFunc
2412 gtk_about_dialog_set_url_hook (GtkAboutDialogActivateLinkFunc func,
2414 GDestroyNotify destroy)
2416 GtkAboutDialogActivateLinkFunc old;
2418 if (activate_url_hook_destroy != NULL)
2419 (* activate_url_hook_destroy) (activate_url_hook_data);
2421 old = activate_url_hook;
2423 activate_url_hook_set = TRUE;
2424 activate_url_hook = func;
2425 activate_url_hook_data = data;
2426 activate_url_hook_destroy = destroy;
2432 close_cb (GtkAboutDialog *about)
2434 GtkAboutDialogPrivate *priv = about->priv;
2436 if (priv->license_dialog != NULL)
2438 gtk_widget_destroy (priv->license_dialog);
2439 priv->license_dialog = NULL;
2442 if (priv->credits_dialog != NULL)
2444 gtk_widget_destroy (priv->credits_dialog);
2445 priv->credits_dialog = NULL;
2448 gtk_widget_hide (GTK_WIDGET (about));
2453 * gtk_show_about_dialog:
2454 * @parent: (allow-none): transient parent, or %NULL for none
2455 * @first_property_name: the name of the first property
2456 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2458 * This is a convenience function for showing an application's about box.
2459 * The constructed dialog is associated with the parent window and
2460 * reused for future invocations of this function.
2465 gtk_show_about_dialog (GtkWindow *parent,
2466 const gchar *first_property_name,
2469 static GtkWidget *global_about_dialog = NULL;
2470 GtkWidget *dialog = NULL;
2474 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2476 dialog = global_about_dialog;
2480 dialog = gtk_about_dialog_new ();
2482 g_object_ref_sink (dialog);
2484 g_signal_connect (dialog, "delete-event",
2485 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2487 /* Close dialog on user response */
2488 g_signal_connect (dialog, "response",
2489 G_CALLBACK (close_cb), NULL);
2491 va_start (var_args, first_property_name);
2492 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2497 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2498 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2499 g_object_set_data_full (G_OBJECT (parent),
2500 I_("gtk-about-dialog"),
2501 dialog, g_object_unref);
2504 global_about_dialog = dialog;
2508 gtk_window_present (GTK_WINDOW (dialog));
2512 * gtk_about_dialog_set_license_type:
2513 * @about: a #GtkAboutDialog
2514 * @license_type: the type of license
2516 * Sets the license of the application showing the @about dialog from a
2517 * list of known licenses.
2519 * This function overrides the license set using
2520 * gtk_about_dialog_set_license().
2525 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2526 GtkLicense license_type)
2528 GtkAboutDialogPrivate *priv;
2530 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2531 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2532 license_type <= GTK_LICENSE_ARTISTIC);
2536 if (priv->license_type != license_type)
2538 g_object_freeze_notify (G_OBJECT (about));
2540 priv->license_type = license_type;
2542 /* custom licenses use the contents of the :license property */
2543 if (priv->license_type != GTK_LICENSE_CUSTOM)
2548 url = gtk_license_urls[priv->license_type];
2550 url = priv->website_url;
2552 /* compose the new license string as:
2554 * <program-name> <copyright>\n
2555 * license preamble + URL
2558 str = g_string_sized_new (256);
2559 g_string_append (str, priv->name);
2560 g_string_append (str, " ");
2561 g_string_append (str, priv->copyright);
2562 g_string_append (str, "\n");
2563 g_string_append_printf (str, gettext (gtk_license_preamble), url);
2565 g_free (priv->license);
2566 priv->license = g_string_free (str, FALSE);
2567 priv->wrap_license = TRUE;
2568 gtk_widget_show (priv->license_button);
2570 g_object_notify (G_OBJECT (about), "wrap-license");
2571 g_object_notify (G_OBJECT (about), "license");
2574 g_object_notify (G_OBJECT (about), "license-type");
2576 g_object_thaw_notify (G_OBJECT (about));
2581 * gtk_about_dialog_get_license_type:
2582 * @about: a #GtkAboutDialog
2584 * Retrieves the license set using gtk_about_dialog_set_license_type()
2586 * Return value: a #GtkLicense value
2591 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2593 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2595 return about->priv->license_type;