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"
62 * SECTION:gtkaboutdialog
63 * @Short_description: Display information about an application
64 * @Title: GtkAboutDialog
65 * @See_also:#GTK_STOCK_ABOUT
67 * The #GtkAboutDialog offers a simple way to display information about
68 * a program like its logo, name, copyright, website and license. It is
69 * also possible to give credits to the authors, documenters, translators
70 * and artists who have worked on the program. An about dialog is typically
71 * opened when the user selects the <literal>About</literal> option from
72 * the <literal>Help</literal> menu. All parts of the dialog are optional.
74 * About dialog often contain links and email addresses. #GtkAboutDialog
75 * supports this by offering global hooks, which are called when the user
76 * clicks on a link or email address, see gtk_about_dialog_set_email_hook()
77 * and gtk_about_dialog_set_url_hook(). Email addresses in the
78 * authors, documenters and artists properties are recognized by looking for
79 * <literal><user@<!-- -->host></literal>, URLs are
80 * recognized by looking for <literal>http://url</literal>, with
81 * <literal>url</literal> extending to the next space, tab or line break.
83 * <para id="gtk-about-dialog-hook-setup">
84 * Since 2.18 #GtkAboutDialog provides default website and email hooks that
88 * If you want provide your own hooks overriding the default ones, it is
89 * important to do so before setting the website and email URL properties,
91 * <informalexample><programlisting>
92 * gtk_about_dialog_set_url_hook (GTK_ABOUT_DIALOG (dialog), launch_url, NULL, NULL);
93 * gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), app_url);
94 * </programlisting></informalexample>
95 * To disable the default hooks, you can pass %NULL as the hook func. Then,
96 * the #GtkAboutDialog widget will not display the website or the
97 * email addresses as clickable.
99 * To make constructing a #GtkAboutDialog as convenient as possible, you can
100 * use the function gtk_show_about_dialog() which constructs and shows a dialog
101 * and keeps it around so that it can be shown again.
103 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
104 * on the dialog window (where %s is replaced by the name of the
105 * application, but in order to ensure proper translation of the title,
106 * applications should set the title property explicitly when constructing
107 * a #GtkAboutDialog, as shown in the following example:
108 * <informalexample><programlisting>
109 * gtk_show_about_dialog (NULL,
110 * "program-name", "ExampleCode",
111 * "logo", example_logo,
112 * "title" _("About ExampleCode"),
114 * </programlisting></informalexample>
115 * Note that prior to GTK+ 2.12, the #GtkAboutDialog:program-name property
116 * was called "name". This was changed to avoid the conflict with the
117 * #GtkWidget:name property.
121 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
122 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
124 struct _GtkAboutDialogPrivate
132 gchar *translator_credits;
139 GtkWidget *logo_image;
140 GtkWidget *name_label;
141 GtkWidget *comments_label;
142 GtkWidget *copyright_label;
143 GtkWidget *website_label;
145 GtkWidget *credits_button;
146 GtkWidget *credits_dialog;
147 GtkWidget *license_button;
148 GtkWidget *license_dialog;
150 GdkCursor *hand_cursor;
151 GdkCursor *regular_cursor;
153 GSList *visited_links;
155 guint hovering_over_link : 1;
156 guint wrap_license : 1;
159 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
174 PROP_TRANSLATOR_CREDITS,
181 static void gtk_about_dialog_finalize (GObject *object);
182 static void gtk_about_dialog_get_property (GObject *object,
186 static void gtk_about_dialog_set_property (GObject *object,
190 static void gtk_about_dialog_show (GtkWidget *widge);
191 static void update_name_version (GtkAboutDialog *about);
192 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
193 static void follow_if_link (GtkAboutDialog *about,
194 GtkTextView *text_view,
196 static void set_cursor_if_appropriate (GtkAboutDialog *about,
197 GtkTextView *text_view,
200 static void display_credits_dialog (GtkWidget *button,
202 static void display_license_dialog (GtkWidget *button,
204 static void close_cb (GtkAboutDialog *about);
205 static void default_url_hook (GtkAboutDialog *about,
208 static void default_email_hook (GtkAboutDialog *about,
209 const gchar *email_address,
212 static gboolean activate_email_hook_set = FALSE;
213 static GtkAboutDialogActivateLinkFunc activate_email_hook = NULL;
214 static gpointer activate_email_hook_data = NULL;
215 static GDestroyNotify activate_email_hook_destroy = NULL;
217 static gboolean activate_url_hook_set = FALSE;
218 static GtkAboutDialogActivateLinkFunc activate_url_hook = NULL;
219 static gpointer activate_url_hook_data = NULL;
220 static GDestroyNotify activate_url_hook_destroy = NULL;
223 default_url_hook (GtkAboutDialog *about,
228 GError *error = NULL;
230 screen = gtk_widget_get_screen (GTK_WIDGET (about));
232 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
236 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
237 GTK_DIALOG_DESTROY_WITH_PARENT |
241 "%s", _("Could not show link"));
242 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
243 "%s", error->message);
244 g_error_free (error);
246 g_signal_connect (dialog, "response",
247 G_CALLBACK (gtk_widget_destroy), NULL);
249 gtk_window_present (GTK_WINDOW (dialog));
254 default_email_hook (GtkAboutDialog *about,
255 const gchar *email_address,
260 escaped = g_uri_escape_string (email_address, NULL, FALSE);
261 uri = g_strdup_printf ("mailto:%s", escaped);
264 default_url_hook (about, uri, user_data);
268 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
271 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
273 GObjectClass *object_class;
274 GtkWidgetClass *widget_class;
276 object_class = (GObjectClass *)klass;
277 widget_class = (GtkWidgetClass *)klass;
279 object_class->set_property = gtk_about_dialog_set_property;
280 object_class->get_property = gtk_about_dialog_get_property;
282 object_class->finalize = gtk_about_dialog_finalize;
284 widget_class->show = gtk_about_dialog_show;
287 * GtkAboutDialog:program-name:
289 * The name of the program.
290 * If this is not set, it defaults to g_get_application_name().
294 g_object_class_install_property (object_class,
296 g_param_spec_string ("program-name",
298 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
300 GTK_PARAM_READWRITE));
303 * GtkAboutDialog:version:
305 * The version of the program.
309 g_object_class_install_property (object_class,
311 g_param_spec_string ("version",
312 P_("Program version"),
313 P_("The version of the program"),
315 GTK_PARAM_READWRITE));
318 * GtkAboutDialog:copyright:
320 * Copyright information for the program.
324 g_object_class_install_property (object_class,
326 g_param_spec_string ("copyright",
327 P_("Copyright string"),
328 P_("Copyright information for the program"),
330 GTK_PARAM_READWRITE));
334 * GtkAboutDialog:comments:
336 * Comments about the program. This string is displayed in a label
337 * in the main dialog, thus it should be a short explanation of
338 * the main purpose of the program, not a detailed list of features.
342 g_object_class_install_property (object_class,
344 g_param_spec_string ("comments",
345 P_("Comments string"),
346 P_("Comments about the program"),
348 GTK_PARAM_READWRITE));
351 * GtkAboutDialog:license:
353 * The license of the program. This string is displayed in a
354 * text view in a secondary dialog, therefore it is fine to use
355 * a long multi-paragraph text. Note that the text is only wrapped
356 * in the text view if the "wrap-license" property is set to %TRUE;
357 * otherwise the text itself must contain the intended linebreaks.
361 g_object_class_install_property (object_class,
363 g_param_spec_string ("license",
365 _("The license of the program"),
367 GTK_PARAM_READWRITE));
370 * GtkAboutDialog:website:
372 * The URL for the link to the website of the program.
373 * This should be a string starting with "http://.
377 g_object_class_install_property (object_class,
379 g_param_spec_string ("website",
381 P_("The URL for the link to the website of the program"),
383 GTK_PARAM_READWRITE));
386 * GtkAboutDialog:website-label:
388 * The label for the link to the website of the program. If this is not set,
389 * it defaults to the URL specified in the #GtkAboutDialog:website property.
393 g_object_class_install_property (object_class,
395 g_param_spec_string ("website-label",
397 P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
399 GTK_PARAM_READWRITE));
402 * GtkAboutDialog:authors:
404 * The authors of the program, as a %NULL-terminated array of strings.
405 * Each string may contain email addresses and URLs, which will be displayed
406 * as links, see the introduction for more details.
410 g_object_class_install_property (object_class,
412 g_param_spec_boxed ("authors",
414 P_("List of authors of the program"),
416 GTK_PARAM_READWRITE));
419 * GtkAboutDialog:documenters:
421 * The people documenting the program, as a %NULL-terminated array of strings.
422 * Each string may contain email addresses and URLs, which will be displayed
423 * as links, see the introduction for more details.
427 g_object_class_install_property (object_class,
429 g_param_spec_boxed ("documenters",
431 P_("List of people documenting the program"),
433 GTK_PARAM_READWRITE));
436 * GtkAboutDialog:artists:
438 * The people who contributed artwork to the program, as a %NULL-terminated
439 * array of strings. Each string may contain email addresses and URLs, which
440 * will be displayed as links, see the introduction for more details.
444 g_object_class_install_property (object_class,
446 g_param_spec_boxed ("artists",
448 P_("List of people who have contributed artwork to the program"),
450 GTK_PARAM_READWRITE));
454 * GtkAboutDialog:translator-credits:
456 * Credits to the translators. This string should be marked as translatable.
457 * The string may contain email addresses and URLs, which will be displayed
458 * as links, see the introduction for more details.
462 g_object_class_install_property (object_class,
463 PROP_TRANSLATOR_CREDITS,
464 g_param_spec_string ("translator-credits",
465 P_("Translator credits"),
466 P_("Credits to the translators. This string should be marked as translatable"),
468 GTK_PARAM_READWRITE));
471 * GtkAboutDialog:logo:
473 * A logo for the about box. If this is not set, it defaults to
474 * gtk_window_get_default_icon_list().
478 g_object_class_install_property (object_class,
480 g_param_spec_object ("logo",
482 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
484 GTK_PARAM_READWRITE));
487 * GtkAboutDialog:logo-icon-name:
489 * A named icon to use as the logo for the about box. This property
490 * overrides the #GtkAboutDialog:logo property.
494 g_object_class_install_property (object_class,
496 g_param_spec_string ("logo-icon-name",
497 P_("Logo Icon Name"),
498 P_("A named icon to use as the logo for the about box."),
500 GTK_PARAM_READWRITE));
502 * GtkAboutDialog:wrap-license:
504 * Whether to wrap the text in the license dialog.
508 g_object_class_install_property (object_class,
510 g_param_spec_boolean ("wrap-license",
512 P_("Whether to wrap the license text."),
514 GTK_PARAM_READWRITE));
517 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
521 website_clicked (GtkLabel *label,
523 GtkAboutDialog *about)
525 GtkAboutDialogActivateLinkFunc url_hook;
526 gpointer url_hook_data;
528 if (activate_url_hook_set)
530 url_hook = activate_url_hook;
531 url_hook_data = activate_url_hook_data;
535 url_hook = default_url_hook;
536 url_hook_data = NULL;
539 url_hook (about, uri, url_hook_data);
545 gtk_about_dialog_init (GtkAboutDialog *about)
547 GtkDialog *dialog = GTK_DIALOG (about);
548 GtkAboutDialogPrivate *priv;
549 GtkWidget *vbox, *hbox, *button, *close_button, *image;
552 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
556 priv->version = NULL;
557 priv->copyright = NULL;
558 priv->comments = NULL;
559 priv->website_url = NULL;
560 priv->website_text = NULL;
561 priv->translator_credits = NULL;
562 priv->license = NULL;
563 priv->authors = NULL;
564 priv->documenters = NULL;
565 priv->artists = NULL;
567 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
568 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
569 priv->hovering_over_link = FALSE;
570 priv->wrap_license = FALSE;
572 gtk_dialog_set_has_separator (dialog, FALSE);
573 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
574 gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
575 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
578 gtk_widget_push_composite_child ();
580 vbox = gtk_vbox_new (FALSE, 8);
581 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
582 gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
584 priv->logo_image = gtk_image_new ();
585 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
587 priv->name_label = gtk_label_new (NULL);
588 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
589 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
590 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
592 priv->comments_label = gtk_label_new (NULL);
593 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
594 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
595 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
596 gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
598 priv->copyright_label = gtk_label_new (NULL);
599 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
600 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
601 gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
603 hbox = gtk_hbox_new (TRUE, 0);
604 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
606 priv->website_label = button = gtk_label_new ("");
607 gtk_widget_set_no_show_all (button, TRUE);
608 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
609 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
610 g_signal_connect (button, "activate-link",
611 G_CALLBACK (website_clicked), about);
613 gtk_widget_show (vbox);
614 gtk_widget_show (priv->logo_image);
615 gtk_widget_show (priv->name_label);
616 gtk_widget_show (hbox);
618 /* Add the close button */
619 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
620 GTK_RESPONSE_CANCEL);
621 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
623 /* Add the credits button */
624 button = gtk_button_new_with_mnemonic (_("C_redits"));
625 gtk_widget_set_can_default (button, TRUE);
626 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
627 gtk_button_set_image (GTK_BUTTON (button), image);
628 gtk_widget_set_no_show_all (button, TRUE);
629 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area),
630 button, FALSE, TRUE, 0);
631 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
632 g_signal_connect (button, "clicked",
633 G_CALLBACK (display_credits_dialog), about);
634 priv->credits_button = button;
635 priv->credits_dialog = NULL;
637 /* Add the license button */
638 button = gtk_button_new_from_stock (_("_License"));
639 gtk_widget_set_can_default (button, TRUE);
640 gtk_widget_set_no_show_all (button, TRUE);
641 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area),
642 button, FALSE, TRUE, 0);
643 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
644 g_signal_connect (button, "clicked",
645 G_CALLBACK (display_license_dialog), about);
646 priv->license_button = button;
647 priv->license_dialog = NULL;
649 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
651 gtk_widget_pop_composite_child ();
653 gtk_widget_grab_default (close_button);
654 gtk_widget_grab_focus (close_button);
657 gtk_about_dialog_set_program_name (about, NULL);
658 gtk_about_dialog_set_logo (about, NULL);
662 gtk_about_dialog_finalize (GObject *object)
664 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
665 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
668 g_free (priv->version);
669 g_free (priv->copyright);
670 g_free (priv->comments);
671 g_free (priv->license);
672 g_free (priv->website_url);
673 g_free (priv->website_text);
674 g_free (priv->translator_credits);
676 g_strfreev (priv->authors);
677 g_strfreev (priv->documenters);
678 g_strfreev (priv->artists);
680 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
681 g_slist_free (priv->visited_links);
683 gdk_cursor_unref (priv->hand_cursor);
684 gdk_cursor_unref (priv->regular_cursor);
686 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
690 gtk_about_dialog_set_property (GObject *object,
695 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
696 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
701 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
704 gtk_about_dialog_set_version (about, g_value_get_string (value));
707 gtk_about_dialog_set_comments (about, g_value_get_string (value));
710 gtk_about_dialog_set_website (about, g_value_get_string (value));
712 case PROP_WEBSITE_LABEL:
713 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
716 gtk_about_dialog_set_license (about, g_value_get_string (value));
719 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
722 gtk_about_dialog_set_logo (about, g_value_get_object (value));
725 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
727 case PROP_DOCUMENTERS:
728 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
731 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
733 case PROP_TRANSLATOR_CREDITS:
734 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
736 case PROP_LOGO_ICON_NAME:
737 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
739 case PROP_WRAP_LICENSE:
740 priv->wrap_license = g_value_get_boolean (value);
743 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
749 gtk_about_dialog_get_property (GObject *object,
754 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
755 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
760 g_value_set_string (value, priv->name);
763 g_value_set_string (value, priv->version);
766 g_value_set_string (value, priv->copyright);
769 g_value_set_string (value, priv->comments);
772 g_value_set_string (value, priv->website_url);
774 case PROP_WEBSITE_LABEL:
775 g_value_set_string (value, priv->website_text);
778 g_value_set_string (value, priv->license);
780 case PROP_TRANSLATOR_CREDITS:
781 g_value_set_string (value, priv->translator_credits);
784 g_value_set_boxed (value, priv->authors);
786 case PROP_DOCUMENTERS:
787 g_value_set_boxed (value, priv->documenters);
790 g_value_set_boxed (value, priv->artists);
793 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
794 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
796 g_value_set_object (value, NULL);
798 case PROP_LOGO_ICON_NAME:
799 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
801 const gchar *icon_name;
803 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
804 g_value_set_string (value, icon_name);
807 g_value_set_string (value, NULL);
809 case PROP_WRAP_LICENSE:
810 g_value_set_boolean (value, priv->wrap_license);
813 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
819 update_website (GtkAboutDialog *about)
821 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
823 gtk_widget_show (priv->website_label);
825 if (priv->website_url && (!activate_url_hook_set || activate_url_hook != NULL))
829 if (priv->website_text)
833 escaped = g_markup_escape_text (priv->website_text, -1);
834 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
835 priv->website_url, escaped);
840 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
841 priv->website_url, priv->website_url);
844 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
849 if (priv->website_url)
850 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
851 else if (priv->website_text)
852 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
854 gtk_widget_hide (priv->website_label);
859 gtk_about_dialog_show (GtkWidget *widget)
861 update_website (GTK_ABOUT_DIALOG (widget));
863 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
867 * gtk_about_dialog_get_program_name:
868 * @about: a #GtkAboutDialog
870 * Returns the program name displayed in the about dialog.
872 * Return value: The program name. The string is owned by the about
873 * dialog and must not be modified.
877 G_CONST_RETURN gchar *
878 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
880 GtkAboutDialogPrivate *priv;
882 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
884 priv = (GtkAboutDialogPrivate *)about->priv;
890 update_name_version (GtkAboutDialog *about)
892 GtkAboutDialogPrivate *priv;
893 gchar *title_string, *name_string;
895 priv = (GtkAboutDialogPrivate *)about->priv;
897 title_string = g_strdup_printf (_("About %s"), priv->name);
898 gtk_window_set_title (GTK_WINDOW (about), title_string);
899 g_free (title_string);
901 if (priv->version != NULL)
902 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
903 priv->name, priv->version);
905 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
908 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
910 g_free (name_string);
914 * gtk_about_dialog_set_program_name:
915 * @about: a #GtkAboutDialog
916 * @name: the program name
918 * Sets the name to display in the about dialog.
919 * If this is not set, it defaults to g_get_application_name().
924 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
927 GtkAboutDialogPrivate *priv;
930 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
932 priv = (GtkAboutDialogPrivate *)about->priv;
934 priv->name = g_strdup (name ? name : g_get_application_name ());
937 update_name_version (about);
939 g_object_notify (G_OBJECT (about), "program-name");
944 * gtk_about_dialog_get_version:
945 * @about: a #GtkAboutDialog
947 * Returns the version string.
949 * Return value: The version string. The string is owned by the about
950 * dialog and must not be modified.
954 G_CONST_RETURN gchar *
955 gtk_about_dialog_get_version (GtkAboutDialog *about)
957 GtkAboutDialogPrivate *priv;
959 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
961 priv = (GtkAboutDialogPrivate *)about->priv;
963 return priv->version;
967 * gtk_about_dialog_set_version:
968 * @about: a #GtkAboutDialog
969 * @version: (allow-none): the version string
971 * Sets the version string to display in the about dialog.
976 gtk_about_dialog_set_version (GtkAboutDialog *about,
977 const gchar *version)
979 GtkAboutDialogPrivate *priv;
982 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
984 priv = (GtkAboutDialogPrivate *)about->priv;
987 priv->version = g_strdup (version);
990 update_name_version (about);
992 g_object_notify (G_OBJECT (about), "version");
996 * gtk_about_dialog_get_copyright:
997 * @about: a #GtkAboutDialog
999 * Returns the copyright string.
1001 * Return value: The copyright string. The string is owned by the about
1002 * dialog and must not be modified.
1006 G_CONST_RETURN gchar *
1007 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1009 GtkAboutDialogPrivate *priv;
1011 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1013 priv = (GtkAboutDialogPrivate *)about->priv;
1015 return priv->copyright;
1019 * gtk_about_dialog_set_copyright:
1020 * @about: a #GtkAboutDialog
1021 * @copyright: (allow-none) the copyright string
1023 * Sets the copyright string to display in the about dialog.
1024 * This should be a short string of one or two lines.
1029 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1030 const gchar *copyright)
1032 GtkAboutDialogPrivate *priv;
1033 gchar *copyright_string, *tmp;
1035 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1037 priv = (GtkAboutDialogPrivate *)about->priv;
1039 tmp = priv->copyright;
1040 priv->copyright = g_strdup (copyright);
1043 if (priv->copyright != NULL)
1045 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1047 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1048 g_free (copyright_string);
1050 gtk_widget_show (priv->copyright_label);
1053 gtk_widget_hide (priv->copyright_label);
1055 g_object_notify (G_OBJECT (about), "copyright");
1059 * gtk_about_dialog_get_comments:
1060 * @about: a #GtkAboutDialog
1062 * Returns the comments string.
1064 * Return value: The comments. The string is owned by the about
1065 * dialog and must not be modified.
1069 G_CONST_RETURN gchar *
1070 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1072 GtkAboutDialogPrivate *priv;
1074 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1076 priv = (GtkAboutDialogPrivate *)about->priv;
1078 return priv->comments;
1082 * gtk_about_dialog_set_comments:
1083 * @about: a #GtkAboutDialog
1084 * @comments: (allow-none): a comments string
1086 * Sets the comments string to display in the about dialog.
1087 * This should be a short string of one or two lines.
1092 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1093 const gchar *comments)
1095 GtkAboutDialogPrivate *priv;
1098 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1100 priv = (GtkAboutDialogPrivate *)about->priv;
1102 tmp = priv->comments;
1105 priv->comments = g_strdup (comments);
1106 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1107 gtk_widget_show (priv->comments_label);
1111 priv->comments = NULL;
1112 gtk_widget_hide (priv->comments_label);
1116 g_object_notify (G_OBJECT (about), "comments");
1120 * gtk_about_dialog_get_license:
1121 * @about: a #GtkAboutDialog
1123 * Returns the license information.
1125 * Return value: The license information. The string is owned by the about
1126 * dialog and must not be modified.
1130 G_CONST_RETURN gchar *
1131 gtk_about_dialog_get_license (GtkAboutDialog *about)
1133 GtkAboutDialogPrivate *priv;
1135 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1137 priv = (GtkAboutDialogPrivate *)about->priv;
1139 return priv->license;
1143 * gtk_about_dialog_set_license:
1144 * @about: a #GtkAboutDialog
1145 * @license: (allow-none): the license information or %NULL
1147 * Sets the license information to be displayed in the secondary
1148 * license dialog. If @license is %NULL, the license button is
1154 gtk_about_dialog_set_license (GtkAboutDialog *about,
1155 const gchar *license)
1157 GtkAboutDialogPrivate *priv;
1160 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1162 priv = (GtkAboutDialogPrivate *)about->priv;
1164 tmp = priv->license;
1167 priv->license = g_strdup (license);
1168 gtk_widget_show (priv->license_button);
1172 priv->license = NULL;
1173 gtk_widget_hide (priv->license_button);
1177 g_object_notify (G_OBJECT (about), "license");
1181 * gtk_about_dialog_get_wrap_license:
1182 * @about: a #GtkAboutDialog
1184 * Returns whether the license text in @about is
1185 * automatically wrapped.
1187 * Returns: %TRUE if the license text is wrapped
1192 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1194 GtkAboutDialogPrivate *priv;
1196 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1198 priv = (GtkAboutDialogPrivate *)about->priv;
1200 return priv->wrap_license;
1204 * gtk_about_dialog_set_wrap_license:
1205 * @about: a #GtkAboutDialog
1206 * @wrap_license: whether to wrap the license
1208 * Sets whether the license text in @about is
1209 * automatically wrapped.
1214 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1215 gboolean wrap_license)
1217 GtkAboutDialogPrivate *priv;
1219 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1221 priv = (GtkAboutDialogPrivate *)about->priv;
1223 wrap_license = wrap_license != FALSE;
1225 if (priv->wrap_license != wrap_license)
1227 priv->wrap_license = wrap_license;
1229 g_object_notify (G_OBJECT (about), "wrap-license");
1234 * gtk_about_dialog_get_website:
1235 * @about: a #GtkAboutDialog
1237 * Returns the website URL.
1239 * Return value: The website URL. The string is owned by the about
1240 * dialog and must not be modified.
1244 G_CONST_RETURN gchar *
1245 gtk_about_dialog_get_website (GtkAboutDialog *about)
1247 GtkAboutDialogPrivate *priv;
1249 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1251 priv = (GtkAboutDialogPrivate *)about->priv;
1253 return priv->website_url;
1257 * gtk_about_dialog_set_website:
1258 * @about: a #GtkAboutDialog
1259 * @website: (allow-none): a URL string starting with "http://"
1261 * Sets the URL to use for the website link.
1263 * Note that that the hook functions need to be set up
1264 * before calling this function.
1269 gtk_about_dialog_set_website (GtkAboutDialog *about,
1270 const gchar *website)
1272 GtkAboutDialogPrivate *priv;
1275 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1277 priv = (GtkAboutDialogPrivate *)about->priv;
1279 tmp = priv->website_url;
1280 priv->website_url = g_strdup (website);
1283 update_website (about);
1285 g_object_notify (G_OBJECT (about), "website");
1289 * gtk_about_dialog_get_website_label:
1290 * @about: a #GtkAboutDialog
1292 * Returns the label used for the website link.
1294 * Return value: The label used for the website link. The string is
1295 * owned by the about dialog and must not be modified.
1299 G_CONST_RETURN gchar *
1300 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1302 GtkAboutDialogPrivate *priv;
1304 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1306 priv = (GtkAboutDialogPrivate *)about->priv;
1308 return priv->website_text;
1312 * gtk_about_dialog_set_website_label:
1313 * @about: a #GtkAboutDialog
1314 * @website_label: the label used for the website link
1316 * Sets the label to be used for the website link.
1317 * It defaults to the website URL.
1322 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1323 const gchar *website_label)
1325 GtkAboutDialogPrivate *priv;
1328 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1330 priv = (GtkAboutDialogPrivate *)about->priv;
1332 tmp = priv->website_text;
1333 priv->website_text = g_strdup (website_label);
1336 update_website (about);
1338 g_object_notify (G_OBJECT (about), "website-label");
1342 * gtk_about_dialog_get_authors:
1343 * @about: a #GtkAboutDialog
1345 * Returns the string which are displayed in the authors tab
1346 * of the secondary credits dialog.
1348 * Return value: A %NULL-terminated string array containing
1349 * the authors. The array is owned by the about dialog
1350 * and must not be modified.
1354 G_CONST_RETURN gchar * G_CONST_RETURN *
1355 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1357 GtkAboutDialogPrivate *priv;
1359 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1361 priv = (GtkAboutDialogPrivate *)about->priv;
1363 return (const gchar * const *) priv->authors;
1367 update_credits_button_visibility (GtkAboutDialog *about)
1369 GtkAboutDialogPrivate *priv = about->priv;
1372 show = priv->authors != NULL ||
1373 priv->documenters != NULL ||
1374 priv->artists != NULL ||
1375 (priv->translator_credits != NULL &&
1376 strcmp (priv->translator_credits, "translator_credits") &&
1377 strcmp (priv->translator_credits, "translator-credits"));
1379 gtk_widget_show (priv->credits_button);
1381 gtk_widget_hide (priv->credits_button);
1385 * gtk_about_dialog_set_authors:
1386 * @about: a #GtkAboutDialog
1387 * @authors: a %NULL-terminated array of strings
1389 * Sets the strings which are displayed in the authors tab
1390 * of the secondary credits dialog.
1395 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1396 const gchar **authors)
1398 GtkAboutDialogPrivate *priv;
1401 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1403 priv = (GtkAboutDialogPrivate *)about->priv;
1405 tmp = priv->authors;
1406 priv->authors = g_strdupv ((gchar **)authors);
1409 update_credits_button_visibility (about);
1411 g_object_notify (G_OBJECT (about), "authors");
1415 * gtk_about_dialog_get_documenters:
1416 * @about: a #GtkAboutDialog
1418 * Returns the string which are displayed in the documenters
1419 * tab of the secondary credits dialog.
1421 * Return value: A %NULL-terminated string array containing
1422 * the documenters. The array is owned by the about dialog
1423 * and must not be modified.
1427 G_CONST_RETURN gchar * G_CONST_RETURN *
1428 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1430 GtkAboutDialogPrivate *priv;
1432 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1434 priv = (GtkAboutDialogPrivate *)about->priv;
1436 return (const gchar * const *)priv->documenters;
1440 * gtk_about_dialog_set_documenters:
1441 * @about: a #GtkAboutDialog
1442 * @documenters: a %NULL-terminated array of strings
1444 * Sets the strings which are displayed in the documenters tab
1445 * of the secondary credits dialog.
1450 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1451 const gchar **documenters)
1453 GtkAboutDialogPrivate *priv;
1456 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1458 priv = (GtkAboutDialogPrivate *)about->priv;
1460 tmp = priv->documenters;
1461 priv->documenters = g_strdupv ((gchar **)documenters);
1464 update_credits_button_visibility (about);
1466 g_object_notify (G_OBJECT (about), "documenters");
1470 * gtk_about_dialog_get_artists:
1471 * @about: a #GtkAboutDialog
1473 * Returns the string which are displayed in the artists tab
1474 * of the secondary credits dialog.
1476 * Return value: A %NULL-terminated string array containing
1477 * the artists. The array is owned by the about dialog
1478 * and must not be modified.
1482 G_CONST_RETURN gchar * G_CONST_RETURN *
1483 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1485 GtkAboutDialogPrivate *priv;
1487 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1489 priv = (GtkAboutDialogPrivate *)about->priv;
1491 return (const gchar * const *)priv->artists;
1495 * gtk_about_dialog_set_artists:
1496 * @about: a #GtkAboutDialog
1497 * @artists: a %NULL-terminated array of strings
1499 * Sets the strings which are displayed in the artists tab
1500 * of the secondary credits dialog.
1505 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1506 const gchar **artists)
1508 GtkAboutDialogPrivate *priv;
1511 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1513 priv = (GtkAboutDialogPrivate *)about->priv;
1515 tmp = priv->artists;
1516 priv->artists = g_strdupv ((gchar **)artists);
1519 update_credits_button_visibility (about);
1521 g_object_notify (G_OBJECT (about), "artists");
1525 * gtk_about_dialog_get_translator_credits:
1526 * @about: a #GtkAboutDialog
1528 * Returns the translator credits string which is displayed
1529 * in the translators tab of the secondary credits dialog.
1531 * Return value: The translator credits string. The string is
1532 * owned by the about dialog and must not be modified.
1536 G_CONST_RETURN gchar *
1537 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1539 GtkAboutDialogPrivate *priv;
1541 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1543 priv = (GtkAboutDialogPrivate *)about->priv;
1545 return priv->translator_credits;
1549 * gtk_about_dialog_set_translator_credits:
1550 * @about: a #GtkAboutDialog
1551 * @translator_credits: (allow-none): the translator credits
1553 * Sets the translator credits string which is displayed in
1554 * the translators tab of the secondary credits dialog.
1556 * The intended use for this string is to display the translator
1557 * of the language which is currently used in the user interface.
1558 * Using gettext(), a simple way to achieve that is to mark the
1559 * string for translation:
1561 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1563 * It is a good idea to use the customary msgid "translator-credits" for this
1564 * purpose, since translators will already know the purpose of that msgid, and
1565 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1571 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1572 const gchar *translator_credits)
1574 GtkAboutDialogPrivate *priv;
1577 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1579 priv = (GtkAboutDialogPrivate *)about->priv;
1581 tmp = priv->translator_credits;
1582 priv->translator_credits = g_strdup (translator_credits);
1585 update_credits_button_visibility (about);
1587 g_object_notify (G_OBJECT (about), "translator-credits");
1591 * gtk_about_dialog_get_logo:
1592 * @about: a #GtkAboutDialog
1594 * Returns the pixbuf displayed as logo in the about dialog.
1596 * Return value: the pixbuf displayed as logo. The pixbuf is
1597 * owned by the about dialog. If you want to keep a reference
1598 * to it, you have to call g_object_ref() on it.
1603 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1605 GtkAboutDialogPrivate *priv;
1607 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1609 priv = (GtkAboutDialogPrivate *)about->priv;
1611 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1612 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1618 icon_set_new_from_pixbufs (GList *pixbufs)
1620 GtkIconSet *icon_set = gtk_icon_set_new ();
1622 for (; pixbufs; pixbufs = pixbufs->next)
1624 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1626 GtkIconSource *icon_source = gtk_icon_source_new ();
1627 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1628 gtk_icon_set_add_source (icon_set, icon_source);
1629 gtk_icon_source_free (icon_source);
1636 * gtk_about_dialog_set_logo:
1637 * @about: a #GtkAboutDialog
1638 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1640 * Sets the pixbuf to be displayed as logo in the about dialog.
1641 * If it is %NULL, the default window icon set with
1642 * gtk_window_set_default_icon() will be used.
1647 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1650 GtkAboutDialogPrivate *priv;
1652 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1654 priv = (GtkAboutDialogPrivate *)about->priv;
1656 g_object_freeze_notify (G_OBJECT (about));
1658 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1659 g_object_notify (G_OBJECT (about), "logo-icon-name");
1662 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1665 GList *pixbufs = gtk_window_get_default_icon_list ();
1667 if (pixbufs != NULL)
1669 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1671 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1672 icon_set, GTK_ICON_SIZE_DIALOG);
1674 gtk_icon_set_unref (icon_set);
1675 g_list_free (pixbufs);
1679 g_object_notify (G_OBJECT (about), "logo");
1681 g_object_thaw_notify (G_OBJECT (about));
1685 * gtk_about_dialog_get_logo_icon_name:
1686 * @about: a #GtkAboutDialog
1688 * Returns the icon name displayed as logo in the about dialog.
1690 * Return value: the icon name displayed as logo. The string is
1691 * owned by the dialog. If you want to keep a reference
1692 * to it, you have to call g_strdup() on it.
1696 G_CONST_RETURN gchar *
1697 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1699 GtkAboutDialogPrivate *priv;
1700 const gchar *icon_name = NULL;
1702 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1704 priv = (GtkAboutDialogPrivate *)about->priv;
1706 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1707 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1713 * gtk_about_dialog_set_logo_icon_name:
1714 * @about: a #GtkAboutDialog
1715 * @icon_name: (allow-none): an icon name, or %NULL
1717 * Sets the pixbuf to be displayed as logo in the about dialog.
1718 * If it is %NULL, the default window icon set with
1719 * gtk_window_set_default_icon() will be used.
1724 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1725 const gchar *icon_name)
1727 GtkAboutDialogPrivate *priv;
1729 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1731 priv = (GtkAboutDialogPrivate *)about->priv;
1733 g_object_freeze_notify (G_OBJECT (about));
1735 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1736 g_object_notify (G_OBJECT (about), "logo");
1738 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1739 GTK_ICON_SIZE_DIALOG);
1740 g_object_notify (G_OBJECT (about), "logo-icon-name");
1742 g_object_thaw_notify (G_OBJECT (about));
1746 follow_if_link (GtkAboutDialog *about,
1747 GtkTextView *text_view,
1750 GSList *tags = NULL, *tagp = NULL;
1751 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
1753 GtkAboutDialogActivateLinkFunc email_hook, url_hook;
1754 gpointer email_hook_data, url_hook_data;
1756 if (activate_email_hook_set)
1758 email_hook = activate_email_hook;
1759 email_hook_data = activate_email_hook_data;
1763 email_hook = default_email_hook;
1764 email_hook_data = NULL;
1767 if (activate_url_hook_set)
1769 url_hook = activate_url_hook;
1770 url_hook_data = activate_url_hook_data;
1774 url_hook = default_url_hook;
1775 url_hook_data = NULL;
1778 tags = gtk_text_iter_get_tags (iter);
1779 for (tagp = tags; tagp != NULL && !url; tagp = tagp->next)
1781 GtkTextTag *tag = tagp->data;
1783 if (email_hook != NULL)
1785 url = g_object_get_data (G_OBJECT (tag), "email");
1787 email_hook (about, url, email_hook_data);
1790 if (!url && url_hook != NULL)
1792 url = g_object_get_data (G_OBJECT (tag), "url");
1794 url_hook (about, url, url_hook_data);
1797 if (url && !g_slist_find_custom (priv->visited_links, url, (GCompareFunc)strcmp))
1799 GdkColor *style_visited_link_color;
1802 gtk_widget_ensure_style (GTK_WIDGET (about));
1803 gtk_widget_style_get (GTK_WIDGET (about),
1804 "visited-link-color", &style_visited_link_color,
1806 if (style_visited_link_color)
1808 color = *style_visited_link_color;
1809 gdk_color_free (style_visited_link_color);
1812 color = default_visited_link_color;
1814 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1816 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (url));
1821 g_slist_free (tags);
1825 text_view_key_press_event (GtkWidget *text_view,
1827 GtkAboutDialog *about)
1830 GtkTextBuffer *buffer;
1832 switch (event->keyval)
1837 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1838 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1839 gtk_text_buffer_get_insert (buffer));
1840 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1851 text_view_event_after (GtkWidget *text_view,
1853 GtkAboutDialog *about)
1855 GtkTextIter start, end, iter;
1856 GtkTextBuffer *buffer;
1857 GdkEventButton *button_event;
1860 if (event->type != GDK_BUTTON_RELEASE)
1863 button_event = (GdkEventButton *)event;
1865 if (button_event->button != 1)
1868 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1870 /* we shouldn't follow a link if the user has selected something */
1871 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1872 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1875 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1876 GTK_TEXT_WINDOW_WIDGET,
1877 button_event->x, button_event->y, &x, &y);
1879 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1881 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1887 set_cursor_if_appropriate (GtkAboutDialog *about,
1888 GtkTextView *text_view,
1892 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
1893 GSList *tags = NULL, *tagp = NULL;
1895 gboolean hovering_over_link = FALSE;
1897 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1899 tags = gtk_text_iter_get_tags (&iter);
1900 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1902 GtkTextTag *tag = tagp->data;
1903 gchar *email = g_object_get_data (G_OBJECT (tag), "email");
1904 gchar *url = g_object_get_data (G_OBJECT (tag), "url");
1906 if (email != NULL || url != NULL)
1908 hovering_over_link = TRUE;
1913 if (hovering_over_link != priv->hovering_over_link)
1915 priv->hovering_over_link = hovering_over_link;
1917 if (hovering_over_link)
1918 gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->hand_cursor);
1920 gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->regular_cursor);
1924 g_slist_free (tags);
1928 text_view_motion_notify_event (GtkWidget *text_view,
1929 GdkEventMotion *event,
1930 GtkAboutDialog *about)
1934 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1935 GTK_TEXT_WINDOW_WIDGET,
1936 event->x, event->y, &x, &y);
1938 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), x, y);
1940 gdk_event_request_motions (event);
1947 text_view_visibility_notify_event (GtkWidget *text_view,
1948 GdkEventVisibility *event,
1949 GtkAboutDialog *about)
1951 gint wx, wy, bx, by;
1953 gdk_window_get_pointer (text_view->window, &wx, &wy, NULL);
1955 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1956 GTK_TEXT_WINDOW_WIDGET,
1959 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), bx, by);
1965 text_view_new (GtkAboutDialog *about,
1968 GtkWrapMode wrap_mode)
1971 gchar *q0, *q1, *q2, *r1, *r2;
1973 GtkTextView *text_view;
1974 GtkTextBuffer *buffer;
1975 gboolean linkify_email, linkify_urls;
1976 GdkColor *style_link_color;
1977 GdkColor *style_visited_link_color;
1979 GdkColor link_color;
1980 GdkColor visited_link_color;
1982 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
1984 linkify_email = (!activate_email_hook_set || activate_email_hook != NULL);
1985 linkify_urls = (!activate_url_hook_set || activate_url_hook != NULL);
1987 gtk_widget_ensure_style (GTK_WIDGET (about));
1988 gtk_widget_style_get (GTK_WIDGET (about),
1989 "link-color", &style_link_color,
1990 "visited-link-color", &style_visited_link_color,
1992 if (style_link_color)
1994 link_color = *style_link_color;
1995 gdk_color_free (style_link_color);
1998 link_color = default_link_color;
2000 if (style_visited_link_color)
2002 visited_link_color = *style_visited_link_color;
2003 gdk_color_free (style_visited_link_color);
2006 visited_link_color = default_visited_link_color;
2008 view = gtk_text_view_new ();
2009 text_view = GTK_TEXT_VIEW (view);
2010 buffer = gtk_text_view_get_buffer (text_view);
2011 gtk_text_view_set_cursor_visible (text_view, FALSE);
2012 gtk_text_view_set_editable (text_view, FALSE);
2013 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2015 gtk_text_view_set_left_margin (text_view, 8);
2016 gtk_text_view_set_right_margin (text_view, 8);
2018 g_signal_connect (view, "key-press-event",
2019 G_CALLBACK (text_view_key_press_event), about);
2020 g_signal_connect (view, "event-after",
2021 G_CALLBACK (text_view_event_after), about);
2022 g_signal_connect (view, "motion-notify-event",
2023 G_CALLBACK (text_view_motion_notify_event), about);
2024 g_signal_connect (view, "visibility-notify-event",
2025 G_CALLBACK (text_view_visibility_notify_event), about);
2027 if (strings == NULL)
2029 gtk_widget_hide (view);
2033 for (p = strings; *p; p++)
2038 q1 = linkify_email ? strchr (q0, '<') : NULL;
2039 q2 = q1 ? strchr (q1, '>') : NULL;
2040 r1 = linkify_urls ? strstr (q0, "http://") : NULL;
2043 r2 = strpbrk (r1, " \n\t");
2045 r2 = strchr (r1, '\0');
2050 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2060 const gchar *link_type;
2065 gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
2066 gtk_text_buffer_get_end_iter (buffer, &end);
2068 link_type = I_("email");
2072 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2073 gtk_text_buffer_get_end_iter (buffer, &end);
2074 link_type = I_("url");
2079 link = g_strndup (q1, q2 - q1);
2081 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2082 color = visited_link_color;
2086 tag = gtk_text_buffer_create_tag (buffer, NULL,
2087 "foreground-gdk", &color,
2088 "underline", PANGO_UNDERLINE_SINGLE,
2090 g_object_set_data_full (G_OBJECT (tag), link_type, g_strdup (link), g_free);
2091 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2097 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2103 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2106 gtk_widget_show (view);
2111 add_credits_page (GtkAboutDialog *about,
2112 GtkWidget *credits_dialog,
2113 GtkWidget *notebook,
2117 GtkWidget *sw, *view;
2119 view = text_view_new (about, credits_dialog, people, GTK_WRAP_NONE);
2121 sw = gtk_scrolled_window_new (NULL, NULL);
2122 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2124 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2125 GTK_POLICY_AUTOMATIC,
2126 GTK_POLICY_AUTOMATIC);
2127 gtk_container_add (GTK_CONTAINER (sw), view);
2129 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
2130 sw, gtk_label_new (title));
2134 display_credits_dialog (GtkWidget *button,
2137 GtkAboutDialog *about = (GtkAboutDialog *)data;
2138 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
2139 GtkWidget *dialog, *notebook;
2140 GtkDialog *credits_dialog;
2142 if (priv->credits_dialog != NULL)
2144 gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2148 dialog = gtk_dialog_new_with_buttons (_("Credits"),
2150 GTK_DIALOG_DESTROY_WITH_PARENT,
2151 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2153 credits_dialog = GTK_DIALOG (dialog);
2154 gtk_dialog_set_has_separator (credits_dialog, FALSE);
2155 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2156 gtk_box_set_spacing (GTK_BOX (credits_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2157 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog->action_area), 5);
2159 priv->credits_dialog = dialog;
2160 gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2161 gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2163 gtk_window_set_modal (GTK_WINDOW (dialog),
2164 gtk_window_get_modal (GTK_WINDOW (about)));
2166 g_signal_connect (dialog, "response",
2167 G_CALLBACK (gtk_widget_destroy), dialog);
2168 g_signal_connect (dialog, "destroy",
2169 G_CALLBACK (gtk_widget_destroyed),
2170 &(priv->credits_dialog));
2172 notebook = gtk_notebook_new ();
2173 gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2174 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, TRUE, 0);
2176 if (priv->authors != NULL)
2177 add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2179 if (priv->documenters != NULL)
2180 add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2182 /* Don't show an untranslated gettext msgid */
2183 if (priv->translator_credits != NULL &&
2184 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2185 strcmp (priv->translator_credits, "translator-credits") != 0)
2187 gchar *translators[2];
2189 translators[0] = priv->translator_credits;
2190 translators[1] = NULL;
2192 add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2195 if (priv->artists != NULL)
2196 add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2198 gtk_widget_show_all (dialog);
2202 set_policy (GtkWidget *sw)
2204 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2205 GTK_POLICY_AUTOMATIC,
2206 GTK_POLICY_AUTOMATIC);
2210 display_license_dialog (GtkWidget *button,
2213 GtkAboutDialog *about = (GtkAboutDialog *)data;
2214 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
2215 GtkWidget *dialog, *view, *sw;
2216 GtkDialog *licence_dialog;
2219 if (priv->license_dialog != NULL)
2221 gtk_window_present (GTK_WINDOW (priv->license_dialog));
2225 dialog = gtk_dialog_new_with_buttons (_("License"),
2227 GTK_DIALOG_DESTROY_WITH_PARENT,
2228 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2230 licence_dialog = GTK_DIALOG (dialog);
2231 gtk_dialog_set_has_separator (licence_dialog, FALSE);
2232 gtk_container_set_border_width (GTK_CONTAINER (licence_dialog), 5);
2233 gtk_box_set_spacing (GTK_BOX (licence_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2234 gtk_container_set_border_width (GTK_CONTAINER (licence_dialog->action_area), 5);
2236 priv->license_dialog = dialog;
2237 gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2238 gtk_dialog_set_default_response (licence_dialog, GTK_RESPONSE_CANCEL);
2240 gtk_window_set_modal (GTK_WINDOW (dialog),
2241 gtk_window_get_modal (GTK_WINDOW (about)));
2243 g_signal_connect (dialog, "response",
2244 G_CALLBACK (gtk_widget_destroy), dialog);
2245 g_signal_connect (dialog, "destroy",
2246 G_CALLBACK (gtk_widget_destroyed),
2247 &(priv->license_dialog));
2249 sw = gtk_scrolled_window_new (NULL, NULL);
2250 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2251 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2253 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2255 GTK_POLICY_AUTOMATIC);
2256 g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2257 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), sw, TRUE, TRUE, 0);
2259 strings[0] = priv->license;
2261 view = text_view_new (about, dialog, strings,
2262 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2264 gtk_container_add (GTK_CONTAINER (sw), view);
2266 gtk_widget_show_all (dialog);
2270 * gtk_about_dialog_new:
2272 * Creates a new #GtkAboutDialog.
2274 * Returns: a newly created #GtkAboutDialog
2279 gtk_about_dialog_new (void)
2281 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2283 return GTK_WIDGET (dialog);
2287 * gtk_about_dialog_set_email_hook:
2288 * @func: a function to call when an email link is activated.
2289 * @data: data to pass to @func
2290 * @destroy: #GDestroyNotify for @data
2292 * Installs a global function to be called whenever the user activates an
2293 * email link in an about dialog.
2295 * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2296 * deactivate it, you can pass %NULL for @func.
2298 * Return value: the previous email hook.
2302 GtkAboutDialogActivateLinkFunc
2303 gtk_about_dialog_set_email_hook (GtkAboutDialogActivateLinkFunc func,
2305 GDestroyNotify destroy)
2307 GtkAboutDialogActivateLinkFunc old;
2309 if (activate_email_hook_destroy != NULL)
2310 (* activate_email_hook_destroy) (activate_email_hook_data);
2312 old = activate_email_hook;
2314 activate_email_hook_set = TRUE;
2315 activate_email_hook = func;
2316 activate_email_hook_data = data;
2317 activate_email_hook_destroy = destroy;
2323 * gtk_about_dialog_set_url_hook:
2324 * @func: a function to call when a URL link is activated.
2325 * @data: data to pass to @func
2326 * @destroy: #GDestroyNotify for @data
2328 * Installs a global function to be called whenever the user activates a
2329 * URL link in an about dialog.
2331 * Since 2.18 there exists a default function which uses gtk_show_uri(). To
2332 * deactivate it, you can pass %NULL for @func.
2334 * Return value: the previous URL hook.
2338 GtkAboutDialogActivateLinkFunc
2339 gtk_about_dialog_set_url_hook (GtkAboutDialogActivateLinkFunc func,
2341 GDestroyNotify destroy)
2343 GtkAboutDialogActivateLinkFunc old;
2345 if (activate_url_hook_destroy != NULL)
2346 (* activate_url_hook_destroy) (activate_url_hook_data);
2348 old = activate_url_hook;
2350 activate_url_hook_set = TRUE;
2351 activate_url_hook = func;
2352 activate_url_hook_data = data;
2353 activate_url_hook_destroy = destroy;
2359 close_cb (GtkAboutDialog *about)
2361 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->priv;
2363 if (priv->license_dialog != NULL)
2365 gtk_widget_destroy (priv->license_dialog);
2366 priv->license_dialog = NULL;
2369 if (priv->credits_dialog != NULL)
2371 gtk_widget_destroy (priv->credits_dialog);
2372 priv->credits_dialog = NULL;
2375 gtk_widget_hide (GTK_WIDGET (about));
2380 * gtk_show_about_dialog:
2381 * @parent: (allow-none): transient parent, or %NULL for none
2382 * @first_property_name: the name of the first property
2383 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2385 * This is a convenience function for showing an application's about box.
2386 * The constructed dialog is associated with the parent window and
2387 * reused for future invocations of this function.
2392 gtk_show_about_dialog (GtkWindow *parent,
2393 const gchar *first_property_name,
2396 static GtkWidget *global_about_dialog = NULL;
2397 GtkWidget *dialog = NULL;
2401 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2403 dialog = global_about_dialog;
2407 dialog = gtk_about_dialog_new ();
2409 g_object_ref_sink (dialog);
2411 g_signal_connect (dialog, "delete-event",
2412 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2414 /* Close dialog on user response */
2415 g_signal_connect (dialog, "response",
2416 G_CALLBACK (close_cb), NULL);
2418 va_start (var_args, first_property_name);
2419 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2424 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2425 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2426 g_object_set_data_full (G_OBJECT (parent),
2427 I_("gtk-about-dialog"),
2428 dialog, g_object_unref);
2431 global_about_dialog = dialog;
2435 gtk_window_present (GTK_WINDOW (dialog));
2438 #define __GTK_ABOUT_DIALOG_C__
2439 #include "gtkaliasdef.c"