summaryrefslogtreecommitdiff
path: root/src/terminal-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/terminal-util.c')
-rw-r--r--src/terminal-util.c81
1 files changed, 75 insertions, 6 deletions
diff --git a/src/terminal-util.c b/src/terminal-util.c
index 1ffb629..3e32a69 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -4,6 +4,7 @@
* Copyright © 2002 Sun Microsystems
* Copyright © 2003 Mariano Suarez-Alvarez
* Copyright © 2008 Christian Persch
+ * Copyright (C) 2012-2021 MATE Developers
*
* Mate-terminal is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,9 +22,9 @@
#include <config.h>
+#define _GNU_SOURCE /* for strchrnul */
#include <string.h>
#include <stdlib.h>
-#include <time.h>
#include <unistd.h>
#include <sys/types.h>
@@ -48,7 +49,8 @@ terminal_util_set_unique_role (GtkWindow *window, const char *prefix)
{
char *role;
- role = g_strdup_printf ("%s-%d-%d-%d", prefix, getpid (), g_random_int (), (int) time (NULL));
+ role = g_strdup_printf ("%s-%d-%d-%" G_GINT64_FORMAT, prefix, getpid (), g_random_int (),
+ g_get_real_time () / G_USEC_PER_SEC);
gtk_window_set_role (window, role);
g_free (role);
}
@@ -167,7 +169,6 @@ terminal_util_set_atk_name_description (GtkWidget *widget,
return;
}
-
if (!GTK_IS_ACCESSIBLE (obj))
return; /* This means GAIL is not loaded so we have the NoOp accessible */
@@ -181,7 +182,7 @@ terminal_util_set_atk_name_description (GtkWidget *widget,
void
terminal_util_open_url (GtkWidget *parent,
const char *orig_url,
- TerminalURLFlavour flavor,
+ TerminalURLFlavor flavor,
guint32 user_time)
{
GError *error = NULL;
@@ -707,6 +708,74 @@ terminal_util_add_proxy_env (GHashTable *env_table)
g_object_unref (settings_socks);
}
+/**
+ * terminal_util_hyperlink_uri_label:
+ * @uri: a URI
+ *
+ * Formats @uri to be displayed in a tooltip.
+ * Performs URI-decoding and converts IDN hostname to UTF-8.
+ *
+ * Returns: (transfer full): The human readable URI as plain text
+ */
+char *terminal_util_hyperlink_uri_label (const char *uri)
+{
+ char *unesc = NULL;
+ gboolean replace_hostname;
+
+ if (uri == NULL)
+ return NULL;
+
+ unesc = g_uri_unescape_string(uri, NULL);
+ if (unesc == NULL)
+ unesc = g_strdup(uri);
+
+ if (g_ascii_strncasecmp(unesc, "ftp://", 6) == 0 ||
+ g_ascii_strncasecmp(unesc, "http://", 7) == 0 ||
+ g_ascii_strncasecmp(unesc, "https://", 8) == 0)
+ {
+ char *unidn = NULL;
+
+ char *hostname = strchr(unesc, '/') + 2;
+ char *hostname_end = strchrnul(hostname, '/');
+ char save = *hostname_end;
+ *hostname_end = '\0';
+ unidn = g_hostname_to_unicode(hostname);
+ replace_hostname = unidn != NULL && g_ascii_strcasecmp(unidn, hostname) != 0;
+ *hostname_end = save;
+ if (replace_hostname)
+ {
+ char *new_unesc = g_strdup_printf("%.*s%s%s",
+ (int) (hostname - unesc),
+ unesc,
+ unidn,
+ hostname_end);
+ g_free(unesc);
+ unesc = new_unesc;
+ }
+ g_free(unidn);
+ }
+ if (g_ascii_strncasecmp(unesc, "mailto:", 7) == 0)
+ {
+ const char *hostname = strchr(unesc, '@');
+ if (hostname != NULL)
+ {
+ const char *unidn = g_hostname_to_unicode(++hostname);
+ replace_hostname = unidn != NULL && g_ascii_strcasecmp(unidn, hostname) != 0;
+ if (replace_hostname)
+ {
+ char *new_unesc = g_strdup_printf("%.*s%s",
+ (int) (hostname - unesc),
+ unesc,
+ unidn);
+ g_free(unesc);
+ unesc = new_unesc;
+ }
+ g_free(unidn);
+ }
+ }
+ return unesc;
+}
+
/* Bidirectional object/widget binding */
typedef struct
@@ -868,9 +937,9 @@ widget_change_notify_cb (PropertyChange *change)
}
else if (GTK_IS_SPIN_BUTTON (widget))
{
- int value;
+ gint value;
- value = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget));
+ value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
g_object_set (object, object_prop, value, NULL);
}
else if (GTK_IS_ENTRY (widget))