void window_item_next(WINDOW_REC *window) { WI_ITEM_REC *next; GSList *tmp; int gone; g_return_if_fail(window != NULL); next = NULL; gone = FALSE; for (tmp = window->items; tmp != NULL; tmp = tmp->next) { WI_ITEM_REC *rec = tmp->data; if (rec == window->active) gone = TRUE; else { if (gone) { /* found the next channel */ next = rec; break; } if (next == NULL) next = rec; /* fallback to first channel */ } } if (next != NULL) window_item_set_active(window, next); }
static void window_item_add_signal(WINDOW_REC *window, WI_ITEM_REC *item, int automatic, int send_signal) { g_return_if_fail(window != NULL); g_return_if_fail(item != NULL); g_return_if_fail(item->window == NULL); item->window = window; if (window->items == NULL) { window->active = item; window->active_server = item->server; } if (!automatic || settings_get_bool("window_auto_change")) { if (automatic) signal_emit("window changed automatic", 1, window); window_set_active(window); } window->items = g_slist_append(window->items, item); if (send_signal) signal_emit("window item new", 2, window, item); if (g_slist_length(window->items) == 1 || (!automatic && settings_get_bool("autofocus_new_items"))) { window->active = NULL; window_item_set_active(window, item); } }
static void cmd_query(gchar *data, IRC_SERVER_REC *server, WI_IRC_REC *item) { WINDOW_REC *window; QUERY_REC *query; g_return_if_fail(data != NULL); if (*data == '\0') { /* remove current query */ cmd_unquery("", server, item); return; } if (*data != '=' && (server == NULL || !server->connected)) cmd_return_error(CMDERR_NOT_CONNECTED); query = query_find(server, data); if (query != NULL) { /* query already existed - change to query window */ window = window_item_window((WI_ITEM_REC *) query); g_return_if_fail(window != NULL); window_set_active(window); window_item_set_active(window, (WI_ITEM_REC *) query); return; } query_create(server, data, FALSE); }
static void cmd_join(const char *data, SERVER_REC *server) { WINDOW_REC *window; CHANNEL_REC *channel; GHashTable *optlist; char *channelname; void *free_arg; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS, "join", &optlist, &channelname)) return; /* -<server tag> */ server = cmd_options_get_server("join", optlist, server); channel = channel_find(server, channelname); if (channel != NULL) { /* already joined to channel, set it active */ window = window_item_window(channel); if (window != active_win) window_set_active(window); window_item_set_active(active_win, (WI_ITEM_REC *) channel); } cmd_params_free(free_arg); }
void window_add_item(WINDOW_REC *window, WI_ITEM_REC *item, int automatic) { g_return_if_fail(window != NULL); g_return_if_fail(item != NULL); MODULE_DATA_SET(item, window); if (window->items == NULL) { window->active = item; window->active_server = item->server; } signal_emit("gui window item init", 1, item); if (!automatic || settings_get_bool("window_auto_change")) { if (automatic) signal_emit("window changed automatic", 1, window); window_set_active(window); } window->items = g_slist_append(window->items, item); signal_emit("window item new", 2, window, item); if (!automatic || g_slist_length(window->items) == 1) { window->active = NULL; window_item_set_active(window, item); } }
/* SYNTAX: WINDOW ITEM GOTO <name> */ static void cmd_window_item_goto(const char *data, SERVER_REC *server) { WI_ITEM_REC *item; item = window_item_find_window(active_win, server, data); if (item != NULL) window_item_set_active(active_win, item); }
/* SYNTAX: JOIN [-window] [-invite] [-<server tag>] <channels> [<keys>] */ static void cmd_join(const char *data, SERVER_REC *server) { WINDOW_REC *window; CHANNEL_REC *channel; GHashTable *optlist; char *pdata; int invite; int samewindow; void *free_arg; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS, "join", &optlist, &pdata)) return; invite = g_hash_table_lookup(optlist, "invite") != NULL; samewindow = g_hash_table_lookup(optlist, "window") != NULL; if (!invite && *pdata == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); /* -<server tag> */ server = cmd_options_get_server("join", optlist, server); channel = channel_find(server, pdata); if (channel != NULL) { /* already joined to channel, set it active */ window = window_item_window(channel); if (window != active_win) window_set_active(window); window_item_set_active(active_win, (WI_ITEM_REC *) channel); } else { if (server == NULL || !server->connected) cmd_param_error(CMDERR_NOT_CONNECTED); if (invite) { if (server->last_invite == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_INVITED); signal_stop(); cmd_params_free(free_arg); return; } pdata = server->last_invite; } if (samewindow) signal_add("channel created", (SIGNAL_FUNC) signal_channel_created_curwin); server->channels_join(server, pdata, FALSE); if (samewindow) signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created_curwin); } cmd_params_free(free_arg); }
static void cmd_join(const char *data, SERVER_REC *server) { CHANNEL_REC *channel; if (strchr(data, ' ') != NULL || strchr(data, ',') != NULL) return; channel = channel_find(server, data); if (channel != NULL) window_item_set_active(active_win, (WI_ITEM_REC *) channel); }
static void sig_query_raise(XMPP_SERVER_REC *server, QUERY_REC *query) { WINDOW_REC *window; g_return_if_fail(query != NULL); window = window_item_window(query); if (window != active_win) window_set_active(window); window_item_set_active(active_win, (WI_ITEM_REC *)query); }
/* SYNTAX: QUERY [-window] <nick> */ static void cmd_query(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { GHashTable *optlist; QUERY_REC *query; char *nick; void *free_arg; g_return_if_fail(data != NULL); if (*data == '\0') { /* remove current query */ cmd_unquery("", server, item); return; } if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS, "query", &optlist, &nick)) return; if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); server = cmd_options_get_server("query", optlist, server); if (server == NULL) { cmd_params_free(free_arg); return; } if (*nick != '=' && (server == NULL || !server->connected)) cmd_param_error(CMDERR_NOT_CONNECTED); if (g_hash_table_lookup(optlist, "window") != NULL) { signal_add("query created", (SIGNAL_FUNC) signal_query_created_curwin); } query = query_find(server, nick); if (query == NULL) CHAT_PROTOCOL(server)->query_create(server->tag, nick, FALSE); else { /* query already existed - set query active / move it to this window */ window_item_set_active(active_win, (WI_ITEM_REC *) query); } if (g_hash_table_lookup(optlist, "window") != NULL) { signal_remove("query created", (SIGNAL_FUNC) signal_query_created_curwin); } cmd_params_free(free_arg); }
/* SYNTAX: WINDOW ITEM MOVE <number>|<name> */ static void cmd_window_item_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { WINDOW_REC *window; if (is_numeric(data, '\0')) { /* move current window item to specified window */ window = window_find_refnum(atoi(data)); } else { /* move specified window item to current window */ item = window_item_find(server, data); window = active_win; } if (window != NULL && item != NULL) window_item_set_active(window, item); }
void window_remove_item(WINDOW_REC *window, WI_ITEM_REC *item) { g_return_if_fail(window != NULL); g_return_if_fail(item != NULL); if (g_slist_find(window->items, item) == NULL) return; MODULE_DATA_SET(item, NULL); window->items = g_slist_remove(window->items, item); if (window->active == item) { window_item_set_active(window, window->items == NULL ? NULL : window->items->data); } signal_emit("window item remove", 2, window, item); }
void window_item_remove(WI_ITEM_REC *item) { WINDOW_REC *window; g_return_if_fail(item != NULL); window = window_item_window(item); if (window == NULL) return; item->window = NULL; window->items = g_slist_remove(window->items, item); if (window->active == item) { window_item_set_active(window, window->items == NULL ? NULL : window->items->data); } signal_emit("window item remove", 2, window, item); }
/* SYNTAX: WINDOW ITEM MOVE <number>|<name> */ static void cmd_window_item_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { WINDOW_REC *window; void *free_arg; char *target; if (!cmd_get_params(data, &free_arg, 1, &target)) return; if (is_numeric(target, '\0')) { /* move current window item to specified window */ window = window_find_refnum(atoi(target)); } else { /* move specified window item to current window */ item = window_item_find(server, target); window = active_win; } if (window != NULL && item != NULL) window_item_set_active(window, item); cmd_params_free(free_arg); }
/* SYNTAX: WINDOW ITEM GOTO <number>|<name> */ static void cmd_window_item_goto(const char *data, SERVER_REC *server) { WI_ITEM_REC *item; GSList *tmp; void *free_arg; char *target; if (!cmd_get_params(data, &free_arg, 1, &target)) return; if (is_numeric(target, '\0')) { /* change to specified number */ tmp = g_slist_nth(active_win->items, atoi(target)-1); item = tmp == NULL ? NULL : tmp->data; } else { item = window_item_find_window(active_win, server, target); } if (item != NULL) window_item_set_active(active_win, item); cmd_params_free(free_arg); }
void window_item_prev(WINDOW_REC *window) { WI_ITEM_REC *last; GSList *tmp; g_return_if_fail(window != NULL); last = NULL; for (tmp = window->items; tmp != NULL; tmp = tmp->next) { WI_ITEM_REC *rec = tmp->data; if (rec != window->active) last = rec; else { /* current channel. did we find anything? if not, go to the last channel */ if (last != NULL) break; } } if (last != NULL) window_item_set_active(window, last); }
/* SYNTAX: QUERY [-window] [-<server tag>] <nick> [<message>] */ static void cmd_query(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { GHashTable *optlist; QUERY_REC *query; char *nick, *msg; void *free_arg; g_return_if_fail(data != NULL); if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS, "query", &optlist, &nick, &msg)) return; if (*nick == '\0') { /* remove current query */ cmd_unquery("", server, item); cmd_params_free(free_arg); return; } server = cmd_options_get_server("query", optlist, server); if (server == NULL) { cmd_params_free(free_arg); return; } if (*nick != '=' && (server == NULL || !server->connected)) cmd_param_error(CMDERR_NOT_CONNECTED); if (g_hash_table_lookup(optlist, "window") != NULL) { signal_add("query created", (SIGNAL_FUNC) signal_query_created_curwin); } query = query_find(server, nick); if (query == NULL) query = CHAT_PROTOCOL(server)-> query_create(server->tag, nick, FALSE); else { /* query already exists, set it active */ WINDOW_REC *window = window_item_window(query); if (window != active_win) window_set_active(window); window_item_set_active(active_win, (WI_ITEM_REC *) query); } if (g_hash_table_lookup(optlist, "window") != NULL) { signal_remove("query created", (SIGNAL_FUNC) signal_query_created_curwin); } if (*msg != '\0') { msg = g_strdup_printf("-nick %s %s", nick, msg); signal_emit("command msg", 3, msg, server, query); g_free(msg); } cmd_params_free(free_arg); }