mirror of
https://github.com/irssi/irssi.git
synced 2026-08-22 10:02:22 +02:00
Merge 5135eee57a into cfa51c5ae2
This commit is contained in:
commit
09c865d9ea
5 changed files with 97 additions and 13 deletions
|
|
@ -164,6 +164,23 @@ int strarray_find(char **array, const char *item)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strarray_find_prefix(char **array, const char *item)
|
||||||
|
{
|
||||||
|
char **tmp;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
g_return_val_if_fail(array != NULL, -1);
|
||||||
|
g_return_val_if_fail(item != NULL, -1);
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
for (tmp = array; *tmp != NULL; tmp++, index++) {
|
||||||
|
if (g_ascii_strncasecmp(*tmp, item, strlen(item)) == 0)
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
GSList *gslist_find_string(GSList *list, const char *key)
|
GSList *gslist_find_string(GSList *list, const char *key)
|
||||||
{
|
{
|
||||||
for (; list != NULL; list = list->next)
|
for (; list != NULL; list = list->next)
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,9 @@ char *replace_chars(char *str, char from, char to);
|
||||||
/* return index of `item' in `array' or -1 if not found */
|
/* return index of `item' in `array' or -1 if not found */
|
||||||
int strarray_find(char **array, const char *item);
|
int strarray_find(char **array, const char *item);
|
||||||
|
|
||||||
|
/* return index of element in `array' starting with `item' or -1 if not found */
|
||||||
|
int strarray_find_prefix(char **array, const char *item);
|
||||||
|
|
||||||
/* string -> uoff_t */
|
/* string -> uoff_t */
|
||||||
uoff_t str_to_uofft(const char *str);
|
uoff_t str_to_uofft(const char *str);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
#include "modules.h"
|
||||||
#include "module-formats.h"
|
#include "module-formats.h"
|
||||||
#include "args.h"
|
#include "args.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
@ -470,26 +471,63 @@ void fe_common_core_finish_init(void)
|
||||||
|
|
||||||
gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest)
|
gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest)
|
||||||
{
|
{
|
||||||
|
const WindowType type = dest->window->active ? window_item_get_type(dest->window->active) : WI_TYPE_OTHER;
|
||||||
|
GSList *targets = NULL, *iterator = NULL;
|
||||||
|
gboolean found = FALSE;
|
||||||
|
|
||||||
g_return_val_if_fail(array != NULL, FALSE);
|
g_return_val_if_fail(array != NULL, FALSE);
|
||||||
|
|
||||||
|
// we ignore all targets
|
||||||
if (strarray_find(array, "*") != -1)
|
if (strarray_find(array, "*") != -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
// exit if not a channel or query
|
||||||
if (strarray_find(array, dest->target) != -1)
|
else if (type & WI_TYPE_OTHER)
|
||||||
|
return FALSE;
|
||||||
|
// we ignore all channels
|
||||||
|
else if (type & WI_TYPE_CHANNEL && strarray_find(array, "#") != -1)
|
||||||
|
return TRUE;
|
||||||
|
// Is this a dcc chat?
|
||||||
|
else if (type & WI_TYPE_DCCCHAT && strarray_find(array, "=") != -1)
|
||||||
|
return TRUE;
|
||||||
|
// Is this a private query window?
|
||||||
|
else if (type & WI_TYPE_PRIVMSG && strarray_find(array, "@") != -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (dest->server_tag != NULL) {
|
if (dest->server_tag == NULL)
|
||||||
char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, "*");
|
return FALSE;
|
||||||
int ret = strarray_find(array, tagtarget);
|
|
||||||
g_free(tagtarget);
|
|
||||||
if (ret != -1)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
tagtarget = g_strdup_printf("%s/%s", dest->server_tag, dest->target);
|
char *prefix = g_strdup_printf("%s/", dest->server_tag);
|
||||||
ret = strarray_find(array, tagtarget);
|
if (strarray_find_prefix(array, prefix) == -1) {
|
||||||
g_free(tagtarget);
|
g_free(prefix);
|
||||||
if (ret != -1)
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(prefix);
|
||||||
|
|
||||||
|
// create a list of types to look for
|
||||||
|
targets = g_slist_append(targets, "*");
|
||||||
|
if (type & WI_TYPE_CHANNEL) {
|
||||||
|
targets = g_slist_append(targets, "#");
|
||||||
|
targets = g_slist_append(targets, (gpointer) dest->target);
|
||||||
|
}
|
||||||
|
else if (type & WI_TYPE_QUERY) {
|
||||||
|
if (type & WI_TYPE_DCCCHAT)
|
||||||
|
targets = g_slist_append(targets, "=");
|
||||||
|
else
|
||||||
|
targets = g_slist_append(targets, "@");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (iterator = targets; iterator; iterator = iterator->next) {
|
||||||
|
char *tagtarget = g_strdup_printf("%s/%s", dest->server_tag, (char *) iterator->data);
|
||||||
|
int ret = strarray_find(array, tagtarget);
|
||||||
|
g_free(tagtarget);
|
||||||
|
if (ret != -1) {
|
||||||
|
found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_slist_free(targets);
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,21 @@ void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WindowType window_item_get_type(WI_ITEM_REC *item)
|
||||||
|
{
|
||||||
|
const char *type = module_find_id_str("WINDOW ITEM TYPE", item->type);
|
||||||
|
if (!g_ascii_strcasecmp(type, "CHANNEL"))
|
||||||
|
return WI_TYPE_CHANNEL;
|
||||||
|
else if (!g_ascii_strcasecmp(type, "QUERY")) {
|
||||||
|
if (item->name[0] == '=')
|
||||||
|
return WI_TYPE_QUERY | WI_TYPE_DCCCHAT;
|
||||||
|
else
|
||||||
|
return WI_TYPE_QUERY | WI_TYPE_PRIVMSG;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return WI_TYPE_OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return TRUE if `item' is the active window item in the window.
|
/* Return TRUE if `item' is the active window item in the window.
|
||||||
`item' can be NULL. */
|
`item' can be NULL. */
|
||||||
int window_item_is_active(WI_ITEM_REC *item)
|
int window_item_is_active(WI_ITEM_REC *item)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,14 @@
|
||||||
|
|
||||||
#include "fe-windows.h"
|
#include "fe-windows.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WI_TYPE_CHANNEL = 1,
|
||||||
|
WI_TYPE_QUERY = 2,
|
||||||
|
WI_TYPE_PRIVMSG = 4,
|
||||||
|
WI_TYPE_DCCCHAT = 8,
|
||||||
|
WI_TYPE_OTHER = 16
|
||||||
|
} WindowType;
|
||||||
|
|
||||||
/* Add/remove/destroy window item from `window' */
|
/* Add/remove/destroy window item from `window' */
|
||||||
void window_item_add(WINDOW_REC *window, WI_ITEM_REC *item, int automatic);
|
void window_item_add(WINDOW_REC *window, WI_ITEM_REC *item, int automatic);
|
||||||
void window_item_remove(WI_ITEM_REC *item);
|
void window_item_remove(WI_ITEM_REC *item);
|
||||||
|
|
@ -23,6 +31,9 @@ int window_item_is_active(WI_ITEM_REC *item);
|
||||||
void window_item_prev(WINDOW_REC *window);
|
void window_item_prev(WINDOW_REC *window);
|
||||||
void window_item_next(WINDOW_REC *window);
|
void window_item_next(WINDOW_REC *window);
|
||||||
|
|
||||||
|
// return WindowType depending on what WI_ITEM_REC is
|
||||||
|
WindowType window_item_get_type(WI_ITEM_REC *item);
|
||||||
|
|
||||||
/* Find wanted window item by name. `server' can be NULL. */
|
/* Find wanted window item by name. `server' can be NULL. */
|
||||||
WI_ITEM_REC *window_item_find(void *server, const char *name);
|
WI_ITEM_REC *window_item_find(void *server, const char *name);
|
||||||
WI_ITEM_REC *window_item_find_window(WINDOW_REC *window,
|
WI_ITEM_REC *window_item_find_window(WINDOW_REC *window,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue