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 * displays these as clickable links. By default, it calls gtk_show_uri()
74 * when a user clicks one. The behaviour can be overridden with the
75 * #GtkAboutDialog::activate-link signal.
77 * To make constructing a GtkAboutDialog as convenient as possible, you can
78 * use the function gtk_show_about_dialog() which constructs and shows a dialog
79 * and keeps it around so that it can be shown again.
81 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
82 * on the dialog window (where %s is replaced by the name of the
83 * application, but in order to ensure proper translation of the title,
84 * applications should set the title property explicitly when constructing
85 * a GtkAboutDialog, as shown in the following example:
86 * <informalexample><programlisting>
87 * gtk_show_about_dialog (NULL,
88 * "program-name", "ExampleCode",
89 * "logo", example_logo,
90 * "title" _("About ExampleCode"),
92 * </programlisting></informalexample>
95 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
96 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
98 /* Translators: this is the license preamble; the string at the end
99 * contains the URL of the license.
101 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit %s");
103 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
104 static const gchar *gtk_license_urls[] = {
108 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
109 "http://www.gnu.org/licenses/gpl.html",
111 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
112 "http://www.gnu.org/licenses/lgpl.html",
114 "http://opensource.org/licenses/bsd-license.php",
115 "http://opensource.org/licenses/mit-license.php",
117 "http://opensource.org/licenses/artistic-license-2.0.php"
120 struct _GtkAboutDialogPrivate
128 gchar *translator_credits;
135 GtkWidget *logo_image;
136 GtkWidget *name_label;
137 GtkWidget *comments_label;
138 GtkWidget *copyright_label;
139 GtkWidget *website_label;
141 GtkWidget *credits_button;
142 GtkWidget *credits_dialog;
143 GtkWidget *license_button;
144 GtkWidget *license_dialog;
146 GdkCursor *hand_cursor;
147 GdkCursor *regular_cursor;
149 GSList *visited_links;
151 GtkLicense license_type;
153 guint hovering_over_link : 1;
154 guint wrap_license : 1;
157 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
172 PROP_TRANSLATOR_CREDITS,
180 static void gtk_about_dialog_finalize (GObject *object);
181 static void gtk_about_dialog_get_property (GObject *object,
185 static void gtk_about_dialog_set_property (GObject *object,
189 static void gtk_about_dialog_show (GtkWidget *widge);
190 static void update_name_version (GtkAboutDialog *about);
191 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
192 static void follow_if_link (GtkAboutDialog *about,
193 GtkTextView *text_view,
195 static void set_cursor_if_appropriate (GtkAboutDialog *about,
196 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 gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
213 static guint signals[LAST_SIGNAL] = { 0 };
215 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
219 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
221 GObjectClass *object_class;
222 GtkWidgetClass *widget_class;
224 object_class = (GObjectClass *)klass;
225 widget_class = (GtkWidgetClass *)klass;
227 object_class->set_property = gtk_about_dialog_set_property;
228 object_class->get_property = gtk_about_dialog_get_property;
230 object_class->finalize = gtk_about_dialog_finalize;
232 widget_class->show = gtk_about_dialog_show;
234 klass->activate_link = gtk_about_dialog_activate_link;
237 * GtkAboutDialog::activate-link:
238 * @label: The object on which the signal was emitted
239 * @uri: the URI that is activated
241 * The signal which gets emitted to activate a URI.
242 * Applications may connect to it to override the default behaviour,
243 * which is to call gtk_show_uri().
245 * Returns: %TRUE if the link has been activated
249 signals[ACTIVATE_LINK] =
250 g_signal_new ("activate-link",
251 G_TYPE_FROM_CLASS (object_class),
253 G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
254 _gtk_boolean_handled_accumulator, NULL,
255 _gtk_marshal_BOOLEAN__STRING,
256 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
259 * GtkAboutDialog:program-name:
261 * The name of the program.
262 * If this is not set, it defaults to g_get_application_name().
266 g_object_class_install_property (object_class,
268 g_param_spec_string ("program-name",
270 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
272 GTK_PARAM_READWRITE));
275 * GtkAboutDialog:version:
277 * The version of the program.
281 g_object_class_install_property (object_class,
283 g_param_spec_string ("version",
284 P_("Program version"),
285 P_("The version of the program"),
287 GTK_PARAM_READWRITE));
290 * GtkAboutDialog:copyright:
292 * Copyright information for the program.
296 g_object_class_install_property (object_class,
298 g_param_spec_string ("copyright",
299 P_("Copyright string"),
300 P_("Copyright information for the program"),
302 GTK_PARAM_READWRITE));
306 * GtkAboutDialog:comments:
308 * Comments about the program. This string is displayed in a label
309 * in the main dialog, thus it should be a short explanation of
310 * the main purpose of the program, not a detailed list of features.
314 g_object_class_install_property (object_class,
316 g_param_spec_string ("comments",
317 P_("Comments string"),
318 P_("Comments about the program"),
320 GTK_PARAM_READWRITE));
323 * GtkAboutDialog:license:
325 * The license of the program. This string is displayed in a
326 * text view in a secondary dialog, therefore it is fine to use
327 * a long multi-paragraph text. Note that the text is only wrapped
328 * in the text view if the "wrap-license" property is set to %TRUE;
329 * otherwise the text itself must contain the intended linebreaks.
330 * When setting this property to a non-%NULL value, the
331 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
336 g_object_class_install_property (object_class,
338 g_param_spec_string ("license",
340 _("The license of the program"),
342 GTK_PARAM_READWRITE));
345 * GtkAboutDialog:license-type:
347 * The license of the program, as a value of the %GtkLicense enumeration.
349 * The #GtkAboutDialog will automatically fill out a standard disclaimer
350 * and link the user to the appropriate online resource for the license
353 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
354 * specified in the #GtkAboutDialog:website property.
356 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
357 * #GtkAboutDialog:license property are used.
359 * For any other #GtkLicense value, the contents of the
360 * #GtkAboutDialog:license property are also set by this property as
365 g_object_class_install_property (object_class,
367 g_param_spec_enum ("license-type",
369 P_("The license type of the program"),
372 GTK_PARAM_READWRITE));
375 * GtkAboutDialog:website:
377 * The URL for the link to the website of the program.
378 * This should be a string starting with "http://.
382 g_object_class_install_property (object_class,
384 g_param_spec_string ("website",
386 P_("The URL for the link to the website of the program"),
388 GTK_PARAM_READWRITE));
391 * GtkAboutDialog:website-label:
393 * The label for the link to the website of the program. If this is not set,
394 * it defaults to the URL specified in the #GtkAboutDialog:website property.
398 g_object_class_install_property (object_class,
400 g_param_spec_string ("website-label",
402 P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
404 GTK_PARAM_READWRITE));
407 * GtkAboutDialog:authors:
409 * The authors of the program, as a %NULL-terminated array of strings.
410 * Each string may contain email addresses and URLs, which will be displayed
411 * as links, see the introduction for more details.
415 g_object_class_install_property (object_class,
417 g_param_spec_boxed ("authors",
419 P_("List of authors of the program"),
421 GTK_PARAM_READWRITE));
424 * GtkAboutDialog:documenters:
426 * The people documenting the program, as a %NULL-terminated array of strings.
427 * Each string may contain email addresses and URLs, which will be displayed
428 * as links, see the introduction for more details.
432 g_object_class_install_property (object_class,
434 g_param_spec_boxed ("documenters",
436 P_("List of people documenting the program"),
438 GTK_PARAM_READWRITE));
441 * GtkAboutDialog:artists:
443 * The people who contributed artwork to the program, as a %NULL-terminated
444 * array of strings. Each string may contain email addresses and URLs, which
445 * will be displayed as links, see the introduction for more details.
449 g_object_class_install_property (object_class,
451 g_param_spec_boxed ("artists",
453 P_("List of people who have contributed artwork to the program"),
455 GTK_PARAM_READWRITE));
459 * GtkAboutDialog:translator-credits:
461 * Credits to the translators. This string should be marked as translatable.
462 * The string may contain email addresses and URLs, which will be displayed
463 * as links, see the introduction for more details.
467 g_object_class_install_property (object_class,
468 PROP_TRANSLATOR_CREDITS,
469 g_param_spec_string ("translator-credits",
470 P_("Translator credits"),
471 P_("Credits to the translators. This string should be marked as translatable"),
473 GTK_PARAM_READWRITE));
476 * GtkAboutDialog:logo:
478 * A logo for the about box. If this is not set, it defaults to
479 * gtk_window_get_default_icon_list().
483 g_object_class_install_property (object_class,
485 g_param_spec_object ("logo",
487 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
489 GTK_PARAM_READWRITE));
492 * GtkAboutDialog:logo-icon-name:
494 * A named icon to use as the logo for the about box. This property
495 * overrides the #GtkAboutDialog:logo property.
499 g_object_class_install_property (object_class,
501 g_param_spec_string ("logo-icon-name",
502 P_("Logo Icon Name"),
503 P_("A named icon to use as the logo for the about box."),
505 GTK_PARAM_READWRITE));
507 * GtkAboutDialog:wrap-license:
509 * Whether to wrap the text in the license dialog.
513 g_object_class_install_property (object_class,
515 g_param_spec_boolean ("wrap-license",
517 P_("Whether to wrap the license text."),
519 GTK_PARAM_READWRITE));
522 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
526 emit_activate_link (GtkAboutDialog *about,
529 gboolean handled = FALSE;
531 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
537 gtk_about_dialog_init (GtkAboutDialog *about)
539 GtkDialog *dialog = GTK_DIALOG (about);
540 GtkAboutDialogPrivate *priv;
541 GtkWidget *vbox, *hbox, *button, *close_button, *image;
542 GtkWidget *content_area, *action_area;
545 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
549 priv->version = NULL;
550 priv->copyright = NULL;
551 priv->comments = NULL;
552 priv->website_url = NULL;
553 priv->website_text = NULL;
554 priv->translator_credits = NULL;
555 priv->license = NULL;
556 priv->authors = NULL;
557 priv->documenters = NULL;
558 priv->artists = NULL;
560 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
561 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
562 priv->hovering_over_link = FALSE;
563 priv->wrap_license = FALSE;
565 priv->license_type = GTK_LICENSE_UNKNOWN;
567 content_area = gtk_dialog_get_content_area (dialog);
568 action_area = gtk_dialog_get_action_area (dialog);
570 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
571 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
572 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
575 gtk_widget_push_composite_child ();
577 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 8);
578 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
579 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
581 priv->logo_image = gtk_image_new ();
582 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
584 priv->name_label = gtk_label_new (NULL);
585 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
586 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
587 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
589 priv->comments_label = gtk_label_new (NULL);
590 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
591 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
592 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
593 gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
595 priv->copyright_label = gtk_label_new (NULL);
596 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
597 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
598 gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
600 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, TRUE, 0);
601 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
603 priv->website_label = button = gtk_label_new ("");
604 gtk_widget_set_no_show_all (button, TRUE);
605 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
606 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
607 g_signal_connect_swapped (button, "activate-link",
608 G_CALLBACK (emit_activate_link), about);
610 gtk_widget_show (vbox);
611 gtk_widget_show (priv->logo_image);
612 gtk_widget_show (priv->name_label);
613 gtk_widget_show (hbox);
615 /* Add the close button */
616 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
617 GTK_RESPONSE_CANCEL);
618 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
620 /* Add the credits button */
621 button = gtk_button_new_with_mnemonic (_("C_redits"));
622 gtk_widget_set_can_default (button, TRUE);
623 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
624 gtk_button_set_image (GTK_BUTTON (button), image);
625 gtk_widget_set_no_show_all (button, TRUE);
626 gtk_box_pack_end (GTK_BOX (action_area),
627 button, FALSE, TRUE, 0);
628 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
629 g_signal_connect (button, "clicked",
630 G_CALLBACK (display_credits_dialog), about);
631 priv->credits_button = button;
632 priv->credits_dialog = NULL;
634 /* Add the license button */
635 button = gtk_button_new_from_stock (_("_License"));
636 gtk_widget_set_can_default (button, TRUE);
637 gtk_widget_set_no_show_all (button, TRUE);
638 gtk_box_pack_end (GTK_BOX (action_area),
639 button, FALSE, TRUE, 0);
640 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
641 g_signal_connect (button, "clicked",
642 G_CALLBACK (display_license_dialog), about);
643 priv->license_button = button;
644 priv->license_dialog = NULL;
646 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
648 gtk_widget_pop_composite_child ();
650 gtk_widget_grab_default (close_button);
651 gtk_widget_grab_focus (close_button);
654 gtk_about_dialog_set_program_name (about, NULL);
655 gtk_about_dialog_set_logo (about, NULL);
659 gtk_about_dialog_finalize (GObject *object)
661 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
662 GtkAboutDialogPrivate *priv = about->priv;
665 g_free (priv->version);
666 g_free (priv->copyright);
667 g_free (priv->comments);
668 g_free (priv->license);
669 g_free (priv->website_url);
670 g_free (priv->website_text);
671 g_free (priv->translator_credits);
673 g_strfreev (priv->authors);
674 g_strfreev (priv->documenters);
675 g_strfreev (priv->artists);
677 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
678 g_slist_free (priv->visited_links);
680 gdk_cursor_unref (priv->hand_cursor);
681 gdk_cursor_unref (priv->regular_cursor);
683 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
687 gtk_about_dialog_set_property (GObject *object,
692 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
693 GtkAboutDialogPrivate *priv = about->priv;
698 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
701 gtk_about_dialog_set_version (about, g_value_get_string (value));
704 gtk_about_dialog_set_comments (about, g_value_get_string (value));
707 gtk_about_dialog_set_website (about, g_value_get_string (value));
709 case PROP_WEBSITE_LABEL:
710 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
713 gtk_about_dialog_set_license (about, g_value_get_string (value));
715 case PROP_LICENSE_TYPE:
716 gtk_about_dialog_set_license_type (about, g_value_get_enum (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 = 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_LICENSE_TYPE:
781 g_value_set_enum (value, priv->license_type);
783 case PROP_TRANSLATOR_CREDITS:
784 g_value_set_string (value, priv->translator_credits);
787 g_value_set_boxed (value, priv->authors);
789 case PROP_DOCUMENTERS:
790 g_value_set_boxed (value, priv->documenters);
793 g_value_set_boxed (value, priv->artists);
796 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
797 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
799 g_value_set_object (value, NULL);
801 case PROP_LOGO_ICON_NAME:
802 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
804 const gchar *icon_name;
806 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
807 g_value_set_string (value, icon_name);
810 g_value_set_string (value, NULL);
812 case PROP_WRAP_LICENSE:
813 g_value_set_boolean (value, priv->wrap_license);
816 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
822 gtk_about_dialog_activate_link (GtkAboutDialog *about,
826 GError *error = NULL;
828 screen = gtk_widget_get_screen (GTK_WIDGET (about));
830 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
834 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
835 GTK_DIALOG_DESTROY_WITH_PARENT |
839 "%s", _("Could not show link"));
840 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
841 "%s", error->message);
842 g_error_free (error);
844 g_signal_connect (dialog, "response",
845 G_CALLBACK (gtk_widget_destroy), NULL);
847 gtk_window_present (GTK_WINDOW (dialog));
854 update_website (GtkAboutDialog *about)
856 GtkAboutDialogPrivate *priv = about->priv;
858 gtk_widget_show (priv->website_label);
860 if (priv->website_url)
864 if (priv->website_text)
868 escaped = g_markup_escape_text (priv->website_text, -1);
869 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
870 priv->website_url, escaped);
875 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
876 priv->website_url, priv->website_url);
879 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
884 if (priv->website_url)
885 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
886 else if (priv->website_text)
887 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
889 gtk_widget_hide (priv->website_label);
894 gtk_about_dialog_show (GtkWidget *widget)
896 update_website (GTK_ABOUT_DIALOG (widget));
898 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
902 * gtk_about_dialog_get_program_name:
903 * @about: a #GtkAboutDialog
905 * Returns the program name displayed in the about dialog.
907 * Return value: The program name. The string is owned by the about
908 * dialog and must not be modified.
912 G_CONST_RETURN gchar *
913 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
915 GtkAboutDialogPrivate *priv;
917 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
925 update_name_version (GtkAboutDialog *about)
927 GtkAboutDialogPrivate *priv;
928 gchar *title_string, *name_string;
932 title_string = g_strdup_printf (_("About %s"), priv->name);
933 gtk_window_set_title (GTK_WINDOW (about), title_string);
934 g_free (title_string);
936 if (priv->version != NULL)
937 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
938 priv->name, priv->version);
940 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
943 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
945 g_free (name_string);
949 * gtk_about_dialog_set_program_name:
950 * @about: a #GtkAboutDialog
951 * @name: the program name
953 * Sets the name to display in the about dialog.
954 * If this is not set, it defaults to g_get_application_name().
959 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
962 GtkAboutDialogPrivate *priv;
965 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
970 priv->name = g_strdup (name ? name : g_get_application_name ());
973 update_name_version (about);
975 g_object_notify (G_OBJECT (about), "program-name");
980 * gtk_about_dialog_get_version:
981 * @about: a #GtkAboutDialog
983 * Returns the version string.
985 * Return value: The version string. The string is owned by the about
986 * dialog and must not be modified.
990 G_CONST_RETURN gchar *
991 gtk_about_dialog_get_version (GtkAboutDialog *about)
993 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
995 return about->priv->version;
999 * gtk_about_dialog_set_version:
1000 * @about: a #GtkAboutDialog
1001 * @version: (allow-none): the version string
1003 * Sets the version string to display in the about dialog.
1008 gtk_about_dialog_set_version (GtkAboutDialog *about,
1009 const gchar *version)
1011 GtkAboutDialogPrivate *priv;
1014 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1018 tmp = priv->version;
1019 priv->version = g_strdup (version);
1022 update_name_version (about);
1024 g_object_notify (G_OBJECT (about), "version");
1028 * gtk_about_dialog_get_copyright:
1029 * @about: a #GtkAboutDialog
1031 * Returns the copyright string.
1033 * Return value: The copyright string. The string is owned by the about
1034 * dialog and must not be modified.
1038 G_CONST_RETURN gchar *
1039 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1041 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1043 return about->priv->copyright;
1047 * gtk_about_dialog_set_copyright:
1048 * @about: a #GtkAboutDialog
1049 * @copyright: (allow-none) the copyright string
1051 * Sets the copyright string to display in the about dialog.
1052 * This should be a short string of one or two lines.
1057 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1058 const gchar *copyright)
1060 GtkAboutDialogPrivate *priv;
1061 gchar *copyright_string, *tmp;
1063 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1067 tmp = priv->copyright;
1068 priv->copyright = g_strdup (copyright);
1071 if (priv->copyright != NULL)
1073 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1075 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1076 g_free (copyright_string);
1078 gtk_widget_show (priv->copyright_label);
1081 gtk_widget_hide (priv->copyright_label);
1083 g_object_notify (G_OBJECT (about), "copyright");
1087 * gtk_about_dialog_get_comments:
1088 * @about: a #GtkAboutDialog
1090 * Returns the comments string.
1092 * Return value: The comments. The string is owned by the about
1093 * dialog and must not be modified.
1097 G_CONST_RETURN gchar *
1098 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1100 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1102 return about->priv->comments;
1106 * gtk_about_dialog_set_comments:
1107 * @about: a #GtkAboutDialog
1108 * @comments: (allow-none): a comments string
1110 * Sets the comments string to display in the about dialog.
1111 * This should be a short string of one or two lines.
1116 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1117 const gchar *comments)
1119 GtkAboutDialogPrivate *priv;
1122 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1126 tmp = priv->comments;
1129 priv->comments = g_strdup (comments);
1130 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1131 gtk_widget_show (priv->comments_label);
1135 priv->comments = NULL;
1136 gtk_widget_hide (priv->comments_label);
1140 g_object_notify (G_OBJECT (about), "comments");
1144 * gtk_about_dialog_get_license:
1145 * @about: a #GtkAboutDialog
1147 * Returns the license information.
1149 * Return value: The license information. The string is owned by the about
1150 * dialog and must not be modified.
1154 G_CONST_RETURN gchar *
1155 gtk_about_dialog_get_license (GtkAboutDialog *about)
1157 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1159 return about->priv->license;
1163 * gtk_about_dialog_set_license:
1164 * @about: a #GtkAboutDialog
1165 * @license: (allow-none): the license information or %NULL
1167 * Sets the license information to be displayed in the secondary
1168 * license dialog. If @license is %NULL, the license button is
1174 gtk_about_dialog_set_license (GtkAboutDialog *about,
1175 const gchar *license)
1177 GtkAboutDialogPrivate *priv;
1180 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1184 tmp = priv->license;
1187 priv->license = g_strdup (license);
1188 priv->license_type = GTK_LICENSE_CUSTOM;
1189 gtk_widget_show (priv->license_button);
1193 priv->license = NULL;
1194 priv->license_type = GTK_LICENSE_UNKNOWN;
1195 gtk_widget_hide (priv->license_button);
1199 g_object_notify (G_OBJECT (about), "license");
1200 g_object_notify (G_OBJECT (about), "license-type");
1204 * gtk_about_dialog_get_wrap_license:
1205 * @about: a #GtkAboutDialog
1207 * Returns whether the license text in @about is
1208 * automatically wrapped.
1210 * Returns: %TRUE if the license text is wrapped
1215 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1217 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1219 return about->priv->wrap_license;
1223 * gtk_about_dialog_set_wrap_license:
1224 * @about: a #GtkAboutDialog
1225 * @wrap_license: whether to wrap the license
1227 * Sets whether the license text in @about is
1228 * automatically wrapped.
1233 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1234 gboolean wrap_license)
1236 GtkAboutDialogPrivate *priv;
1238 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1242 wrap_license = wrap_license != FALSE;
1244 if (priv->wrap_license != wrap_license)
1246 priv->wrap_license = wrap_license;
1248 g_object_notify (G_OBJECT (about), "wrap-license");
1253 * gtk_about_dialog_get_website:
1254 * @about: a #GtkAboutDialog
1256 * Returns the website URL.
1258 * Return value: The website URL. The string is owned by the about
1259 * dialog and must not be modified.
1263 G_CONST_RETURN gchar *
1264 gtk_about_dialog_get_website (GtkAboutDialog *about)
1266 GtkAboutDialogPrivate *priv;
1268 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1272 return priv->website_url;
1276 * gtk_about_dialog_set_website:
1277 * @about: a #GtkAboutDialog
1278 * @website: (allow-none): a URL string starting with "http://"
1280 * Sets the URL to use for the website link.
1285 gtk_about_dialog_set_website (GtkAboutDialog *about,
1286 const gchar *website)
1288 GtkAboutDialogPrivate *priv;
1291 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1295 tmp = priv->website_url;
1296 priv->website_url = g_strdup (website);
1299 update_website (about);
1301 g_object_notify (G_OBJECT (about), "website");
1305 * gtk_about_dialog_get_website_label:
1306 * @about: a #GtkAboutDialog
1308 * Returns the label used for the website link.
1310 * Return value: The label used for the website link. The string is
1311 * owned by the about dialog and must not be modified.
1315 G_CONST_RETURN gchar *
1316 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1318 GtkAboutDialogPrivate *priv;
1320 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1324 return priv->website_text;
1328 * gtk_about_dialog_set_website_label:
1329 * @about: a #GtkAboutDialog
1330 * @website_label: the label used for the website link
1332 * Sets the label to be used for the website link.
1333 * It defaults to the website URL.
1338 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1339 const gchar *website_label)
1341 GtkAboutDialogPrivate *priv;
1344 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1348 tmp = priv->website_text;
1349 priv->website_text = g_strdup (website_label);
1352 update_website (about);
1354 g_object_notify (G_OBJECT (about), "website-label");
1358 * gtk_about_dialog_get_authors:
1359 * @about: a #GtkAboutDialog
1361 * Returns the string which are displayed in the authors tab
1362 * of the secondary credits dialog.
1364 * Return value: A %NULL-terminated string array containing
1365 * the authors. The array is owned by the about dialog
1366 * and must not be modified.
1370 G_CONST_RETURN gchar * G_CONST_RETURN *
1371 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1373 GtkAboutDialogPrivate *priv;
1375 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1379 return (const gchar * const *) priv->authors;
1383 update_credits_button_visibility (GtkAboutDialog *about)
1385 GtkAboutDialogPrivate *priv = about->priv;
1388 show = priv->authors != NULL ||
1389 priv->documenters != NULL ||
1390 priv->artists != NULL ||
1391 (priv->translator_credits != NULL &&
1392 strcmp (priv->translator_credits, "translator_credits") &&
1393 strcmp (priv->translator_credits, "translator-credits"));
1395 gtk_widget_show (priv->credits_button);
1397 gtk_widget_hide (priv->credits_button);
1401 * gtk_about_dialog_set_authors:
1402 * @about: a #GtkAboutDialog
1403 * @authors: a %NULL-terminated array of strings
1405 * Sets the strings which are displayed in the authors tab
1406 * of the secondary credits dialog.
1411 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1412 const gchar **authors)
1414 GtkAboutDialogPrivate *priv;
1417 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1421 tmp = priv->authors;
1422 priv->authors = g_strdupv ((gchar **)authors);
1425 update_credits_button_visibility (about);
1427 g_object_notify (G_OBJECT (about), "authors");
1431 * gtk_about_dialog_get_documenters:
1432 * @about: a #GtkAboutDialog
1434 * Returns the string which are displayed in the documenters
1435 * tab of the secondary credits dialog.
1437 * Return value: A %NULL-terminated string array containing
1438 * the documenters. The array is owned by the about dialog
1439 * and must not be modified.
1443 G_CONST_RETURN gchar * G_CONST_RETURN *
1444 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1446 GtkAboutDialogPrivate *priv;
1448 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1452 return (const gchar * const *)priv->documenters;
1456 * gtk_about_dialog_set_documenters:
1457 * @about: a #GtkAboutDialog
1458 * @documenters: a %NULL-terminated array of strings
1460 * Sets the strings which are displayed in the documenters tab
1461 * of the secondary credits dialog.
1466 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1467 const gchar **documenters)
1469 GtkAboutDialogPrivate *priv;
1472 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1476 tmp = priv->documenters;
1477 priv->documenters = g_strdupv ((gchar **)documenters);
1480 update_credits_button_visibility (about);
1482 g_object_notify (G_OBJECT (about), "documenters");
1486 * gtk_about_dialog_get_artists:
1487 * @about: a #GtkAboutDialog
1489 * Returns the string which are displayed in the artists tab
1490 * of the secondary credits dialog.
1492 * Return value: A %NULL-terminated string array containing
1493 * the artists. The array is owned by the about dialog
1494 * and must not be modified.
1498 G_CONST_RETURN gchar * G_CONST_RETURN *
1499 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1501 GtkAboutDialogPrivate *priv;
1503 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1507 return (const gchar * const *)priv->artists;
1511 * gtk_about_dialog_set_artists:
1512 * @about: a #GtkAboutDialog
1513 * @artists: a %NULL-terminated array of strings
1515 * Sets the strings which are displayed in the artists tab
1516 * of the secondary credits dialog.
1521 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1522 const gchar **artists)
1524 GtkAboutDialogPrivate *priv;
1527 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1531 tmp = priv->artists;
1532 priv->artists = g_strdupv ((gchar **)artists);
1535 update_credits_button_visibility (about);
1537 g_object_notify (G_OBJECT (about), "artists");
1541 * gtk_about_dialog_get_translator_credits:
1542 * @about: a #GtkAboutDialog
1544 * Returns the translator credits string which is displayed
1545 * in the translators tab of the secondary credits dialog.
1547 * Return value: The translator credits string. The string is
1548 * owned by the about dialog and must not be modified.
1552 G_CONST_RETURN gchar *
1553 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1555 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1557 return about->priv->translator_credits;
1561 * gtk_about_dialog_set_translator_credits:
1562 * @about: a #GtkAboutDialog
1563 * @translator_credits: (allow-none): the translator credits
1565 * Sets the translator credits string which is displayed in
1566 * the translators tab of the secondary credits dialog.
1568 * The intended use for this string is to display the translator
1569 * of the language which is currently used in the user interface.
1570 * Using gettext(), a simple way to achieve that is to mark the
1571 * string for translation:
1573 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1575 * It is a good idea to use the customary msgid "translator-credits" for this
1576 * purpose, since translators will already know the purpose of that msgid, and
1577 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1583 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1584 const gchar *translator_credits)
1586 GtkAboutDialogPrivate *priv;
1589 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1593 tmp = priv->translator_credits;
1594 priv->translator_credits = g_strdup (translator_credits);
1597 update_credits_button_visibility (about);
1599 g_object_notify (G_OBJECT (about), "translator-credits");
1603 * gtk_about_dialog_get_logo:
1604 * @about: a #GtkAboutDialog
1606 * Returns the pixbuf displayed as logo in the about dialog.
1608 * Return value: the pixbuf displayed as logo. The pixbuf is
1609 * owned by the about dialog. If you want to keep a reference
1610 * to it, you have to call g_object_ref() on it.
1615 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1617 GtkAboutDialogPrivate *priv;
1619 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1623 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1624 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1630 icon_set_new_from_pixbufs (GList *pixbufs)
1632 GtkIconSet *icon_set = gtk_icon_set_new ();
1634 for (; pixbufs; pixbufs = pixbufs->next)
1636 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1638 GtkIconSource *icon_source = gtk_icon_source_new ();
1639 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1640 gtk_icon_set_add_source (icon_set, icon_source);
1641 gtk_icon_source_free (icon_source);
1648 * gtk_about_dialog_set_logo:
1649 * @about: a #GtkAboutDialog
1650 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1652 * Sets the pixbuf to be displayed as logo in the about dialog.
1653 * If it is %NULL, the default window icon set with
1654 * gtk_window_set_default_icon() will be used.
1659 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1662 GtkAboutDialogPrivate *priv;
1664 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1668 g_object_freeze_notify (G_OBJECT (about));
1670 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1671 g_object_notify (G_OBJECT (about), "logo-icon-name");
1674 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1677 GList *pixbufs = gtk_window_get_default_icon_list ();
1679 if (pixbufs != NULL)
1681 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1683 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1684 icon_set, GTK_ICON_SIZE_DIALOG);
1686 gtk_icon_set_unref (icon_set);
1687 g_list_free (pixbufs);
1691 g_object_notify (G_OBJECT (about), "logo");
1693 g_object_thaw_notify (G_OBJECT (about));
1697 * gtk_about_dialog_get_logo_icon_name:
1698 * @about: a #GtkAboutDialog
1700 * Returns the icon name displayed as logo in the about dialog.
1702 * Return value: the icon name displayed as logo. The string is
1703 * owned by the dialog. If you want to keep a reference
1704 * to it, you have to call g_strdup() on it.
1708 G_CONST_RETURN gchar *
1709 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1711 GtkAboutDialogPrivate *priv;
1712 const gchar *icon_name = NULL;
1714 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1718 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1719 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1725 * gtk_about_dialog_set_logo_icon_name:
1726 * @about: a #GtkAboutDialog
1727 * @icon_name: (allow-none): an icon name, or %NULL
1729 * Sets the pixbuf to be displayed as logo in the about dialog.
1730 * If it is %NULL, the default window icon set with
1731 * gtk_window_set_default_icon() will be used.
1736 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1737 const gchar *icon_name)
1739 GtkAboutDialogPrivate *priv;
1741 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1745 g_object_freeze_notify (G_OBJECT (about));
1747 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1748 g_object_notify (G_OBJECT (about), "logo");
1750 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1751 GTK_ICON_SIZE_DIALOG);
1752 g_object_notify (G_OBJECT (about), "logo-icon-name");
1754 g_object_thaw_notify (G_OBJECT (about));
1758 follow_if_link (GtkAboutDialog *about,
1759 GtkTextView *text_view,
1762 GSList *tags = NULL, *tagp = NULL;
1763 GtkAboutDialogPrivate *priv = about->priv;
1766 tags = gtk_text_iter_get_tags (iter);
1767 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1769 GtkTextTag *tag = tagp->data;
1771 uri = g_object_get_data (G_OBJECT (tag), "uri");
1773 emit_activate_link (about, uri);
1775 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1777 GdkColor *style_visited_link_color;
1780 gtk_widget_ensure_style (GTK_WIDGET (about));
1781 gtk_widget_style_get (GTK_WIDGET (about),
1782 "visited-link-color", &style_visited_link_color,
1784 if (style_visited_link_color)
1786 color = *style_visited_link_color;
1787 gdk_color_free (style_visited_link_color);
1790 color = default_visited_link_color;
1792 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1794 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1799 g_slist_free (tags);
1803 text_view_key_press_event (GtkWidget *text_view,
1805 GtkAboutDialog *about)
1808 GtkTextBuffer *buffer;
1810 switch (event->keyval)
1812 case GDK_KEY_Return:
1813 case GDK_KEY_ISO_Enter:
1814 case GDK_KEY_KP_Enter:
1815 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1816 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1817 gtk_text_buffer_get_insert (buffer));
1818 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1829 text_view_event_after (GtkWidget *text_view,
1831 GtkAboutDialog *about)
1833 GtkTextIter start, end, iter;
1834 GtkTextBuffer *buffer;
1835 GdkEventButton *button_event;
1838 if (event->type != GDK_BUTTON_RELEASE)
1841 button_event = (GdkEventButton *)event;
1843 if (button_event->button != 1)
1846 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1848 /* we shouldn't follow a link if the user has selected something */
1849 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1850 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1853 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1854 GTK_TEXT_WINDOW_WIDGET,
1855 button_event->x, button_event->y, &x, &y);
1857 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1859 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1865 set_cursor_if_appropriate (GtkAboutDialog *about,
1866 GtkTextView *text_view,
1871 GtkAboutDialogPrivate *priv = about->priv;
1872 GSList *tags = NULL, *tagp = NULL;
1874 gboolean hovering_over_link = FALSE;
1876 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1878 tags = gtk_text_iter_get_tags (&iter);
1879 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1881 GtkTextTag *tag = tagp->data;
1882 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1886 hovering_over_link = TRUE;
1891 if (hovering_over_link != priv->hovering_over_link)
1893 priv->hovering_over_link = hovering_over_link;
1895 if (hovering_over_link)
1896 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1898 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
1902 g_slist_free (tags);
1906 text_view_motion_notify_event (GtkWidget *text_view,
1907 GdkEventMotion *event,
1908 GtkAboutDialog *about)
1912 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1913 GTK_TEXT_WINDOW_WIDGET,
1914 event->x, event->y, &x, &y);
1916 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
1918 gdk_event_request_motions (event);
1925 text_view_visibility_notify_event (GtkWidget *text_view,
1926 GdkEventVisibility *event,
1927 GtkAboutDialog *about)
1929 GdkDeviceManager *device_manager;
1930 GdkDisplay *display;
1932 gint wx, wy, bx, by;
1934 display = gdk_window_get_display (event->window);
1935 device_manager = gdk_display_get_device_manager (display);
1936 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1938 for (d = devices; d; d = d->next)
1940 GdkDevice *dev = d->data;
1942 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
1945 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1946 GTK_TEXT_WINDOW_WIDGET,
1949 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
1956 text_view_new (GtkAboutDialog *about,
1959 GtkWrapMode wrap_mode)
1962 gchar *q0, *q1, *q2, *r1, *r2;
1964 GtkTextView *text_view;
1965 GtkTextBuffer *buffer;
1966 GdkColor *style_link_color;
1967 GdkColor *style_visited_link_color;
1969 GdkColor link_color;
1970 GdkColor visited_link_color;
1972 GtkAboutDialogPrivate *priv = about->priv;
1974 gtk_widget_ensure_style (GTK_WIDGET (about));
1975 gtk_widget_style_get (GTK_WIDGET (about),
1976 "link-color", &style_link_color,
1977 "visited-link-color", &style_visited_link_color,
1979 if (style_link_color)
1981 link_color = *style_link_color;
1982 gdk_color_free (style_link_color);
1985 link_color = default_link_color;
1987 if (style_visited_link_color)
1989 visited_link_color = *style_visited_link_color;
1990 gdk_color_free (style_visited_link_color);
1993 visited_link_color = default_visited_link_color;
1995 view = gtk_text_view_new ();
1996 text_view = GTK_TEXT_VIEW (view);
1997 buffer = gtk_text_view_get_buffer (text_view);
1998 gtk_text_view_set_cursor_visible (text_view, FALSE);
1999 gtk_text_view_set_editable (text_view, FALSE);
2000 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2002 gtk_text_view_set_left_margin (text_view, 8);
2003 gtk_text_view_set_right_margin (text_view, 8);
2005 g_signal_connect (view, "key-press-event",
2006 G_CALLBACK (text_view_key_press_event), about);
2007 g_signal_connect (view, "event-after",
2008 G_CALLBACK (text_view_event_after), about);
2009 g_signal_connect (view, "motion-notify-event",
2010 G_CALLBACK (text_view_motion_notify_event), about);
2011 g_signal_connect (view, "visibility-notify-event",
2012 G_CALLBACK (text_view_visibility_notify_event), about);
2014 if (strings == NULL)
2016 gtk_widget_hide (view);
2020 for (p = strings; *p; p++)
2025 q1 = strchr (q0, '<');
2026 q2 = q1 ? strchr (q1, '>') : NULL;
2027 r1 = strstr (q0, "http://");
2030 r2 = strpbrk (r1, " \n\t");
2032 r2 = strchr (r1, '\0');
2037 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2048 const gchar *link_type;
2053 gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
2054 gtk_text_buffer_get_end_iter (buffer, &end);
2056 link_type = "email";
2060 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2061 gtk_text_buffer_get_end_iter (buffer, &end);
2067 link = g_strndup (q1, q2 - q1);
2069 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2070 color = visited_link_color;
2074 tag = gtk_text_buffer_create_tag (buffer, NULL,
2075 "foreground-gdk", &color,
2076 "underline", PANGO_UNDERLINE_SINGLE,
2078 if (strcmp (link_type, "email") == 0)
2082 escaped = g_uri_escape_string (link, NULL, FALSE);
2083 uri = g_strconcat ("mailto:", escaped, NULL);
2088 uri = g_strdup (link);
2090 g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, 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 = about->priv;
2139 GtkWidget *dialog, *notebook;
2140 GtkDialog *credits_dialog;
2141 GtkWidget *content_area;
2142 GtkWidget *action_area;
2144 if (priv->credits_dialog != NULL)
2146 gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2150 dialog = gtk_dialog_new_with_buttons (_("Credits"),
2152 GTK_DIALOG_DESTROY_WITH_PARENT,
2153 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2155 credits_dialog = GTK_DIALOG (dialog);
2157 content_area = gtk_dialog_get_content_area (credits_dialog);
2158 action_area = gtk_dialog_get_action_area (credits_dialog);
2160 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2161 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2162 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2164 priv->credits_dialog = dialog;
2165 gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2166 gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2168 gtk_window_set_modal (GTK_WINDOW (dialog),
2169 gtk_window_get_modal (GTK_WINDOW (about)));
2171 g_signal_connect (dialog, "response",
2172 G_CALLBACK (gtk_widget_destroy), dialog);
2173 g_signal_connect (dialog, "destroy",
2174 G_CALLBACK (gtk_widget_destroyed),
2175 &(priv->credits_dialog));
2177 notebook = gtk_notebook_new ();
2178 gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2179 gtk_box_pack_start (GTK_BOX (content_area), notebook, TRUE, TRUE, 0);
2181 if (priv->authors != NULL)
2182 add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2184 if (priv->documenters != NULL)
2185 add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2187 /* Don't show an untranslated gettext msgid */
2188 if (priv->translator_credits != NULL &&
2189 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2190 strcmp (priv->translator_credits, "translator-credits") != 0)
2192 gchar *translators[2];
2194 translators[0] = priv->translator_credits;
2195 translators[1] = NULL;
2197 add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2200 if (priv->artists != NULL)
2201 add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2203 gtk_widget_show_all (dialog);
2207 set_policy (GtkWidget *sw)
2209 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2210 GTK_POLICY_AUTOMATIC,
2211 GTK_POLICY_AUTOMATIC);
2215 display_license_dialog (GtkWidget *button,
2218 GtkAboutDialog *about = (GtkAboutDialog *)data;
2219 GtkAboutDialogPrivate *priv = about->priv;
2220 GtkWidget *dialog, *view, *sw;
2221 GtkDialog *license_dialog;
2222 GtkWidget *content_area;
2223 GtkWidget *action_area;
2226 if (priv->license_dialog != NULL)
2228 gtk_window_present (GTK_WINDOW (priv->license_dialog));
2232 dialog = gtk_dialog_new_with_buttons (_("License"),
2234 GTK_DIALOG_DESTROY_WITH_PARENT,
2235 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2237 license_dialog = GTK_DIALOG (dialog);
2239 content_area = gtk_dialog_get_content_area (license_dialog);
2240 action_area = gtk_dialog_get_action_area (license_dialog);
2242 gtk_container_set_border_width (GTK_CONTAINER (license_dialog), 5);
2243 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2244 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2246 priv->license_dialog = dialog;
2247 gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2248 gtk_dialog_set_default_response (license_dialog, GTK_RESPONSE_CANCEL);
2250 gtk_window_set_modal (GTK_WINDOW (dialog),
2251 gtk_window_get_modal (GTK_WINDOW (about)));
2253 g_signal_connect (dialog, "response",
2254 G_CALLBACK (gtk_widget_destroy), dialog);
2255 g_signal_connect (dialog, "destroy",
2256 G_CALLBACK (gtk_widget_destroyed),
2257 &(priv->license_dialog));
2259 sw = gtk_scrolled_window_new (NULL, NULL);
2260 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2261 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2263 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2265 GTK_POLICY_AUTOMATIC);
2266 g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2267 gtk_box_pack_start (GTK_BOX (content_area), sw, TRUE, TRUE, 0);
2269 strings[0] = priv->license;
2271 view = text_view_new (about, dialog, strings,
2272 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2274 gtk_container_add (GTK_CONTAINER (sw), view);
2276 gtk_widget_show_all (dialog);
2280 * gtk_about_dialog_new:
2282 * Creates a new #GtkAboutDialog.
2284 * Returns: a newly created #GtkAboutDialog
2289 gtk_about_dialog_new (void)
2291 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2293 return GTK_WIDGET (dialog);
2297 close_cb (GtkAboutDialog *about)
2299 GtkAboutDialogPrivate *priv = about->priv;
2301 if (priv->license_dialog != NULL)
2303 gtk_widget_destroy (priv->license_dialog);
2304 priv->license_dialog = NULL;
2307 if (priv->credits_dialog != NULL)
2309 gtk_widget_destroy (priv->credits_dialog);
2310 priv->credits_dialog = NULL;
2313 gtk_widget_hide (GTK_WIDGET (about));
2318 * gtk_show_about_dialog:
2319 * @parent: (allow-none): transient parent, or %NULL for none
2320 * @first_property_name: the name of the first property
2321 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2323 * This is a convenience function for showing an application's about box.
2324 * The constructed dialog is associated with the parent window and
2325 * reused for future invocations of this function.
2330 gtk_show_about_dialog (GtkWindow *parent,
2331 const gchar *first_property_name,
2334 static GtkWidget *global_about_dialog = NULL;
2335 GtkWidget *dialog = NULL;
2339 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2341 dialog = global_about_dialog;
2345 dialog = gtk_about_dialog_new ();
2347 g_object_ref_sink (dialog);
2349 g_signal_connect (dialog, "delete-event",
2350 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2352 /* Close dialog on user response */
2353 g_signal_connect (dialog, "response",
2354 G_CALLBACK (close_cb), NULL);
2356 va_start (var_args, first_property_name);
2357 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2362 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2363 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2364 g_object_set_data_full (G_OBJECT (parent),
2365 I_("gtk-about-dialog"),
2366 dialog, g_object_unref);
2369 global_about_dialog = dialog;
2373 gtk_window_present (GTK_WINDOW (dialog));
2377 * gtk_about_dialog_set_license_type:
2378 * @about: a #GtkAboutDialog
2379 * @license_type: the type of license
2381 * Sets the license of the application showing the @about dialog from a
2382 * list of known licenses.
2384 * This function overrides the license set using
2385 * gtk_about_dialog_set_license().
2390 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2391 GtkLicense license_type)
2393 GtkAboutDialogPrivate *priv;
2395 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2396 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2397 license_type <= GTK_LICENSE_ARTISTIC);
2401 if (priv->license_type != license_type)
2403 g_object_freeze_notify (G_OBJECT (about));
2405 priv->license_type = license_type;
2407 /* custom licenses use the contents of the :license property */
2408 if (priv->license_type != GTK_LICENSE_CUSTOM)
2413 url = gtk_license_urls[priv->license_type];
2415 url = priv->website_url;
2417 /* compose the new license string as:
2420 * <copyright line 1>\n
2422 * <copyright line n>\n
2424 * license preamble + URL
2427 str = g_string_sized_new (256);
2428 g_string_append (str, priv->name);
2429 g_string_append (str, "\n");
2430 g_string_append (str, priv->copyright);
2431 g_string_append (str, "\n\n");
2432 g_string_append_printf (str, _(gtk_license_preamble), url);
2434 g_free (priv->license);
2435 priv->license = g_string_free (str, FALSE);
2436 priv->wrap_license = TRUE;
2437 gtk_widget_show (priv->license_button);
2439 g_object_notify (G_OBJECT (about), "wrap-license");
2440 g_object_notify (G_OBJECT (about), "license");
2443 g_object_notify (G_OBJECT (about), "license-type");
2445 g_object_thaw_notify (G_OBJECT (about));
2450 * gtk_about_dialog_get_license_type:
2451 * @about: a #GtkAboutDialog
2453 * Retrieves the license set using gtk_about_dialog_set_license_type()
2455 * Return value: a #GtkLicense value
2460 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2462 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2464 return about->priv->license_type;