Mercurial > hg
changeset 1520:41d3457af815
Add option "url_regex"
author | franky@diable.fs |
---|---|
date | Tue, 30 Sep 2008 09:05:05 +0200 |
parents | ac5a2c262098 |
children | 33f8f795abd2 |
files | mcabber/mcabberrc.example mcabber/src/screen.c |
diffstat | 2 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/mcabberrc.example Sat Sep 27 22:44:02 2008 +0200 +++ b/mcabber/mcabberrc.example Tue Sep 30 09:05:05 2008 +0200 @@ -419,6 +419,9 @@ # # Set "info" to anything you'd like to see in your lower status line #set info = woot +# Set url_regex to a regular expression matching urls. If it matches an url +# in an incoming messages, it'll print it to the log window. +#set url_regex = "(((https?|ftps?|nntp)://)|www[.][-a-z0-9.]+|(mailto:|news:))(%[0-9A-F]{2}|[-_.!~*';/?:@&=+$,#[:alnum:]])+" # Contacts PGP information # You can provide a PGP key to be used for a given Jabber user, or
--- a/mcabber/src/screen.c Sat Sep 27 22:44:02 2008 +0200 +++ b/mcabber/src/screen.c Tue Sep 30 09:05:05 2008 +0200 @@ -144,6 +144,8 @@ gint value; } keyseq; +static GRegex *url_regex; + GSList *keyseqlist; static void add_keyseq(char *seqstr, guint mkeycode, gint value); @@ -745,6 +747,10 @@ inputLine[0] = 0; ptr_inputline = inputLine; + if (settings_opt_get("url_regex")) + url_regex = g_regex_new(settings_opt_get("url_regex"), + G_REGEX_OPTIMIZE, 0, NULL); + Curses = TRUE; return; } @@ -755,6 +761,8 @@ clear(); refresh(); endwin(); + if (url_regex) + g_regex_unref(url_regex); Curses = FALSE; return; } @@ -1990,6 +1998,21 @@ } } +inline void scr_LogUrls(const gchar *string) +{ + GMatchInfo *match_info; + GError *error = NULL; + + g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, &error); + while (g_match_info_matches(match_info)) { + gchar *url = g_match_info_fetch(match_info, 0); + scr_print_logwindow(url); + g_free(url); + g_match_info_next(match_info, &error); + } + g_match_info_free(match_info); +} + inline void scr_WriteMessage(const char *bjid, const char *text, time_t timestamp, guint prefix_flags, unsigned mucnicklen) @@ -2015,6 +2038,8 @@ ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT)) prefix |= HBB_PREFIX_IN; + if (url_regex) + scr_LogUrls(text); scr_WriteMessage(jidfrom, text, timestamp, prefix, mucnicklen); }