summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-10-25 19:13:43 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-10-25 19:13:43 +0200
commitb712ed09d7237762b71434a74e067f3522683fab (patch)
treee477b6ad3b1bc55b953d577017b2bc805a91d157 /src/gui
parent707034442ab75c8c426f9c8b4906d10ad7312b4d (diff)
downloadweechat-b712ed09d7237762b71434a74e067f3522683fab.zip
Add smart join/part/quit message filter in IRC plugin, add names for filters
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-completion.c21
-rw-r--r--src/gui/gui-filter.c43
-rw-r--r--src/gui/gui-filter.h6
3 files changed, 59 insertions, 11 deletions
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index 5dfb20a3c..f5dcf2bf5 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -43,6 +43,7 @@
#include "gui-bar.h"
#include "gui-buffer.h"
#include "gui-color.h"
+#include "gui-filter.h"
#include "gui-keyboard.h"
#include "gui-nicklist.h"
@@ -464,6 +465,23 @@ gui_completion_list_add_filename (struct t_gui_completion *completion)
}
/*
+ * gui_completion_list_add_filters: add filters to completion list
+ */
+
+void
+gui_completion_list_add_filters (struct t_gui_completion *completion)
+{
+ struct t_gui_filter *ptr_filter;
+
+ for (ptr_filter = gui_filters; ptr_filter;
+ ptr_filter = ptr_filter->next_filter)
+ {
+ gui_completion_list_add (completion, ptr_filter->name,
+ 0, WEECHAT_LIST_POS_SORT);
+ }
+}
+
+/*
* gui_completion_list_add_command_hooks: add command hooks to completion list
*/
@@ -931,6 +949,9 @@ gui_completion_build_list_template (struct t_gui_completion *completion,
case 'f': /* filename */
gui_completion_list_add_filename (completion);
break;
+ case 'F': /* filters */
+ gui_completion_list_add_filters (completion);
+ break;
case 'h': /* command hooks */
gui_completion_list_add_command_hooks (completion);
break;
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c
index 158971cbb..a2e841ea6 100644
--- a/src/gui/gui-filter.c
+++ b/src/gui/gui-filter.c
@@ -253,22 +253,19 @@ gui_filter_search (const char *buffer, const char *tags, const char *regex)
}
/*
- * gui_filter_search_by_number: search a filter by number (first is #1)
+ * gui_filter_search_by_name: search a filter by name
*/
struct t_gui_filter *
-gui_filter_search_by_number (int number)
+gui_filter_search_by_name (const char *name)
{
struct t_gui_filter *ptr_filter;
- int i;
-
- i = 1;
+
for (ptr_filter = gui_filters; ptr_filter;
ptr_filter = ptr_filter->next_filter)
{
- if (i == number)
+ if (strcmp (ptr_filter->name, name) == 0)
return ptr_filter;
- i++;
}
/* filter not found */
@@ -280,15 +277,18 @@ gui_filter_search_by_number (int number)
*/
struct t_gui_filter *
-gui_filter_new (int enabled, const char *buffer, const char *tags,
- const char *regex)
+gui_filter_new (int enabled, const char *name, const char *buffer,
+ const char *tags, const char *regex)
{
struct t_gui_filter *new_filter;
regex_t *regex1, *regex2;
char *pos_tab, *regex_prefix;
const char *pos_regex_message;
- if (!buffer || !tags || !regex)
+ if (!name || !buffer || !tags || !regex)
+ return NULL;
+
+ if (gui_filter_search_by_name (name))
return NULL;
regex1 = NULL;
@@ -347,6 +347,7 @@ gui_filter_new (int enabled, const char *buffer, const char *tags,
{
/* init filter */
new_filter->enabled = enabled;
+ new_filter->name = strdup (name);
new_filter->buffer = (buffer) ? strdup (buffer) : strdup ("*");
if (tags)
{
@@ -383,6 +384,25 @@ gui_filter_new (int enabled, const char *buffer, const char *tags,
}
/*
+ * gui_filter_rename: rename a filter
+ */
+
+int
+gui_filter_rename (struct t_gui_filter *filter, const char *new_name)
+{
+ if (!filter || !new_name)
+ return 0;
+
+ if (gui_filter_search_by_name (new_name))
+ return 0;
+
+ free (filter->name);
+ filter->name = strdup (new_name);
+
+ return 1;
+}
+
+/*
* gui_filter_free: remove a filter
*/
@@ -393,6 +413,8 @@ gui_filter_free (struct t_gui_filter *filter)
WEECHAT_HOOK_SIGNAL_POINTER, filter);
/* free data */
+ if (filter->name)
+ free (filter->name);
if (filter->buffer)
free (filter->buffer);
if (filter->tags)
@@ -501,6 +523,7 @@ gui_filter_print_log ()
log_printf ("");
log_printf ("[filter (addr:0x%x)]", ptr_filter);
log_printf (" enabled. . . . . . . . : %d", ptr_filter->enabled);
+ log_printf (" name . . . . . . . . . : '%s'", ptr_filter->name);
log_printf (" buffer . . . . . . . . : '%s'", ptr_filter->buffer);
log_printf (" tags . . . . . . . . . : '%s'", ptr_filter->tags);
log_printf (" regex. . . . . . . . . : '%s'", ptr_filter->regex);
diff --git a/src/gui/gui-filter.h b/src/gui/gui-filter.h
index 0d79a5eef..f49513e37 100644
--- a/src/gui/gui-filter.h
+++ b/src/gui/gui-filter.h
@@ -31,6 +31,7 @@ struct t_gui_line;
struct t_gui_filter
{
int enabled; /* 1 if filter enabled, otherwise 0 */
+ char *name;
char *buffer; /* name of buffer */
char *tags; /* tags */
int tags_count; /* number of tags */
@@ -59,11 +60,14 @@ extern void gui_filter_disable (struct t_gui_filter *filter);
extern struct t_gui_filter *gui_filter_search (const char *buffer,
const char *tags,
const char *regex);
-extern struct t_gui_filter *gui_filter_search_by_number (int number);
+extern struct t_gui_filter *gui_filter_search_by_name (const char *name);
extern struct t_gui_filter *gui_filter_new (int enabled,
+ const char *name,
const char *buffer,
const char *tags,
const char *regex);
+extern int gui_filter_rename (struct t_gui_filter *filter,
+ const char *new_name);
extern void gui_filter_free (struct t_gui_filter *filter);
extern void gui_filter_free_all ();
extern int gui_filter_add_to_infolist (struct t_infolist *infolist,