1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2001 CodeFactory AB
3 * Copyright (C) 2001, 2002 Anders Carlsson
4 * Copyright (C) 2003, 2004 Matthias Clasen <mclasen@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Author: Anders Carlsson <andersca@gnome.org>
25 * Modified by the GTK+ Team and others 1997-2004. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #include <gdk/gdkkeysyms.h>
37 #include "gtkaboutdialog.h"
38 #include "gtkbutton.h"
40 #include "gtkdialog.h"
44 #include "gtklinkbutton.h"
45 #include "gtkmarshalers.h"
46 #include "gtknotebook.h"
47 #include "gtkscrolledwindow.h"
49 #include "gtktextview.h"
51 #include "gtkiconfactory.h"
52 #include "gtkprivate.h"
57 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
58 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
60 typedef struct _GtkAboutDialogPrivate GtkAboutDialogPrivate;
61 struct _GtkAboutDialogPrivate
69 gchar *translator_credits;
76 GtkWidget *logo_image;
77 GtkWidget *name_label;
78 GtkWidget *comments_label;
79 GtkWidget *copyright_label;
80 GtkWidget *website_button;
81 GtkWidget *website_label;
83 GtkWidget *credits_button;
84 GtkWidget *credits_dialog;
85 GtkWidget *license_button;
86 GtkWidget *license_dialog;
88 GdkCursor *hand_cursor;
89 GdkCursor *regular_cursor;
91 GSList *visited_links;
93 guint hovering_over_link : 1;
94 guint wrap_license : 1;
97 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
112 PROP_TRANSLATOR_CREDITS,
119 static void gtk_about_dialog_finalize (GObject *object);
120 static void gtk_about_dialog_get_property (GObject *object,
124 static void gtk_about_dialog_set_property (GObject *object,
128 static void gtk_about_dialog_show (GtkWidget *widge);
129 static void update_name_version (GtkAboutDialog *about);
130 static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs);
131 static void activate_url (GtkWidget *widget,
133 static void follow_if_link (GtkAboutDialog *about,
134 GtkTextView *text_view,
136 static void set_cursor_if_appropriate (GtkAboutDialog *about,
137 GtkTextView *text_view,
140 static void add_credits_page (GtkAboutDialog *about,
144 static gboolean credits_key_press_event (GtkWidget *text_view,
146 GtkAboutDialog *about);
147 static gboolean credits_event_after (GtkWidget *text_view,
149 GtkAboutDialog *about);
150 static gboolean credits_motion_notify_event (GtkWidget *text_view,
151 GdkEventMotion *event,
152 GtkAboutDialog *about);
153 static gboolean credits_visibility_notify_event (GtkWidget *text_view,
154 GdkEventVisibility *event,
155 GtkAboutDialog *about);
156 static void display_credits_dialog (GtkWidget *button,
158 static void display_license_dialog (GtkWidget *button,
160 static void close_cb (GtkAboutDialog *about);
163 static GtkAboutDialogActivateLinkFunc activate_email_hook = NULL;
164 static gpointer activate_email_hook_data = NULL;
165 static GDestroyNotify activate_email_hook_destroy = NULL;
167 static GtkAboutDialogActivateLinkFunc activate_url_hook = NULL;
168 static gpointer activate_url_hook_data = NULL;
169 static GDestroyNotify activate_url_hook_destroy = NULL;
171 G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
174 gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
176 GObjectClass *object_class;
177 GtkWidgetClass *widget_class;
179 object_class = (GObjectClass *)klass;
180 widget_class = (GtkWidgetClass *)klass;
182 object_class->set_property = gtk_about_dialog_set_property;
183 object_class->get_property = gtk_about_dialog_get_property;
185 object_class->finalize = gtk_about_dialog_finalize;
187 widget_class->show = gtk_about_dialog_show;
190 * GtkAboutDialog:program-name:
192 * The name of the program.
193 * If this is not set, it defaults to g_get_application_name().
197 g_object_class_install_property (object_class,
199 g_param_spec_string ("program-name",
201 P_("The name of the program. If this is not set, it defaults to g_get_application_name()"),
203 GTK_PARAM_READWRITE));
206 * GtkAboutDialog:version:
208 * The version of the program.
212 g_object_class_install_property (object_class,
214 g_param_spec_string ("version",
215 P_("Program version"),
216 P_("The version of the program"),
218 GTK_PARAM_READWRITE));
221 * GtkAboutDialog:copyright:
223 * Copyright information for the program.
227 g_object_class_install_property (object_class,
229 g_param_spec_string ("copyright",
230 P_("Copyright string"),
231 P_("Copyright information for the program"),
233 GTK_PARAM_READWRITE));
237 * GtkAboutDialog:comments:
239 * Comments about the program. This string is displayed in a label
240 * in the main dialog, thus it should be a short explanation of
241 * the main purpose of the program, not a detailed list of features.
245 g_object_class_install_property (object_class,
247 g_param_spec_string ("comments",
248 P_("Comments string"),
249 P_("Comments about the program"),
251 GTK_PARAM_READWRITE));
254 * GtkAboutDialog:license:
256 * The license of the program. This string is displayed in a
257 * text view in a secondary dialog, therefore it is fine to use
258 * a long multi-paragraph text. Note that the text is only wrapped
259 * in the text view if the "wrap-license" property is set to %TRUE;
260 * otherwise the text itself must contain the intended linebreaks.
264 g_object_class_install_property (object_class,
266 g_param_spec_string ("license",
268 _("The license of the program"),
270 GTK_PARAM_READWRITE));
273 * GtkAboutDialog:website:
275 * The URL for the link to the website of the program.
276 * This should be a string starting with "http://.
280 g_object_class_install_property (object_class,
282 g_param_spec_string ("website",
284 P_("The URL for the link to the website of the program"),
286 GTK_PARAM_READWRITE));
289 * GtkAboutDialog:website-label:
291 * The label for the link to the website of the program. If this is not set,
292 * it defaults to the URL specified in the
293 * <link linkend="GtkAboutDialog--website">website</link> property.
297 g_object_class_install_property (object_class,
299 g_param_spec_string ("website-label",
301 P_("The label for the link to the website of the program. If this is not set, it defaults to the URL"),
303 GTK_PARAM_READWRITE));
306 * GtkAboutDialog:authors:
308 * The authors of the program, as a %NULL-terminated array of strings.
309 * Each string may contain email addresses and URLs, which will be displayed
310 * as links, see the introduction for more details.
314 g_object_class_install_property (object_class,
316 g_param_spec_boxed ("authors",
318 P_("List of authors of the program"),
320 GTK_PARAM_READWRITE));
323 * GtkAboutDialog:documenters:
325 * The people documenting the program, as a %NULL-terminated array of strings.
326 * Each string may contain email addresses and URLs, which will be displayed
327 * as links, see the introduction for more details.
331 g_object_class_install_property (object_class,
333 g_param_spec_boxed ("documenters",
335 P_("List of people documenting the program"),
337 GTK_PARAM_READWRITE));
340 * GtkAboutDialog:artists:
342 * The people who contributed artwork to the program, as a %NULL-terminated array of strings.
343 * Each string may contain email addresses and URLs, which will be displayed
344 * as links, see the introduction for more details.
348 g_object_class_install_property (object_class,
350 g_param_spec_boxed ("artists",
352 P_("List of people who have contributed artwork to the program"),
354 GTK_PARAM_READWRITE));
358 * GtkAboutDialog:translator-credits:
360 * Credits to the translators. This string should be marked as translatable.
361 * The string may contain email addresses and URLs, which will be displayed
362 * as links, see the introduction for more details.
366 g_object_class_install_property (object_class,
367 PROP_TRANSLATOR_CREDITS,
368 g_param_spec_string ("translator-credits",
369 P_("Translator credits"),
370 P_("Credits to the translators. This string should be marked as translatable"),
372 GTK_PARAM_READWRITE));
375 * GtkAboutDialog:logo:
377 * A logo for the about box. If this is not set, it defaults to
378 * gtk_window_get_default_icon_list().
382 g_object_class_install_property (object_class,
384 g_param_spec_object ("logo",
386 P_("A logo for the about box. If this is not set, it defaults to gtk_window_get_default_icon_list()"),
388 GTK_PARAM_READWRITE));
391 * GtkAboutDialog:logo-icon-name:
393 * A named icon to use as the logo for the about box. This property
394 * overrides the <link linkend="GtkAboutDialog--logo">logo</link> property.
398 g_object_class_install_property (object_class,
400 g_param_spec_string ("logo-icon-name",
401 P_("Logo Icon Name"),
402 P_("A named icon to use as the logo for the about box."),
404 GTK_PARAM_READWRITE));
406 * GtkAboutDialog:wrap-license:
408 * Whether to wrap the text in the license dialog.
412 g_object_class_install_property (object_class,
414 g_param_spec_boolean ("wrap-license",
416 P_("Whether to wrap the license text."),
418 GTK_PARAM_READWRITE));
421 g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
425 gtk_about_dialog_init (GtkAboutDialog *about)
427 GtkDialog *dialog = GTK_DIALOG (about);
428 GtkAboutDialogPrivate *priv;
429 GtkWidget *vbox, *hbox, *button, *close_button, *image;
432 priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
433 about->private_data = priv;
436 priv->version = NULL;
437 priv->copyright = NULL;
438 priv->comments = NULL;
439 priv->website_url = NULL;
440 priv->website_text = NULL;
441 priv->translator_credits = NULL;
442 priv->license = NULL;
443 priv->authors = NULL;
444 priv->documenters = NULL;
445 priv->artists = NULL;
447 priv->hand_cursor = gdk_cursor_new (GDK_HAND2);
448 priv->regular_cursor = gdk_cursor_new (GDK_XTERM);
449 priv->hovering_over_link = FALSE;
450 priv->wrap_license = FALSE;
452 gtk_dialog_set_has_separator (dialog, FALSE);
453 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
454 gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
455 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
458 gtk_widget_push_composite_child ();
460 vbox = gtk_vbox_new (FALSE, 8);
461 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
462 gtk_box_pack_start (GTK_BOX (dialog->vbox), vbox, TRUE, TRUE, 0);
464 priv->logo_image = gtk_image_new ();
465 gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
467 priv->name_label = gtk_label_new (NULL);
468 gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
469 gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
470 gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
472 priv->comments_label = gtk_label_new (NULL);
473 gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
474 gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
475 gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
476 gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0);
478 priv->copyright_label = gtk_label_new (NULL);
479 gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
480 gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
481 gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
483 hbox = gtk_hbox_new (TRUE, 0);
484 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
486 priv->website_button = button = gtk_link_button_new ("");
487 gtk_widget_set_no_show_all (button, TRUE);
488 g_signal_connect (G_OBJECT (button), "clicked",
489 G_CALLBACK (activate_url), about);
490 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
492 priv->website_label = button = gtk_label_new ("");
493 gtk_widget_set_no_show_all (button, TRUE);
494 gtk_label_set_selectable (GTK_LABEL (button), TRUE);
495 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
497 gtk_widget_show (vbox);
498 gtk_widget_show (priv->logo_image);
499 gtk_widget_show (priv->name_label);
500 gtk_widget_show (hbox);
502 /* Add the OK button */
503 close_button = gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE,
504 GTK_RESPONSE_CANCEL);
505 gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
507 /* Add the credits button */
508 button = gtk_button_new_with_mnemonic (_("C_redits"));
509 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
510 image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
511 gtk_button_set_image (GTK_BUTTON (button), image);
512 gtk_widget_set_no_show_all (button, TRUE);
513 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area),
514 button, FALSE, TRUE, 0);
515 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
516 g_signal_connect (button, "clicked",
517 G_CALLBACK (display_credits_dialog), about);
518 priv->credits_button = button;
519 priv->credits_dialog = NULL;
521 /* Add the license button */
522 button = gtk_button_new_from_stock (_("_License"));
523 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
524 gtk_widget_set_no_show_all (button, TRUE);
525 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (about)->action_area),
526 button, FALSE, TRUE, 0);
527 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE);
528 g_signal_connect (button, "clicked",
529 G_CALLBACK (display_license_dialog), about);
530 priv->license_button = button;
531 priv->license_dialog = NULL;
533 gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
535 gtk_widget_pop_composite_child ();
537 gtk_widget_grab_default (close_button);
538 gtk_widget_grab_focus (close_button);
541 gtk_about_dialog_set_program_name (about, NULL);
542 gtk_about_dialog_set_logo (about, NULL);
546 gtk_about_dialog_finalize (GObject *object)
548 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
549 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
552 g_free (priv->version);
553 g_free (priv->copyright);
554 g_free (priv->comments);
555 g_free (priv->license);
556 g_free (priv->website_url);
557 g_free (priv->website_text);
558 g_free (priv->translator_credits);
560 g_strfreev (priv->authors);
561 g_strfreev (priv->documenters);
562 g_strfreev (priv->artists);
564 g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
565 g_slist_free (priv->visited_links);
567 gdk_cursor_unref (priv->hand_cursor);
568 gdk_cursor_unref (priv->regular_cursor);
570 G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object);
574 gtk_about_dialog_set_property (GObject *object,
579 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
580 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
585 gtk_about_dialog_set_program_name (about, g_value_get_string (value));
588 gtk_about_dialog_set_version (about, g_value_get_string (value));
591 gtk_about_dialog_set_comments (about, g_value_get_string (value));
594 gtk_about_dialog_set_website (about, g_value_get_string (value));
596 case PROP_WEBSITE_LABEL:
597 gtk_about_dialog_set_website_label (about, g_value_get_string (value));
600 gtk_about_dialog_set_license (about, g_value_get_string (value));
603 gtk_about_dialog_set_copyright (about, g_value_get_string (value));
606 gtk_about_dialog_set_logo (about, g_value_get_object (value));
609 gtk_about_dialog_set_authors (about, (const gchar**)g_value_get_boxed (value));
611 case PROP_DOCUMENTERS:
612 gtk_about_dialog_set_documenters (about, (const gchar**)g_value_get_boxed (value));
615 gtk_about_dialog_set_artists (about, (const gchar**)g_value_get_boxed (value));
617 case PROP_TRANSLATOR_CREDITS:
618 gtk_about_dialog_set_translator_credits (about, g_value_get_string (value));
620 case PROP_LOGO_ICON_NAME:
621 gtk_about_dialog_set_logo_icon_name (about, g_value_get_string (value));
623 case PROP_WRAP_LICENSE:
624 priv->wrap_license = g_value_get_boolean (value);
627 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
633 gtk_about_dialog_get_property (GObject *object,
638 GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
639 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
644 g_value_set_string (value, priv->name);
647 g_value_set_string (value, priv->version);
650 g_value_set_string (value, priv->copyright);
653 g_value_set_string (value, priv->comments);
656 g_value_set_string (value, priv->website_url);
658 case PROP_WEBSITE_LABEL:
659 g_value_set_string (value, priv->website_text);
662 g_value_set_string (value, priv->license);
664 case PROP_TRANSLATOR_CREDITS:
665 g_value_set_string (value, priv->translator_credits);
668 g_value_set_boxed (value, priv->authors);
670 case PROP_DOCUMENTERS:
671 g_value_set_boxed (value, priv->documenters);
674 g_value_set_boxed (value, priv->artists);
677 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
678 g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image)));
680 g_value_set_object (value, NULL);
682 case PROP_LOGO_ICON_NAME:
683 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
685 const gchar *icon_name;
687 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
688 g_value_set_string (value, icon_name);
691 g_value_set_string (value, NULL);
693 case PROP_WRAP_LICENSE:
694 g_value_set_boolean (value, priv->wrap_license);
697 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
703 update_website (GtkAboutDialog *about)
705 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
707 if (priv->website_url && activate_url_hook)
709 gtk_widget_show (priv->website_button);
710 gtk_widget_hide (priv->website_label);
712 gtk_link_button_set_uri (GTK_LINK_BUTTON (priv->website_button), priv->website_url);
713 if (priv->website_text)
714 gtk_button_set_label (GTK_BUTTON (priv->website_button), priv->website_text);
716 gtk_button_set_label (GTK_BUTTON (priv->website_button), priv->website_url);
720 gtk_widget_show (priv->website_label);
721 gtk_widget_hide (priv->website_button);
723 if (priv->website_url)
724 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_url);
725 else if (priv->website_text)
726 gtk_label_set_text (GTK_LABEL (priv->website_label), priv->website_text);
728 gtk_widget_hide (priv->website_label);
733 gtk_about_dialog_show (GtkWidget *widget)
735 update_website (GTK_ABOUT_DIALOG (widget));
737 GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->show (widget);
741 * gtk_about_dialog_get_name:
742 * @about: a #GtkAboutDialog
744 * Returns the program name displayed in the about dialog.
746 * Return value: The program name. The string is owned by the about
747 * dialog and must not be modified.
751 * Deprecated: 2.12: Use gtk_about_dialog_get_program_name() instead.
753 G_CONST_RETURN gchar *
754 gtk_about_dialog_get_name (GtkAboutDialog *about)
756 return gtk_about_dialog_get_program_name (about);
760 * gtk_about_dialog_get_program_name:
761 * @about: a #GtkAboutDialog
763 * Returns the program name displayed in the about dialog.
765 * Return value: The program name. The string is owned by the about
766 * dialog and must not be modified.
770 G_CONST_RETURN gchar *
771 gtk_about_dialog_get_program_name (GtkAboutDialog *about)
773 GtkAboutDialogPrivate *priv;
775 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
777 priv = (GtkAboutDialogPrivate *)about->private_data;
783 update_name_version (GtkAboutDialog *about)
785 GtkAboutDialogPrivate *priv;
786 gchar *title_string, *name_string;
788 priv = (GtkAboutDialogPrivate *)about->private_data;
790 title_string = g_strdup_printf (_("About %s"), priv->name);
791 gtk_window_set_title (GTK_WINDOW (about), title_string);
792 g_free (title_string);
794 if (priv->version != NULL)
795 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>",
796 priv->name, priv->version);
798 name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">%s</span>",
801 gtk_label_set_markup (GTK_LABEL (priv->name_label), name_string);
803 g_free (name_string);
807 * gtk_about_dialog_set_name:
808 * @about: a #GtkAboutDialog
809 * @name: the program name
811 * Sets the name to display in the about dialog.
812 * If this is not set, it defaults to g_get_application_name().
816 * Deprecated: 2.12: Use gtk_about_dialog_set_program_name() instead.
819 gtk_about_dialog_set_name (GtkAboutDialog *about,
822 gtk_about_dialog_set_program_name (about, name);
826 * gtk_about_dialog_set_program_name:
827 * @about: a #GtkAboutDialog
828 * @name: the program name
830 * Sets the name to display in the about dialog.
831 * If this is not set, it defaults to g_get_application_name().
836 gtk_about_dialog_set_program_name (GtkAboutDialog *about,
839 GtkAboutDialogPrivate *priv;
842 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
844 priv = (GtkAboutDialogPrivate *)about->private_data;
846 priv->name = g_strdup (name ? name : g_get_application_name ());
849 update_name_version (about);
851 g_object_notify (G_OBJECT (about), "program-name");
856 * gtk_about_dialog_get_version:
857 * @about: a #GtkAboutDialog
859 * Returns the version string.
861 * Return value: The version string. The string is owned by the about
862 * dialog and must not be modified.
866 G_CONST_RETURN gchar *
867 gtk_about_dialog_get_version (GtkAboutDialog *about)
869 GtkAboutDialogPrivate *priv;
871 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
873 priv = (GtkAboutDialogPrivate *)about->private_data;
875 return priv->version;
879 * gtk_about_dialog_set_version:
880 * @about: a #GtkAboutDialog
881 * @version: the version string
883 * Sets the version string to display in the about dialog.
888 gtk_about_dialog_set_version (GtkAboutDialog *about,
889 const gchar *version)
891 GtkAboutDialogPrivate *priv;
894 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
896 priv = (GtkAboutDialogPrivate *)about->private_data;
899 priv->version = g_strdup (version);
902 update_name_version (about);
904 g_object_notify (G_OBJECT (about), "version");
908 * gtk_about_dialog_get_copyright:
909 * @about: a #GtkAboutDialog
911 * Returns the copyright string.
913 * Return value: The copyright string. The string is owned by the about
914 * dialog and must not be modified.
918 G_CONST_RETURN gchar *
919 gtk_about_dialog_get_copyright (GtkAboutDialog *about)
921 GtkAboutDialogPrivate *priv;
923 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
925 priv = (GtkAboutDialogPrivate *)about->private_data;
927 return priv->copyright;
931 * gtk_about_dialog_set_copyright:
932 * @about: a #GtkAboutDialog
933 * @copyright: the copyright string
935 * Sets the copyright string to display in the about dialog.
936 * This should be a short string of one or two lines.
941 gtk_about_dialog_set_copyright (GtkAboutDialog *about,
942 const gchar *copyright)
944 GtkAboutDialogPrivate *priv;
945 gchar *copyright_string, *tmp;
947 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
949 priv = (GtkAboutDialogPrivate *)about->private_data;
951 tmp = priv->copyright;
952 priv->copyright = g_strdup (copyright);
955 if (priv->copyright != NULL)
957 copyright_string = g_markup_printf_escaped ("<span size=\"small\">%s</span>",
959 gtk_label_set_markup (GTK_LABEL (priv->copyright_label), copyright_string);
960 g_free (copyright_string);
962 gtk_widget_show (priv->copyright_label);
965 gtk_widget_hide (priv->copyright_label);
967 g_object_notify (G_OBJECT (about), "copyright");
971 * gtk_about_dialog_get_comments:
972 * @about: a #GtkAboutDialog
974 * Returns the comments string.
976 * Return value: The comments. The string is owned by the about
977 * dialog and must not be modified.
981 G_CONST_RETURN gchar *
982 gtk_about_dialog_get_comments (GtkAboutDialog *about)
984 GtkAboutDialogPrivate *priv;
986 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
988 priv = (GtkAboutDialogPrivate *)about->private_data;
990 return priv->comments;
994 * gtk_about_dialog_set_comments:
995 * @about: a #GtkAboutDialog
996 * @comments: a comments string
998 * Sets the comments string to display in the about
999 * dialog. This should be a short string of one or
1005 gtk_about_dialog_set_comments (GtkAboutDialog *about,
1006 const gchar *comments)
1008 GtkAboutDialogPrivate *priv;
1011 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1013 priv = (GtkAboutDialogPrivate *)about->private_data;
1015 tmp = priv->comments;
1018 priv->comments = g_strdup (comments);
1019 gtk_label_set_text (GTK_LABEL (priv->comments_label), priv->comments);
1020 gtk_widget_show (priv->comments_label);
1024 priv->comments = NULL;
1025 gtk_widget_hide (priv->comments_label);
1029 g_object_notify (G_OBJECT (about), "comments");
1033 * gtk_about_dialog_get_license:
1034 * @about: a #GtkAboutDialog
1036 * Returns the license information.
1038 * Return value: The license information. The string is owned by the about
1039 * dialog and must not be modified.
1043 G_CONST_RETURN gchar *
1044 gtk_about_dialog_get_license (GtkAboutDialog *about)
1046 GtkAboutDialogPrivate *priv;
1048 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1050 priv = (GtkAboutDialogPrivate *)about->private_data;
1052 return priv->license;
1056 * gtk_about_dialog_set_license:
1057 * @about: a #GtkAboutDialog
1058 * @license: the license information or %NULL
1060 * Sets the license information to be displayed in the secondary
1061 * license dialog. If @license is %NULL, the license button is
1067 gtk_about_dialog_set_license (GtkAboutDialog *about,
1068 const gchar *license)
1070 GtkAboutDialogPrivate *priv;
1073 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1075 priv = (GtkAboutDialogPrivate *)about->private_data;
1077 tmp = priv->license;
1080 priv->license = g_strdup (license);
1081 gtk_widget_show (priv->license_button);
1085 priv->license = NULL;
1086 gtk_widget_hide (priv->license_button);
1090 g_object_notify (G_OBJECT (about), "license");
1094 * gtk_about_dialog_get_wrap_license:
1095 * @about: a #GtkAboutDialog
1097 * Returns whether the license text in @about is
1098 * automatically wrapped.
1100 * Returns: %TRUE if the license text is wrapped
1105 gtk_about_dialog_get_wrap_license (GtkAboutDialog *about)
1107 GtkAboutDialogPrivate *priv;
1109 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), FALSE);
1111 priv = (GtkAboutDialogPrivate *)about->private_data;
1113 return priv->wrap_license;
1117 * gtk_about_dialog_set_wrap_license:
1118 * @about: a #GtkAboutDialog
1119 * @wrap_license: whether to wrap the license
1121 * Sets whether the license text in @about is
1122 * automatically wrapped.
1127 gtk_about_dialog_set_wrap_license (GtkAboutDialog *about,
1128 gboolean wrap_license)
1130 GtkAboutDialogPrivate *priv;
1132 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1134 priv = (GtkAboutDialogPrivate *)about->private_data;
1136 wrap_license = wrap_license != FALSE;
1138 if (priv->wrap_license != wrap_license)
1140 priv->wrap_license = wrap_license;
1142 g_object_notify (G_OBJECT (about), "wrap-license");
1147 * gtk_about_dialog_get_website:
1148 * @about: a #GtkAboutDialog
1150 * Returns the website URL.
1152 * Return value: The website URL. The string is owned by the about
1153 * dialog and must not be modified.
1157 G_CONST_RETURN gchar *
1158 gtk_about_dialog_get_website (GtkAboutDialog *about)
1160 GtkAboutDialogPrivate *priv;
1162 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1164 priv = (GtkAboutDialogPrivate *)about->private_data;
1166 return priv->website_url;
1170 * gtk_about_dialog_set_website:
1171 * @about: a #GtkAboutDialog
1172 * @website: a URL string starting with "http://"
1174 * Sets the URL to use for the website link.
1176 * Note that that the hook functions need to be set up
1177 * before calling this function.
1182 gtk_about_dialog_set_website (GtkAboutDialog *about,
1183 const gchar *website)
1185 GtkAboutDialogPrivate *priv;
1188 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1190 priv = (GtkAboutDialogPrivate *)about->private_data;
1192 tmp = priv->website_url;
1193 priv->website_url = g_strdup (website);
1196 update_website (about);
1198 g_object_notify (G_OBJECT (about), "website");
1202 * gtk_about_dialog_get_website_label:
1203 * @about: a #GtkAboutDialog
1205 * Returns the label used for the website link.
1207 * Return value: The label used for the website link. The string is owned by the about
1208 * dialog and must not be modified.
1212 G_CONST_RETURN gchar *
1213 gtk_about_dialog_get_website_label (GtkAboutDialog *about)
1215 GtkAboutDialogPrivate *priv;
1217 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1219 priv = (GtkAboutDialogPrivate *)about->private_data;
1221 return priv->website_text;
1225 * gtk_about_dialog_set_website_label:
1226 * @about: a #GtkAboutDialog
1227 * @website_label: the label used for the website link
1229 * Sets the label to be used for the website link.
1230 * It defaults to the website URL.
1235 gtk_about_dialog_set_website_label (GtkAboutDialog *about,
1236 const gchar *website_label)
1238 GtkAboutDialogPrivate *priv;
1241 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1243 priv = (GtkAboutDialogPrivate *)about->private_data;
1245 tmp = priv->website_text;
1246 priv->website_text = g_strdup (website_label);
1249 update_website (about);
1251 g_object_notify (G_OBJECT (about), "website-label");
1255 * gtk_about_dialog_get_authors:
1256 * @about: a #GtkAboutDialog
1258 * Returns the string which are displayed in the authors tab
1259 * of the secondary credits dialog.
1261 * Return value: A %NULL-terminated string array containing
1262 * the authors. The array is owned by the about dialog
1263 * and must not be modified.
1267 G_CONST_RETURN gchar * G_CONST_RETURN *
1268 gtk_about_dialog_get_authors (GtkAboutDialog *about)
1270 GtkAboutDialogPrivate *priv;
1272 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1274 priv = (GtkAboutDialogPrivate *)about->private_data;
1276 return (const gchar * const *) priv->authors;
1280 update_credits_button_visibility (GtkAboutDialog *about)
1282 GtkAboutDialogPrivate *priv = about->private_data;
1285 show = priv->authors != NULL ||
1286 priv->documenters != NULL ||
1287 priv->artists != NULL ||
1288 (priv->translator_credits != NULL &&
1289 strcmp (priv->translator_credits, "translator_credits") &&
1290 strcmp (priv->translator_credits, "translator-credits"));
1292 gtk_widget_show (priv->credits_button);
1294 gtk_widget_hide (priv->credits_button);
1298 * gtk_about_dialog_set_authors:
1299 * @about: a #GtkAboutDialog
1300 * @authors: a %NULL-terminated array of strings
1302 * Sets the strings which are displayed in the authors tab
1303 * of the secondary credits dialog.
1308 gtk_about_dialog_set_authors (GtkAboutDialog *about,
1309 const gchar **authors)
1311 GtkAboutDialogPrivate *priv;
1314 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1316 priv = (GtkAboutDialogPrivate *)about->private_data;
1318 tmp = priv->authors;
1319 priv->authors = g_strdupv ((gchar **)authors);
1322 update_credits_button_visibility (about);
1324 g_object_notify (G_OBJECT (about), "authors");
1328 * gtk_about_dialog_get_documenters:
1329 * @about: a #GtkAboutDialog
1331 * Returns the string which are displayed in the documenters
1332 * tab of the secondary credits dialog.
1334 * Return value: A %NULL-terminated string array containing
1335 * the documenters. The array is owned by the about dialog
1336 * and must not be modified.
1340 G_CONST_RETURN gchar * G_CONST_RETURN *
1341 gtk_about_dialog_get_documenters (GtkAboutDialog *about)
1343 GtkAboutDialogPrivate *priv;
1345 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1347 priv = (GtkAboutDialogPrivate *)about->private_data;
1349 return (const gchar * const *)priv->documenters;
1353 * gtk_about_dialog_set_documenters:
1354 * @about: a #GtkAboutDialog
1355 * @documenters: a %NULL-terminated array of strings
1357 * Sets the strings which are displayed in the documenters tab
1358 * of the secondary credits dialog.
1363 gtk_about_dialog_set_documenters (GtkAboutDialog *about,
1364 const gchar **documenters)
1366 GtkAboutDialogPrivate *priv;
1369 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1371 priv = (GtkAboutDialogPrivate *)about->private_data;
1373 tmp = priv->documenters;
1374 priv->documenters = g_strdupv ((gchar **)documenters);
1377 update_credits_button_visibility (about);
1379 g_object_notify (G_OBJECT (about), "documenters");
1383 * gtk_about_dialog_get_artists:
1384 * @about: a #GtkAboutDialog
1386 * Returns the string which are displayed in the artists tab
1387 * of the secondary credits dialog.
1389 * Return value: A %NULL-terminated string array containing
1390 * the artists. The array is owned by the about dialog
1391 * and must not be modified.
1395 G_CONST_RETURN gchar * G_CONST_RETURN *
1396 gtk_about_dialog_get_artists (GtkAboutDialog *about)
1398 GtkAboutDialogPrivate *priv;
1400 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1402 priv = (GtkAboutDialogPrivate *)about->private_data;
1404 return (const gchar * const *)priv->artists;
1408 * gtk_about_dialog_set_artists:
1409 * @about: a #GtkAboutDialog
1410 * @artists: a %NULL-terminated array of strings
1412 * Sets the strings which are displayed in the artists tab
1413 * of the secondary credits dialog.
1418 gtk_about_dialog_set_artists (GtkAboutDialog *about,
1419 const gchar **artists)
1421 GtkAboutDialogPrivate *priv;
1424 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1426 priv = (GtkAboutDialogPrivate *)about->private_data;
1428 tmp = priv->artists;
1429 priv->artists = g_strdupv ((gchar **)artists);
1432 update_credits_button_visibility (about);
1434 g_object_notify (G_OBJECT (about), "artists");
1438 * gtk_about_dialog_get_translator_credits:
1439 * @about: a #GtkAboutDialog
1441 * Returns the translator credits string which is displayed
1442 * in the translators tab of the secondary credits dialog.
1444 * Return value: The translator credits string. The string is
1445 * owned by the about dialog and must not be modified.
1449 G_CONST_RETURN gchar *
1450 gtk_about_dialog_get_translator_credits (GtkAboutDialog *about)
1452 GtkAboutDialogPrivate *priv;
1454 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1456 priv = (GtkAboutDialogPrivate *)about->private_data;
1458 return priv->translator_credits;
1462 * gtk_about_dialog_set_translator_credits:
1463 * @about: a #GtkAboutDialog
1464 * @translator_credits: the translator credits
1466 * Sets the translator credits string which is displayed in
1467 * the translators tab of the secondary credits dialog.
1469 * The intended use for this string is to display the translator
1470 * of the language which is currently used in the user interface.
1471 * Using gettext(), a simple way to achieve that is to mark the
1472 * string for translation:
1474 * gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
1476 * It is a good idea to use the customary msgid "translator-credits" for this
1477 * purpose, since translators will already know the purpose of that msgid, and
1478 * since #GtkAboutDialog will detect if "translator-credits" is untranslated
1484 gtk_about_dialog_set_translator_credits (GtkAboutDialog *about,
1485 const gchar *translator_credits)
1487 GtkAboutDialogPrivate *priv;
1490 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1492 priv = (GtkAboutDialogPrivate *)about->private_data;
1494 tmp = priv->translator_credits;
1495 priv->translator_credits = g_strdup (translator_credits);
1498 update_credits_button_visibility (about);
1500 g_object_notify (G_OBJECT (about), "translator-credits");
1504 * gtk_about_dialog_get_logo:
1505 * @about: a #GtkAboutDialog
1507 * Returns the pixbuf displayed as logo in the about dialog.
1509 * Return value: the pixbuf displayed as logo. The pixbuf is
1510 * owned by the about dialog. If you want to keep a reference
1511 * to it, you have to call g_object_ref() on it.
1516 gtk_about_dialog_get_logo (GtkAboutDialog *about)
1518 GtkAboutDialogPrivate *priv;
1520 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1522 priv = (GtkAboutDialogPrivate *)about->private_data;
1524 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1525 return gtk_image_get_pixbuf (GTK_IMAGE (priv->logo_image));
1531 icon_set_new_from_pixbufs (GList *pixbufs)
1533 GtkIconSet *icon_set = gtk_icon_set_new ();
1535 for (; pixbufs; pixbufs = pixbufs->next)
1537 GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs->data);
1539 GtkIconSource *icon_source = gtk_icon_source_new ();
1540 gtk_icon_source_set_pixbuf (icon_source, pixbuf);
1541 gtk_icon_set_add_source (icon_set, icon_source);
1542 gtk_icon_source_free (icon_source);
1549 * gtk_about_dialog_set_logo:
1550 * @about: a #GtkAboutDialog
1551 * @logo: a #GdkPixbuf, or %NULL
1553 * Sets the pixbuf to be displayed as logo in
1554 * the about dialog. If it is %NULL, the default
1555 * window icon set with gtk_window_set_default_icon ()
1561 gtk_about_dialog_set_logo (GtkAboutDialog *about,
1564 GtkAboutDialogPrivate *priv;
1566 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1568 priv = (GtkAboutDialogPrivate *)about->private_data;
1570 g_object_freeze_notify (G_OBJECT (about));
1572 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1573 g_object_notify (G_OBJECT (about), "logo-icon-name");
1576 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->logo_image), logo);
1579 GList *pixbufs = gtk_window_get_default_icon_list ();
1581 if (pixbufs != NULL)
1583 GtkIconSet *icon_set = icon_set_new_from_pixbufs (pixbufs);
1585 gtk_image_set_from_icon_set (GTK_IMAGE (priv->logo_image),
1586 icon_set, GTK_ICON_SIZE_DIALOG);
1588 gtk_icon_set_unref (icon_set);
1589 g_list_free (pixbufs);
1593 g_object_notify (G_OBJECT (about), "logo");
1595 g_object_thaw_notify (G_OBJECT (about));
1599 * gtk_about_dialog_get_logo_icon_name:
1600 * @about: a #GtkAboutDialog
1602 * Returns the icon name displayed as logo in the about dialog.
1604 * Return value: the icon name displayed as logo. The string is
1605 * owned by the dialog. If you want to keep a reference
1606 * to it, you have to call g_strdup() on it.
1610 G_CONST_RETURN gchar *
1611 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
1613 GtkAboutDialogPrivate *priv;
1614 const gchar *icon_name = NULL;
1616 g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
1618 priv = (GtkAboutDialogPrivate *)about->private_data;
1620 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
1621 gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
1627 * gtk_about_dialog_set_logo_icon_name:
1628 * @about: a #GtkAboutDialog
1629 * @icon_name: an icon name, or %NULL
1631 * Sets the pixbuf to be displayed as logo in
1632 * the about dialog. If it is %NULL, the default
1633 * window icon set with gtk_window_set_default_icon()
1639 gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about,
1640 const gchar *icon_name)
1642 GtkAboutDialogPrivate *priv;
1644 g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
1646 priv = (GtkAboutDialogPrivate *)about->private_data;
1648 g_object_freeze_notify (G_OBJECT (about));
1650 if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_PIXBUF)
1651 g_object_notify (G_OBJECT (about), "logo");
1653 gtk_image_set_from_icon_name (GTK_IMAGE (priv->logo_image), icon_name,
1654 GTK_ICON_SIZE_DIALOG);
1655 g_object_notify (G_OBJECT (about), "logo-icon-name");
1657 g_object_thaw_notify (G_OBJECT (about));
1661 activate_url (GtkWidget *widget,
1664 GtkAboutDialog *about = GTK_ABOUT_DIALOG (data);
1665 const gchar *url = gtk_link_button_get_uri (GTK_LINK_BUTTON (widget));
1667 if (activate_url_hook != NULL)
1668 (* activate_url_hook) (about, url, activate_url_hook_data);
1672 follow_if_link (GtkAboutDialog *about,
1673 GtkTextView *text_view,
1676 GSList *tags = NULL, *tagp = NULL;
1677 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
1680 tags = gtk_text_iter_get_tags (iter);
1681 for (tagp = tags; tagp != NULL && !url; tagp = tagp->next)
1683 GtkTextTag *tag = tagp->data;
1685 if (activate_email_hook != NULL)
1687 url = g_object_get_data (G_OBJECT (tag), "email");
1689 (* activate_email_hook) (about, url, activate_email_hook_data);
1692 if (!url && activate_url_hook != NULL)
1694 url = g_object_get_data (G_OBJECT (tag), "url");
1696 (* activate_url_hook) (about, url, activate_url_hook_data);
1699 if (url && !g_slist_find_custom (priv->visited_links, url, (GCompareFunc)strcmp))
1701 GdkColor *style_visited_link_color;
1704 gtk_widget_ensure_style (GTK_WIDGET (about));
1705 gtk_widget_style_get (GTK_WIDGET (about),
1706 "visited-link-color", &style_visited_link_color,
1708 if (style_visited_link_color)
1710 color = *style_visited_link_color;
1711 gdk_color_free (style_visited_link_color);
1714 color = default_visited_link_color;
1716 g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
1718 priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (url));
1723 g_slist_free (tags);
1727 credits_key_press_event (GtkWidget *text_view,
1729 GtkAboutDialog *about)
1732 GtkTextBuffer *buffer;
1734 switch (event->keyval)
1739 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1740 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1741 gtk_text_buffer_get_insert (buffer));
1742 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1753 credits_event_after (GtkWidget *text_view,
1755 GtkAboutDialog *about)
1757 GtkTextIter start, end, iter;
1758 GtkTextBuffer *buffer;
1759 GdkEventButton *button_event;
1762 if (event->type != GDK_BUTTON_RELEASE)
1765 button_event = (GdkEventButton *)event;
1767 if (button_event->button != 1)
1770 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
1772 /* we shouldn't follow a link if the user has selected something */
1773 gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
1774 if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
1777 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1778 GTK_TEXT_WINDOW_WIDGET,
1779 button_event->x, button_event->y, &x, &y);
1781 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
1783 follow_if_link (about, GTK_TEXT_VIEW (text_view), &iter);
1789 set_cursor_if_appropriate (GtkAboutDialog *about,
1790 GtkTextView *text_view,
1794 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
1795 GSList *tags = NULL, *tagp = NULL;
1797 gboolean hovering_over_link = FALSE;
1799 gtk_text_view_get_iter_at_location (text_view, &iter, x, y);
1801 tags = gtk_text_iter_get_tags (&iter);
1802 for (tagp = tags; tagp != NULL; tagp = tagp->next)
1804 GtkTextTag *tag = tagp->data;
1805 gchar *email = g_object_get_data (G_OBJECT (tag), "email");
1806 gchar *url = g_object_get_data (G_OBJECT (tag), "url");
1808 if (email != NULL || url != NULL)
1810 hovering_over_link = TRUE;
1815 if (hovering_over_link != priv->hovering_over_link)
1817 priv->hovering_over_link = hovering_over_link;
1819 if (hovering_over_link)
1820 gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->hand_cursor);
1822 gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT), priv->regular_cursor);
1826 g_slist_free (tags);
1830 credits_motion_notify_event (GtkWidget *text_view,
1831 GdkEventMotion *event,
1832 GtkAboutDialog *about)
1836 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1837 GTK_TEXT_WINDOW_WIDGET,
1838 event->x, event->y, &x, &y);
1840 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), x, y);
1842 gdk_event_request_motions (event);
1849 credits_visibility_notify_event (GtkWidget *text_view,
1850 GdkEventVisibility *event,
1851 GtkAboutDialog *about)
1853 gint wx, wy, bx, by;
1855 gdk_window_get_pointer (text_view->window, &wx, &wy, NULL);
1857 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
1858 GTK_TEXT_WINDOW_WIDGET,
1861 set_cursor_if_appropriate (about, GTK_TEXT_VIEW (text_view), bx, by);
1867 add_credits_page (GtkAboutDialog *about,
1868 GtkWidget *notebook,
1873 gchar *q0, *q1, *q2, *r1, *r2;
1874 GtkWidget *sw, *view;
1875 GtkTextBuffer *buffer;
1876 gboolean linkify_email, linkify_urls;
1877 GdkColor *style_link_color;
1878 GdkColor *style_visited_link_color;
1880 GdkColor link_color;
1881 GdkColor visited_link_color;
1882 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
1884 linkify_email = (activate_email_hook != NULL);
1885 linkify_urls = (activate_url_hook != NULL);
1887 gtk_widget_ensure_style (GTK_WIDGET (about));
1888 gtk_widget_style_get (GTK_WIDGET (about),
1889 "link-color", &style_link_color,
1890 "visited-link-color", &style_visited_link_color,
1892 if (style_link_color)
1894 link_color = *style_link_color;
1895 gdk_color_free (style_link_color);
1898 link_color = default_link_color;
1900 if (style_visited_link_color)
1902 visited_link_color = *style_visited_link_color;
1903 gdk_color_free (style_visited_link_color);
1906 visited_link_color = default_visited_link_color;
1908 view = gtk_text_view_new ();
1910 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
1911 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
1912 gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
1914 gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 8);
1915 gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 8);
1917 g_signal_connect (view, "key-press-event",
1918 G_CALLBACK (credits_key_press_event), about);
1919 g_signal_connect (view, "event-after",
1920 G_CALLBACK (credits_event_after), about);
1921 g_signal_connect (view, "motion-notify-event",
1922 G_CALLBACK (credits_motion_notify_event), about);
1923 g_signal_connect (view, "visibility-notify-event",
1924 G_CALLBACK (credits_visibility_notify_event), about);
1926 sw = gtk_scrolled_window_new (NULL, NULL);
1927 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
1929 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
1930 GTK_POLICY_AUTOMATIC,
1931 GTK_POLICY_AUTOMATIC);
1932 gtk_container_add (GTK_CONTAINER (sw), view);
1934 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
1935 sw, gtk_label_new (title));
1939 gtk_widget_hide (view);
1943 gtk_widget_show (view);
1945 for (p = people; *p; p++)
1950 q1 = linkify_email ? strchr (q0, '<') : NULL;
1951 q2 = q1 ? strchr (q1, '>') : NULL;
1952 r1 = linkify_urls ? strstr (q0, "http://") : NULL;
1955 r2 = strpbrk (r1, " \n\t");
1957 r2 = strchr (r1, '\0');
1962 if (r1 && r2 && (!q1 || !q2 || (r1 < q1)))
1972 const gchar *link_type;
1977 gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
1978 gtk_text_buffer_get_end_iter (buffer, &end);
1980 link_type = I_("email");
1984 gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
1985 gtk_text_buffer_get_end_iter (buffer, &end);
1986 link_type = I_("url");
1991 link = g_strndup (q1, q2 - q1);
1993 if (g_slist_find_custom (priv->visited_links, link, (GCompareFunc)strcmp))
1994 color = visited_link_color;
1998 tag = gtk_text_buffer_create_tag (buffer, NULL,
1999 "foreground-gdk", &color,
2000 "underline", PANGO_UNDERLINE_SINGLE,
2002 g_object_set_data_full (G_OBJECT (tag), link_type, g_strdup (link), g_free);
2003 gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
2009 gtk_text_buffer_insert_at_cursor (buffer, q0, -1);
2015 gtk_text_buffer_insert_at_cursor (buffer, "\n", 1);
2020 display_credits_dialog (GtkWidget *button,
2023 GtkAboutDialog *about = (GtkAboutDialog *)data;
2024 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
2025 GtkWidget *dialog, *notebook;
2026 GtkDialog *credits_dialog;
2028 if (priv->credits_dialog != NULL)
2030 gtk_window_present (GTK_WINDOW (priv->credits_dialog));
2034 dialog = gtk_dialog_new_with_buttons (_("Credits"),
2036 GTK_DIALOG_DESTROY_WITH_PARENT,
2037 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2039 credits_dialog = GTK_DIALOG (dialog);
2040 gtk_dialog_set_has_separator (credits_dialog, FALSE);
2041 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
2042 gtk_box_set_spacing (GTK_BOX (credits_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2043 gtk_container_set_border_width (GTK_CONTAINER (credits_dialog->action_area), 5);
2045 priv->credits_dialog = dialog;
2046 gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260);
2047 gtk_dialog_set_default_response (credits_dialog, GTK_RESPONSE_CANCEL);
2049 gtk_window_set_modal (GTK_WINDOW (dialog),
2050 gtk_window_get_modal (GTK_WINDOW (about)));
2052 g_signal_connect (dialog, "response",
2053 G_CALLBACK (gtk_widget_destroy), dialog);
2054 g_signal_connect (dialog, "destroy",
2055 G_CALLBACK (gtk_widget_destroyed),
2056 &(priv->credits_dialog));
2058 notebook = gtk_notebook_new ();
2059 gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
2060 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, TRUE, 0);
2062 if (priv->authors != NULL)
2063 add_credits_page (about, notebook, _("Written by"), priv->authors);
2065 if (priv->documenters != NULL)
2066 add_credits_page (about, notebook, _("Documented by"), priv->documenters);
2068 /* Don't show an untranslated gettext msgid */
2069 if (priv->translator_credits != NULL &&
2070 strcmp (priv->translator_credits, "translator_credits") &&
2071 strcmp (priv->translator_credits, "translator-credits"))
2073 gchar *translators[2];
2075 translators[0] = priv->translator_credits;
2076 translators[1] = NULL;
2078 add_credits_page (about, notebook, _("Translated by"), translators);
2081 if (priv->artists != NULL)
2082 add_credits_page (about, notebook, _("Artwork by"), priv->artists);
2084 gtk_widget_show_all (dialog);
2088 set_policy (GtkWidget *sw)
2090 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2091 GTK_POLICY_AUTOMATIC,
2092 GTK_POLICY_AUTOMATIC);
2096 display_license_dialog (GtkWidget *button,
2099 GtkAboutDialog *about = (GtkAboutDialog *)data;
2100 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
2101 GtkWidget *dialog, *view, *sw;
2102 GtkDialog *licence_dialog;
2104 if (priv->license_dialog != NULL)
2106 gtk_window_present (GTK_WINDOW (priv->license_dialog));
2110 dialog = gtk_dialog_new_with_buttons (_("License"),
2112 GTK_DIALOG_DESTROY_WITH_PARENT,
2113 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
2115 licence_dialog = GTK_DIALOG (dialog);
2116 gtk_dialog_set_has_separator (licence_dialog, FALSE);
2117 gtk_container_set_border_width (GTK_CONTAINER (licence_dialog), 5);
2118 gtk_box_set_spacing (GTK_BOX (licence_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
2119 gtk_container_set_border_width (GTK_CONTAINER (licence_dialog->action_area), 5);
2121 priv->license_dialog = dialog;
2122 gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 320);
2123 gtk_dialog_set_default_response (licence_dialog, GTK_RESPONSE_CANCEL);
2125 gtk_window_set_modal (GTK_WINDOW (dialog),
2126 gtk_window_get_modal (GTK_WINDOW (about)));
2128 g_signal_connect (dialog, "response",
2129 G_CALLBACK (gtk_widget_destroy), dialog);
2130 g_signal_connect (dialog, "destroy",
2131 G_CALLBACK (gtk_widget_destroyed),
2132 &(priv->license_dialog));
2134 sw = gtk_scrolled_window_new (NULL, NULL);
2135 gtk_container_set_border_width (GTK_CONTAINER (sw), 5);
2136 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
2138 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
2140 GTK_POLICY_AUTOMATIC);
2141 g_signal_connect (sw, "map", G_CALLBACK (set_policy), NULL);
2142 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), sw, TRUE, TRUE, 0);
2144 view = gtk_text_view_new ();
2145 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view),
2146 priv->wrap_license ? GTK_WRAP_WORD : GTK_WRAP_NONE);
2147 gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)),
2150 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
2151 gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
2153 gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 8);
2154 gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 8);
2156 gtk_container_add (GTK_CONTAINER (sw), view);
2158 gtk_widget_show_all (dialog);
2162 * gtk_about_dialog_new:
2164 * Creates a new #GtkAboutDialog.
2166 * Returns: a newly created #GtkAboutDialog
2171 gtk_about_dialog_new (void)
2173 GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
2175 return GTK_WIDGET (dialog);
2179 * gtk_about_dialog_set_email_hook:
2180 * @func: a function to call when an email link is activated.
2181 * @data: data to pass to @func
2182 * @destroy: #GDestroyNotify for @data
2184 * Installs a global function to be called whenever the user activates an
2185 * email link in an about dialog.
2187 * Return value: the previous email hook.
2191 GtkAboutDialogActivateLinkFunc
2192 gtk_about_dialog_set_email_hook (GtkAboutDialogActivateLinkFunc func,
2194 GDestroyNotify destroy)
2196 GtkAboutDialogActivateLinkFunc old;
2198 if (activate_email_hook_destroy != NULL)
2199 (* activate_email_hook_destroy) (activate_email_hook_data);
2201 old = activate_email_hook;
2203 activate_email_hook = func;
2204 activate_email_hook_data = data;
2205 activate_email_hook_destroy = destroy;
2211 * gtk_about_dialog_set_url_hook:
2212 * @func: a function to call when a URL link is activated.
2213 * @data: data to pass to @func
2214 * @destroy: #GDestroyNotify for @data
2216 * Installs a global function to be called whenever the user activates a
2217 * URL link in an about dialog.
2219 * Return value: the previous URL hook.
2223 GtkAboutDialogActivateLinkFunc
2224 gtk_about_dialog_set_url_hook (GtkAboutDialogActivateLinkFunc func,
2226 GDestroyNotify destroy)
2228 GtkAboutDialogActivateLinkFunc old;
2230 if (activate_url_hook_destroy != NULL)
2231 (* activate_url_hook_destroy) (activate_url_hook_data);
2233 old = activate_url_hook;
2235 activate_url_hook = func;
2236 activate_url_hook_data = data;
2237 activate_url_hook_destroy = destroy;
2243 close_cb (GtkAboutDialog *about)
2245 GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)about->private_data;
2247 if (priv->license_dialog != NULL)
2249 gtk_widget_destroy (priv->license_dialog);
2250 priv->license_dialog = NULL;
2253 if (priv->credits_dialog != NULL)
2255 gtk_widget_destroy (priv->credits_dialog);
2256 priv->credits_dialog = NULL;
2259 gtk_widget_hide (GTK_WIDGET (about));
2264 * gtk_show_about_dialog:
2265 * @parent: transient parent, or %NULL for none
2266 * @first_property_name: the name of the first property
2267 * @Varargs: value of first property, followed by more properties, %NULL-terminated
2269 * This is a convenience function for showing an application's about box.
2270 * The constructed dialog is associated with the parent window and
2271 * reused for future invocations of this function.
2276 gtk_show_about_dialog (GtkWindow *parent,
2277 const gchar *first_property_name,
2280 static GtkWidget *global_about_dialog = NULL;
2281 GtkWidget *dialog = NULL;
2285 dialog = g_object_get_data (G_OBJECT (parent), "gtk-about-dialog");
2287 dialog = global_about_dialog;
2291 dialog = gtk_about_dialog_new ();
2293 g_object_ref_sink (dialog);
2295 g_signal_connect (dialog, "delete-event",
2296 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2298 /* Close dialog on user response */
2299 g_signal_connect (dialog, "response",
2300 G_CALLBACK (close_cb), NULL);
2302 va_start (var_args, first_property_name);
2303 g_object_set_valist (G_OBJECT (dialog), first_property_name, var_args);
2308 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
2309 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
2310 g_object_set_data_full (G_OBJECT (parent),
2311 I_("gtk-about-dialog"),
2312 dialog, g_object_unref);
2315 global_about_dialog = dialog;
2319 gtk_window_present (GTK_WINDOW (dialog));
2322 #define __GTK_ABOUT_DIALOG_C__
2323 #include "gtkaliasdef.c"