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 "gtkalignment.h"
39 #include "gtkbutton.h"
41 #include "gtkdialog.h"
46 #include "gtklinkbutton.h"
47 #include "gtkmarshalers.h"
48 #include "gtknotebook.h"
49 #include "gtkorientable.h"
50 #include "gtkscrolledwindow.h"
52 #include "gtktextview.h"
54 #include "gtkiconfactory.h"
57 #include "gtkmessagedialog.h"
58 #include "gtktogglebutton.h"
59 #include "gtkprivate.h"
64 * SECTION:gtkaboutdialog
65 * @Short_description: Display information about an application
66 * @Title: GtkAboutDialog
67 * @See_also: #GTK_STOCK_ABOUT
69 * The GtkAboutDialog offers a simple way to display information about
70 * a program like its logo, name, copyright, website and license. It is
71 * also possible to give credits to the authors, documenters, translators
72 * and artists who have worked on the program. An about dialog is typically
73 * opened when the user selects the <literal>About</literal> option from
74 * the <literal>Help</literal> menu. All parts of the dialog are optional.
76 * About dialog often contain links and email addresses. GtkAboutDialog
77 * displays these as clickable links. By default, it calls gtk_show_uri()
78 * when a user clicks one. The behaviour can be overridden with the
79 * #GtkAboutDialog::activate-link signal.
81 * To make constructing a GtkAboutDialog as convenient as possible, you can
82 * use the function gtk_show_about_dialog() which constructs and shows a dialog
83 * and keeps it around so that it can be shown again.
85 * Note that GTK+ sets a default title of <literal>_("About %s")</literal>
86 * on the dialog window (where %s is replaced by the name of the
87 * application, but in order to ensure proper translation of the title,
88 * applications should set the title property explicitly when constructing
89 * a GtkAboutDialog, as shown in the following example:
90 * <informalexample><programlisting>
91 * gtk_show_about_dialog (NULL,
92 * "program-name", "ExampleCode",
93 * "logo", example_logo,
94 * "title" _("About ExampleCode"),
96 * </programlisting></informalexample>
99 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
100 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
102 /* Translators: this is the license preamble; the string at the end
103 * contains the URL of the license.
105 static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit <a href=\"%s\">%s</a>");
107 /* URLs for each GtkLicense type; keep in the same order as the enumeration */
108 static const gchar *gtk_license_urls[] = {
112 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
113 "http://www.gnu.org/licenses/gpl.html",
115 "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
116 "http://www.gnu.org/licenses/lgpl.html",
118 "http://opensource.org/licenses/bsd-license.php",
119 "http://opensource.org/licenses/mit-license.php",
121 "http://opensource.org/licenses/artistic-license-2.0.php"
124 struct _GtkAboutDialogPrivate
132 gchar *translator_credits;
143 GtkWidget *logo_image;
144 GtkWidget *name_label;
145 GtkWidget *version_label;
146 GtkWidget *comments_label;
147 GtkWidget *copyright_label;
148 GtkWidget *license_label;
149 GtkWidget *website_label;
151 GtkWidget *credits_button;
152 GtkWidget *license_button;
154 GdkCursor *hand_cursor;
155 GdkCursor *regular_cursor;
157 GSList *visited_links;
159 GtkLicense license_type;
161 guint hovering_over_link : 1;
162 guint wrap_license : 1;
165 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
180 PROP_TRANSLATOR_CREDITS,
188 static void gtk_about_dialog_finalize (GObject *object);
189 static void gtk_about_dialog_get_property (GObject *object,
193 static void gtk_about_dialog_set_property (GObject *object,
197 static void gtk_about_dialog_show (GtkWidget *widge);
198 static void update_name_version (GtkAboutDialog *about);
199 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
200 static void follow_if_link (GtkAboutDialog *about,
201 GtkTextView *text_view,
203 static void set_cursor_if_appropriate (GtkAboutDialog *about,
204 GtkTextView *text_view,
208 static void display_credits_page (GtkWidget *button,
210 static void display_license_page (GtkWidget *button,
212 static void close_cb (GtkAboutDialog *about);
213 static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
221 static guint signals[LAST_SIGNAL] = { 0 };
223 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
227 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
229 GObjectClass *object_class;
230 GtkWidgetClass *widget_class;
232 object_class = (GObjectClass *)klass;
233 widget_class = (GtkWidgetClass *)klass;
235 object_class->set_property = gtk_about_dialog_set_property;
236 object_class->get_property = gtk_about_dialog_get_property;
238 object_class->finalize = gtk_about_dialog_finalize;
240 widget_class->show = gtk_about_dialog_show;
242 klass->activate_link = gtk_about_dialog_activate_link;
245 * GtkAboutDialog::activate-link:
246 * @label: The object on which the signal was emitted
247 * @uri: the URI that is activated
249 * The signal which gets emitted to activate a URI.
250 * Applications may connect to it to override the default behaviour,
251 * which is to call gtk_show_uri().
253 * Returns: %TRUE if the link has been activated
257 signals[ACTIVATE_LINK] =
258 g_signal_new ("activate-link",
259 G_TYPE_FROM_CLASS (object_class),
261 G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
262 _gtk_boolean_handled_accumulator, NULL,
263 _gtk_marshal_BOOLEAN__STRING,
264 G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
267 * GtkAboutDialog:program-name:
269 * The name of the program.
270 * If this is not set, it defaults to g_get_application_name().
274 g_object_class_install_property (object_class,
276 g_param_spec_string ("program-name",
278 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
280 GTK_PARAM_READWRITE));
283 * GtkAboutDialog:version:
285 * The version of the program.
289 g_object_class_install_property (object_class,
291 g_param_spec_string ("version",
292 P_("Program version"),
293 P_("The version of the program"),
295 GTK_PARAM_READWRITE));
298 * GtkAboutDialog:copyright:
300 * Copyright information for the program.
304 g_object_class_install_property (object_class,
306 g_param_spec_string ("copyright",
307 P_("Copyright string"),
308 P_("Copyright information for the program"),
310 GTK_PARAM_READWRITE));
314 * GtkAboutDialog:comments:
316 * Comments about the program. This string is displayed in a label
317 * in the main dialog, thus it should be a short explanation of
318 * the main purpose of the program, not a detailed list of features.
322 g_object_class_install_property (object_class,
324 g_param_spec_string ("comments",
325 P_("Comments string"),
326 P_("Comments about the program"),
328 GTK_PARAM_READWRITE));
331 * GtkAboutDialog:license:
333 * The license of the program. This string is displayed in a
334 * text view in a secondary dialog, therefore it is fine to use
335 * a long multi-paragraph text. Note that the text is only wrapped
336 * in the text view if the "wrap-license" property is set to %TRUE;
337 * otherwise the text itself must contain the intended linebreaks.
338 * When setting this property to a non-%NULL value, the
339 * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
344 g_object_class_install_property (object_class,
346 g_param_spec_string ("license",
348 _("The license of the program"),
350 GTK_PARAM_READWRITE));
353 * GtkAboutDialog:license-type:
355 * The license of the program, as a value of the %GtkLicense enumeration.
357 * The #GtkAboutDialog will automatically fill out a standard disclaimer
358 * and link the user to the appropriate online resource for the license
361 * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
362 * specified in the #GtkAboutDialog:website property.
364 * If %GTK_LICENSE_CUSTOM is used, the current contents of the
365 * #GtkAboutDialog:license property are used.
367 * For any other #GtkLicense value, the contents of the
368 * #GtkAboutDialog:license property are also set by this property as
373 g_object_class_install_property (object_class,
375 g_param_spec_enum ("license-type",
377 P_("The license type of the program"),
380 GTK_PARAM_READWRITE));
383 * GtkAboutDialog:website:
385 * The URL for the link to the website of the program.
386 * This should be a string starting with "http://.
390 g_object_class_install_property (object_class,
392 g_param_spec_string ("website",
394 P_("The URL for the link to the website of the program"),
396 GTK_PARAM_READWRITE));
399 * GtkAboutDialog:website-label:
401 * The label for the link to the website of the program. If this is not set,
402 * it defaults to the URL specified in the #GtkAboutDialog:website property.
406 g_object_class_install_property (object_class,
408 g_param_spec_string ("website-label",
410 P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
412 GTK_PARAM_READWRITE));
415 * GtkAboutDialog:authors:
417 * The authors of the program, as a %NULL-terminated array of strings.
418 * Each string may contain email addresses and URLs, which will be displayed
419 * as links, see the introduction for more details.
423 g_object_class_install_property (object_class,
425 g_param_spec_boxed ("authors",
427 P_("List of authors of the program"),
429 GTK_PARAM_READWRITE));
432 * GtkAboutDialog:documenters:
434 * The people documenting the program, as a %NULL-terminated array of strings.
435 * Each string may contain email addresses and URLs, which will be displayed
436 * as links, see the introduction for more details.
440 g_object_class_install_property (object_class,
442 g_param_spec_boxed ("documenters",
444 P_("List of people documenting the program"),
446 GTK_PARAM_READWRITE));
449 * GtkAboutDialog:artists:
451 * The people who contributed artwork to the program, as a %NULL-terminated
452 * array of strings. Each string may contain email addresses and URLs, which
453 * will be displayed as links, see the introduction for more details.
457 g_object_class_install_property (object_class,
459 g_param_spec_boxed ("artists",
461 P_("List of people who have contributed artwork to the program"),
463 GTK_PARAM_READWRITE));
467 * GtkAboutDialog:translator-credits:
469 * Credits to the translators. This string should be marked as translatable.
470 * The string may contain email addresses and URLs, which will be displayed
471 * as links, see the introduction for more details.
475 g_object_class_install_property (object_class,
476 PROP_TRANSLATOR_CREDITS,
477 g_param_spec_string ("translator-credits",
478 P_("Translator credits"),
479 P_("Credits to the translators. This string should be marked as translatable"),
481 GTK_PARAM_READWRITE));
484 * GtkAboutDialog:logo:
486 * A logo for the about box. If this is not set, it defaults to
487 * gtk_window_get_default_icon_list().
491 g_object_class_install_property (object_class,
493 g_param_spec_object ("logo",
495 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
497 GTK_PARAM_READWRITE));
500 * GtkAboutDialog:logo-icon-name:
502 * A named icon to use as the logo for the about box. This property
503 * overrides the #GtkAboutDialog:logo property.
507 g_object_class_install_property (object_class,
509 g_param_spec_string ("logo-icon-name",
510 P_("Logo Icon Name"),
511 P_("A named icon to use as the logo for the about box."),
513 GTK_PARAM_READWRITE));
515 * GtkAboutDialog:wrap-license:
517 * Whether to wrap the text in the license dialog.
521 g_object_class_install_property (object_class,
523 g_param_spec_boolean ("wrap-license",
525 P_("Whether to wrap the license text."),
527 GTK_PARAM_READWRITE));
530 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
534 emit_activate_link (GtkAboutDialog *about,
537 gboolean handled = FALSE;
539 g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
545 update_license_button_visibility (GtkAboutDialog *about)
547 GtkAboutDialogPrivate *priv = about->priv;
549 if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL)
550 gtk_widget_show (priv->license_button);
552 gtk_widget_hide (priv->license_button);
556 update_credits_button_visibility (GtkAboutDialog *about)
558 GtkAboutDialogPrivate *priv = about->priv;
561 show = (priv->authors != NULL ||
562 priv->documenters != NULL ||
563 priv->artists != NULL ||
564 (priv->translator_credits != NULL &&
565 strcmp (priv->translator_credits, "translator_credits") &&
566 strcmp (priv->translator_credits, "translator-credits")));
568 gtk_widget_show (priv->credits_button);
570 gtk_widget_hide (priv->credits_button);
574 switch_page (GtkAboutDialog *about,
577 GtkAboutDialogPrivate *priv = about->priv;
579 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page);
583 display_main_page (GtkButton *button,
586 GtkAboutDialog *about = (GtkAboutDialog *)data;
588 switch_page (about, 0);
592 credits_button_clicked (GtkButton *button,
595 GtkAboutDialog *about = (GtkAboutDialog *)data;
596 GtkAboutDialogPrivate *priv = about->priv;
599 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
603 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
604 display_credits_page (NULL, data);
608 display_main_page (NULL, data);
613 license_button_clicked (GtkButton *button,
616 GtkAboutDialog *about = (GtkAboutDialog *)data;
617 GtkAboutDialogPrivate *priv = about->priv;
620 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
624 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
625 display_license_page (NULL, data);
629 display_main_page (NULL, data);
633 gtk_about_dialog_init (GtkAboutDialog *about)
635 GtkDialog *dialog = GTK_DIALOG (about);
636 GtkAboutDialogPrivate *priv;
637 GtkWidget *vbox, *page_vbox, *hbox, *button, *close_button, *image;
638 GtkWidget *content_area, *action_area;
641 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
645 priv->version = NULL;
646 priv->copyright = NULL;
647 priv->comments = NULL;
648 priv->website_url = NULL;
649 priv->website_text = NULL;
650 priv->translator_credits = NULL;
651 priv->license = NULL;
652 priv->authors = NULL;
653 priv->documenters = NULL;
654 priv->artists = NULL;
656 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
657 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
658 priv->hovering_over_link = FALSE;
659 priv->wrap_license = FALSE;
661 priv->license_type = GTK_LICENSE_UNKNOWN;
663 content_area = gtk_dialog_get_content_area (dialog);
664 action_area = gtk_dialog_get_action_area (dialog);
666 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
667 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
668 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
671 gtk_widget_push_composite_child ();
673 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
674 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
675 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
677 priv->logo_image = gtk_image_new ();
678 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
680 priv->name_label = gtk_label_new (NULL);
681 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
682 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
683 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
685 priv->notebook = gtk_notebook_new ();
686 gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
687 gtk_widget_set_size_request (priv->notebook, 400, 100);
689 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
690 gtk_widget_show (page_vbox);
691 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
692 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
693 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
695 priv->version_label = gtk_label_new (NULL);
696 gtk_label_set_selectable (GTK_LABEL (priv->version_label), TRUE);
697 gtk_label_set_justify (GTK_LABEL (priv->version_label), GTK_JUSTIFY_CENTER);
698 gtk_box_pack_start (GTK_BOX (page_vbox), priv->version_label, FALSE, FALSE, 0);
700 priv->comments_label = gtk_label_new (NULL);
701 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
702 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
703 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
704 gtk_box_pack_start (GTK_BOX (page_vbox), priv->comments_label, FALSE, FALSE, 0);
706 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
707 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
708 gtk_box_pack_start (GTK_BOX (page_vbox), hbox, FALSE, FALSE, 0);
710 priv->website_label = button = gtk_label_new ("");
711 gtk_widget_set_no_show_all (button, TRUE);
712 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
713 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
714 g_signal_connect_swapped (button, "activate-link",
715 G_CALLBACK (emit_activate_link), about);
717 priv->license_label = gtk_label_new (NULL);
718 gtk_label_set_use_markup (GTK_LABEL (priv->license_label), TRUE);
719 gtk_label_set_selectable (GTK_LABEL (priv->license_label), TRUE);
720 gtk_label_set_justify (GTK_LABEL (priv->license_label), GTK_JUSTIFY_CENTER);
721 gtk_box_pack_end (GTK_BOX (page_vbox), priv->license_label, FALSE, FALSE, 0);
722 gtk_label_set_line_wrap (GTK_LABEL (priv->license_label), TRUE);
724 priv->copyright_label = gtk_label_new (NULL);
725 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
726 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
727 gtk_box_pack_end (GTK_BOX (page_vbox), priv->copyright_label, FALSE, FALSE, 0);
729 gtk_widget_show (vbox);
730 gtk_widget_show (priv->notebook);
731 gtk_widget_show (priv->logo_image);
732 gtk_widget_show (priv->name_label);
733 gtk_widget_show (hbox);
735 /* Add the close button */
736 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
737 GTK_RESPONSE_CANCEL);
738 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
740 /* Add the credits button */
741 button = gtk_toggle_button_new_with_mnemonic (_("C_redits"));
742 gtk_widget_set_can_default (button, TRUE);
743 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
744 gtk_button_set_image (GTK_BUTTON (button), image);
745 gtk_widget_set_no_show_all (button, TRUE);
746 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
747 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
748 g_signal_connect (button, "clicked",
749 G_CALLBACK (credits_button_clicked), about);
750 priv->credits_button = button;
751 priv->credits_page = 0;
753 /* Add the license button */
754 button = gtk_toggle_button_new_with_mnemonic (_("_License"));
755 gtk_widget_set_can_default (button, TRUE);
756 gtk_widget_set_no_show_all (button, TRUE);
757 gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
758 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
759 g_signal_connect (button, "clicked",
760 G_CALLBACK (license_button_clicked), about);
761 priv->license_button = button;
762 priv->license_page = 0;
764 switch_page (about, 0);
766 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
768 gtk_widget_pop_composite_child ();
770 gtk_widget_grab_default (close_button);
771 gtk_widget_grab_focus (close_button);
774 gtk_about_dialog_set_program_name (about, NULL);
775 gtk_about_dialog_set_logo (about, NULL);
779 gtk_about_dialog_finalize (GObject *object)
781 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
782 GtkAboutDialogPrivate *priv = about->priv;
785 g_free (priv->version);
786 g_free (priv->copyright);
787 g_free (priv->comments);
788 g_free (priv->license);
789 g_free (priv->website_url);
790 g_free (priv->website_text);
791 g_free (priv->translator_credits);
793 g_strfreev (priv->authors);
794 g_strfreev (priv->documenters);
795 g_strfreev (priv->artists);
797 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
798 g_slist_free (priv->visited_links);
800 gdk_cursor_unref (priv->hand_cursor);
801 gdk_cursor_unref (priv->regular_cursor);
803 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
807 gtk_about_dialog_set_property (GObject *object,
812 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
813 GtkAboutDialogPrivate *priv = about->priv;
818 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
821 gtk_about_dialog_set_version (about, g_value_get_string (value));
824 gtk_about_dialog_set_comments (about, g_value_get_string (value));
827 gtk_about_dialog_set_website (about, g_value_get_string (value));
829 case PROP_WEBSITE_LABEL:
830 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
833 gtk_about_dialog_set_license (about, g_value_get_string (value));
835 case PROP_LICENSE_TYPE:
836 gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
839 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
842 gtk_about_dialog_set_logo (about, g_value_get_object (value));
845 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
847 case PROP_DOCUMENTERS:
848 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
851 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
853 case PROP_TRANSLATOR_CREDITS:
854 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
856 case PROP_LOGO_ICON_NAME:
857 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
859 case PROP_WRAP_LICENSE:
860 priv->wrap_license = g_value_get_boolean (value);
863 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
869 gtk_about_dialog_get_property (GObject *object,
874 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
875 GtkAboutDialogPrivate *priv = about->priv;
880 g_value_set_string (value, priv->name);
883 g_value_set_string (value, priv->version);
886 g_value_set_string (value, priv->copyright);
889 g_value_set_string (value, priv->comments);
892 g_value_set_string (value, priv->website_url);
894 case PROP_WEBSITE_LABEL:
895 g_value_set_string (value, priv->website_text);
898 g_value_set_string (value, priv->license);
900 case PROP_LICENSE_TYPE:
901 g_value_set_enum (value, priv->license_type);
903 case PROP_TRANSLATOR_CREDITS:
904 g_value_set_string (value, priv->translator_credits);
907 g_value_set_boxed (value, priv->authors);
909 case PROP_DOCUMENTERS:
910 g_value_set_boxed (value, priv->documenters);
913 g_value_set_boxed (value, priv->artists);
916 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
917 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
919 g_value_set_object (value, NULL);
921 case PROP_LOGO_ICON_NAME:
922 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
924 const gchar *icon_name;
926 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
927 g_value_set_string (value, icon_name);
930 g_value_set_string (value, NULL);
932 case PROP_WRAP_LICENSE:
933 g_value_set_boolean (value, priv->wrap_license);
936 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
942 gtk_about_dialog_activate_link (GtkAboutDialog *about,
946 GError *error = NULL;
948 screen = gtk_widget_get_screen (GTK_WIDGET (about));
950 if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
954 dialog = gtk_message_dialog_new (GTK_WINDOW (about),
955 GTK_DIALOG_DESTROY_WITH_PARENT |
959 "%s", _("Could not show link"));
960 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
961 "%s", error->message);
962 g_error_free (error);
964 g_signal_connect (dialog, "response",
965 G_CALLBACK (gtk_widget_destroy), NULL);
967 gtk_window_present (GTK_WINDOW (dialog));
974 update_website (GtkAboutDialog *about)
976 GtkAboutDialogPrivate *priv = about->priv;
978 gtk_widget_show (priv->website_label);
980 if (priv->website_url)
984 if (priv->website_text)
988 escaped = g_markup_escape_text (priv->website_text, -1);
989 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
990 priv->website_url, escaped);
995 markup = g_strdup_printf ("<a href=\"%s\">%s</a>",
996 priv->website_url, _("Homepage"));
999 gtk_label_set_markup (GTK_LABEL (priv->website_label), markup);
1004 if (priv->website_url)
1005 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
1006 else if (priv->website_text)
1007 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
1009 gtk_widget_hide (priv->website_label);
1014 gtk_about_dialog_show (GtkWidget *widget)
1016 update_website (GTK_ABOUT_DIALOG (widget));
1018 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
1022 * gtk_about_dialog_get_program_name:
1023 * @about: a #GtkAboutDialog
1025 * Returns the program name displayed in the about dialog.
1027 * Return value: The program name. The string is owned by the about
1028 * dialog and must not be modified.
1032 G_CONST_RETURN gchar *
1033 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
1035 GtkAboutDialogPrivate *priv;
1037 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1045 update_name_version (GtkAboutDialog *about)
1047 GtkAboutDialogPrivate *priv;
1048 gchar *title_string, *name_string;
1052 title_string = g_strdup_printf (_("About %s"), priv->name);
1053 gtk_window_set_title (GTK_WINDOW (about), title_string);
1054 g_free (title_string);
1056 if (priv->version != NULL)
1058 gtk_label_set_markup (GTK_LABEL (priv->version_label), priv->version);
1059 gtk_widget_show (priv->version_label);
1062 gtk_widget_hide (priv->version_label);
1064 name_string = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
1066 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
1067 g_free (name_string);
1071 * gtk_about_dialog_set_program_name:
1072 * @about: a #GtkAboutDialog
1073 * @name: the program name
1075 * Sets the name to display in the about dialog.
1076 * If this is not set, it defaults to g_get_application_name().
1081 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
1084 GtkAboutDialogPrivate *priv;
1087 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1092 priv->name = g_strdup (name ? name : g_get_application_name ());
1095 update_name_version (about);
1097 g_object_notify (G_OBJECT (about), "program-name");
1102 * gtk_about_dialog_get_version:
1103 * @about: a #GtkAboutDialog
1105 * Returns the version string.
1107 * Return value: The version string. The string is owned by the about
1108 * dialog and must not be modified.
1112 G_CONST_RETURN gchar *
1113 gtk_about_dialog_get_version (GtkAboutDialog *about)
1115 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1117 return about->priv->version;
1121 * gtk_about_dialog_set_version:
1122 * @about: a #GtkAboutDialog
1123 * @version: (allow-none): the version string
1125 * Sets the version string to display in the about dialog.
1130 gtk_about_dialog_set_version (GtkAboutDialog *about,
1131 const gchar *version)
1133 GtkAboutDialogPrivate *priv;
1136 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1140 tmp = priv->version;
1141 priv->version = g_strdup (version);
1144 update_name_version (about);
1146 g_object_notify (G_OBJECT (about), "version");
1150 * gtk_about_dialog_get_copyright:
1151 * @about: a #GtkAboutDialog
1153 * Returns the copyright string.
1155 * Return value: The copyright string. The string is owned by the about
1156 * dialog and must not be modified.
1160 G_CONST_RETURN gchar *
1161 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
1163 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1165 return about->priv->copyright;
1169 * gtk_about_dialog_set_copyright:
1170 * @about: a #GtkAboutDialog
1171 * @copyright: (allow-none) the copyright string
1173 * Sets the copyright string to display in the about dialog.
1174 * This should be a short string of one or two lines.
1179 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
1180 const gchar *copyright)
1182 GtkAboutDialogPrivate *priv;
1183 gchar *copyright_string, *tmp;
1185 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1189 tmp = priv->copyright;
1190 priv->copyright = g_strdup (copyright);
1193 if (priv->copyright != NULL)
1195 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
1197 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
1198 g_free (copyright_string);
1200 gtk_widget_show (priv->copyright_label);
1203 gtk_widget_hide (priv->copyright_label);
1205 g_object_notify (G_OBJECT (about), "copyright");
1209 * gtk_about_dialog_get_comments:
1210 * @about: a #GtkAboutDialog
1212 * Returns the comments string.
1214 * Return value: The comments. The string is owned by the about
1215 * dialog and must not be modified.
1219 G_CONST_RETURN gchar *
1220 gtk_about_dialog_get_comments (GtkAboutDialog *about)
1222 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1224 return about->priv->comments;
1228 * gtk_about_dialog_set_comments:
1229 * @about: a #GtkAboutDialog
1230 * @comments: (allow-none): a comments string
1232 * Sets the comments string to display in the about dialog.
1233 * This should be a short string of one or two lines.
1238 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1239 const gchar *comments)
1241 GtkAboutDialogPrivate *priv;
1244 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1248 tmp = priv->comments;
1251 priv->comments = g_strdup (comments);
1252 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1253 gtk_widget_show (priv->comments_label);
1257 priv->comments = NULL;
1258 gtk_widget_hide (priv->comments_label);
1262 g_object_notify (G_OBJECT (about), "comments");
1266 * gtk_about_dialog_get_license:
1267 * @about: a #GtkAboutDialog
1269 * Returns the license information.
1271 * Return value: The license information. The string is owned by the about
1272 * dialog and must not be modified.
1276 G_CONST_RETURN gchar *
1277 gtk_about_dialog_get_license (GtkAboutDialog *about)
1279 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1281 return about->priv->license;
1285 * gtk_about_dialog_set_license:
1286 * @about: a #GtkAboutDialog
1287 * @license: (allow-none): the license information or %NULL
1289 * Sets the license information to be displayed in the secondary
1290 * license dialog. If @license is %NULL, the license button is
1296 gtk_about_dialog_set_license (GtkAboutDialog *about,
1297 const gchar *license)
1299 GtkAboutDialogPrivate *priv;
1302 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1306 tmp = priv->license;
1309 priv->license = g_strdup (license);
1310 priv->license_type = GTK_LICENSE_CUSTOM;
1314 priv->license = NULL;
1315 priv->license_type = GTK_LICENSE_UNKNOWN;
1319 gtk_widget_hide (priv->license_label);
1321 update_license_button_visibility (about);
1323 g_object_notify (G_OBJECT (about), "license");
1324 g_object_notify (G_OBJECT (about), "license-type");
1328 * gtk_about_dialog_get_wrap_license:
1329 * @about: a #GtkAboutDialog
1331 * Returns whether the license text in @about is
1332 * automatically wrapped.
1334 * Returns: %TRUE if the license text is wrapped
1339 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1341 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1343 return about->priv->wrap_license;
1347 * gtk_about_dialog_set_wrap_license:
1348 * @about: a #GtkAboutDialog
1349 * @wrap_license: whether to wrap the license
1351 * Sets whether the license text in @about is
1352 * automatically wrapped.
1357 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1358 gboolean wrap_license)
1360 GtkAboutDialogPrivate *priv;
1362 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1366 wrap_license = wrap_license != FALSE;
1368 if (priv->wrap_license != wrap_license)
1370 priv->wrap_license = wrap_license;
1372 g_object_notify (G_OBJECT (about), "wrap-license");
1377 * gtk_about_dialog_get_website:
1378 * @about: a #GtkAboutDialog
1380 * Returns the website URL.
1382 * Return value: The website URL. The string is owned by the about
1383 * dialog and must not be modified.
1387 G_CONST_RETURN gchar *
1388 gtk_about_dialog_get_website (GtkAboutDialog *about)
1390 GtkAboutDialogPrivate *priv;
1392 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1396 return priv->website_url;
1400 * gtk_about_dialog_set_website:
1401 * @about: a #GtkAboutDialog
1402 * @website: (allow-none): a URL string starting with "http://"
1404 * Sets the URL to use for the website link.
1409 gtk_about_dialog_set_website (GtkAboutDialog *about,
1410 const gchar *website)
1412 GtkAboutDialogPrivate *priv;
1415 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1419 tmp = priv->website_url;
1420 priv->website_url = g_strdup (website);
1423 update_website (about);
1425 g_object_notify (G_OBJECT (about), "website");
1429 * gtk_about_dialog_get_website_label:
1430 * @about: a #GtkAboutDialog
1432 * Returns the label used for the website link.
1434 * Return value: The label used for the website link. The string is
1435 * owned by the about dialog and must not be modified.
1439 G_CONST_RETURN gchar *
1440 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1442 GtkAboutDialogPrivate *priv;
1444 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1448 return priv->website_text;
1452 * gtk_about_dialog_set_website_label:
1453 * @about: a #GtkAboutDialog
1454 * @website_label: the label used for the website link
1456 * Sets the label to be used for the website link.
1457 * It defaults to the website URL.
1462 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1463 const gchar *website_label)
1465 GtkAboutDialogPrivate *priv;
1468 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1472 tmp = priv->website_text;
1473 priv->website_text = g_strdup (website_label);
1476 update_website (about);
1478 g_object_notify (G_OBJECT (about), "website-label");
1482 * gtk_about_dialog_get_authors:
1483 * @about: a #GtkAboutDialog
1485 * Returns the string which are displayed in the authors tab
1486 * of the secondary credits dialog.
1488 * Return value: A %NULL-terminated string array containing
1489 * the authors. The array is owned by the about dialog
1490 * and must not be modified.
1494 G_CONST_RETURN gchar * G_CONST_RETURN *
1495 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1497 GtkAboutDialogPrivate *priv;
1499 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1503 return (const gchar * const *) priv->authors;
1507 * gtk_about_dialog_set_authors:
1508 * @about: a #GtkAboutDialog
1509 * @authors: (array zero-terminated=1): a %NULL-terminated array of strings
1511 * Sets the strings which are displayed in the authors tab
1512 * of the secondary credits dialog.
1517 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1518 const gchar **authors)
1520 GtkAboutDialogPrivate *priv;
1523 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1527 tmp = priv->authors;
1528 priv->authors = g_strdupv ((gchar **)authors);
1531 update_credits_button_visibility (about);
1533 g_object_notify (G_OBJECT (about), "authors");
1537 * gtk_about_dialog_get_documenters:
1538 * @about: a #GtkAboutDialog
1540 * Returns the string which are displayed in the documenters
1541 * tab of the secondary credits dialog.
1543 * Return value: A %NULL-terminated string array containing
1544 * the documenters. The array is owned by the about dialog
1545 * and must not be modified.
1549 G_CONST_RETURN gchar * G_CONST_RETURN *
1550 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1552 GtkAboutDialogPrivate *priv;
1554 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1558 return (const gchar * const *)priv->documenters;
1562 * gtk_about_dialog_set_documenters:
1563 * @about: a #GtkAboutDialog
1564 * @documenters: (array zero-terminated=1): a %NULL-terminated array of strings
1566 * Sets the strings which are displayed in the documenters tab
1567 * of the secondary credits dialog.
1572 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1573 const gchar **documenters)
1575 GtkAboutDialogPrivate *priv;
1578 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1582 tmp = priv->documenters;
1583 priv->documenters = g_strdupv ((gchar **)documenters);
1586 update_credits_button_visibility (about);
1588 g_object_notify (G_OBJECT (about), "documenters");
1592 * gtk_about_dialog_get_artists:
1593 * @about: a #GtkAboutDialog
1595 * Returns the string which are displayed in the artists tab
1596 * of the secondary credits dialog.
1598 * Return value: A %NULL-terminated string array containing
1599 * the artists. The array is owned by the about dialog
1600 * and must not be modified.
1604 G_CONST_RETURN gchar * G_CONST_RETURN *
1605 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1607 GtkAboutDialogPrivate *priv;
1609 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1613 return (const gchar * const *)priv->artists;
1617 * gtk_about_dialog_set_artists:
1618 * @about: a #GtkAboutDialog
1619 * @artists: (array zero-terminated=1): a %NULL-terminated array of strings
1621 * Sets the strings which are displayed in the artists tab
1622 * of the secondary credits dialog.
1627 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1628 const gchar **artists)
1630 GtkAboutDialogPrivate *priv;
1633 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1637 tmp = priv->artists;
1638 priv->artists = g_strdupv ((gchar **)artists);
1641 update_credits_button_visibility (about);
1643 g_object_notify (G_OBJECT (about), "artists");
1647 * gtk_about_dialog_get_translator_credits:
1648 * @about: a #GtkAboutDialog
1650 * Returns the translator credits string which is displayed
1651 * in the translators tab of the secondary credits dialog.
1653 * Return value: The translator credits string. The string is
1654 * owned by the about dialog and must not be modified.
1658 G_CONST_RETURN gchar *
1659 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1661 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1663 return about->priv->translator_credits;
1667 * gtk_about_dialog_set_translator_credits:
1668 * @about: a #GtkAboutDialog
1669 * @translator_credits: (allow-none): the translator credits
1671 * Sets the translator credits string which is displayed in
1672 * the translators tab of the secondary credits dialog.
1674 * The intended use for this string is to display the translator
1675 * of the language which is currently used in the user interface.
1676 * Using gettext(), a simple way to achieve that is to mark the
1677 * string for translation:
1679 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1681 * It is a good idea to use the customary msgid "translator-credits" for this
1682 * purpose, since translators will already know the purpose of that msgid, and
1683 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1689 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1690 const gchar *translator_credits)
1692 GtkAboutDialogPrivate *priv;
1695 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1699 tmp = priv->translator_credits;
1700 priv->translator_credits = g_strdup (translator_credits);
1703 update_credits_button_visibility (about);
1705 g_object_notify (G_OBJECT (about), "translator-credits");
1709 * gtk_about_dialog_get_logo:
1710 * @about: a #GtkAboutDialog
1712 * Returns the pixbuf displayed as logo in the about dialog.
1714 * Return value: the pixbuf displayed as logo. The pixbuf is
1715 * owned by the about dialog. If you want to keep a reference
1716 * to it, you have to call g_object_ref() on it.
1721 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1723 GtkAboutDialogPrivate *priv;
1725 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1729 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1730 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1736 icon_set_new_from_pixbufs (GList *pixbufs)
1738 GtkIconSet *icon_set = gtk_icon_set_new ();
1740 for (; pixbufs; pixbufs = pixbufs->next)
1742 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1744 GtkIconSource *icon_source = gtk_icon_source_new ();
1745 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1746 gtk_icon_set_add_source (icon_set, icon_source);
1747 gtk_icon_source_free (icon_source);
1754 * gtk_about_dialog_set_logo:
1755 * @about: a #GtkAboutDialog
1756 * @logo: (allow-none): a #GdkPixbuf, or %NULL
1758 * Sets the pixbuf to be displayed as logo in the about dialog.
1759 * If it is %NULL, the default window icon set with
1760 * gtk_window_set_default_icon() will be used.
1765 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1768 GtkAboutDialogPrivate *priv;
1770 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1774 g_object_freeze_notify (G_OBJECT (about));
1776 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1777 g_object_notify (G_OBJECT (about), "logo-icon-name");
1780 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1783 GList *pixbufs = gtk_window_get_default_icon_list ();
1785 if (pixbufs != NULL)
1787 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1789 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1790 icon_set, GTK_ICON_SIZE_DIALOG);
1792 gtk_icon_set_unref (icon_set);
1793 g_list_free (pixbufs);
1797 g_object_notify (G_OBJECT (about), "logo");
1799 g_object_thaw_notify (G_OBJECT (about));
1803 * gtk_about_dialog_get_logo_icon_name:
1804 * @about: a #GtkAboutDialog
1806 * Returns the icon name displayed as logo in the about dialog.
1808 * Return value: the icon name displayed as logo. The string is
1809 * owned by the dialog. If you want to keep a reference
1810 * to it, you have to call g_strdup() on it.
1814 G_CONST_RETURN gchar *
1815 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1817 GtkAboutDialogPrivate *priv;
1818 const gchar *icon_name = NULL;
1820 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1824 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1825 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1831 * gtk_about_dialog_set_logo_icon_name:
1832 * @about: a #GtkAboutDialog
1833 * @icon_name: (allow-none): an icon name, or %NULL
1835 * Sets the pixbuf to be displayed as logo in the about dialog.
1836 * If it is %NULL, the default window icon set with
1837 * gtk_window_set_default_icon() will be used.
1842 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1843 const gchar *icon_name)
1845 GtkAboutDialogPrivate *priv;
1847 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1851 g_object_freeze_notify (G_OBJECT (about));
1853 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1854 g_object_notify (G_OBJECT (about), "logo");
1856 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1857 GTK_ICON_SIZE_DIALOG);
1858 g_object_notify (G_OBJECT (about), "logo-icon-name");
1860 g_object_thaw_notify (G_OBJECT (about));
1864 follow_if_link (GtkAboutDialog *about,
1865 GtkTextView *text_view,
1868 GSList *tags = NULL, *tagp = NULL;
1869 GtkAboutDialogPrivate *priv = about->priv;
1872 tags = gtk_text_iter_get_tags (iter);
1873 for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
1875 GtkTextTag *tag = tagp->data;
1877 uri = g_object_get_data (G_OBJECT (tag), "uri");
1879 emit_activate_link (about, uri);
1881 if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
1883 GdkColor *style_visited_link_color;
1886 gtk_widget_ensure_style (GTK_WIDGET (about));
1887 gtk_widget_style_get (GTK_WIDGET (about),
1888 "visited-link-color", &style_visited_link_color,
1890 if (style_visited_link_color)
1892 color = *style_visited_link_color;
1893 gdk_color_free (style_visited_link_color);
1896 color = default_visited_link_color;
1898 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1900 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
1905 g_slist_free (tags);
1909 text_view_key_press_event (GtkWidget *text_view,
1911 GtkAboutDialog *about)
1914 GtkTextBuffer *buffer;
1916 switch (event->keyval)
1918 case GDK_KEY_Return:
1919 case GDK_KEY_ISO_Enter:
1920 case GDK_KEY_KP_Enter:
1921 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1922 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1923 gtk_text_buffer_get_insert (buffer));
1924 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1935 text_view_event_after (GtkWidget *text_view,
1937 GtkAboutDialog *about)
1939 GtkTextIter start, end, iter;
1940 GtkTextBuffer *buffer;
1941 GdkEventButton *button_event;
1944 if (event->type != GDK_BUTTON_RELEASE)
1947 button_event = (GdkEventButton *)event;
1949 if (button_event->button != 1)
1952 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1954 /* we shouldn't follow a link if the user has selected something */
1955 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1956 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1959 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1960 GTK_TEXT_WINDOW_WIDGET,
1961 button_event->x, button_event->y, &x, &y);
1963 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1965 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1971 set_cursor_if_appropriate (GtkAboutDialog *about,
1972 GtkTextView *text_view,
1977 GtkAboutDialogPrivate *priv = about->priv;
1978 GSList *tags = NULL, *tagp = NULL;
1980 gboolean hovering_over_link = FALSE;
1982 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1984 tags = gtk_text_iter_get_tags (&iter);
1985 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1987 GtkTextTag *tag = tagp->data;
1988 gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
1992 hovering_over_link = TRUE;
1997 if (hovering_over_link != priv->hovering_over_link)
1999 priv->hovering_over_link = hovering_over_link;
2001 if (hovering_over_link)
2002 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->hand_cursor);
2004 gdk_window_set_device_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), device, priv->regular_cursor);
2008 g_slist_free (tags);
2012 text_view_motion_notify_event (GtkWidget *text_view,
2013 GdkEventMotion *event,
2014 GtkAboutDialog *about)
2018 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2019 GTK_TEXT_WINDOW_WIDGET,
2020 event->x, event->y, &x, &y);
2022 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), event->device, x, y);
2024 gdk_event_request_motions (event);
2031 text_view_visibility_notify_event (GtkWidget *text_view,
2032 GdkEventVisibility *event,
2033 GtkAboutDialog *about)
2035 GdkDeviceManager *device_manager;
2036 GdkDisplay *display;
2038 gint wx, wy, bx, by;
2040 display = gdk_window_get_display (event->window);
2041 device_manager = gdk_display_get_device_manager (display);
2042 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
2044 for (d = devices; d; d = d->next)
2046 GdkDevice *dev = d->data;
2048 gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
2051 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
2052 GTK_TEXT_WINDOW_WIDGET,
2055 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), dev, bx, by);
2062 text_view_new (GtkAboutDialog *about,
2064 GtkWrapMode wrap_mode)
2067 gchar *q0, *q1, *q2, *r1, *r2;
2069 GtkTextView *text_view;
2070 GtkTextBuffer *buffer;
2071 GdkColor *style_link_color;
2072 GdkColor *style_visited_link_color;
2074 GdkColor link_color;
2075 GdkColor visited_link_color;
2077 PangoFontDescription *font_desc;
2079 GtkAboutDialogPrivate *priv = about->priv;
2081 gtk_widget_ensure_style (GTK_WIDGET (about));
2082 gtk_widget_style_get (GTK_WIDGET (about),
2083 "link-color", &style_link_color,
2084 "visited-link-color", &style_visited_link_color,
2086 if (style_link_color)
2088 link_color = *style_link_color;
2089 gdk_color_free (style_link_color);
2092 link_color = default_link_color;
2094 if (style_visited_link_color)
2096 visited_link_color = *style_visited_link_color;
2097 gdk_color_free (style_visited_link_color);
2100 visited_link_color = default_visited_link_color;
2102 view = gtk_text_view_new ();
2103 text_view = GTK_TEXT_VIEW (view);
2104 buffer = gtk_text_view_get_buffer (text_view);
2105 gtk_text_view_set_cursor_visible (text_view, FALSE);
2106 gtk_text_view_set_editable (text_view, FALSE);
2107 gtk_text_view_set_wrap_mode (text_view, wrap_mode);
2109 size = pango_font_description_get_size (gtk_widget_get_style (view)->font_desc);
2110 font_desc = pango_font_description_new ();
2111 pango_font_description_set_size (font_desc, size * PANGO_SCALE_SMALL);
2112 gtk_widget_modify_font (view, font_desc);
2113 pango_font_description_free (font_desc);
2115 gtk_text_view_set_left_margin (text_view, 8);
2116 gtk_text_view_set_right_margin (text_view, 8);
2118 g_signal_connect (view, "key-press-event",
2119 G_CALLBACK (text_view_key_press_event), about);
2120 g_signal_connect (view, "event-after",
2121 G_CALLBACK (text_view_event_after), about);
2122 g_signal_connect (view, "motion-notify-event",
2123 G_CALLBACK (text_view_motion_notify_event), about);
2124 g_signal_connect (view, "visibility-notify-event",
2125 G_CALLBACK (text_view_visibility_notify_event), about);
2127 if (strings == NULL)
2129 gtk_widget_hide (view);
2133 for (p = strings; *p; p++)
2138 q1 = strchr (q0, '<');
2139 q2 = q1 ? strchr (q1, '>') : NULL;
2140 r1 = strstr (q0, "http://");
2143 r2 = strpbrk (r1, " \n\t");
2145 r2 = strchr (r1, '\0');
2150 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2161 const gchar *link_type;
2166 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0 + 1);
2167 gtk_text_buffer_get_end_iter (buffer, &end);
2169 link_type = "email";
2173 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
2174 gtk_text_buffer_get_end_iter (buffer, &end);
2180 link = g_strndup (q1, q2 - q1);
2182 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
2183 color = visited_link_color;
2187 tag = gtk_text_buffer_create_tag (buffer, NULL,
2188 "foreground-gdk", &color,
2189 "underline", PANGO_UNDERLINE_SINGLE,
2191 if (strcmp (link_type, "email") == 0)
2195 escaped = g_uri_escape_string (link, NULL, FALSE);
2196 uri = g_strconcat ("mailto:", escaped, NULL);
2201 uri = g_strdup (link);
2203 g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
2204 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2210 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2216 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2219 gtk_widget_show (view);
2224 add_credits_section (GtkAboutDialog *about,
2233 gchar *q0, *q1, *q2, *r1, *r2;
2238 markup = g_strdup_printf ("<span size=\"small\">%s</span>", title);
2239 label = gtk_label_new (markup);
2240 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2242 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
2243 gtk_grid_attach (grid, label, 0, *row, 1, 1);
2245 for (p = people; *p; p++)
2249 str = g_string_new ("<span size=\"small\">");
2254 q1 = strchr (q0, '<');
2255 q2 = q1 ? strchr (q1, '>') : NULL;
2256 r1 = strstr (q0, "http://");
2259 r2 = strpbrk (r1, " \n\t");
2261 r2 = strchr (r1, '\0');
2266 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
2271 else if (q1 && (q1[1] == 'a' || q1[1] == 'A') && q1[2] == ' ')
2273 /* if it is a <a> link leave it for the label to parse */
2287 text = g_strstrip (g_strndup (q0, q1 - q0));
2289 link = g_strndup (q1, q2 - q1);
2291 escaped = g_uri_escape_string (link, NULL, FALSE);
2292 g_string_append_printf (str,
2293 "<a href=\"mailto:%s\">%s</a>",
2303 text = g_strstrip (g_strndup (q0, q1 - q0));
2304 link = g_strndup (q1, q2 - q1);
2305 g_string_append_printf (str,
2306 "<a href=\"%s\">%s</a>",
2317 g_string_append (str, q0);
2321 g_string_append (str, "</span>");
2323 label = gtk_label_new (str->str);
2324 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
2325 g_string_free (str, TRUE);
2326 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2327 gtk_grid_attach (grid, label, 1, *row, 1, 1);
2331 /* skip one at the end */
2336 create_credits_page (GtkAboutDialog *about)
2338 GtkAboutDialogPrivate *priv = about->priv;
2339 GtkWidget *page_vbox;
2342 GtkWidget *alignment;
2345 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2346 gtk_widget_show (page_vbox);
2347 priv->credits_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2349 sw = gtk_scrolled_window_new (NULL, NULL);
2350 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
2351 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2353 GTK_POLICY_AUTOMATIC);
2354 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2356 alignment = gtk_alignment_new (0.5, 0, 0, 0);
2357 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), alignment);
2359 grid = gtk_grid_new ();
2360 gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
2361 gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
2362 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2363 gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
2364 gtk_container_add (GTK_CONTAINER (alignment), grid);
2366 if (priv->authors != NULL)
2367 add_credits_section (about, GTK_GRID (grid), &row, _("Created by"), priv->authors);
2369 if (priv->documenters != NULL)
2370 add_credits_section (about, GTK_GRID (grid), &row, _("Documented by"), priv->documenters);
2372 /* Don't show an untranslated gettext msgid */
2373 if (priv->translator_credits != NULL &&
2374 strcmp (priv->translator_credits, "translator_credits") != 0 &&
2375 strcmp (priv->translator_credits, "translator-credits") != 0)
2377 gchar *translators[2];
2379 translators[0] = priv->translator_credits;
2380 translators[1] = NULL;
2382 add_credits_section (about, GTK_GRID (grid), &row, _("Translated by"), translators);
2385 if (priv->artists != NULL)
2386 add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
2388 gtk_widget_show_all (sw);
2392 display_credits_page (GtkWidget *button,
2395 GtkAboutDialog *about = (GtkAboutDialog *)data;
2396 GtkAboutDialogPrivate *priv = about->priv;
2398 if (priv->credits_page == 0)
2399 create_credits_page (about);
2401 switch_page (about, priv->credits_page);
2405 create_license_page (GtkAboutDialog *about)
2407 GtkAboutDialogPrivate *priv = about->priv;
2408 GtkWidget *page_vbox;
2413 page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
2414 priv->license_page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
2416 sw = gtk_scrolled_window_new (NULL, NULL);
2417 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2418 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
2419 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2420 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
2421 gtk_box_pack_start (GTK_BOX (page_vbox), sw, TRUE, TRUE, 0);
2423 strings[0] = priv->license;
2425 view = text_view_new (about, strings,
2426 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2428 gtk_container_add (GTK_CONTAINER (sw), view);
2430 gtk_widget_show_all (page_vbox);
2434 display_license_page (GtkWidget *button,
2437 GtkAboutDialog *about = (GtkAboutDialog *)data;
2438 GtkAboutDialogPrivate *priv = about->priv;
2440 if (priv->license_page == 0)
2441 create_license_page (about);
2443 switch_page (about, priv->license_page);
2447 * gtk_about_dialog_new:
2449 * Creates a new #GtkAboutDialog.
2451 * Returns: a newly created #GtkAboutDialog
2456 gtk_about_dialog_new (void)
2458 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2460 return GTK_WIDGET (dialog);
2464 close_cb (GtkAboutDialog *about)
2466 switch_page (about, 0);
2467 gtk_widget_hide (GTK_WIDGET (about));
2471 * gtk_show_about_dialog:
2472 * @parent: (allow-none): transient parent, or %NULL for none
2473 * @first_property_name: the name of the first property
2474 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2476 * This is a convenience function for showing an application's about box.
2477 * The constructed dialog is associated with the parent window and
2478 * reused for future invocations of this function.
2483 gtk_show_about_dialog (GtkWindow *parent,
2484 const gchar *first_property_name,
2487 static GtkWidget *global_about_dialog = NULL;
2488 GtkWidget *dialog = NULL;
2492 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2494 dialog = global_about_dialog;
2498 dialog = gtk_about_dialog_new ();
2500 g_object_ref_sink (dialog);
2502 g_signal_connect (dialog, "delete-event",
2503 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2505 /* Close dialog on user response */
2506 g_signal_connect (dialog, "response",
2507 G_CALLBACK (close_cb), NULL);
2509 va_start (var_args, first_property_name);
2510 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2515 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2516 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2517 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2518 g_object_set_data_full (G_OBJECT (parent),
2519 I_("gtk-about-dialog"),
2520 dialog, g_object_unref);
2523 global_about_dialog = dialog;
2527 gtk_window_present (GTK_WINDOW (dialog));
2531 * gtk_about_dialog_set_license_type:
2532 * @about: a #GtkAboutDialog
2533 * @license_type: the type of license
2535 * Sets the license of the application showing the @about dialog from a
2536 * list of known licenses.
2538 * This function overrides the license set using
2539 * gtk_about_dialog_set_license().
2544 gtk_about_dialog_set_license_type (GtkAboutDialog *about,
2545 GtkLicense license_type)
2547 GtkAboutDialogPrivate *priv;
2549 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
2550 g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
2551 license_type <= GTK_LICENSE_ARTISTIC);
2555 if (priv->license_type != license_type)
2557 g_object_freeze_notify (G_OBJECT (about));
2559 priv->license_type = license_type;
2561 /* custom licenses use the contents of the :license property */
2562 if (priv->license_type != GTK_LICENSE_CUSTOM)
2565 gchar *license_string;
2568 url = gtk_license_urls[priv->license_type];
2570 url = priv->website_url;
2572 str = g_string_sized_new (256);
2573 g_string_append_printf (str, _(gtk_license_preamble), url, url);
2575 g_free (priv->license);
2576 priv->license = g_string_free (str, FALSE);
2577 priv->wrap_license = TRUE;
2579 license_string = g_strdup_printf ("<span size=\"small\">%s</span>",
2581 gtk_label_set_markup (GTK_LABEL (priv->license_label), license_string);
2582 g_free (license_string);
2583 gtk_widget_show (priv->license_label);
2585 update_license_button_visibility (about);
2587 g_object_notify (G_OBJECT (about), "wrap-license");
2588 g_object_notify (G_OBJECT (about), "license");
2592 gtk_widget_show (priv->license_label);
2595 g_object_notify (G_OBJECT (about), "license-type");
2597 g_object_thaw_notify (G_OBJECT (about));
2602 * gtk_about_dialog_get_license_type:
2603 * @about: a #GtkAboutDialog
2605 * Retrieves the license set using gtk_about_dialog_set_license_type()
2607 * Return value: a #GtkLicense value
2612 gtk_about_dialog_get_license_type (GtkAboutDialog *about)
2614 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
2616 return about->priv->license_type;