aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Barisione <marco.barisione@collabora.co.uk>2013-07-30 23:15:05 +0800
committerMarco Barisione <marco.barisione@collabora.co.uk>2013-08-20 18:03:06 +0800
commit6609b50bce338fdb3fe470f57727d30211c8d104 (patch)
treeca18cf4fe74d628f26aa1ecf00e7ba48e05cd6eb
parent5c0d938cf15d07c0f7511c5acb9a3d8e42278e0d (diff)
downloadgsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.tar
gsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.tar.gz
gsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.tar.bz2
gsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.tar.lz
gsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.tar.xz
gsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.tar.zst
gsoc2013-empathy-6609b50bce338fdb3fe470f57727d30211c8d104.zip
tpaw-utils: copy URL handling functions from Empathy to tp-aw
This commit also changes the licence of the moved code from GPL to LGPL. See GOSSIP-RELICENSING.txt for details. https://bugzilla.gnome.org/show_bug.cgi?id=699492
-rw-r--r--libempathy-gtk/empathy-ui-utils.c43
-rw-r--r--libempathy-gtk/empathy-ui-utils.h4
-rw-r--r--tp-account-widgets/tpaw-string-parser.c4
-rw-r--r--tp-account-widgets/tpaw-utils.c40
-rw-r--r--tp-account-widgets/tpaw-utils.h5
5 files changed, 50 insertions, 46 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 272c42513..174eceac4 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -37,6 +37,7 @@
#include <glib/gi18n-lib.h>
#include <gio/gdesktopappinfo.h>
#include <tp-account-widgets/tpaw-live-search.h>
+#include <tp-account-widgets/tpaw-utils.h>
#include "empathy-ft-factory.h"
#include "empathy-images.h"
@@ -810,46 +811,6 @@ empathy_filename_from_icon_name (const gchar *icon_name,
return ret;
}
-/** empathy_make_absolute_url_len:
- * @url: an url
- * @len: a length
- *
- * Same as #empathy_make_absolute_url but for a limited string length
- */
-gchar *
-empathy_make_absolute_url_len (const gchar *url,
- guint len)
-{
- g_return_val_if_fail (url != NULL, NULL);
-
- if (g_str_has_prefix (url, "help:") ||
- g_str_has_prefix (url, "mailto:") ||
- strstr (url, ":/"))
- return g_strndup (url, len);
-
- if (strstr (url, "@"))
- return g_strdup_printf ("mailto:%.*s", len, url);
-
- return g_strdup_printf ("http://%.*s", len, url);
-}
-
-/** empathy_make_absolute_url:
- * @url: an url
- *
- * The URL opening code can't handle schemeless strings, so we try to be
- * smart and add http if there is no scheme or doesn't look like a mail
- * address. This should work in most cases, and let us click on strings
- * like "www.gnome.org".
- *
- * Returns: a newly allocated url with proper mailto: or http:// prefix, use
- * g_free when your are done with it
- */
-gchar *
-empathy_make_absolute_url (const gchar *url)
-{
- return empathy_make_absolute_url_len (url, strlen (url));
-}
-
void
empathy_url_show (GtkWidget *parent,
const char *url)
@@ -860,7 +821,7 @@ empathy_url_show (GtkWidget *parent,
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
g_return_if_fail (url != NULL);
- real_url = empathy_make_absolute_url (url);
+ real_url = tpaw_make_absolute_url (url);
gtk_show_uri (parent ? gtk_widget_get_screen (parent) : NULL, real_url,
gtk_get_current_event_time (), &error);
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 79e3e1160..3478e8605 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -98,10 +98,6 @@ void empathy_move_to_window_desktop (GtkWindow *window,
guint32 timestamp);
/* URL */
-gchar * empathy_make_absolute_url (const gchar *url);
-
-gchar * empathy_make_absolute_url_len (const gchar *url,
- guint len);
void empathy_url_show (GtkWidget *parent,
const char *url);
diff --git a/tp-account-widgets/tpaw-string-parser.c b/tp-account-widgets/tpaw-string-parser.c
index 172a76303..de7778203 100644
--- a/tp-account-widgets/tpaw-string-parser.c
+++ b/tp-account-widgets/tpaw-string-parser.c
@@ -21,6 +21,8 @@
#include "config.h"
#include "tpaw-string-parser.h"
+#include <tp-account-widgets/tpaw-utils.h>
+
#include "empathy-ui-utils.h"
#define SCHEMES "([a-zA-Z\\+]+)"
@@ -134,7 +136,7 @@ tpaw_string_replace_link (const gchar *text,
gchar *title;
gchar *markup;
- real_url = empathy_make_absolute_url_len (text, len);
+ real_url = tpaw_make_absolute_url_len (text, len);
/* Need to copy manually, because g_markup_printf_escaped does not work
* with string precision pitfalls. */
diff --git a/tp-account-widgets/tpaw-utils.c b/tp-account-widgets/tpaw-utils.c
index a31fc2681..6ee9cbed1 100644
--- a/tp-account-widgets/tpaw-utils.c
+++ b/tp-account-widgets/tpaw-utils.c
@@ -272,3 +272,43 @@ tpaw_get_toplevel_window (GtkWidget *widget)
return NULL;
}
+
+/** tpaw_make_absolute_url_len:
+ * @url: an url
+ * @len: a length
+ *
+ * Same as #tpaw_make_absolute_url but for a limited string length
+ */
+gchar *
+tpaw_make_absolute_url_len (const gchar *url,
+ guint len)
+{
+ g_return_val_if_fail (url != NULL, NULL);
+
+ if (g_str_has_prefix (url, "help:") ||
+ g_str_has_prefix (url, "mailto:") ||
+ strstr (url, ":/"))
+ return g_strndup (url, len);
+
+ if (strstr (url, "@"))
+ return g_strdup_printf ("mailto:%.*s", len, url);
+
+ return g_strdup_printf ("http://%.*s", len, url);
+}
+
+/** tpaw_make_absolute_url:
+ * @url: an url
+ *
+ * The URL opening code can't handle schemeless strings, so we try to be
+ * smart and add http if there is no scheme or doesn't look like a mail
+ * address. This should work in most cases, and let us click on strings
+ * like "www.gnome.org".
+ *
+ * Returns: a newly allocated url with proper mailto: or http:// prefix, use
+ * g_free when your are done with it
+ */
+gchar *
+tpaw_make_absolute_url (const gchar *url)
+{
+ return tpaw_make_absolute_url_len (url, strlen (url));
+}
diff --git a/tp-account-widgets/tpaw-utils.h b/tp-account-widgets/tpaw-utils.h
index 8a40dc93b..f8fad91ef 100644
--- a/tp-account-widgets/tpaw-utils.h
+++ b/tp-account-widgets/tpaw-utils.h
@@ -58,6 +58,11 @@ void tpaw_window_present_with_time (GtkWindow *window,
guint32 timestamp);
GtkWindow * tpaw_get_toplevel_window (GtkWidget *widget);
+/* URL */
+gchar * tpaw_make_absolute_url (const gchar *url);
+gchar * tpaw_make_absolute_url_len (const gchar *url,
+ guint len);
+
/* Copied from wocky/wocky-utils.h */
#define tpaw_implement_finish_void(source, tag) \