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 "gtkaboutdialog.h"
36 #include "gtkbutton.h"
38 #include "gtkdialog.h"
43 #include "gtklinkbutton.h"
44 #include "gtkmarshalers.h"
45 #include "gtknotebook.h"
46 #include "gtkorientable.h"
47 #include "gtkscrolledwindow.h"
49 #include "gtktextview.h"
51 #include "gtkiconfactory.h"
53 #include "gtkmainprivate.h"
54 #include "gtkmessagedialog.h"
55 #include "gtktogglebutton.h"
56 #include "gtktypebuiltins.h"
57 #include "gtkprivate.h"
62 * SECTION:gtkaboutdialog
63 * @Short_description: Display information about an application
64 * @Title: GtkAboutDialog
65 * @See_also: #GTK_STOCK_ABOUT
67 * The GtkAboutDialog offers a simple way to display information about
68 * a program like its logo, name, copyright, website and license. It is
69 * also possible to give credits to the authors, documenters, translators
70 * and artists who have worked on the program. An about dialog is typically
71 * opened when the user selects the <literal>About</literal> option from
72 * the <literal>Help</literal> menu. All parts of the dialog are optional.
74 * About dialog often contain links and email addresses. GtkAboutDialog
75 * displays these as clickable links. By default, it calls gtk_show_uri()
76 * when a user clicks one. The behaviour can be overridden with the
77 * #GtkAboutDialog::activate-link signal.
79 * To make constructing a GtkAboutDialog as convenient as possible, you can
80 * use the function gtk_show_about_dialog() which constructs and shows a dialog
81 * and keeps it around so that it can be shown again.
83 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
84 * on the dialog window (where %s is replaced by the name of the
85 * application, but in order to ensure proper translation of the title,
86 * applications should set the title property explicitly when constructing
87 * a GtkAboutDialog, as shown in the following example:
88 * <informalexample><programlisting>
89 * gtk_show_about_dialog (NULL,
90 * "program-name", "ExampleCode",
91 * "logo", example_logo,
92 * "title" _("About ExampleCode"),
94 * </programlisting></informalexample>
97 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
98 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
100 /* Translators: this is the license preamble; the string at the end
101 * contains the URL of the license.
103 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit <a href=\"%s\">%s</a>");
105 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
106 static const gchar *gtk_license_urls[] = {
110 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
111 "http://www.gnu.org/licenses/gpl.html",
113 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
114 "http://www.gnu.org/licenses/lgpl.html",
116 "http://opensource.org/licenses/bsd-license.php",
117 "http://opensource.org/licenses/mit-license.php",
119 "http://opensource.org/licenses/artistic-license-2.0.php"
122 struct _GtkAboutDialogPrivate
130 gchar *translator_credits;
141 GtkWidget *logo_image;
142 GtkWidget *name_label;
143 GtkWidget *version_label;
144 GtkWidget *comments_label;
145 GtkWidget *copyright_label;
146 GtkWidget *license_label;
147 GtkWidget *website_label;
149 GtkWidget *credits_button;
150 GtkWidget *license_button;
152 GdkCursor *hand_cursor;
153 GdkCursor *regular_cursor;
155 GSList *visited_links;
157 GtkLicense license_type;
159 guint hovering_over_link : 1;
160 guint wrap_license : 1;
163 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
178 PROP_TRANSLATOR_CREDITS,
186 static void gtk_about_dialog_finalize (GObject *object);
187 static void gtk_about_dialog_get_property (GObject *object,
191 static void gtk_about_dialog_set_property (GObject *object,
195 static void gtk_about_dialog_show (GtkWidget *widge);
196 static void update_name_version (GtkAboutDialog *about);
197 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
198 static void follow_if_link (GtkAboutDialog *about,
199 GtkTextView *text_view,
201 static void set_cursor_if_appropriate (GtkAboutDialog *about,
202 GtkTextView *text_view,
206 static void display_credits_page (GtkWidget *button,
208 static void display_license_page (GtkWidget *button,
210 static void close_cb (GtkAboutDialog *about);
211 static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
219 static guint signals[LAST_SIGNAL] = { 0 };
221 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
225 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
227 GObjectClass *object_class;
228 GtkWidgetClass *widget_class;
230 object_class = (GObjectClass *)klass;
231 widget_class = (GtkWidgetClass *)klass;
233 object_class->set_property = gtk_about_dialog_set_property;
234 object_class->get_property = gtk_about_dialog_get_property;
236 object_class->finalize = gtk_about_dialog_finalize;
238 widget_class->show = gtk_about_dialog_show;
240 klass->activate_link = gtk_about_dialog_activate_link;
243 * GtkAboutDialog::activate-link:
244 * @label: The object on which the signal was emitted
245 * @uri: the URI that is activated
247 * The signal which gets emitted to activate a URI.
248 * Applications may connect to it to override the default behaviour,
249 * which is to call gtk_show_uri().
251 * Returns: %TRUE if the link has been activated
255 signals[ACTIVATE_LINK] =
256 g_signal_new ("activate-link",
257 G_TYPE_FROM_CLASS (object_class),
259 G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
260 _gtk_boolean_handled_accumulator, NULL,
261 _gtk_marshal_BOOLEAN__STRING,
262 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
265 * GtkAboutDialog:program-name:
267 * The name of the program.
268 * If this is not set, it defaults to g_get_application_name().
272 g_object_class_install_property (object_class,
274 g_param_spec_string ("program-name",
276 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
278 GTK_PARAM_READWRITE));
281 * GtkAboutDialog:version:
283 * The version of the program.
287 g_object_class_install_property (object_class,
289 g_param_spec_string ("version",
290 P_("Program version"),
291 P_("The version of the program"),
293 GTK_PARAM_READWRITE));
296 * GtkAboutDialog:copyright:
298 * Copyright information for the program.
302 g_object_class_install_property (object_class,
304 g_param_spec_string ("copyright",
305 P_("Copyright string"),
306 P_("Copyright information for the program"),
308 GTK_PARAM_READWRITE));
312 * GtkAboutDialog:comments:
314 * Comments about the program. This string is displayed in a label
315 * in the main dialog, thus it should be a short explanation of
316 * the main purpose of the program, not a detailed list of features.
320 g_object_class_install_property (object_class,
322 g_param_spec_string ("comments",
323 P_("Comments string"),
324 P_("Comments about the program"),
326 GTK_PARAM_READWRITE));
329 * GtkAboutDialog:license:
331 * The license of the program. This string is displayed in a
332 * text view in a secondary dialog, therefore it is fine to use
333 * a long multi-paragraph text. Note that the text is only wrapped
334 * in the text view if the "wrap-license" property is set to %TRUE;
335 * otherwise the text itself must contain the intended linebreaks.
336 * When setting this property to a non-%NULL value, the
337 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
342 g_object_class_install_property (object_class,
344 g_param_spec_string ("license",
346 _("The license of the program"),
348 GTK_PARAM_READWRITE));
351 * GtkAboutDialog:license-type:
353 * The license of the program, as a value of the %GtkLicense enumeration.
355 * The #GtkAboutDialog will automatically fill out a standard disclaimer
356 * and link the user to the appropriate online resource for the license
359 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
360 * specified in the #GtkAboutDialog:website property.
362 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
363 * #GtkAboutDialog:license property are used.
365 * For any other #GtkLicense value, the contents of the
366 * #GtkAboutDialog:license property are also set by this property as
371 g_object_class_install_property (object_class,
373 g_param_spec_enum ("license-type",
375 P_("The license type of the program"),
378 GTK_PARAM_READWRITE));
381 * GtkAboutDialog:website:
383 * The URL for the link to the website of the program.
384 * This should be a string starting with "http://.
388 g_object_class_install_property (object_class,
390 g_param_spec_string ("website",
392 P_("The URL for the link to the website of the program"),
394 GTK_PARAM_READWRITE));
397 * GtkAboutDialog:website-label:
399 * The label for the link to the website of the program.
403 g_object_class_install_property (object_class,
405 g_param_spec_string ("website-label",
407 P_("The label for the link to the website of the program"),
409 GTK_PARAM_READWRITE));
412 * GtkAboutDialog:authors:
414 * The authors of the program, as a %NULL-terminated array of strings.
415 * Each string may contain email addresses and URLs, which will be displayed
416 * as links, see the introduction for more details.
420 g_object_class_install_property (object_class,
422 g_param_spec_boxed ("authors",
424 P_("List of authors of the program"),
426 GTK_PARAM_READWRITE));
429 * GtkAboutDialog:documenters:
431 * The people documenting the program, as a %NULL-terminated array of strings.
432 * Each string may contain email addresses and URLs, which will be displayed
433 * as links, see the introduction for more details.
437 g_object_class_install_property (object_class,
439 g_param_spec_boxed ("documenters",
441 P_("List of people documenting the program"),
443 GTK_PARAM_READWRITE));
446 * GtkAboutDialog:artists:
448 * The people who contributed artwork to the program, as a %NULL-terminated
449 * array of strings. Each string may contain email addresses and URLs, which
450 * will be displayed as links, see the introduction for more details.
454 g_object_class_install_property (object_class,
456 g_param_spec_boxed ("artists",
458 P_("List of people who have contributed artwork to the program"),
460 GTK_PARAM_READWRITE));
464 * GtkAboutDialog:translator-credits:
466 * Credits to the translators. This string should be marked as translatable.
467 * The string may contain email addresses and URLs, which will be displayed
468 * as links, see the introduction for more details.
472 g_object_class_install_property (object_class,
473 PROP_TRANSLATOR_CREDITS,
474 g_param_spec_string ("translator-credits",
475 P_("Translator credits"),
476 P_("Credits to the translators. This string should be marked as translatable"),
478 GTK_PARAM_READWRITE));
481 * GtkAboutDialog:logo:
483 * A logo for the about box. If this is not set, it defaults to
484 * gtk_window_get_default_icon_list().
488 g_object_class_install_property (object_class,
490 g_param_spec_object ("logo",
492 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
494 GTK_PARAM_READWRITE));
497 * GtkAboutDialog:logo-icon-name:
499 * A named icon to use as the logo for the about box. This property
500 * overrides the #GtkAboutDialog:logo property.
504 g_object_class_install_property (object_class,
506 g_param_spec_string ("logo-icon-name",
507 P_("Logo Icon Name"),
508 P_("A named icon to use as the logo for the about box."),
510 GTK_PARAM_READWRITE));
512 * GtkAboutDialog:wrap-license:
514 * Whether to wrap the text in the license dialog.
518 g_object_class_install_property (object_class,
520 g_param_spec_boolean ("wrap-license",
522 P_("Whether to wrap the license text."),
524 GTK_PARAM_READWRITE));
527 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
531 emit_activate_link (GtkAboutDialog *about,
534 gboolean handled = FALSE;
536 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
542 update_license_button_visibility (GtkAboutDialog *about)
544 GtkAboutDialogPrivate *priv = about->priv;
546 if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL)
547 gtk_widget_show (priv->license_button);
549 gtk_widget_hide (priv->license_button);
553 update_credits_button_visibility (GtkAboutDialog *about)
555 GtkAboutDialogPrivate *priv = about->priv;
558 show = (priv->authors != NULL ||
559 priv->documenters != NULL ||
560 priv->artists != NULL ||
561 (priv->translator_credits != NULL &&
562 strcmp (priv->translator_credits, "translator_credits") &&
563 strcmp (priv->translator_credits, "translator-credits")));
565 gtk_widget_show (priv->credits_button);
567 gtk_widget_hide (priv->credits_button);
571 switch_page (GtkAboutDialog *about,
574 GtkAboutDialogPrivate *priv = about->priv;
576 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page);
580 display_main_page (GtkButton *button,
583 GtkAboutDialog *about = (GtkAboutDialog *)data;
585 switch_page (about, 0);
589 credits_button_clicked (GtkButton *button,
592 GtkAboutDialog *about = (GtkAboutDialog *)data;
593 GtkAboutDialogPrivate *priv = about->priv;
596 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
600 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
601 display_credits_page (NULL, data);
605 display_main_page (NULL, data);
610 license_button_clicked (GtkButton *button,
613 GtkAboutDialog *about = (GtkAboutDialog *)data;
614 GtkAboutDialogPrivate *priv = about->priv;
617 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
621 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
622 display_license_page (NULL, data);
626 display_main_page (NULL, data);
630 gtk_about_dialog_init (GtkAboutDialog *about)
632 GtkDialog *dialog = GTK_DIALOG (about);
633 GtkAboutDialogPrivate *priv;
634 GtkWidget *vbox, *page_vbox, *hbox, *button, *close_button, *image;
635 GtkWidget *content_area, *action_area;
638 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
642 priv->version = NULL;
643 priv->copyright = NULL;
644 priv->comments = NULL;
645 priv->website_url = NULL;
646 priv->website_text = NULL;
647 priv->translator_credits = NULL;
648 priv->license = NULL;
649 priv->authors = NULL;
650 priv->documenters = NULL;
651 priv->artists = NULL;
653 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
654 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
655 priv->hovering_over_link = FALSE;
656 priv->wrap_license = FALSE;
658 priv->license_type = GTK_LICENSE_UNKNOWN;
660 content_area = gtk_dialog_get_content_area (dialog);
661 action_area = gtk_dialog_get_action_area (dialog);
663 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
664 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
665 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
668 gtk_widget_push_composite_child ();
670 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
671 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
672 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
674 priv->logo_image = gtk_image_new ();
675 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
677 priv->name_label = gtk_label_new (NULL);
678 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
679 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
680 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
682 priv->notebook = gtk_notebook_new ();
683 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
684 gtk_widget_set_size_request (priv->notebook, 400, 100);
686 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
687 gtk_widget_show (page_vbox);
688 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
689 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
690 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
692 priv->version_label = gtk_label_new (NULL);
693 gtk_label_set_selectable (GTK_LABEL (priv->version_label), TRUE);
694 gtk_label_set_justify (GTK_LABEL (priv->version_label), GTK_JUSTIFY_CENTER);
695 gtk_box_pack_start (GTK_BOX (page_vbox), priv->version_label, FALSE, FALSE, 0);
697 priv->comments_label = gtk_label_new (NULL);
698 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
699 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
700 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
701 gtk_box_pack_start (GTK_BOX (page_vbox), priv->comments_label, FALSE, FALSE, 0);
703 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
704 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
705 gtk_box_pack_start (GTK_BOX (page_vbox), hbox, FALSE, FALSE, 0);
707 priv->website_label = button = gtk_label_new ("");
708 gtk_widget_set_no_show_all (button, TRUE);
709 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
710 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
711 g_signal_connect_swapped (button, "activate-link",
712 G_CALLBACK (emit_activate_link), about);
714 priv->license_label = gtk_label_new (NULL);
715 gtk_label_set_use_markup (GTK_LABEL (priv->license_label), TRUE);
716 gtk_label_set_selectable (GTK_LABEL (priv->license_label), TRUE);
717 gtk_label_set_justify (GTK_LABEL (priv->license_label), GTK_JUSTIFY_CENTER);
718 gtk_box_pack_end (GTK_BOX (page_vbox), priv->license_label, FALSE, FALSE, 0);
719 gtk_label_set_line_wrap (GTK_LABEL (priv->license_label), TRUE);
721 priv->copyright_label = gtk_label_new (NULL);
722 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
723 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
724 gtk_box_pack_end (GTK_BOX (page_vbox), priv->copyright_label, FALSE, FALSE, 0);
726 gtk_widget_show (vbox);
727 gtk_widget_show (priv->notebook);
728 gtk_widget_show (priv->logo_image);
729 gtk_widget_show (priv->name_label);
730 gtk_widget_show (hbox);
732 /* Add the close button */
733 close_button = gtk_dialog_add_button (GTK_DIALOG (about),
734 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL);
735 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
737 /* Add the credits button */
738 button = gtk_toggle_button_new_with_mnemonic (_("C_redits"));
739 gtk_widget_set_can_default (button, TRUE);
740 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
741 gtk_button_set_image (GTK_BUTTON (button), image);
742 gtk_widget_set_no_show_all (button, TRUE);
743 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
744 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
745 g_signal_connect (button, "clicked",
746 G_CALLBACK (credits_button_clicked), about);
747 priv->credits_button = button;
748 priv->credits_page = 0;
750 /* Add the license button */
751 button = gtk_toggle_button_new_with_mnemonic (_("_License"));
752 gtk_widget_set_can_default (button, TRUE);
753 gtk_widget_set_no_show_all (button, TRUE);
754 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
755 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
756 g_signal_connect (button, "clicked",
757 G_CALLBACK (license_button_clicked), about);
758 priv->license_button = button;
759 priv->license_page = 0;
761 switch_page (about, 0);
763 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
765 gtk_widget_pop_composite_child ();
767 gtk_widget_grab_default (close_button);
768 gtk_widget_grab_focus (close_button);
771 gtk_about_dialog_set_program_name (about, NULL);
772 gtk_about_dialog_set_logo (about, NULL);
776 gtk_about_dialog_finalize (GObject *object)
778 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
779 GtkAboutDialogPrivate *priv = about->priv;
782 g_free (priv->version);
783 g_free (priv->copyright);
784 g_free (priv->comments);
785 g_free (priv->license);
786 g_free (priv->website_url);
787 g_free (priv->website_text);
788 g_free (priv->translator_credits);
790 g_strfreev (priv->authors);
791 g_strfreev (priv->documenters);
792 g_strfreev (priv->artists);
794 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
795 g_slist_free (priv->visited_links);
797 g_object_unref (priv->hand_cursor);
798 g_object_unref (priv->regular_cursor);
800 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
804 gtk_about_dialog_set_property (GObject *object,
809 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
810 GtkAboutDialogPrivate *priv = about->priv;
815 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
818 gtk_about_dialog_set_version (about, g_value_get_string (value));
821 gtk_about_dialog_set_comments (about, g_value_get_string (value));
824 gtk_about_dialog_set_website (about, g_value_get_string (value));
826 case PROP_WEBSITE_LABEL:
827 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
830 gtk_about_dialog_set_license (about, g_value_get_string (value));
832 case PROP_LICENSE_TYPE:
833 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
836 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
839 gtk_about_dialog_set_logo (about, g_value_get_object (value));
842 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
844 case PROP_DOCUMENTERS:
845 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
848 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
850 case PROP_TRANSLATOR_CREDITS:
851 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
853 case PROP_LOGO_ICON_NAME:
854 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
856 case PROP_WRAP_LICENSE:
857 priv->wrap_license = g_value_get_boolean (value);
860 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
866 gtk_about_dialog_get_property (GObject *object,
871 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
872 GtkAboutDialogPrivate *priv = about->priv;
877 g_value_set_string (value, priv->name);
880 g_value_set_string (value, priv->version);
883 g_value_set_string (value, priv->copyright);
886 g_value_set_string (value, priv->comments);
889 g_value_set_string (value, priv->website_url);
891 case PROP_WEBSITE_LABEL:
892 g_value_set_string (value, priv->website_text);
895 g_value_set_string (value, priv->license);
897 case PROP_LICENSE_TYPE:
898 g_value_set_enum (value, priv->license_type);
900 case PROP_TRANSLATOR_CREDITS:
901 g_value_set_string (value, priv->translator_credits);
904 g_value_set_boxed (value, priv->authors);
906 case PROP_DOCUMENTERS:
907 g_value_set_boxed (value, priv->documenters);
910 g_value_set_boxed (value, priv->artists);
913 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
914 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
916 g_value_set_object (value, NULL);
918 case PROP_LOGO_ICON_NAME:
919 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
921 const gchar *icon_name;
923 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
924 g_value_set_string (value, icon_name);
927 g_value_set_string (value, NULL);
929 case PROP_WRAP_LICENSE:
930 g_value_set_boolean (value, priv->wrap_license);
933 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
939 gtk_about_dialog_activate_link (GtkAboutDialog *about,
943 GError *error = NULL;
945 screen = gtk_widget_get_screen (GTK_WIDGET (about));
947 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
951 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
952 GTK_DIALOG_DESTROY_WITH_PARENT |
956 "%s", _("Could not show link"));
957 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
958 "%s", error->message);
959 g_error_free (error);
961 g_signal_connect (dialog, "response",
962 G_CALLBACK (gtk_widget_destroy), NULL);
964 gtk_window_present (GTK_WINDOW (dialog));
971 update_website (GtkAboutDialog *about)
973 GtkAboutDialogPrivate *priv = about->priv;
975 gtk_widget_show (priv->website_label);
977 if (priv->website_url)
981 if (priv->website_text)
985 escaped = g_markup_escape_text (priv->website_text, -1);
986 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
987 priv->website_url, escaped);
992 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
993 priv->website_url, _("Homepage"));
996 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
1001 if (priv->website_text)
1002 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
1004 gtk_widget_hide (priv->website_label);
1009 gtk_about_dialog_show (GtkWidget *widget)
1011 update_website (GTK_ABOUT_DIALOG (widget));
1013 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
1017 * gtk_about_dialog_get_program_name:
1018 * @about: a #GtkAboutDialog
1020 * Returns the program name displayed in the about dialog.
1022 * Return value: The program name. The string is owned by the about
1023 * dialog and must not be modified.
1027 G_CONST_RETURN gchar *
1028 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
1030 GtkAboutDialogPrivate *priv;
1032 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1040 update_name_version (GtkAboutDialog *about)
1042 GtkAboutDialogPrivate *priv;
1043 gchar *title_string, *name_string;
1047 title_string = g_strdup_printf (_("About %s"), priv->name);
1048 gtk_window_set_title (GTK_WINDOW (about), title_string);
1049 g_free (title_string);
1051 if (priv->version != NULL)
1053 gtk_label_set_markup (GTK_LABEL (priv->version_label), priv->version);
1054 gtk_widget_show (priv->version_label);
1057 gtk_widget_hide (priv->version_label);
1059 name_string = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
1061 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
1062 g_free (name_string);
1066 * gtk_about_dialog_set_program_name:
1067 * @about: a #GtkAboutDialog
1068 * @name: the program name
1070 * Sets the name to display in the about dialog.
1071 * If this is not set, it defaults to g_get_application_name().
1076 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
1079 GtkAboutDialogPrivate *priv;
1082 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1087 priv->name = g_strdup (name ? name : g_get_application_name ());
1090 update_name_version (about);
1092 g_object_notify (G_OBJECT (about), "program-name");
1097 * gtk_about_dialog_get_version:
1098 * @about: a #GtkAboutDialog
1100 * Returns the version string.
1102 * Return value: The version string. The string is owned by the about
1103 * dialog and must not be modified.
1107 G_CONST_RETURN gchar *
1108 gtk_about_dialog_get_version (GtkAboutDialog *about)
1110 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1112 return about->priv->version;
1116 * gtk_about_dialog_set_version:
1117 * @about: a #GtkAboutDialog
1118 * @version: (allow-none): the version string
1120 * Sets the version string to display in the about dialog.
1125 gtk_about_dialog_set_version (GtkAboutDialog *about,
1126 const gchar *version)
1128 GtkAboutDialogPrivate *priv;
1131 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1135 tmp = priv->version;
1136 priv->version = g_strdup (version);
1139 update_name_version (about);
1141 g_object_notify (G_OBJECT (about), "version");
1145 * gtk_about_dialog_get_copyright:
1146 * @about: a #GtkAboutDialog
1148 * Returns the copyright string.
1150 * Return value: The copyright string. The string is owned by the about
1151 * dialog and must not be modified.
1155 G_CONST_RETURN gchar *
1156 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1158 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1160 return about->priv->copyright;
1164 * gtk_about_dialog_set_copyright:
1165 * @about: a #GtkAboutDialog
1166 * @copyright: (allow-none) the copyright string
1168 * Sets the copyright string to display in the about dialog.
1169 * This should be a short string of one or two lines.
1174 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1175 const gchar *copyright)
1177 GtkAboutDialogPrivate *priv;
1178 gchar *copyright_string, *tmp;
1180 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1184 tmp = priv->copyright;
1185 priv->copyright = g_strdup (copyright);
1188 if (priv->copyright != NULL)
1190 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1192 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1193 g_free (copyright_string);
1195 gtk_widget_show (priv->copyright_label);
1198 gtk_widget_hide (priv->copyright_label);
1200 g_object_notify (G_OBJECT (about), "copyright");
1204 * gtk_about_dialog_get_comments:
1205 * @about: a #GtkAboutDialog
1207 * Returns the comments string.
1209 * Return value: The comments. The string is owned by the about
1210 * dialog and must not be modified.
1214 G_CONST_RETURN gchar *
1215 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1217 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1219 return about->priv->comments;
1223 * gtk_about_dialog_set_comments:
1224 * @about: a #GtkAboutDialog
1225 * @comments: (allow-none): a comments string
1227 * Sets the comments string to display in the about dialog.
1228 * This should be a short string of one or two lines.
1233 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1234 const gchar *comments)
1236 GtkAboutDialogPrivate *priv;
1239 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1243 tmp = priv->comments;
1246 priv->comments = g_strdup (comments);
1247 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1248 gtk_widget_show (priv->comments_label);
1252 priv->comments = NULL;
1253 gtk_widget_hide (priv->comments_label);
1257 g_object_notify (G_OBJECT (about), "comments");
1261 * gtk_about_dialog_get_license:
1262 * @about: a #GtkAboutDialog
1264 * Returns the license information.
1266 * Return value: The license information. The string is owned by the about
1267 * dialog and must not be modified.
1271 G_CONST_RETURN gchar *
1272 gtk_about_dialog_get_license (GtkAboutDialog *about)
1274 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1276 return about->priv->license;
1280 * gtk_about_dialog_set_license:
1281 * @about: a #GtkAboutDialog
1282 * @license: (allow-none): the license information or %NULL
1284 * Sets the license information to be displayed in the secondary
1285 * license dialog. If @license is %NULL, the license button is
1291 gtk_about_dialog_set_license (GtkAboutDialog *about,
1292 const gchar *license)
1294 GtkAboutDialogPrivate *priv;
1297 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1301 tmp = priv->license;
1304 priv->license = g_strdup (license);
1305 priv->license_type = GTK_LICENSE_CUSTOM;
1309 priv->license = NULL;
1310 priv->license_type = GTK_LICENSE_UNKNOWN;
1314 gtk_widget_hide (priv->license_label);
1316 update_license_button_visibility (about);
1318 g_object_notify (G_OBJECT (about), "license");
1319 g_object_notify (G_OBJECT (about), "license-type");
1323 * gtk_about_dialog_get_wrap_license:
1324 * @about: a #GtkAboutDialog
1326 * Returns whether the license text in @about is
1327 * automatically wrapped.
1329 * Returns: %TRUE if the license text is wrapped
1334 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1336 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1338 return about->priv->wrap_license;
1342 * gtk_about_dialog_set_wrap_license:
1343 * @about: a #GtkAboutDialog
1344 * @wrap_license: whether to wrap the license
1346 * Sets whether the license text in @about is
1347 * automatically wrapped.
1352 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1353 gboolean wrap_license)
1355 GtkAboutDialogPrivate *priv;
1357 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1361 wrap_license = wrap_license != FALSE;
1363 if (priv->wrap_license != wrap_license)
1365 priv->wrap_license = wrap_license;
1367 g_object_notify (G_OBJECT (about), "wrap-license");
1372 * gtk_about_dialog_get_website:
1373 * @about: a #GtkAboutDialog
1375 * Returns the website URL.
1377 * Return value: The website URL. The string is owned by the about
1378 * dialog and must not be modified.
1382 G_CONST_RETURN gchar *
1383 gtk_about_dialog_get_website (GtkAboutDialog *about)
1385 GtkAboutDialogPrivate *priv;
1387 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1391 return priv->website_url;
1395 * gtk_about_dialog_set_website:
1396 * @about: a #GtkAboutDialog
1397 * @website: (allow-none): a URL string starting with "http://"
1399 * Sets the URL to use for the website link.
1404 gtk_about_dialog_set_website (GtkAboutDialog *about,
1405 const gchar *website)
1407 GtkAboutDialogPrivate *priv;
1410 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1414 tmp = priv->website_url;
1415 priv->website_url = g_strdup (website);
1418 update_website (about);
1420 g_object_notify (G_OBJECT (about), "website");
1424 * gtk_about_dialog_get_website_label:
1425 * @about: a #GtkAboutDialog
1427 * Returns the label used for the website link.
1429 * Return value: The label used for the website link. The string is
1430 * owned by the about dialog and must not be modified.
1434 G_CONST_RETURN gchar *
1435 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1437 GtkAboutDialogPrivate *priv;
1439 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1443 return priv->website_text;
1447 * gtk_about_dialog_set_website_label:
1448 * @about: a #GtkAboutDialog
1449 * @website_label: the label used for the website link
1451 * Sets the label to be used for the website link.
1456 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1457 const gchar *website_label)
1459 GtkAboutDialogPrivate *priv;
1462 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1466 tmp = priv->website_text;
1467 priv->website_text = g_strdup (website_label);
1470 update_website (about);
1472 g_object_notify (G_OBJECT (about), "website-label");
1476 * gtk_about_dialog_get_authors:
1477 * @about: a #GtkAboutDialog
1479 * Returns the string which are displayed in the authors tab
1480 * of the secondary credits dialog.
1482 * Return value: (array zero-terminated=1) (transfer none): A
1483 * %NULL-terminated string array containing the authors. The array is
1484 * owned by the about dialog and must not be modified.
1488 G_CONST_RETURN gchar * G_CONST_RETURN *
1489 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1491 GtkAboutDialogPrivate *priv;
1493 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1497 return (const gchar * const *) priv->authors;
1501 * gtk_about_dialog_set_authors:
1502 * @about: a #GtkAboutDialog
1503 * @authors: (array zero-terminated=1): a %NULL-terminated array of strings
1505 * Sets the strings which are displayed in the authors tab
1506 * of the secondary credits dialog.
1511 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1512 const gchar **authors)
1514 GtkAboutDialogPrivate *priv;
1517 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1521 tmp = priv->authors;
1522 priv->authors = g_strdupv ((gchar **)authors);
1525 update_credits_button_visibility (about);
1527 g_object_notify (G_OBJECT (about), "authors");
1531 * gtk_about_dialog_get_documenters:
1532 * @about: a #GtkAboutDialog
1534 * Returns the string which are displayed in the documenters
1535 * tab of the secondary credits dialog.
1537 * Return value: (array zero-terminated=1) (transfer none): A
1538 * %NULL-terminated string array containing the documenters. The
1539 * array is owned by the about dialog and must not be modified.
1543 G_CONST_RETURN gchar * G_CONST_RETURN *
1544 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1546 GtkAboutDialogPrivate *priv;
1548 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1552 return (const gchar * const *)priv->documenters;
1556 * gtk_about_dialog_set_documenters:
1557 * @about: a #GtkAboutDialog
1558 * @documenters: (array zero-terminated=1): a %NULL-terminated array of strings
1560 * Sets the strings which are displayed in the documenters tab
1561 * of the secondary credits dialog.
1566 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1567 const gchar **documenters)
1569 GtkAboutDialogPrivate *priv;
1572 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1576 tmp = priv->documenters;
1577 priv->documenters = g_strdupv ((gchar **)documenters);
1580 update_credits_button_visibility (about);
1582 g_object_notify (G_OBJECT (about), "documenters");
1586 * gtk_about_dialog_get_artists:
1587 * @about: a #GtkAboutDialog
1589 * Returns the string which are displayed in the artists tab
1590 * of the secondary credits dialog.
1592 * Return value: (array zero-terminated=1) (transfer none): A
1593 * %NULL-terminated string array containing the artists. The array is
1594 * owned by the about dialog and must not be modified.
1598 G_CONST_RETURN gchar * G_CONST_RETURN *
1599 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1601 GtkAboutDialogPrivate *priv;
1603 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1607 return (const gchar * const *)priv->artists;
1611 * gtk_about_dialog_set_artists:
1612 * @about: a #GtkAboutDialog
1613 * @artists: (array zero-terminated=1): a %NULL-terminated array of strings
1615 * Sets the strings which are displayed in the artists tab
1616 * of the secondary credits dialog.
1621 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1622 const gchar **artists)
1624 GtkAboutDialogPrivate *priv;
1627 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1631 tmp = priv->artists;
1632 priv->artists = g_strdupv ((gchar **)artists);
1635 update_credits_button_visibility (about);
1637 g_object_notify (G_OBJECT (about), "artists");
1641 * gtk_about_dialog_get_translator_credits:
1642 * @about: a #GtkAboutDialog
1644 * Returns the translator credits string which is displayed
1645 * in the translators tab of the secondary credits dialog.
1647 * Return value: The translator credits string. The string is
1648 * owned by the about dialog and must not be modified.
1652 G_CONST_RETURN gchar *
1653 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1655 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1657 return about->priv->translator_credits;
1661 * gtk_about_dialog_set_translator_credits:
1662 * @about: a #GtkAboutDialog
1663 * @translator_credits: (allow-none): the translator credits
1665 * Sets the translator credits string which is displayed in
1666 * the translators tab of the secondary credits dialog.
1668 * The intended use for this string is to display the translator
1669 * of the language which is currently used in the user interface.
1670 * Using gettext(), a simple way to achieve that is to mark the
1671 * string for translation:
1673 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1675 * It is a good idea to use the customary msgid "translator-credits" for this
1676 * purpose, since translators will already know the purpose of that msgid, and
1677 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1683 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1684 const gchar *translator_credits)
1686 GtkAboutDialogPrivate *priv;
1689 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1693 tmp = priv->translator_credits;
1694 priv->translator_credits = g_strdup (translator_credits);
1697 update_credits_button_visibility (about);
1699 g_object_notify (G_OBJECT (about), "translator-credits");
1703 * gtk_about_dialog_get_logo:
1704 * @about: a #GtkAboutDialog
1706 * Returns the pixbuf displayed as logo in the about dialog.
1708 * Return value: (transfer none): the pixbuf displayed as logo. The
1709 * pixbuf is owned by the about dialog. If you want to keep a
1710 * reference to it, you have to call g_object_ref() on it.
1715 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1717 GtkAboutDialogPrivate *priv;
1719 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1723 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1724 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1730 icon_set_new_from_pixbufs (GList *pixbufs)
1732 GtkIconSet *icon_set = gtk_icon_set_new ();
1734 for (; pixbufs; pixbufs = pixbufs->next)
1736 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1738 GtkIconSource *icon_source = gtk_icon_source_new ();
1739 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1740 gtk_icon_set_add_source (icon_set, icon_source);
1741 gtk_icon_source_free (icon_source);
1748 * gtk_about_dialog_set_logo:
1749 * @about: a #GtkAboutDialog
1750 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1752 * Sets the pixbuf to be displayed as logo in the about dialog.
1753 * If it is %NULL, the default window icon set with
1754 * gtk_window_set_default_icon() will be used.
1759 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1762 GtkAboutDialogPrivate *priv;
1764 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1768 g_object_freeze_notify (G_OBJECT (about));
1770 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1771 g_object_notify (G_OBJECT (about), "logo-icon-name");
1774 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1777 GList *pixbufs = gtk_window_get_default_icon_list ();
1779 if (pixbufs != NULL)
1781 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1783 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1784 icon_set, GTK_ICON_SIZE_DIALOG);
1786 gtk_icon_set_unref (icon_set);
1787 g_list_free (pixbufs);
1791 g_object_notify (G_OBJECT (about), "logo");
1793 g_object_thaw_notify (G_OBJECT (about));
1797 * gtk_about_dialog_get_logo_icon_name:
1798 * @about: a #GtkAboutDialog
1800 * Returns the icon name displayed as logo in the about dialog.
1802 * Return value: the icon name displayed as logo. The string is
1803 * owned by the dialog. If you want to keep a reference
1804 * to it, you have to call g_strdup() on it.
1808 G_CONST_RETURN gchar *
1809 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1811 GtkAboutDialogPrivate *priv;
1812 const gchar *icon_name = NULL;
1814 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1818 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1819 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1825 * gtk_about_dialog_set_logo_icon_name:
1826 * @about: a #GtkAboutDialog
1827 * @icon_name: (allow-none): an icon name, or %NULL
1829 * Sets the pixbuf to be displayed as logo in the about dialog.
1830 * If it is %NULL, the default window icon set with
1831 * gtk_window_set_default_icon() will be used.
1836 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1837 const gchar *icon_name)
1839 GtkAboutDialogPrivate *priv;
1841 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1845 g_object_freeze_notify (G_OBJECT (about));
1847 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1848 g_object_notify (G_OBJECT (about), "logo");
1850 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1851 GTK_ICON_SIZE_DIALOG);
1852 g_object_notify (G_OBJECT (about), "logo-icon-name");
1854 g_object_thaw_notify (G_OBJECT (about));
1858 follow_if_link (GtkAboutDialog *about,
1859 GtkTextView *text_view,
1862 GSList *tags = NULL, *tagp = NULL;
1863 GtkAboutDialogPrivate *priv = about->priv;
1866 tags = gtk_text_iter_get_tags (iter);
1867 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1869 GtkTextTag *tag = tagp->data;
1871 uri = g_object_get_data (G_OBJECT (tag), "uri");
1873 emit_activate_link (about, uri);
1875 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1877 GdkColor *style_visited_link_color;
1880 gtk_widget_style_get (GTK_WIDGET (about),
1881 "visited-link-color", &style_visited_link_color,
1883 if (style_visited_link_color)
1885 color = *style_visited_link_color;
1886 gdk_color_free (style_visited_link_color);
1889 color = default_visited_link_color;
1891 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1893 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1898 g_slist_free (tags);
1902 text_view_key_press_event (GtkWidget *text_view,
1904 GtkAboutDialog *about)
1907 GtkTextBuffer *buffer;
1909 switch (event->keyval)
1911 case GDK_KEY_Return:
1912 case GDK_KEY_ISO_Enter:
1913 case GDK_KEY_KP_Enter:
1914 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1915 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1916 gtk_text_buffer_get_insert (buffer));
1917 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1928 text_view_event_after (GtkWidget *text_view,
1930 GtkAboutDialog *about)
1932 GtkTextIter start, end, iter;
1933 GtkTextBuffer *buffer;
1934 GdkEventButton *button_event;
1937 if (event->type != GDK_BUTTON_RELEASE)
1940 button_event = (GdkEventButton *)event;
1942 if (button_event->button != 1)
1945 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1947 /* we shouldn't follow a link if the user has selected something */
1948 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1949 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1952 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1953 GTK_TEXT_WINDOW_WIDGET,
1954 button_event->x, button_event->y, &x, &y);
1956 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1958 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1964 set_cursor_if_appropriate (GtkAboutDialog *about,
1965 GtkTextView *text_view,
1970 GtkAboutDialogPrivate *priv = about->priv;
1971 GSList *tags = NULL, *tagp = NULL;
1973 gboolean hovering_over_link = FALSE;
1975 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1977 tags = gtk_text_iter_get_tags (&iter);
1978 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1980 GtkTextTag *tag = tagp->data;
1981 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1985 hovering_over_link = TRUE;
1990 if (hovering_over_link != priv->hovering_over_link)
1992 priv->hovering_over_link = hovering_over_link;
1994 if (hovering_over_link)
1995 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
1997 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
2001 g_slist_free (tags);
2005 text_view_motion_notify_event (GtkWidget *text_view,
2006 GdkEventMotion *event,
2007 GtkAboutDialog *about)
2011 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2012 GTK_TEXT_WINDOW_WIDGET,
2013 event->x, event->y, &x, &y);
2015 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
2017 gdk_event_request_motions (event);
2024 text_view_visibility_notify_event (GtkWidget *text_view,
2025 GdkEventVisibility *event,
2026 GtkAboutDialog *about)
2028 GdkDeviceManager *device_manager;
2029 GdkDisplay *display;
2031 gint wx, wy, bx, by;
2033 display = gdk_window_get_display (event->window);
2034 device_manager = gdk_display_get_device_manager (display);
2035 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2037 for (d = devices; d; d = d->next)
2039 GdkDevice *dev = d->data;
2041 if (gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD)
2044 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
2047 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2048 GTK_TEXT_WINDOW_WIDGET,
2051 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
2054 g_list_free (devices);
2060 text_view_new (GtkAboutDialog *about,
2062 GtkWrapMode wrap_mode)
2065 gchar *q0, *q1, *q2, *r1, *r2;
2067 GtkTextView *text_view;
2068 GtkTextBuffer *buffer;
2069 GdkColor *style_link_color;
2070 GdkColor *style_visited_link_color;
2072 GdkColor link_color;
2073 GdkColor visited_link_color;
2075 PangoFontDescription *font_desc;
2076 GtkAboutDialogPrivate *priv = about->priv;
2077 GtkStyleContext *context;
2078 GtkStateFlags state;
2080 gtk_widget_style_get (GTK_WIDGET (about),
2081 "link-color", &style_link_color,
2082 "visited-link-color", &style_visited_link_color,
2084 if (style_link_color)
2086 link_color = *style_link_color;
2087 gdk_color_free (style_link_color);
2090 link_color = default_link_color;
2092 if (style_visited_link_color)
2094 visited_link_color = *style_visited_link_color;
2095 gdk_color_free (style_visited_link_color);
2098 visited_link_color = default_visited_link_color;
2100 view = gtk_text_view_new ();
2101 text_view = GTK_TEXT_VIEW (view);
2102 buffer = gtk_text_view_get_buffer (text_view);
2103 gtk_text_view_set_cursor_visible (text_view, FALSE);
2104 gtk_text_view_set_editable (text_view, FALSE);
2105 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2107 context = gtk_widget_get_style_context (view);
2108 state = gtk_widget_get_state_flags (view);
2110 size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
2111 font_desc = pango_font_description_new ();
2112 pango_font_description_set_size (font_desc, size * PANGO_SCALE_SMALL);
2113 gtk_widget_modify_font (view, font_desc);
2114 pango_font_description_free (font_desc);
2116 gtk_text_view_set_left_margin (text_view, 8);
2117 gtk_text_view_set_right_margin (text_view, 8);
2119 g_signal_connect (view, "key-press-event",
2120 G_CALLBACK (text_view_key_press_event), about);
2121 g_signal_connect (view, "event-after",
2122 G_CALLBACK (text_view_event_after), about);
2123 g_signal_connect (view, "motion-notify-event",
2124 G_CALLBACK (text_view_motion_notify_event), about);
2125 g_signal_connect (view, "visibility-notify-event",
2126 G_CALLBACK (text_view_visibility_notify_event), about);
2128 if (strings == NULL)
2130 gtk_widget_hide (view);
2134 for (p = strings; *p; p++)
2139 q1 = strchr (q0, '<');
2140 q2 = q1 ? strchr (q1, '>') : NULL;
2141 r1 = strstr (q0, "http://");
2144 r2 = strpbrk (r1, " \n\t");
2146 r2 = strchr (r1, '\0');
2151 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2162 const gchar *link_type;
2167 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0 + 1);
2168 gtk_text_buffer_get_end_iter (buffer, &end);
2170 link_type = "email";
2174 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2175 gtk_text_buffer_get_end_iter (buffer, &end);
2181 link = g_strndup (q1, q2 - q1);
2183 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2184 color = visited_link_color;
2188 tag = gtk_text_buffer_create_tag (buffer, NULL,
2189 "foreground-gdk", &color,
2190 "underline", PANGO_UNDERLINE_SINGLE,
2192 if (strcmp (link_type, "email") == 0)
2196 escaped = g_uri_escape_string (link, NULL, FALSE);
2197 uri = g_strconcat ("mailto:", escaped, NULL);
2202 uri = g_strdup (link);
2204 g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
2205 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2211 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2217 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2220 gtk_widget_show (view);
2225 add_credits_section (GtkAboutDialog *about,
2234 gchar *q0, *q1, *q2, *r1, *r2;
2239 markup = g_strdup_printf ("<span size=\"small\">%s</span>", title);
2240 label = gtk_label_new (markup);
2241 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2243 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
2244 gtk_grid_attach (grid, label, 0, *row, 1, 1);
2246 for (p = people; *p; p++)
2250 str = g_string_new ("<span size=\"small\">");
2255 q1 = strchr (q0, '<');
2256 q2 = q1 ? strchr (q1, '>') : NULL;
2257 r1 = strstr (q0, "http://");
2260 r2 = strpbrk (r1, " \n\t");
2262 r2 = strchr (r1, '\0');
2267 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2272 else if (q1 && (q1[1] == 'a' || q1[1] == 'A') && q1[2] == ' ')
2274 /* if it is a <a> link leave it for the label to parse */
2289 text = g_strstrip (g_strndup (q0, q1 - q0));
2290 name = g_markup_escape_text (text, -1);
2292 link = g_strndup (q1, q2 - q1);
2294 escaped = g_uri_escape_string (link, NULL, FALSE);
2295 g_string_append_printf (str,
2296 "<a href=\"mailto:%s\">%s</a>",
2298 name[0] ? name : link);
2307 text = g_strstrip (g_strndup (q0, q1 - q0));
2308 name = g_markup_escape_text (text, -1);
2309 link = g_strndup (q1, q2 - q1);
2310 g_string_append_printf (str,
2311 "<a href=\"%s\">%s</a>",
2313 name[0] ? name : link);
2323 g_string_append (str, q0);
2327 g_string_append (str, "</span>");
2329 label = gtk_label_new (str->str);
2330 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2331 g_string_free (str, TRUE);
2332 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2333 gtk_grid_attach (grid, label, 1, *row, 1, 1);
2337 /* skip one at the end */
2342 create_credits_page (GtkAboutDialog *about)
2344 GtkAboutDialogPrivate *priv = about->priv;
2345 GtkWidget *page_vbox;
2350 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2351 gtk_widget_show (page_vbox);
2352 priv->credits_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2354 sw = gtk_scrolled_window_new (NULL, NULL);
2355 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
2356 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2358 GTK_POLICY_AUTOMATIC);
2359 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2361 grid = gtk_grid_new ();
2362 gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
2363 gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
2364 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2365 gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
2366 gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
2367 gtk_widget_set_valign (grid, GTK_ALIGN_START);
2368 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), grid);
2370 if (priv->authors != NULL)
2371 add_credits_section (about, GTK_GRID (grid), &row, _("Created by"), priv->authors);
2373 if (priv->documenters != NULL)
2374 add_credits_section (about, GTK_GRID (grid), &row, _("Documented by"), priv->documenters);
2376 /* Don't show an untranslated gettext msgid */
2377 if (priv->translator_credits != NULL &&
2378 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2379 strcmp (priv->translator_credits, "translator-credits") != 0)
2381 gchar **translators;
2383 translators = g_strsplit (priv->translator_credits, "\n", 0);
2384 add_credits_section (about, GTK_GRID (grid), &row, _("Translated by"), translators);
2385 g_strfreev (translators);
2388 if (priv->artists != NULL)
2389 add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
2391 gtk_widget_show_all (sw);
2395 display_credits_page (GtkWidget *button,
2398 GtkAboutDialog *about = (GtkAboutDialog *)data;
2399 GtkAboutDialogPrivate *priv = about->priv;
2401 if (priv->credits_page == 0)
2402 create_credits_page (about);
2404 switch_page (about, priv->credits_page);
2408 create_license_page (GtkAboutDialog *about)
2410 GtkAboutDialogPrivate *priv = about->priv;
2411 GtkWidget *page_vbox;
2416 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2417 priv->license_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2419 sw = gtk_scrolled_window_new (NULL, NULL);
2420 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2421 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
2422 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2423 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
2424 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2426 strings[0] = priv->license;
2428 view = text_view_new (about, strings,
2429 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2431 gtk_container_add (GTK_CONTAINER (sw), view);
2433 gtk_widget_show_all (page_vbox);
2437 display_license_page (GtkWidget *button,
2440 GtkAboutDialog *about = (GtkAboutDialog *)data;
2441 GtkAboutDialogPrivate *priv = about->priv;
2443 if (priv->license_page == 0)
2444 create_license_page (about);
2446 switch_page (about, priv->license_page);
2450 * gtk_about_dialog_new:
2452 * Creates a new #GtkAboutDialog.
2454 * Returns: a newly created #GtkAboutDialog
2459 gtk_about_dialog_new (void)
2461 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2463 return GTK_WIDGET (dialog);
2467 close_cb (GtkAboutDialog *about)
2469 GtkAboutDialogPrivate *priv = about->priv;
2471 switch_page (about, 0);
2472 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
2473 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
2474 gtk_widget_hide (GTK_WIDGET (about));
2478 * gtk_show_about_dialog:
2479 * @parent: (allow-none): transient parent, or %NULL for none
2480 * @first_property_name: the name of the first property
2481 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2483 * This is a convenience function for showing an application's about box.
2484 * The constructed dialog is associated with the parent window and
2485 * reused for future invocations of this function.
2490 gtk_show_about_dialog (GtkWindow *parent,
2491 const gchar *first_property_name,
2494 static GtkWidget *global_about_dialog = NULL;
2495 GtkWidget *dialog = NULL;
2499 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2501 dialog = global_about_dialog;
2505 dialog = gtk_about_dialog_new ();
2507 g_object_ref_sink (dialog);
2509 g_signal_connect (dialog, "delete-event",
2510 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2512 /* Close dialog on user response */
2513 g_signal_connect (dialog, "response",
2514 G_CALLBACK (close_cb), NULL);
2516 va_start (var_args, first_property_name);
2517 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2522 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2523 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2524 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2525 g_object_set_data_full (G_OBJECT (parent),
2526 I_("gtk-about-dialog"),
2527 dialog, g_object_unref);
2530 global_about_dialog = dialog;
2534 gtk_window_present (GTK_WINDOW (dialog));
2538 * gtk_about_dialog_set_license_type:
2539 * @about: a #GtkAboutDialog
2540 * @license_type: the type of license
2542 * Sets the license of the application showing the @about dialog from a
2543 * list of known licenses.
2545 * This function overrides the license set using
2546 * gtk_about_dialog_set_license().
2551 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2552 GtkLicense license_type)
2554 GtkAboutDialogPrivate *priv;
2556 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2557 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2558 license_type <= GTK_LICENSE_ARTISTIC);
2562 if (priv->license_type != license_type)
2564 g_object_freeze_notify (G_OBJECT (about));
2566 priv->license_type = license_type;
2568 /* custom licenses use the contents of the :license property */
2569 if (priv->license_type != GTK_LICENSE_CUSTOM)
2572 gchar *license_string;
2575 url = gtk_license_urls[priv->license_type];
2577 url = priv->website_url;
2579 str = g_string_sized_new (256);
2580 g_string_append_printf (str, _(gtk_license_preamble), url, url);
2582 g_free (priv->license);
2583 priv->license = g_string_free (str, FALSE);
2584 priv->wrap_license = TRUE;
2586 license_string = g_strdup_printf ("<span size=\"small\">%s</span>",
2588 gtk_label_set_markup (GTK_LABEL (priv->license_label), license_string);
2589 g_free (license_string);
2590 gtk_widget_show (priv->license_label);
2592 update_license_button_visibility (about);
2594 g_object_notify (G_OBJECT (about), "wrap-license");
2595 g_object_notify (G_OBJECT (about), "license");
2599 gtk_widget_show (priv->license_label);
2602 g_object_notify (G_OBJECT (about), "license-type");
2604 g_object_thaw_notify (G_OBJECT (about));
2609 * gtk_about_dialog_get_license_type:
2610 * @about: a #GtkAboutDialog
2612 * Retrieves the license set using gtk_about_dialog_set_license_type()
2614 * Return value: a #GtkLicense value
2619 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2621 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2623 return about->priv->license_type;