* SECTION:gtkaboutdialog
* @Short_description: Display information about an application
* @Title: GtkAboutDialog
- * @See_also:#GTK_STOCK_ABOUT
+ * @See_also: #GTK_STOCK_ABOUT
*
- * The #GtkAboutDialog offers a simple way to display information about
+ * The GtkAboutDialog offers a simple way to display information about
* a program like its logo, name, copyright, website and license. It is
* also possible to give credits to the authors, documenters, translators
* and artists who have worked on the program. An about dialog is typically
* opened when the user selects the <literal>About</literal> option from
* the <literal>Help</literal> menu. All parts of the dialog are optional.
*
- * About dialog often contain links and email addresses. #GtkAboutDialog
- * supports this by offering global hooks, which are called when the user
- * clicks on a link or email address, see gtk_about_dialog_set_email_hook()
- * and gtk_about_dialog_set_url_hook(). Email addresses in the
- * authors, documenters and artists properties are recognized by looking for
- * <literal><user@<!-- -->host></literal>, URLs are
- * recognized by looking for <literal>http://url</literal>, with
- * <literal>url</literal> extending to the next space, tab or line break.
- *
- * <para id="gtk-about-dialog-hook-setup">
- * Since 2.18 #GtkAboutDialog provides default website and email hooks that
- * use gtk_show_uri().
- * </para>
- *
- * If you want provide your own hooks overriding the default ones, it is
- * important to do so before setting the website and email URL properties,
- * like this:
- * <informalexample><programlisting>
- * gtk_about_dialog_set_url_hook (GTK_ABOUT_DIALOG (dialog), launch_url, NULL, NULL);
- * gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), app_url);
- * </programlisting></informalexample>
- * To disable the default hooks, you can pass %NULL as the hook func. Then,
- * the #GtkAboutDialog widget will not display the website or the
- * email addresses as clickable.
+ * About dialog often contain links and email addresses. GtkAboutDialog
+ * displays these as clickable links. By default, it calls gtk_show_uri()
+ * when a user clicks one. The behaviour can be overridden with the
+ * #GtkAboutDialog::activate-link signal.
*
- * To make constructing a #GtkAboutDialog as convenient as possible, you can
+ * To make constructing a GtkAboutDialog as convenient as possible, you can
* use the function gtk_show_about_dialog() which constructs and shows a dialog
* and keeps it around so that it can be shown again.
*
* on the dialog window (where %s is replaced by the name of the
* application, but in order to ensure proper translation of the title,
* applications should set the title property explicitly when constructing
- * a #GtkAboutDialog, as shown in the following example:
+ * a GtkAboutDialog, as shown in the following example:
* <informalexample><programlisting>
* gtk_show_about_dialog (NULL,
* "program-name", "ExampleCode",
* "title" _("About ExampleCode"),
* NULL);
* </programlisting></informalexample>
- * Note that prior to GTK+ 2.12, the #GtkAboutDialog:program-name property
- * was called "name". This was changed to avoid the conflict with the
- * #GtkWidget:name property.
*/
-
static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
+/* Translators: this is the license preamble; the string at the end
+ * contains the URL of the license.
+ */
+static const gchar *gtk_license_preamble = N_("This program comes with ABSOLUTELY NO WARRANTY; for details, visit %s");
+
+/* URLs for each GtkLicense type; keep in the same order as the enumeration */
+static const gchar *gtk_license_urls[] = {
+ NULL,
+ NULL,
+
+ "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html",
+ "http://www.gnu.org/licenses/gpl.html",
+
+ "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
+ "http://www.gnu.org/licenses/lgpl.html",
+
+ "http://opensource.org/licenses/bsd-license.php",
+ "http://opensource.org/licenses/mit-license.php",
+
+ "http://opensource.org/licenses/artistic-license-2.0.php"
+};
+
struct _GtkAboutDialogPrivate
{
gchar *name;
GSList *visited_links;
+ GtkLicense license_type;
+
guint hovering_over_link : 1;
guint wrap_license : 1;
};
PROP_ARTISTS,
PROP_LOGO,
PROP_LOGO_ICON_NAME,
- PROP_WRAP_LICENSE
+ PROP_WRAP_LICENSE,
+ PROP_LICENSE_TYPE
};
static void gtk_about_dialog_finalize (GObject *object);
GtkTextView *text_view,
GtkTextIter *iter);
static void set_cursor_if_appropriate (GtkAboutDialog *about,
- GtkTextView *text_view,
+ GtkTextView *text_view,
GdkDevice *device,
- gint x,
- gint y);
+ gint x,
+ gint y);
static void display_credits_dialog (GtkWidget *button,
gpointer data);
static void display_license_dialog (GtkWidget *button,
gpointer data);
static void close_cb (GtkAboutDialog *about);
-static void default_url_hook (GtkAboutDialog *about,
- const gchar *uri,
- gpointer user_data);
-static void default_email_hook (GtkAboutDialog *about,
- const gchar *email_address,
- gpointer user_data);
-
-static gboolean activate_email_hook_set = FALSE;
-static GtkAboutDialogActivateLinkFunc activate_email_hook = NULL;
-static gpointer activate_email_hook_data = NULL;
-static GDestroyNotify activate_email_hook_destroy = NULL;
-
-static gboolean activate_url_hook_set = FALSE;
-static GtkAboutDialogActivateLinkFunc activate_url_hook = NULL;
-static gpointer activate_url_hook_data = NULL;
-static GDestroyNotify activate_url_hook_destroy = NULL;
+static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
+ const gchar *uri);
-static void
-default_url_hook (GtkAboutDialog *about,
- const gchar *uri,
- gpointer user_data)
-{
- GdkScreen *screen;
- GError *error = NULL;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (about));
-
- if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
- {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (about),
- GTK_DIALOG_DESTROY_WITH_PARENT |
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s", _("Could not show link"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", error->message);
- g_error_free (error);
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
-
- gtk_window_present (GTK_WINDOW (dialog));
- }
-}
-
-static void
-default_email_hook (GtkAboutDialog *about,
- const gchar *email_address,
- gpointer user_data)
-{
- char *escaped, *uri;
-
- escaped = g_uri_escape_string (email_address, NULL, FALSE);
- uri = g_strdup_printf ("mailto:%s", escaped);
- g_free (escaped);
+enum {
+ ACTIVATE_LINK,
+ LAST_SIGNAL
+};
- default_url_hook (about, uri, user_data);
- g_free (uri);
-}
+static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
+
static void
gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
{
widget_class->show = gtk_about_dialog_show;
+ klass->activate_link = gtk_about_dialog_activate_link;
+
+ /**
+ * GtkAboutDialog::activate-link:
+ * @label: The object on which the signal was emitted
+ * @uri: the URI that is activated
+ *
+ * The signal which gets emitted to activate a URI.
+ * Applications may connect to it to override the default behaviour,
+ * which is to call gtk_show_uri().
+ *
+ * Returns: %TRUE if the link has been activated
+ *
+ * Since: 2.24
+ */
+ signals[ACTIVATE_LINK] =
+ g_signal_new ("activate-link",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkAboutDialogClass, activate_link),
+ _gtk_boolean_handled_accumulator, NULL,
+ _gtk_marshal_BOOLEAN__STRING,
+ G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
+
/**
* GtkAboutDialog:program-name:
*
* a long multi-paragraph text. Note that the text is only wrapped
* in the text view if the "wrap-license" property is set to %TRUE;
* otherwise the text itself must contain the intended linebreaks.
+ * When setting this property to a non-%NULL value, the
+ * #GtkAboutDialog:license-type property is set to %GTK_LICENSE_CUSTOM
+ * as a side effect.
*
* Since: 2.6
*/
NULL,
GTK_PARAM_READWRITE));
+ /**
+ * GtkAboutDialog:license-type:
+ *
+ * The license of the program, as a value of the %GtkLicense enumeration.
+ *
+ * The #GtkAboutDialog will automatically fill out a standard disclaimer
+ * and link the user to the appropriate online resource for the license
+ * text.
+ *
+ * If %GTK_LICENSE_UNKNOWN is used, the link used will be the same
+ * specified in the #GtkAboutDialog:website property.
+ *
+ * If %GTK_LICENSE_CUSTOM is used, the current contents of the
+ * #GtkAboutDialog:license property are used.
+ *
+ * For any other #GtkLicense value, the contents of the
+ * #GtkAboutDialog:license property are also set by this property as
+ * a side effect.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (object_class,
+ PROP_LICENSE_TYPE,
+ g_param_spec_enum ("license-type",
+ P_("License Type"),
+ P_("The license type of the program"),
+ GTK_TYPE_LICENSE,
+ GTK_LICENSE_UNKNOWN,
+ GTK_PARAM_READWRITE));
+
/**
* GtkAboutDialog:website:
*
}
static gboolean
-website_clicked (GtkLabel *label,
- const gchar *uri,
- GtkAboutDialog *about)
+emit_activate_link (GtkAboutDialog *about,
+ const gchar *uri)
{
- GtkAboutDialogActivateLinkFunc url_hook;
- gpointer url_hook_data;
-
- if (activate_url_hook_set)
- {
- url_hook = activate_url_hook;
- url_hook_data = activate_url_hook_data;
- }
- else
- {
- url_hook = default_url_hook;
- url_hook_data = NULL;
- }
+ gboolean handled = FALSE;
- url_hook (about, uri, url_hook_data);
+ g_signal_emit (about, signals[ACTIVATE_LINK], 0, uri, &handled);
return TRUE;
}
priv->hovering_over_link = FALSE;
priv->wrap_license = FALSE;
+ priv->license_type = GTK_LICENSE_UNKNOWN;
+
content_area = gtk_dialog_get_content_area (dialog);
action_area = gtk_dialog_get_action_area (dialog);
- gtk_dialog_set_has_separator (dialog, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
/* Widgets */
gtk_widget_push_composite_child ();
- vbox = gtk_vbox_new (FALSE, 8);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0);
- hbox = gtk_hbox_new (TRUE, 0);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
priv->website_label = button = gtk_label_new ("");
gtk_widget_set_no_show_all (button, TRUE);
gtk_label_set_selectable (GTK_LABEL (button), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
- g_signal_connect (button, "activate-link",
- G_CALLBACK (website_clicked), about);
+ g_signal_connect_swapped (button, "activate-link",
+ G_CALLBACK (emit_activate_link), about);
gtk_widget_show (vbox);
gtk_widget_show (priv->logo_image);
gtk_button_set_image (GTK_BUTTON (button), image);
gtk_widget_set_no_show_all (button, TRUE);
gtk_box_pack_end (GTK_BOX (action_area),
- button, FALSE, TRUE, 0);
+ button, FALSE, TRUE, 0);
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
g_signal_connect (button, "clicked",
G_CALLBACK (display_credits_dialog), about);
gtk_widget_set_can_default (button, TRUE);
gtk_widget_set_no_show_all (button, TRUE);
gtk_box_pack_end (GTK_BOX (action_area),
- button, FALSE, TRUE, 0);
+ button, FALSE, TRUE, 0);
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
g_signal_connect (button, "clicked",
G_CALLBACK (display_license_dialog), about);
case PROP_LICENSE:
gtk_about_dialog_set_license (about, g_value_get_string (value));
break;
+ case PROP_LICENSE_TYPE:
+ gtk_about_dialog_set_license_type (about, g_value_get_enum (value));
+ break;
case PROP_COPYRIGHT:
gtk_about_dialog_set_copyright (about, g_value_get_string (value));
break;
{
GtkAboutDialog *about = GTK_ABOUT_DIALOG (object);
GtkAboutDialogPrivate *priv = about->priv;
-
+
switch (prop_id)
{
case PROP_NAME:
case PROP_LICENSE:
g_value_set_string (value, priv->license);
break;
+ case PROP_LICENSE_TYPE:
+ g_value_set_enum (value, priv->license_type);
+ break;
case PROP_TRANSLATOR_CREDITS:
g_value_set_string (value, priv->translator_credits);
break;
}
}
+static gboolean
+gtk_about_dialog_activate_link (GtkAboutDialog *about,
+ const gchar *uri)
+{
+ GdkScreen *screen;
+ GError *error = NULL;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (about));
+
+ if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
+ {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (about),
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", _("Could not show link"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+ g_error_free (error);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_window_present (GTK_WINDOW (dialog));
+ }
+
+ return TRUE;
+}
+
static void
update_website (GtkAboutDialog *about)
{
gtk_widget_show (priv->website_label);
- if (priv->website_url && (!activate_url_hook_set || activate_url_hook != NULL))
+ if (priv->website_url)
{
gchar *markup;
if (license)
{
priv->license = g_strdup (license);
+ priv->license_type = GTK_LICENSE_CUSTOM;
gtk_widget_show (priv->license_button);
}
else
{
priv->license = NULL;
+ priv->license_type = GTK_LICENSE_UNKNOWN;
gtk_widget_hide (priv->license_button);
}
g_free (tmp);
g_object_notify (G_OBJECT (about), "license");
+ g_object_notify (G_OBJECT (about), "license-type");
}
/**
*
* Sets the URL to use for the website link.
*
- * Note that that the hook functions need to be set up
- * before calling this function.
- *
* Since: 2.6
*/
void
{
GSList *tags = NULL, *tagp = NULL;
GtkAboutDialogPrivate *priv = about->priv;
- gchar *url = NULL;
- GtkAboutDialogActivateLinkFunc email_hook, url_hook;
- gpointer email_hook_data, url_hook_data;
-
- if (activate_email_hook_set)
- {
- email_hook = activate_email_hook;
- email_hook_data = activate_email_hook_data;
- }
- else
- {
- email_hook = default_email_hook;
- email_hook_data = NULL;
- }
-
- if (activate_url_hook_set)
- {
- url_hook = activate_url_hook;
- url_hook_data = activate_url_hook_data;
- }
- else
- {
- url_hook = default_url_hook;
- url_hook_data = NULL;
- }
+ gchar *uri = NULL;
tags = gtk_text_iter_get_tags (iter);
- for (tagp = tags; tagp != NULL && !url; tagp = tagp->next)
+ for (tagp = tags; tagp != NULL && !uri; tagp = tagp->next)
{
GtkTextTag *tag = tagp->data;
- if (email_hook != NULL)
- {
- url = g_object_get_data (G_OBJECT (tag), "email");
- if (url)
- email_hook (about, url, email_hook_data);
- }
-
- if (!url && url_hook != NULL)
- {
- url = g_object_get_data (G_OBJECT (tag), "url");
- if (url)
- url_hook (about, url, url_hook_data);
- }
+ uri = g_object_get_data (G_OBJECT (tag), "uri");
+ if (uri)
+ emit_activate_link (about, uri);
- if (url && !g_slist_find_custom (priv->visited_links, url, (GCompareFunc)strcmp))
+ if (uri && !g_slist_find_custom (priv->visited_links, uri, (GCompareFunc)strcmp))
{
GdkColor *style_visited_link_color;
GdkColor color;
g_object_set (G_OBJECT (tag), "foreground-gdk", &color, NULL);
- priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (url));
+ priv->visited_links = g_slist_prepend (priv->visited_links, g_strdup (uri));
}
}
switch (event->keyval)
{
- case GDK_Return:
- case GDK_ISO_Enter:
- case GDK_KP_Enter:
+ case GDK_KEY_Return:
+ case GDK_KEY_ISO_Enter:
+ case GDK_KEY_KP_Enter:
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
gtk_text_buffer_get_insert (buffer));
static void
set_cursor_if_appropriate (GtkAboutDialog *about,
- GtkTextView *text_view,
+ GtkTextView *text_view,
GdkDevice *device,
- gint x,
- gint y)
+ gint x,
+ gint y)
{
GtkAboutDialogPrivate *priv = about->priv;
GSList *tags = NULL, *tagp = NULL;
for (tagp = tags; tagp != NULL; tagp = tagp->next)
{
GtkTextTag *tag = tagp->data;
- gchar *email = g_object_get_data (G_OBJECT (tag), "email");
- gchar *url = g_object_get_data (G_OBJECT (tag), "url");
+ gchar *uri = g_object_get_data (G_OBJECT (tag), "uri");
- if (email != NULL || url != NULL)
+ if (uri != NULL)
{
hovering_over_link = TRUE;
break;
GList *devices, *d;
gint wx, wy, bx, by;
- display = gdk_drawable_get_display (event->window);
+ display = gdk_window_get_display (event->window);
device_manager = gdk_display_get_device_manager (display);
devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
{
GdkDevice *dev = d->data;
- gdk_window_get_device_position (text_view->window, dev, &wx, &wy, NULL);
+ gdk_window_get_device_position (gtk_widget_get_window (text_view), dev,
+ &wx, &wy, NULL);
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
GTK_TEXT_WINDOW_WIDGET,
GtkWidget *view;
GtkTextView *text_view;
GtkTextBuffer *buffer;
- gboolean linkify_email, linkify_urls;
GdkColor *style_link_color;
GdkColor *style_visited_link_color;
GdkColor color;
GtkAboutDialogPrivate *priv = about->priv;
- linkify_email = (!activate_email_hook_set || activate_email_hook != NULL);
- linkify_urls = (!activate_url_hook_set || activate_url_hook != NULL);
-
gtk_widget_ensure_style (GTK_WIDGET (about));
gtk_widget_style_get (GTK_WIDGET (about),
"link-color", &style_link_color,
q0 = *p;
while (*q0)
{
- q1 = linkify_email ? strchr (q0, '<') : NULL;
+ q1 = strchr (q0, '<');
q2 = q1 ? strchr (q1, '>') : NULL;
- r1 = linkify_urls ? strstr (q0, "http://") : NULL;
+ r1 = strstr (q0, "http://");
if (r1)
{
r2 = strpbrk (r1, " \n\t");
{
GtkTextIter end;
gchar *link;
+ gchar *uri;
const gchar *link_type;
GtkTextTag *tag;
gtk_text_buffer_insert_at_cursor (buffer, q0, (q1 - q0) + 1);
gtk_text_buffer_get_end_iter (buffer, &end);
q1++;
- link_type = I_("email");
+ link_type = "email";
}
else
{
gtk_text_buffer_insert_at_cursor (buffer, q0, q1 - q0);
gtk_text_buffer_get_end_iter (buffer, &end);
- link_type = I_("url");
+ link_type = "uri";
}
q0 = q2;
"foreground-gdk", &color,
"underline", PANGO_UNDERLINE_SINGLE,
NULL);
- g_object_set_data_full (G_OBJECT (tag), link_type, g_strdup (link), g_free);
+ if (strcmp (link_type, "email") == 0)
+ {
+ gchar *escaped;
+
+ escaped = g_uri_escape_string (link, NULL, FALSE);
+ uri = g_strconcat ("mailto:", escaped, NULL);
+ g_free (escaped);
+ }
+ else
+ {
+ uri = g_strdup (link);
+ }
+ g_object_set_data_full (G_OBJECT (tag), I_("uri"), uri, g_free);
gtk_text_buffer_insert_with_tags (buffer, &end, link, -1, tag, NULL);
g_free (link);
content_area = gtk_dialog_get_content_area (credits_dialog);
action_area = gtk_dialog_get_action_area (credits_dialog);
- gtk_dialog_set_has_separator (credits_dialog, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (credits_dialog), 5);
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
}
dialog = gtk_dialog_new_with_buttons (_("License"),
- GTK_WINDOW (about),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
- NULL);
+ GTK_WINDOW (about),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
+ NULL);
license_dialog = GTK_DIALOG (dialog);
content_area = gtk_dialog_get_content_area (license_dialog);
action_area = gtk_dialog_get_action_area (license_dialog);
- gtk_dialog_set_has_separator (license_dialog, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (license_dialog), 5);
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
return GTK_WIDGET (dialog);
}
-/**
- * gtk_about_dialog_set_email_hook:
- * @func: a function to call when an email link is activated.
- * @data: data to pass to @func
- * @destroy: #GDestroyNotify for @data
- *
- * Installs a global function to be called whenever the user activates an
- * email link in an about dialog.
- *
- * Since 2.18 there exists a default function which uses gtk_show_uri(). To
- * deactivate it, you can pass %NULL for @func.
- *
- * Return value: the previous email hook.
- *
- * Since: 2.6
- */
-GtkAboutDialogActivateLinkFunc
-gtk_about_dialog_set_email_hook (GtkAboutDialogActivateLinkFunc func,
- gpointer data,
- GDestroyNotify destroy)
-{
- GtkAboutDialogActivateLinkFunc old;
-
- if (activate_email_hook_destroy != NULL)
- (* activate_email_hook_destroy) (activate_email_hook_data);
-
- old = activate_email_hook;
-
- activate_email_hook_set = TRUE;
- activate_email_hook = func;
- activate_email_hook_data = data;
- activate_email_hook_destroy = destroy;
-
- return old;
-}
-
-/**
- * gtk_about_dialog_set_url_hook:
- * @func: a function to call when a URL link is activated.
- * @data: data to pass to @func
- * @destroy: #GDestroyNotify for @data
- *
- * Installs a global function to be called whenever the user activates a
- * URL link in an about dialog.
- *
- * Since 2.18 there exists a default function which uses gtk_show_uri(). To
- * deactivate it, you can pass %NULL for @func.
- *
- * Return value: the previous URL hook.
- *
- * Since: 2.6
- */
-GtkAboutDialogActivateLinkFunc
-gtk_about_dialog_set_url_hook (GtkAboutDialogActivateLinkFunc func,
- gpointer data,
- GDestroyNotify destroy)
-{
- GtkAboutDialogActivateLinkFunc old;
-
- if (activate_url_hook_destroy != NULL)
- (* activate_url_hook_destroy) (activate_url_hook_data);
-
- old = activate_url_hook;
-
- activate_url_hook_set = TRUE;
- activate_url_hook = func;
- activate_url_hook_data = data;
- activate_url_hook_destroy = destroy;
-
- return old;
-}
-
static void
close_cb (GtkAboutDialog *about)
{
gtk_window_present (GTK_WINDOW (dialog));
}
+
+/**
+ * gtk_about_dialog_set_license_type:
+ * @about: a #GtkAboutDialog
+ * @license_type: the type of license
+ *
+ * Sets the license of the application showing the @about dialog from a
+ * list of known licenses.
+ *
+ * This function overrides the license set using
+ * gtk_about_dialog_set_license().
+ *
+ * Since: 3.0
+ */
+void
+gtk_about_dialog_set_license_type (GtkAboutDialog *about,
+ GtkLicense license_type)
+{
+ GtkAboutDialogPrivate *priv;
+
+ g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
+ g_return_if_fail (license_type >= GTK_LICENSE_UNKNOWN &&
+ license_type <= GTK_LICENSE_ARTISTIC);
+
+ priv = about->priv;
+
+ if (priv->license_type != license_type)
+ {
+ g_object_freeze_notify (G_OBJECT (about));
+
+ priv->license_type = license_type;
+
+ /* custom licenses use the contents of the :license property */
+ if (priv->license_type != GTK_LICENSE_CUSTOM)
+ {
+ const gchar *url;
+ GString *str;
+
+ url = gtk_license_urls[priv->license_type];
+ if (url == NULL)
+ url = priv->website_url;
+
+ /* compose the new license string as:
+ *
+ * <program-name>\n
+ * <copyright line 1>\n
+ * ...
+ * <copyright line n>\n
+ * \n
+ * license preamble + URL
+ *
+ */
+ str = g_string_sized_new (256);
+ g_string_append (str, priv->name);
+ g_string_append (str, "\n");
+ g_string_append (str, priv->copyright);
+ g_string_append (str, "\n\n");
+ g_string_append_printf (str, _(gtk_license_preamble), url);
+
+ g_free (priv->license);
+ priv->license = g_string_free (str, FALSE);
+ priv->wrap_license = TRUE;
+ gtk_widget_show (priv->license_button);
+
+ g_object_notify (G_OBJECT (about), "wrap-license");
+ g_object_notify (G_OBJECT (about), "license");
+ }
+
+ g_object_notify (G_OBJECT (about), "license-type");
+
+ g_object_thaw_notify (G_OBJECT (about));
+ }
+}
+
+/**
+ * gtk_about_dialog_get_license_type:
+ * @about: a #GtkAboutDialog
+ *
+ * Retrieves the license set using gtk_about_dialog_set_license_type()
+ *
+ * Return value: a #GtkLicense value
+ *
+ * Since: 3.0
+ */
+GtkLicense
+gtk_about_dialog_get_license_type (GtkAboutDialog *about)
+{
+ g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), GTK_LICENSE_UNKNOWN);
+
+ return about->priv->license_type;
+}