1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2001 CodeFactory AB
3 * Copyright (C) 2001, 2002 Anders Carlsson
4 * Copyright (C) 2003, 2004 Matthias Clasen <mclasen@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Author: Anders Carlsson <andersca@gnome.org>
25 * Modified by the GTK+ Team and others 1997-2004. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #include <gdk/gdkkeysyms.h>
37 #include "gtkaboutdialog.h"
38 #include "gtkbutton.h"
40 #include "gtkdialog.h"
44 #include "gtklinkbutton.h"
45 #include "gtkmarshalers.h"
46 #include "gtknotebook.h"
47 #include "gtkscrolledwindow.h"
49 #include "gtktextview.h"
51 #include "gtkiconfactory.h"
54 #include "gtkmessagedialog.h"
55 #include "gtkprivate.h"
60 * SECTION:gtkaboutdialog
61 * @Short_description: Display information about an application
62 * @Title: GtkAboutDialog
63 * @See_also:#GTK_STOCK_ABOUT
65 * The #GtkAboutDialog offers a simple way to display information about
66 * a program like its logo, name, copyright, website and license. It is
67 * also possible to give credits to the authors, documenters, translators
68 * and artists who have worked on the program. An about dialog is typically
69 * opened when the user selects the <literal>About</literal> option from
70 * the <literal>Help</literal> menu. All parts of the dialog are optional.
72 * About dialog often contain links and email addresses. #GtkAboutDialog
73 * supports this by offering global hooks, which are called when the user
74 * clicks on a link or email address, see gtk_about_dialog_set_email_hook()
75 * and gtk_about_dialog_set_url_hook(). Email addresses in the
76 * authors, documenters and artists properties are recognized by looking for
77 * <literal><user@<!-- -->host></literal>, URLs are
78 * recognized by looking for <literal>http://url</literal>, with
79 * <literal>url</literal> extending to the next space, tab or line break.
81 * <para id="gtk-about-dialog-hook-setup">
82 * Since 2.18 #GtkAboutDialog provides default website and email hooks that
86 * If you want provide your own hooks overriding the default ones, it is
87 * important to do so before setting the website and email URL properties,
89 * <informalexample><programlisting>
90 * gtk_about_dialog_set_url_hook (GTK_ABOUT_DIALOG (dialog), launch_url, NULL, NULL);
91 * gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), app_url);
92 * </programlisting></informalexample>
93 * To disable the default hooks, you can pass %NULL as the hook func. Then,
94 * the #GtkAboutDialog widget will not display the website or the
95 * email addresses as clickable.
97 * To make constructing a #GtkAboutDialog as convenient as possible, you can
98 * use the function gtk_show_about_dialog() which constructs and shows a dialog
99 * and keeps it around so that it can be shown again.
101 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
102 * on the dialog window (where %s is replaced by the name of the
103 * application, but in order to ensure proper translation of the title,
104 * applications should set the title property explicitly when constructing
105 * a #GtkAboutDialog, as shown in the following example:
106 * <informalexample><programlisting>
107 * gtk_show_about_dialog (NULL,
108 * "program-name", "ExampleCode",
109 * "logo", example_logo,
110 * "title" _("About ExampleCode"),
112 * </programlisting></informalexample>
113 * Note that prior to GTK+ 2.12, the #GtkAboutDialog:program-name property
114 * was called "name". This was changed to avoid the conflict with the
115 * #GtkWidget:name property.
118 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
119 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
121 /* Translators: this is the license preamble; the string at the end
122 * contains the URL of the license.
124 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit %s");
126 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
127 static const gchar *gtk_license_urls[] = {
131 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
132 "http://www.gnu.org/licenses/gpl.html",
134 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
135 "http://www.gnu.org/licenses/lgpl.html",
137 "http://opensource.org/licenses/bsd-license.php",
138 "http://opensource.org/licenses/mit-license.php",
140 "http://opensource.org/licenses/artistic-license-2.0.php"
143 struct _GtkAboutDialogPrivate
151 gchar *translator_credits;
158 GtkWidget *logo_image;
159 GtkWidget *name_label;
160 GtkWidget *comments_label;
161 GtkWidget *copyright_label;
162 GtkWidget *website_label;
164 GtkWidget *credits_button;
165 GtkWidget *credits_dialog;
166 GtkWidget *license_button;
167 GtkWidget *license_dialog;
169 GdkCursor *hand_cursor;
170 GdkCursor *regular_cursor;
172 GSList *visited_links;
174 GtkLicense license_type;
176 guint hovering_over_link : 1;
177 guint wrap_license : 1;
180 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
195 PROP_TRANSLATOR_CREDITS,
203 static void gtk_about_dialog_finalize (GObject *object);
204 static void gtk_about_dialog_get_property (GObject *object,
208 static void gtk_about_dialog_set_property (GObject *object,
212 static void gtk_about_dialog_show (GtkWidget *widge);
213 static void update_name_version (GtkAboutDialog *about);
214 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
215 static void follow_if_link (GtkAboutDialog *about,
216 GtkTextView *text_view,
218 static void set_cursor_if_appropriate (GtkAboutDialog *about,
219 GtkTextView *text_view,
223 static void display_credits_dialog (GtkWidget *button,
225 static void display_license_dialog (GtkWidget *button,
227 static void close_cb (GtkAboutDialog *about);
228 static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
236 static guint signals[LAST_SIGNAL] = { 0 };
238 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
242 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
244 GObjectClass *object_class;
245 GtkWidgetClass *widget_class;
247 object_class = (GObjectClass *)klass;
248 widget_class = (GtkWidgetClass *)klass;
250 object_class->set_property = gtk_about_dialog_set_property;
251 object_class->get_property = gtk_about_dialog_get_property;
253 object_class->finalize = gtk_about_dialog_finalize;
255 widget_class->show = gtk_about_dialog_show;
257 klass->activate_link = gtk_about_dialog_activate_link;
260 * GtkAboutDialog::activate-link:
261 * @label: The object on which the signal was emitted
262 * @uri: the URI that is activated
264 * The signal which gets emitted to activate a URI.
265 * Applications may connect to it to override the default behaviour,
266 * which is to call gtk_show_uri().
268 * Returns: %TRUE if the link has been activated
272 signals[ACTIVATE_LINK] =
273 g_signal_new ("activate-link",
274 G_TYPE_FROM_CLASS (object_class),
276 G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
277 _gtk_boolean_handled_accumulator, NULL,
278 _gtk_marshal_BOOLEAN__STRING,
279 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
282 * GtkAboutDialog:program-name:
284 * The name of the program.
285 * If this is not set, it defaults to g_get_application_name().
289 g_object_class_install_property (object_class,
291 g_param_spec_string ("program-name",
293 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
295 GTK_PARAM_READWRITE));
298 * GtkAboutDialog:version:
300 * The version of the program.
304 g_object_class_install_property (object_class,
306 g_param_spec_string ("version",
307 P_("Program version"),
308 P_("The version of the program"),
310 GTK_PARAM_READWRITE));
313 * GtkAboutDialog:copyright:
315 * Copyright information for the program.
319 g_object_class_install_property (object_class,
321 g_param_spec_string ("copyright",
322 P_("Copyright string"),
323 P_("Copyright information for the program"),
325 GTK_PARAM_READWRITE));
329 * GtkAboutDialog:comments:
331 * Comments about the program. This string is displayed in a label
332 * in the main dialog, thus it should be a short explanation of
333 * the main purpose of the program, not a detailed list of features.
337 g_object_class_install_property (object_class,
339 g_param_spec_string ("comments",
340 P_("Comments string"),
341 P_("Comments about the program"),
343 GTK_PARAM_READWRITE));
346 * GtkAboutDialog:license:
348 * The license of the program. This string is displayed in a
349 * text view in a secondary dialog, therefore it is fine to use
350 * a long multi-paragraph text. Note that the text is only wrapped
351 * in the text view if the "wrap-license" property is set to %TRUE;
352 * otherwise the text itself must contain the intended linebreaks.
353 * When setting this property to a non-%NULL value, the
354 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
359 g_object_class_install_property (object_class,
361 g_param_spec_string ("license",
363 _("The license of the program"),
365 GTK_PARAM_READWRITE));
368 * GtkAboutDialog:license-type:
370 * The license of the program, as a value of the %GtkLicense enumeration.
372 * The #GtkAboutDialog will automatically fill out a standard disclaimer
373 * and link the user to the appropriate online resource for the license
376 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
377 * specified in the #GtkAboutDialog:website property.
379 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
380 * #GtkAboutDialog:license property are used.
382 * For any other #GtkLicense value, the contents of the
383 * #GtkAboutDialog:license property are also set by this property as
388 g_object_class_install_property (object_class,
390 g_param_spec_enum ("license-type",
392 P_("The license type of the program"),
395 GTK_PARAM_READWRITE));
398 * GtkAboutDialog:website:
400 * The URL for the link to the website of the program.
401 * This should be a string starting with "http://.
405 g_object_class_install_property (object_class,
407 g_param_spec_string ("website",
409 P_("The URL for the link to the website of the program"),
411 GTK_PARAM_READWRITE));
414 * GtkAboutDialog:website-label:
416 * The label for the link to the website of the program. If this is not set,
417 * it defaults to the URL specified in the #GtkAboutDialog:website property.
421 g_object_class_install_property (object_class,
423 g_param_spec_string ("website-label",
425 P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
427 GTK_PARAM_READWRITE));
430 * GtkAboutDialog:authors:
432 * The authors of the program, as a %NULL-terminated array of strings.
433 * Each string may contain email addresses and URLs, which will be displayed
434 * as links, see the introduction for more details.
438 g_object_class_install_property (object_class,
440 g_param_spec_boxed ("authors",
442 P_("List of authors of the program"),
444 GTK_PARAM_READWRITE));
447 * GtkAboutDialog:documenters:
449 * The people documenting the program, as a %NULL-terminated array of strings.
450 * Each string may contain email addresses and URLs, which will be displayed
451 * as links, see the introduction for more details.
455 g_object_class_install_property (object_class,
457 g_param_spec_boxed ("documenters",
459 P_("List of people documenting the program"),
461 GTK_PARAM_READWRITE));
464 * GtkAboutDialog:artists:
466 * The people who contributed artwork to the program, as a %NULL-terminated
467 * array of strings. Each string may contain email addresses and URLs, which
468 * will be displayed as links, see the introduction for more details.
472 g_object_class_install_property (object_class,
474 g_param_spec_boxed ("artists",
476 P_("List of people who have contributed artwork to the program"),
478 GTK_PARAM_READWRITE));
482 * GtkAboutDialog:translator-credits:
484 * Credits to the translators. This string should be marked as translatable.
485 * The string may contain email addresses and URLs, which will be displayed
486 * as links, see the introduction for more details.
490 g_object_class_install_property (object_class,
491 PROP_TRANSLATOR_CREDITS,
492 g_param_spec_string ("translator-credits",
493 P_("Translator credits"),
494 P_("Credits to the translators. This string should be marked as translatable"),
496 GTK_PARAM_READWRITE));
499 * GtkAboutDialog:logo:
501 * A logo for the about box. If this is not set, it defaults to
502 * gtk_window_get_default_icon_list().
506 g_object_class_install_property (object_class,
508 g_param_spec_object ("logo",
510 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
512 GTK_PARAM_READWRITE));
515 * GtkAboutDialog:logo-icon-name:
517 * A named icon to use as the logo for the about box. This property
518 * overrides the #GtkAboutDialog:logo property.
522 g_object_class_install_property (object_class,
524 g_param_spec_string ("logo-icon-name",
525 P_("Logo Icon Name"),
526 P_("A named icon to use as the logo for the about box."),
528 GTK_PARAM_READWRITE));
530 * GtkAboutDialog:wrap-license:
532 * Whether to wrap the text in the license dialog.
536 g_object_class_install_property (object_class,
538 g_param_spec_boolean ("wrap-license",
540 P_("Whether to wrap the license text."),
542 GTK_PARAM_READWRITE));
545 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
549 emit_activate_link (GtkAboutDialog *about,
552 gboolean handled = FALSE;
554 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
560 gtk_about_dialog_init (GtkAboutDialog *about)
562 GtkDialog *dialog = GTK_DIALOG (about);
563 GtkAboutDialogPrivate *priv;
564 GtkWidget *vbox, *hbox, *button, *close_button, *image;
565 GtkWidget *content_area, *action_area;
568 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
572 priv->version = NULL;
573 priv->copyright = NULL;
574 priv->comments = NULL;
575 priv->website_url = NULL;
576 priv->website_text = NULL;
577 priv->translator_credits = NULL;
578 priv->license = NULL;
579 priv->authors = NULL;
580 priv->documenters = NULL;
581 priv->artists = NULL;
583 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
584 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
585 priv->hovering_over_link = FALSE;
586 priv->wrap_license = FALSE;
588 priv->license_type = GTK_LICENSE_UNKNOWN;
590 content_area = gtk_dialog_get_content_area (dialog);
591 action_area = gtk_dialog_get_action_area (dialog);
593 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
594 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
595 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
598 gtk_widget_push_composite_child ();
600 vbox = gtk_vbox_new (FALSE, 8);
601 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
602 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
604 priv->logo_image = gtk_image_new ();
605 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
607 priv->name_label = gtk_label_new (NULL);
608 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
609 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
610 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
612 priv->comments_label = gtk_label_new (NULL);
613 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
614 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
615 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
616 gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
618 priv->copyright_label = gtk_label_new (NULL);
619 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
620 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
621 gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
623 hbox = gtk_hbox_new (TRUE, 0);
624 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
626 priv->website_label = button = gtk_label_new ("");
627 gtk_widget_set_no_show_all (button, TRUE);
628 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
629 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
630 g_signal_connect_swapped (button, "activate-link",
631 G_CALLBACK (emit_activate_link), about);
633 gtk_widget_show (vbox);
634 gtk_widget_show (priv->logo_image);
635 gtk_widget_show (priv->name_label);
636 gtk_widget_show (hbox);
638 /* Add the close button */
639 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
640 GTK_RESPONSE_CANCEL);
641 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
643 /* Add the credits button */
644 button = gtk_button_new_with_mnemonic (_("C_redits"));
645 gtk_widget_set_can_default (button, TRUE);
646 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
647 gtk_button_set_image (GTK_BUTTON (button), image);
648 gtk_widget_set_no_show_all (button, TRUE);
649 gtk_box_pack_end (GTK_BOX (action_area),
650 button, FALSE, TRUE, 0);
651 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
652 g_signal_connect (button, "clicked",
653 G_CALLBACK (display_credits_dialog), about);
654 priv->credits_button = button;
655 priv->credits_dialog = NULL;
657 /* Add the license button */
658 button = gtk_button_new_from_stock (_("_License"));
659 gtk_widget_set_can_default (button, TRUE);
660 gtk_widget_set_no_show_all (button, TRUE);
661 gtk_box_pack_end (GTK_BOX (action_area),
662 button, FALSE, TRUE, 0);
663 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
664 g_signal_connect (button, "clicked",
665 G_CALLBACK (display_license_dialog), about);
666 priv->license_button = button;
667 priv->license_dialog = NULL;
669 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
671 gtk_widget_pop_composite_child ();
673 gtk_widget_grab_default (close_button);
674 gtk_widget_grab_focus (close_button);
677 gtk_about_dialog_set_program_name (about, NULL);
678 gtk_about_dialog_set_logo (about, NULL);
682 gtk_about_dialog_finalize (GObject *object)
684 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
685 GtkAboutDialogPrivate *priv = about->priv;
688 g_free (priv->version);
689 g_free (priv->copyright);
690 g_free (priv->comments);
691 g_free (priv->license);
692 g_free (priv->website_url);
693 g_free (priv->website_text);
694 g_free (priv->translator_credits);
696 g_strfreev (priv->authors);
697 g_strfreev (priv->documenters);
698 g_strfreev (priv->artists);
700 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
701 g_slist_free (priv->visited_links);
703 gdk_cursor_unref (priv->hand_cursor);
704 gdk_cursor_unref (priv->regular_cursor);
706 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
710 gtk_about_dialog_set_property (GObject *object,
715 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
716 GtkAboutDialogPrivate *priv = about->priv;
721 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
724 gtk_about_dialog_set_version (about, g_value_get_string (value));
727 gtk_about_dialog_set_comments (about, g_value_get_string (value));
730 gtk_about_dialog_set_website (about, g_value_get_string (value));
732 case PROP_WEBSITE_LABEL:
733 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
736 gtk_about_dialog_set_license (about, g_value_get_string (value));
738 case PROP_LICENSE_TYPE:
739 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
742 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
745 gtk_about_dialog_set_logo (about, g_value_get_object (value));
748 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
750 case PROP_DOCUMENTERS:
751 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
754 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
756 case PROP_TRANSLATOR_CREDITS:
757 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
759 case PROP_LOGO_ICON_NAME:
760 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
762 case PROP_WRAP_LICENSE:
763 priv->wrap_license = g_value_get_boolean (value);
766 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
772 gtk_about_dialog_get_property (GObject *object,
777 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
778 GtkAboutDialogPrivate *priv = about->priv;
783 g_value_set_string (value, priv->name);
786 g_value_set_string (value, priv->version);
789 g_value_set_string (value, priv->copyright);
792 g_value_set_string (value, priv->comments);
795 g_value_set_string (value, priv->website_url);
797 case PROP_WEBSITE_LABEL:
798 g_value_set_string (value, priv->website_text);
801 g_value_set_string (value, priv->license);
803 case PROP_LICENSE_TYPE:
804 g_value_set_enum (value, priv->license_type);
806 case PROP_TRANSLATOR_CREDITS:
807 g_value_set_string (value, priv->translator_credits);
810 g_value_set_boxed (value, priv->authors);
812 case PROP_DOCUMENTERS:
813 g_value_set_boxed (value, priv->documenters);
816 g_value_set_boxed (value, priv->artists);
819 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
820 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
822 g_value_set_object (value, NULL);
824 case PROP_LOGO_ICON_NAME:
825 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
827 const gchar *icon_name;
829 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
830 g_value_set_string (value, icon_name);
833 g_value_set_string (value, NULL);
835 case PROP_WRAP_LICENSE:
836 g_value_set_boolean (value, priv->wrap_license);
839 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
845 gtk_about_dialog_activate_link (GtkAboutDialog *about,
849 GError *error = NULL;
851 screen = gtk_widget_get_screen (GTK_WIDGET (about));
853 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
857 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
858 GTK_DIALOG_DESTROY_WITH_PARENT |
862 "%s", _("Could not show link"));
863 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
864 "%s", error->message);
865 g_error_free (error);
867 g_signal_connect (dialog, "response",
868 G_CALLBACK (gtk_widget_destroy), NULL);
870 gtk_window_present (GTK_WINDOW (dialog));
877 update_website (GtkAboutDialog *about)
879 GtkAboutDialogPrivate *priv = about->priv;
881 gtk_widget_show (priv->website_label);
883 if (priv->website_url)
887 if (priv->website_text)
891 escaped = g_markup_escape_text (priv->website_text, -1);
892 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
893 priv->website_url, escaped);
898 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
899 priv->website_url, priv->website_url);
902 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
907 if (priv->website_url)
908 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
909 else if (priv->website_text)
910 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
912 gtk_widget_hide (priv->website_label);
917 gtk_about_dialog_show (GtkWidget *widget)
919 update_website (GTK_ABOUT_DIALOG (widget));
921 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
925 * gtk_about_dialog_get_program_name:
926 * @about: a #GtkAboutDialog
928 * Returns the program name displayed in the about dialog.
930 * Return value: The program name. The string is owned by the about
931 * dialog and must not be modified.
935 G_CONST_RETURN gchar *
936 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
938 GtkAboutDialogPrivate *priv;
940 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
948 update_name_version (GtkAboutDialog *about)
950 GtkAboutDialogPrivate *priv;
951 gchar *title_string, *name_string;
955 title_string = g_strdup_printf (_("About %s"), priv->name);
956 gtk_window_set_title (GTK_WINDOW (about), title_string);
957 g_free (title_string);
959 if (priv->version != NULL)
960 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
961 priv->name, priv->version);
963 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
966 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
968 g_free (name_string);
972 * gtk_about_dialog_set_program_name:
973 * @about: a #GtkAboutDialog
974 * @name: the program name
976 * Sets the name to display in the about dialog.
977 * If this is not set, it defaults to g_get_application_name().
982 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
985 GtkAboutDialogPrivate *priv;
988 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
993 priv->name = g_strdup (name ? name : g_get_application_name ());
996 update_name_version (about);
998 g_object_notify (G_OBJECT (about), "program-name");
1003 * gtk_about_dialog_get_version:
1004 * @about: a #GtkAboutDialog
1006 * Returns the version string.
1008 * Return value: The version string. The string is owned by the about
1009 * dialog and must not be modified.
1013 G_CONST_RETURN gchar *
1014 gtk_about_dialog_get_version (GtkAboutDialog *about)
1016 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1018 return about->priv->version;
1022 * gtk_about_dialog_set_version:
1023 * @about: a #GtkAboutDialog
1024 * @version: (allow-none): the version string
1026 * Sets the version string to display in the about dialog.
1031 gtk_about_dialog_set_version (GtkAboutDialog *about,
1032 const gchar *version)
1034 GtkAboutDialogPrivate *priv;
1037 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1041 tmp = priv->version;
1042 priv->version = g_strdup (version);
1045 update_name_version (about);
1047 g_object_notify (G_OBJECT (about), "version");
1051 * gtk_about_dialog_get_copyright:
1052 * @about: a #GtkAboutDialog
1054 * Returns the copyright string.
1056 * Return value: The copyright string. The string is owned by the about
1057 * dialog and must not be modified.
1061 G_CONST_RETURN gchar *
1062 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1064 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1066 return about->priv->copyright;
1070 * gtk_about_dialog_set_copyright:
1071 * @about: a #GtkAboutDialog
1072 * @copyright: (allow-none) the copyright string
1074 * Sets the copyright string to display in the about dialog.
1075 * This should be a short string of one or two lines.
1080 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1081 const gchar *copyright)
1083 GtkAboutDialogPrivate *priv;
1084 gchar *copyright_string, *tmp;
1086 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1090 tmp = priv->copyright;
1091 priv->copyright = g_strdup (copyright);
1094 if (priv->copyright != NULL)
1096 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1098 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1099 g_free (copyright_string);
1101 gtk_widget_show (priv->copyright_label);
1104 gtk_widget_hide (priv->copyright_label);
1106 g_object_notify (G_OBJECT (about), "copyright");
1110 * gtk_about_dialog_get_comments:
1111 * @about: a #GtkAboutDialog
1113 * Returns the comments string.
1115 * Return value: The comments. The string is owned by the about
1116 * dialog and must not be modified.
1120 G_CONST_RETURN gchar *
1121 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1123 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1125 return about->priv->comments;
1129 * gtk_about_dialog_set_comments:
1130 * @about: a #GtkAboutDialog
1131 * @comments: (allow-none): a comments string
1133 * Sets the comments string to display in the about dialog.
1134 * This should be a short string of one or two lines.
1139 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1140 const gchar *comments)
1142 GtkAboutDialogPrivate *priv;
1145 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1149 tmp = priv->comments;
1152 priv->comments = g_strdup (comments);
1153 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1154 gtk_widget_show (priv->comments_label);
1158 priv->comments = NULL;
1159 gtk_widget_hide (priv->comments_label);
1163 g_object_notify (G_OBJECT (about), "comments");
1167 * gtk_about_dialog_get_license:
1168 * @about: a #GtkAboutDialog
1170 * Returns the license information.
1172 * Return value: The license information. The string is owned by the about
1173 * dialog and must not be modified.
1177 G_CONST_RETURN gchar *
1178 gtk_about_dialog_get_license (GtkAboutDialog *about)
1180 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1182 return about->priv->license;
1186 * gtk_about_dialog_set_license:
1187 * @about: a #GtkAboutDialog
1188 * @license: (allow-none): the license information or %NULL
1190 * Sets the license information to be displayed in the secondary
1191 * license dialog. If @license is %NULL, the license button is
1197 gtk_about_dialog_set_license (GtkAboutDialog *about,
1198 const gchar *license)
1200 GtkAboutDialogPrivate *priv;
1203 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1207 tmp = priv->license;
1210 priv->license = g_strdup (license);
1211 priv->license_type = GTK_LICENSE_CUSTOM;
1212 gtk_widget_show (priv->license_button);
1216 priv->license = NULL;
1217 priv->license_type = GTK_LICENSE_UNKNOWN;
1218 gtk_widget_hide (priv->license_button);
1222 g_object_notify (G_OBJECT (about), "license");
1223 g_object_notify (G_OBJECT (about), "license-type");
1227 * gtk_about_dialog_get_wrap_license:
1228 * @about: a #GtkAboutDialog
1230 * Returns whether the license text in @about is
1231 * automatically wrapped.
1233 * Returns: %TRUE if the license text is wrapped
1238 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1240 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1242 return about->priv->wrap_license;
1246 * gtk_about_dialog_set_wrap_license:
1247 * @about: a #GtkAboutDialog
1248 * @wrap_license: whether to wrap the license
1250 * Sets whether the license text in @about is
1251 * automatically wrapped.
1256 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1257 gboolean wrap_license)
1259 GtkAboutDialogPrivate *priv;
1261 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1265 wrap_license = wrap_license != FALSE;
1267 if (priv->wrap_license != wrap_license)
1269 priv->wrap_license = wrap_license;
1271 g_object_notify (G_OBJECT (about), "wrap-license");
1276 * gtk_about_dialog_get_website:
1277 * @about: a #GtkAboutDialog
1279 * Returns the website URL.
1281 * Return value: The website URL. The string is owned by the about
1282 * dialog and must not be modified.
1286 G_CONST_RETURN gchar *
1287 gtk_about_dialog_get_website (GtkAboutDialog *about)
1289 GtkAboutDialogPrivate *priv;
1291 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1295 return priv->website_url;
1299 * gtk_about_dialog_set_website:
1300 * @about: a #GtkAboutDialog
1301 * @website: (allow-none): a URL string starting with "http://"
1303 * Sets the URL to use for the website link.
1305 * Note that that the hook functions need to be set up
1306 * before calling this function.
1311 gtk_about_dialog_set_website (GtkAboutDialog *about,
1312 const gchar *website)
1314 GtkAboutDialogPrivate *priv;
1317 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1321 tmp = priv->website_url;
1322 priv->website_url = g_strdup (website);
1325 update_website (about);
1327 g_object_notify (G_OBJECT (about), "website");
1331 * gtk_about_dialog_get_website_label:
1332 * @about: a #GtkAboutDialog
1334 * Returns the label used for the website link.
1336 * Return value: The label used for the website link. The string is
1337 * owned by the about dialog and must not be modified.
1341 G_CONST_RETURN gchar *
1342 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1344 GtkAboutDialogPrivate *priv;
1346 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1350 return priv->website_text;
1354 * gtk_about_dialog_set_website_label:
1355 * @about: a #GtkAboutDialog
1356 * @website_label: the label used for the website link
1358 * Sets the label to be used for the website link.
1359 * It defaults to the website URL.
1364 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1365 const gchar *website_label)
1367 GtkAboutDialogPrivate *priv;
1370 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1374 tmp = priv->website_text;
1375 priv->website_text = g_strdup (website_label);
1378 update_website (about);
1380 g_object_notify (G_OBJECT (about), "website-label");
1384 * gtk_about_dialog_get_authors:
1385 * @about: a #GtkAboutDialog
1387 * Returns the string which are displayed in the authors tab
1388 * of the secondary credits dialog.
1390 * Return value: A %NULL-terminated string array containing
1391 * the authors. The array is owned by the about dialog
1392 * and must not be modified.
1396 G_CONST_RETURN gchar * G_CONST_RETURN *
1397 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1399 GtkAboutDialogPrivate *priv;
1401 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1405 return (const gchar * const *) priv->authors;
1409 update_credits_button_visibility (GtkAboutDialog *about)
1411 GtkAboutDialogPrivate *priv = about->priv;
1414 show = priv->authors != NULL ||
1415 priv->documenters != NULL ||
1416 priv->artists != NULL ||
1417 (priv->translator_credits != NULL &&
1418 strcmp (priv->translator_credits, "translator_credits") &&
1419 strcmp (priv->translator_credits, "translator-credits"));
1421 gtk_widget_show (priv->credits_button);
1423 gtk_widget_hide (priv->credits_button);
1427 * gtk_about_dialog_set_authors:
1428 * @about: a #GtkAboutDialog
1429 * @authors: a %NULL-terminated array of strings
1431 * Sets the strings which are displayed in the authors tab
1432 * of the secondary credits dialog.
1437 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1438 const gchar **authors)
1440 GtkAboutDialogPrivate *priv;
1443 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1447 tmp = priv->authors;
1448 priv->authors = g_strdupv ((gchar **)authors);
1451 update_credits_button_visibility (about);
1453 g_object_notify (G_OBJECT (about), "authors");
1457 * gtk_about_dialog_get_documenters:
1458 * @about: a #GtkAboutDialog
1460 * Returns the string which are displayed in the documenters
1461 * tab of the secondary credits dialog.
1463 * Return value: A %NULL-terminated string array containing
1464 * the documenters. The array is owned by the about dialog
1465 * and must not be modified.
1469 G_CONST_RETURN gchar * G_CONST_RETURN *
1470 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1472 GtkAboutDialogPrivate *priv;
1474 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1478 return (const gchar * const *)priv->documenters;
1482 * gtk_about_dialog_set_documenters:
1483 * @about: a #GtkAboutDialog
1484 * @documenters: a %NULL-terminated array of strings
1486 * Sets the strings which are displayed in the documenters tab
1487 * of the secondary credits dialog.
1492 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1493 const gchar **documenters)
1495 GtkAboutDialogPrivate *priv;
1498 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1502 tmp = priv->documenters;
1503 priv->documenters = g_strdupv ((gchar **)documenters);
1506 update_credits_button_visibility (about);
1508 g_object_notify (G_OBJECT (about), "documenters");
1512 * gtk_about_dialog_get_artists:
1513 * @about: a #GtkAboutDialog
1515 * Returns the string which are displayed in the artists tab
1516 * of the secondary credits dialog.
1518 * Return value: A %NULL-terminated string array containing
1519 * the artists. The array is owned by the about dialog
1520 * and must not be modified.
1524 G_CONST_RETURN gchar * G_CONST_RETURN *
1525 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1527 GtkAboutDialogPrivate *priv;
1529 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1533 return (const gchar * const *)priv->artists;
1537 * gtk_about_dialog_set_artists:
1538 * @about: a #GtkAboutDialog
1539 * @artists: a %NULL-terminated array of strings
1541 * Sets the strings which are displayed in the artists tab
1542 * of the secondary credits dialog.
1547 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1548 const gchar **artists)
1550 GtkAboutDialogPrivate *priv;
1553 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1557 tmp = priv->artists;
1558 priv->artists = g_strdupv ((gchar **)artists);
1561 update_credits_button_visibility (about);
1563 g_object_notify (G_OBJECT (about), "artists");
1567 * gtk_about_dialog_get_translator_credits:
1568 * @about: a #GtkAboutDialog
1570 * Returns the translator credits string which is displayed
1571 * in the translators tab of the secondary credits dialog.
1573 * Return value: The translator credits string. The string is
1574 * owned by the about dialog and must not be modified.
1578 G_CONST_RETURN gchar *
1579 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1581 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1583 return about->priv->translator_credits;
1587 * gtk_about_dialog_set_translator_credits:
1588 * @about: a #GtkAboutDialog
1589 * @translator_credits: (allow-none): the translator credits
1591 * Sets the translator credits string which is displayed in
1592 * the translators tab of the secondary credits dialog.
1594 * The intended use for this string is to display the translator
1595 * of the language which is currently used in the user interface.
1596 * Using gettext(), a simple way to achieve that is to mark the
1597 * string for translation:
1599 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1601 * It is a good idea to use the customary msgid "translator-credits" for this
1602 * purpose, since translators will already know the purpose of that msgid, and
1603 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1609 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1610 const gchar *translator_credits)
1612 GtkAboutDialogPrivate *priv;
1615 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1619 tmp = priv->translator_credits;
1620 priv->translator_credits = g_strdup (translator_credits);
1623 update_credits_button_visibility (about);
1625 g_object_notify (G_OBJECT (about), "translator-credits");
1629 * gtk_about_dialog_get_logo:
1630 * @about: a #GtkAboutDialog
1632 * Returns the pixbuf displayed as logo in the about dialog.
1634 * Return value: the pixbuf displayed as logo. The pixbuf is
1635 * owned by the about dialog. If you want to keep a reference
1636 * to it, you have to call g_object_ref() on it.
1641 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1643 GtkAboutDialogPrivate *priv;
1645 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1649 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1650 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1656 icon_set_new_from_pixbufs (GList *pixbufs)
1658 GtkIconSet *icon_set = gtk_icon_set_new ();
1660 for (; pixbufs; pixbufs = pixbufs->next)
1662 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1664 GtkIconSource *icon_source = gtk_icon_source_new ();
1665 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1666 gtk_icon_set_add_source (icon_set, icon_source);
1667 gtk_icon_source_free (icon_source);
1674 * gtk_about_dialog_set_logo:
1675 * @about: a #GtkAboutDialog
1676 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1678 * Sets the pixbuf to be displayed as logo in the about dialog.
1679 * If it is %NULL, the default window icon set with
1680 * gtk_window_set_default_icon() will be used.
1685 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1688 GtkAboutDialogPrivate *priv;
1690 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1694 g_object_freeze_notify (G_OBJECT (about));
1696 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1697 g_object_notify (G_OBJECT (about), "logo-icon-name");
1700 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1703 GList *pixbufs = gtk_window_get_default_icon_list ();
1705 if (pixbufs != NULL)
1707 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1709 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1710 icon_set, GTK_ICON_SIZE_DIALOG);
1712 gtk_icon_set_unref (icon_set);
1713 g_list_free (pixbufs);
1717 g_object_notify (G_OBJECT (about), "logo");
1719 g_object_thaw_notify (G_OBJECT (about));
1723 * gtk_about_dialog_get_logo_icon_name:
1724 * @about: a #GtkAboutDialog
1726 * Returns the icon name displayed as logo in the about dialog.
1728 * Return value: the icon name displayed as logo. The string is
1729 * owned by the dialog. If you want to keep a reference
1730 * to it, you have to call g_strdup() on it.
1734 G_CONST_RETURN gchar *
1735 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1737 GtkAboutDialogPrivate *priv;
1738 const gchar *icon_name = NULL;
1740 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1744 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1745 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1751 * gtk_about_dialog_set_logo_icon_name:
1752 * @about: a #GtkAboutDialog
1753 * @icon_name: (allow-none): an icon name, or %NULL
1755 * Sets the pixbuf to be displayed as logo in the about dialog.
1756 * If it is %NULL, the default window icon set with
1757 * gtk_window_set_default_icon() will be used.
1762 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1763 const gchar *icon_name)
1765 GtkAboutDialogPrivate *priv;
1767 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1771 g_object_freeze_notify (G_OBJECT (about));
1773 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1774 g_object_notify (G_OBJECT (about), "logo");
1776 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1777 GTK_ICON_SIZE_DIALOG);
1778 g_object_notify (G_OBJECT (about), "logo-icon-name");
1780 g_object_thaw_notify (G_OBJECT (about));
1784 follow_if_link (GtkAboutDialog *about,
1785 GtkTextView *text_view,
1788 GSList *tags = NULL, *tagp = NULL;
1789 GtkAboutDialogPrivate *priv = about->priv;
1792 tags = gtk_text_iter_get_tags (iter);
1793 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1795 GtkTextTag *tag = tagp->data;
1797 uri = g_object_get_data (G_OBJECT (tag), "uri");
1799 emit_activate_link (about, uri);
1801 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1803 GdkColor *style_visited_link_color;
1806 gtk_widget_ensure_style (GTK_WIDGET (about));
1807 gtk_widget_style_get (GTK_WIDGET (about),
1808 "visited-link-color", &style_visited_link_color,
1810 if (style_visited_link_color)
1812 color = *style_visited_link_color;
1813 gdk_color_free (style_visited_link_color);
1816 color = default_visited_link_color;
1818 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1820 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1825 g_slist_free (tags);
1829 text_view_key_press_event (GtkWidget *text_view,
1831 GtkAboutDialog *about)
1834 GtkTextBuffer *buffer;
1836 switch (event->keyval)
1838 case GDK_KEY_Return:
1839 case GDK_KEY_ISO_Enter:
1840 case GDK_KEY_KP_Enter:
1841 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1842 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1843 gtk_text_buffer_get_insert (buffer));
1844 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1855 text_view_event_after (GtkWidget *text_view,
1857 GtkAboutDialog *about)
1859 GtkTextIter start, end, iter;
1860 GtkTextBuffer *buffer;
1861 GdkEventButton *button_event;
1864 if (event->type != GDK_BUTTON_RELEASE)
1867 button_event = (GdkEventButton *)event;
1869 if (button_event->button != 1)
1872 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1874 /* we shouldn't follow a link if the user has selected something */
1875 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1876 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1879 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1880 GTK_TEXT_WINDOW_WIDGET,
1881 button_event->x, button_event->y, &x, &y);
1883 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1885 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1891 set_cursor_if_appropriate (GtkAboutDialog *about,
1892 GtkTextView *text_view,
1897 GtkAboutDialogPrivate *priv = about->priv;
1898 GSList *tags = NULL, *tagp = NULL;
1900 gboolean hovering_over_link = FALSE;
1902 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1904 tags = gtk_text_iter_get_tags (&iter);
1905 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1907 GtkTextTag *tag = tagp->data;
1908 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1912 hovering_over_link = TRUE;
1917 if (hovering_over_link != priv->hovering_over_link)
1919 priv->hovering_over_link = hovering_over_link;
1921 if (hovering_over_link)
1922 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1924 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
1928 g_slist_free (tags);
1932 text_view_motion_notify_event (GtkWidget *text_view,
1933 GdkEventMotion *event,
1934 GtkAboutDialog *about)
1938 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1939 GTK_TEXT_WINDOW_WIDGET,
1940 event->x, event->y, &x, &y);
1942 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
1944 gdk_event_request_motions (event);
1951 text_view_visibility_notify_event (GtkWidget *text_view,
1952 GdkEventVisibility *event,
1953 GtkAboutDialog *about)
1955 GdkDeviceManager *device_manager;
1956 GdkDisplay *display;
1958 gint wx, wy, bx, by;
1960 display = gdk_drawable_get_display (event->window);
1961 device_manager = gdk_display_get_device_manager (display);
1962 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1964 for (d = devices; d; d = d->next)
1966 GdkDevice *dev = d->data;
1968 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
1971 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1972 GTK_TEXT_WINDOW_WIDGET,
1975 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
1982 text_view_new (GtkAboutDialog *about,
1985 GtkWrapMode wrap_mode)
1988 gchar *q0, *q1, *q2, *r1, *r2;
1990 GtkTextView *text_view;
1991 GtkTextBuffer *buffer;
1992 GdkColor *style_link_color;
1993 GdkColor *style_visited_link_color;
1995 GdkColor link_color;
1996 GdkColor visited_link_color;
1998 GtkAboutDialogPrivate *priv = about->priv;
2000 gtk_widget_ensure_style (GTK_WIDGET (about));
2001 gtk_widget_style_get (GTK_WIDGET (about),
2002 "link-color", &style_link_color,
2003 "visited-link-color", &style_visited_link_color,
2005 if (style_link_color)
2007 link_color = *style_link_color;
2008 gdk_color_free (style_link_color);
2011 link_color = default_link_color;
2013 if (style_visited_link_color)
2015 visited_link_color = *style_visited_link_color;
2016 gdk_color_free (style_visited_link_color);
2019 visited_link_color = default_visited_link_color;
2021 view = gtk_text_view_new ();
2022 text_view = GTK_TEXT_VIEW (view);
2023 buffer = gtk_text_view_get_buffer (text_view);
2024 gtk_text_view_set_cursor_visible (text_view, FALSE);
2025 gtk_text_view_set_editable (text_view, FALSE);
2026 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2028 gtk_text_view_set_left_margin (text_view, 8);
2029 gtk_text_view_set_right_margin (text_view, 8);
2031 g_signal_connect (view, "key-press-event",
2032 G_CALLBACK (text_view_key_press_event), about);
2033 g_signal_connect (view, "event-after",
2034 G_CALLBACK (text_view_event_after), about);
2035 g_signal_connect (view, "motion-notify-event",
2036 G_CALLBACK (text_view_motion_notify_event), about);
2037 g_signal_connect (view, "visibility-notify-event",
2038 G_CALLBACK (text_view_visibility_notify_event), about);
2040 if (strings == NULL)
2042 gtk_widget_hide (view);
2046 for (p = strings; *p; p++)
2051 q1 = strchr (q0, '<');
2052 q2 = q1 ? strchr (q1, '>') : NULL;
2053 r1 = strstr (q0, "http://");
2056 r2 = strpbrk (r1, " \n\t");
2058 r2 = strchr (r1, '\0');
2063 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2074 const gchar *link_type;
2079 gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
2080 gtk_text_buffer_get_end_iter (buffer, &end);
2082 link_type = "email";
2086 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2087 gtk_text_buffer_get_end_iter (buffer, &end);
2093 link = g_strndup (q1, q2 - q1);
2095 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2096 color = visited_link_color;
2100 tag = gtk_text_buffer_create_tag (buffer, NULL,
2101 "foreground-gdk", &color,
2102 "underline", PANGO_UNDERLINE_SINGLE,
2104 if (strcmp (link_type, "email") == 0)
2108 escaped = g_uri_escape_string (link, NULL, FALSE);
2109 uri = g_strconcat ("mailto:", escaped, NULL);
2114 uri = g_strdup (link);
2116 g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
2117 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2123 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2129 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2132 gtk_widget_show (view);
2137 add_credits_page (GtkAboutDialog *about,
2138 GtkWidget *credits_dialog,
2139 GtkWidget *notebook,
2143 GtkWidget *sw, *view;
2145 view = text_view_new (about, credits_dialog, people, GTK_WRAP_NONE);
2147 sw = gtk_scrolled_window_new (NULL, NULL);
2148 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2150 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2151 GTK_POLICY_AUTOMATIC,
2152 GTK_POLICY_AUTOMATIC);
2153 gtk_container_add (GTK_CONTAINER (sw), view);
2155 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
2156 sw, gtk_label_new (title));
2160 display_credits_dialog (GtkWidget *button,
2163 GtkAboutDialog *about = (GtkAboutDialog *)data;
2164 GtkAboutDialogPrivate *priv = about->priv;
2165 GtkWidget *dialog, *notebook;
2166 GtkDialog *credits_dialog;
2167 GtkWidget *content_area;
2168 GtkWidget *action_area;
2170 if (priv->credits_dialog != NULL)
2172 gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2176 dialog = gtk_dialog_new_with_buttons (_("Credits"),
2178 GTK_DIALOG_DESTROY_WITH_PARENT,
2179 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2181 credits_dialog = GTK_DIALOG (dialog);
2183 content_area = gtk_dialog_get_content_area (credits_dialog);
2184 action_area = gtk_dialog_get_action_area (credits_dialog);
2186 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2187 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2188 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2190 priv->credits_dialog = dialog;
2191 gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2192 gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2194 gtk_window_set_modal (GTK_WINDOW (dialog),
2195 gtk_window_get_modal (GTK_WINDOW (about)));
2197 g_signal_connect (dialog, "response",
2198 G_CALLBACK (gtk_widget_destroy), dialog);
2199 g_signal_connect (dialog, "destroy",
2200 G_CALLBACK (gtk_widget_destroyed),
2201 &(priv->credits_dialog));
2203 notebook = gtk_notebook_new ();
2204 gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2205 gtk_box_pack_start (GTK_BOX (content_area), notebook, TRUE, TRUE, 0);
2207 if (priv->authors != NULL)
2208 add_credits_page (about, dialog, notebook, _("Written by"), priv->authors);
2210 if (priv->documenters != NULL)
2211 add_credits_page (about, dialog, notebook, _("Documented by"), priv->documenters);
2213 /* Don't show an untranslated gettext msgid */
2214 if (priv->translator_credits != NULL &&
2215 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2216 strcmp (priv->translator_credits, "translator-credits") != 0)
2218 gchar *translators[2];
2220 translators[0] = priv->translator_credits;
2221 translators[1] = NULL;
2223 add_credits_page (about, dialog, notebook, _("Translated by"), translators);
2226 if (priv->artists != NULL)
2227 add_credits_page (about, dialog, notebook, _("Artwork by"), priv->artists);
2229 gtk_widget_show_all (dialog);
2233 set_policy (GtkWidget *sw)
2235 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2236 GTK_POLICY_AUTOMATIC,
2237 GTK_POLICY_AUTOMATIC);
2241 display_license_dialog (GtkWidget *button,
2244 GtkAboutDialog *about = (GtkAboutDialog *)data;
2245 GtkAboutDialogPrivate *priv = about->priv;
2246 GtkWidget *dialog, *view, *sw;
2247 GtkDialog *license_dialog;
2248 GtkWidget *content_area;
2249 GtkWidget *action_area;
2252 if (priv->license_dialog != NULL)
2254 gtk_window_present (GTK_WINDOW (priv->license_dialog));
2258 dialog = gtk_dialog_new_with_buttons (_("License"),
2260 GTK_DIALOG_DESTROY_WITH_PARENT,
2261 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2263 license_dialog = GTK_DIALOG (dialog);
2265 content_area = gtk_dialog_get_content_area (license_dialog);
2266 action_area = gtk_dialog_get_action_area (license_dialog);
2268 gtk_container_set_border_width (GTK_CONTAINER (license_dialog), 5);
2269 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
2270 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
2272 priv->license_dialog = dialog;
2273 gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2274 gtk_dialog_set_default_response (license_dialog, GTK_RESPONSE_CANCEL);
2276 gtk_window_set_modal (GTK_WINDOW (dialog),
2277 gtk_window_get_modal (GTK_WINDOW (about)));
2279 g_signal_connect (dialog, "response",
2280 G_CALLBACK (gtk_widget_destroy), dialog);
2281 g_signal_connect (dialog, "destroy",
2282 G_CALLBACK (gtk_widget_destroyed),
2283 &(priv->license_dialog));
2285 sw = gtk_scrolled_window_new (NULL, NULL);
2286 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2287 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2289 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2291 GTK_POLICY_AUTOMATIC);
2292 g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2293 gtk_box_pack_start (GTK_BOX (content_area), sw, TRUE, TRUE, 0);
2295 strings[0] = priv->license;
2297 view = text_view_new (about, dialog, strings,
2298 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2300 gtk_container_add (GTK_CONTAINER (sw), view);
2302 gtk_widget_show_all (dialog);
2306 * gtk_about_dialog_new:
2308 * Creates a new #GtkAboutDialog.
2310 * Returns: a newly created #GtkAboutDialog
2315 gtk_about_dialog_new (void)
2317 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2319 return GTK_WIDGET (dialog);
2323 close_cb (GtkAboutDialog *about)
2325 GtkAboutDialogPrivate *priv = about->priv;
2327 if (priv->license_dialog != NULL)
2329 gtk_widget_destroy (priv->license_dialog);
2330 priv->license_dialog = NULL;
2333 if (priv->credits_dialog != NULL)
2335 gtk_widget_destroy (priv->credits_dialog);
2336 priv->credits_dialog = NULL;
2339 gtk_widget_hide (GTK_WIDGET (about));
2344 * gtk_show_about_dialog:
2345 * @parent: (allow-none): transient parent, or %NULL for none
2346 * @first_property_name: the name of the first property
2347 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2349 * This is a convenience function for showing an application's about box.
2350 * The constructed dialog is associated with the parent window and
2351 * reused for future invocations of this function.
2356 gtk_show_about_dialog (GtkWindow *parent,
2357 const gchar *first_property_name,
2360 static GtkWidget *global_about_dialog = NULL;
2361 GtkWidget *dialog = NULL;
2365 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2367 dialog = global_about_dialog;
2371 dialog = gtk_about_dialog_new ();
2373 g_object_ref_sink (dialog);
2375 g_signal_connect (dialog, "delete-event",
2376 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2378 /* Close dialog on user response */
2379 g_signal_connect (dialog, "response",
2380 G_CALLBACK (close_cb), NULL);
2382 va_start (var_args, first_property_name);
2383 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2388 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2389 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2390 g_object_set_data_full (G_OBJECT (parent),
2391 I_("gtk-about-dialog"),
2392 dialog, g_object_unref);
2395 global_about_dialog = dialog;
2399 gtk_window_present (GTK_WINDOW (dialog));
2403 * gtk_about_dialog_set_license_type:
2404 * @about: a #GtkAboutDialog
2405 * @license_type: the type of license
2407 * Sets the license of the application showing the @about dialog from a
2408 * list of known licenses.
2410 * This function overrides the license set using
2411 * gtk_about_dialog_set_license().
2416 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2417 GtkLicense license_type)
2419 GtkAboutDialogPrivate *priv;
2421 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2422 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2423 license_type <= GTK_LICENSE_ARTISTIC);
2427 if (priv->license_type != license_type)
2429 g_object_freeze_notify (G_OBJECT (about));
2431 priv->license_type = license_type;
2433 /* custom licenses use the contents of the :license property */
2434 if (priv->license_type != GTK_LICENSE_CUSTOM)
2439 url = gtk_license_urls[priv->license_type];
2441 url = priv->website_url;
2443 /* compose the new license string as:
2446 * <copyright line 1>\n
2448 * <copyright line n>\n
2450 * license preamble + URL
2453 str = g_string_sized_new (256);
2454 g_string_append (str, priv->name);
2455 g_string_append (str, "\n");
2456 g_string_append (str, priv->copyright);
2457 g_string_append (str, "\n\n");
2458 g_string_append_printf (str, _(gtk_license_preamble), url);
2460 g_free (priv->license);
2461 priv->license = g_string_free (str, FALSE);
2462 priv->wrap_license = TRUE;
2463 gtk_widget_show (priv->license_button);
2465 g_object_notify (G_OBJECT (about), "wrap-license");
2466 g_object_notify (G_OBJECT (about), "license");
2469 g_object_notify (G_OBJECT (about), "license-type");
2471 g_object_thaw_notify (G_OBJECT (about));
2476 * gtk_about_dialog_get_license_type:
2477 * @about: a #GtkAboutDialog
2479 * Retrieves the license set using gtk_about_dialog_set_license_type()
2481 * Return value: a #GtkLicense value
2486 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2488 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2490 return about->priv->license_type;