summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/trg-general-panel.c16
-rw-r--r--src/util.c17
-rw-r--r--src/util.h1
3 files changed, 22 insertions, 12 deletions
diff --git a/src/trg-general-panel.c b/src/trg-general-panel.c
index 88c0545..827d9ef 100644
--- a/src/trg-general-panel.c
+++ b/src/trg-general-panel.c
@@ -113,8 +113,7 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t,
TrgGeneralPanelPrivate *priv;
gchar buf[32];
gint sizeOfBuf;
- gchar *statusString, *fullStatusString, *completedAtString;
- const gchar *comment;
+ gchar *statusString, *fullStatusString, *completedAtString, *comment;
const gchar *errorStr;
gint64 eta, uploaded, downloaded, completedAt;
GtkLabel *keyLabel;
@@ -180,16 +179,9 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t,
gtk_label_set_text(GTK_LABEL(priv->gen_downloaddir_label),
torrent_get_download_dir(t));
- comment = torrent_get_comment(t);
- if(g_str_has_prefix(comment, "http")) {
- /* starts with http -> url, converting to markup */
- gchar *commentMarkup = g_markup_printf_escaped("<a href='%s'>%s</a>",
- comment, comment);
- gtk_label_set_markup(GTK_LABEL(priv->gen_comment_label), commentMarkup);
- g_free(commentMarkup);
- } else {
- gtk_label_set_markup(GTK_LABEL(priv->gen_comment_label), comment);
- }
+ comment = add_links_to_text(torrent_get_comment(t));
+ gtk_label_set_markup(GTK_LABEL(priv->gen_comment_label), comment);
+ g_free(comment);
errorStr = torrent_get_errorstr(t);
keyLabel =
diff --git a/src/util.c b/src/util.c
index a67a5db..613ed50 100644
--- a/src/util.c
+++ b/src/util.c
@@ -506,6 +506,23 @@ gchar *epoch_to_string(gint64 epoch)
#endif
}
+/* wrap a link in text with a hyperlink, for use in pango markup.
+ * with or without any links - a newly allocated string is returned. */
+
+gchar *add_links_to_text(const gchar *original) {
+ /* only perform replacement if string doesn't contains links */
+ if (!g_regex_match_simple("<a\\s.*>", original, 0, 0)) {
+ GRegex *regex = g_regex_new("(https?://[a-zA-Z0-9_\\-\\./?=]+)", 0, 0,
+ NULL);
+ gchar *newText = g_regex_replace(regex, original, -1, 0,
+ "<a href='\\1'>\\1</a>", 0, NULL);
+ g_regex_unref(regex);
+ return newText;
+ } else {
+ return g_strdup(original);
+ }
+}
+
size_t tr_strlcpy(char *dst, const void *src, size_t siz)
{
#ifdef HAVE_STRLCPY
diff --git a/src/util.h b/src/util.h
index dd064f4..fe342d1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -55,6 +55,7 @@ GRegex *trg_uri_host_regex_new(void);
gchar *trg_gregex_get_first(GRegex * rx, const gchar * uri);
gchar *make_error_message(JsonObject * response, int status);
void trg_error_dialog(GtkWindow * parent, trg_response * response);
+gchar *add_links_to_text(const gchar *original);
void
tr_formatter_size_init(unsigned int kilo,