comparison mcabber/src/screen.c @ 1520:41d3457af815

Add option "url_regex"
author franky@diable.fs
date Tue, 30 Sep 2008 09:05:05 +0200
parents ac5a2c262098
children 33f8f795abd2
comparison
equal deleted inserted replaced
1519:ac5a2c262098 1520:41d3457af815
141 typedef struct { 141 typedef struct {
142 char *seqstr; 142 char *seqstr;
143 guint mkeycode; 143 guint mkeycode;
144 gint value; 144 gint value;
145 } keyseq; 145 } keyseq;
146
147 static GRegex *url_regex;
146 148
147 GSList *keyseqlist; 149 GSList *keyseqlist;
148 static void add_keyseq(char *seqstr, guint mkeycode, gint value); 150 static void add_keyseq(char *seqstr, guint mkeycode, gint value);
149 151
150 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, 152 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp,
743 // to update Log_Win_Height and set max{X,Y} 745 // to update Log_Win_Height and set max{X,Y}
744 746
745 inputLine[0] = 0; 747 inputLine[0] = 0;
746 ptr_inputline = inputLine; 748 ptr_inputline = inputLine;
747 749
750 if (settings_opt_get("url_regex"))
751 url_regex = g_regex_new(settings_opt_get("url_regex"),
752 G_REGEX_OPTIMIZE, 0, NULL);
753
748 Curses = TRUE; 754 Curses = TRUE;
749 return; 755 return;
750 } 756 }
751 757
752 void scr_TerminateCurses(void) 758 void scr_TerminateCurses(void)
753 { 759 {
754 if (!Curses) return; 760 if (!Curses) return;
755 clear(); 761 clear();
756 refresh(); 762 refresh();
757 endwin(); 763 endwin();
764 if (url_regex)
765 g_regex_unref(url_regex);
758 Curses = FALSE; 766 Curses = FALSE;
759 return; 767 return;
760 } 768 }
761 769
762 void scr_Beep(void) 770 void scr_Beep(void)
1988 scr_Resize(); 1996 scr_Resize();
1989 redrawwin(stdscr); 1997 redrawwin(stdscr);
1990 } 1998 }
1991 } 1999 }
1992 2000
2001 inline void scr_LogUrls(const gchar *string)
2002 {
2003 GMatchInfo *match_info;
2004 GError *error = NULL;
2005
2006 g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, &error);
2007 while (g_match_info_matches(match_info)) {
2008 gchar *url = g_match_info_fetch(match_info, 0);
2009 scr_print_logwindow(url);
2010 g_free(url);
2011 g_match_info_next(match_info, &error);
2012 }
2013 g_match_info_free(match_info);
2014 }
2015
1993 inline void scr_WriteMessage(const char *bjid, const char *text, 2016 inline void scr_WriteMessage(const char *bjid, const char *text,
1994 time_t timestamp, guint prefix_flags, 2017 time_t timestamp, guint prefix_flags,
1995 unsigned mucnicklen) 2018 unsigned mucnicklen)
1996 { 2019 {
1997 char *xtext; 2020 char *xtext;
2013 if (!(prefix & 2036 if (!(prefix &
2014 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT & 2037 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT &
2015 ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT)) 2038 ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT))
2016 prefix |= HBB_PREFIX_IN; 2039 prefix |= HBB_PREFIX_IN;
2017 2040
2041 if (url_regex)
2042 scr_LogUrls(text);
2018 scr_WriteMessage(jidfrom, text, timestamp, prefix, mucnicklen); 2043 scr_WriteMessage(jidfrom, text, timestamp, prefix, mucnicklen);
2019 } 2044 }
2020 2045
2021 void scr_WriteOutgoingMessage(const char *jidto, const char *text, guint prefix) 2046 void scr_WriteOutgoingMessage(const char *jidto, const char *text, guint prefix)
2022 { 2047 {