static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { char *line, *str; g_return_if_fail(data != NULL); if (item == NULL) return; line = settings_get_bool("expand_escapes") ? expand_escapes(data, server, item) : g_strdup(data); /* check for automatic nick completion */ if (completion_auto && IS_CHANNEL(item)) { str = auto_complete(CHANNEL(item), line); if (str != NULL) { g_free(line); line = str; } } str = g_strdup_printf(IS_CHANNEL(item) ? "-channel %s %s" : IS_QUERY(item) ? "-nick %s %s" : "%s %s", item->name, line); signal_emit("command msg", 3, str, server, item); g_free(str); g_free(line); signal_stop(); }
static void sig_layout_save_item(WINDOW_REC *window, WI_ITEM_REC *item, CONFIG_NODE *node) { CONFIG_NODE *subnode; CHAT_PROTOCOL_REC *proto; const char *type; type = module_find_id_str("WINDOW ITEM TYPE", item->type); if (type == NULL) return; subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK); iconfig_node_set_str(subnode, "type", type); proto = item->chat_type == 0 ? NULL : chat_protocol_find_id(item->chat_type); if (proto != NULL) iconfig_node_set_str(subnode, "chat_type", proto->name); iconfig_node_set_str(subnode, "name", item->visible_name); if (item->server != NULL) iconfig_node_set_str(subnode, "tag", item->server->tag); else if (IS_QUERY(item)) { iconfig_node_set_str(subnode, "tag", QUERY(item)->server_tag); } }
static void e_data_cal_view_dispose (GObject *object) { EDataCalView *query; EDataCalViewPrivate *priv; g_return_if_fail (object != NULL); g_return_if_fail (IS_QUERY (object)); query = QUERY (object); priv = query->priv; if (priv->backend) { e_cal_backend_remove_query (priv->backend, query); g_object_unref (priv->backend); priv->backend = NULL; } if (priv->sexp) { g_object_unref (priv->sexp); priv->sexp = NULL; } g_mutex_lock (priv->pending_mutex); if (priv->flush_id) { g_source_remove (priv->flush_id); priv->flush_id = 0; } g_mutex_unlock (priv->pending_mutex); (* G_OBJECT_CLASS (e_data_cal_view_parent_class)->dispose) (object); }
/** * e_data_cal_view_get_object_sexp: * @query: A query object. * * Get the #ECalBackendSExp object used for the given query. * * Returns: The expression object used to search. */ ECalBackendSExp * e_data_cal_view_get_object_sexp (EDataCalView *query) { g_return_val_if_fail (IS_QUERY (query), NULL); return query->priv->sexp; }
/** * e_data_cal_view_get_matched_objects: * @query: A query object. * * Gets the list of objects already matched for the given query. * * Returns: A list of matched objects. */ GList * e_data_cal_view_get_matched_objects (EDataCalView *query) { g_return_val_if_fail (IS_QUERY (query), NULL); /* TODO e_data_cal_view_get_matched_objects */ return NULL; }
/** * e_data_cal_view_get_text: * @query: A #EDataCalView object. * * Get the expression used for the given query. * * Returns: the query expression used to search. */ const gchar * e_data_cal_view_get_text (EDataCalView *query) { g_return_val_if_fail (IS_QUERY (query), NULL); return e_cal_backend_sexp_text (query->priv->sexp); }
static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node) { CONFIG_NODE *subnode; GSList *tmp; const char *type; node = config_node_section(node, "items", NODE_TYPE_LIST); for (tmp = window->items; tmp != NULL; tmp = tmp->next) { WI_ITEM_REC *rec = tmp->data; SERVER_REC *server = rec->server; type = module_find_id_str("WINDOW ITEM TYPE", rec->type); if (type == NULL) continue; subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK); iconfig_node_set_str(subnode, "type", type); type = chat_protocol_find_id(rec->chat_type)->name; iconfig_node_set_str(subnode, "chat_type", type); iconfig_node_set_str(subnode, "name", rec->name); if (server != NULL) iconfig_node_set_str(subnode, "tag", server->tag); else if (IS_QUERY(rec)) { iconfig_node_set_str(subnode, "tag", QUERY(rec)->server_tag); } } }
void query_change_address(QUERY_REC *query, const char *address) { g_return_if_fail(IS_QUERY(query)); g_free_not_null(query->address); query->address = g_strdup(address); signal_emit("query address changed", 1, query); }
static void signal_window_item_server_changed(WINDOW_REC *window, QUERY_REC *query) { if (IS_QUERY(query)) { g_free_and_null(query->server_tag); if (query->server != NULL) query->server_tag = g_strdup(query->server->tag); } }
static void signal_query_created(QUERY_REC *query, gpointer automatic) { g_return_if_fail(IS_QUERY(query)); if (window_item_find(query->server, query->name) != NULL) return; window_item_create((WI_ITEM_REC *) query, GPOINTER_TO_INT(automatic)); printformat(query->server, query->name, MSGLEVEL_CLIENTNOTICE, TXT_QUERY_STARTED, query->name); }
void query_change_nick(QUERY_REC *query, const char *nick) { char *oldnick; g_return_if_fail(IS_QUERY(query)); oldnick = query->name; query->name = g_strdup(nick); signal_emit("query nick changed", 2, query, oldnick); g_free(oldnick); }
/** * e_data_cal_view_is_done: * @query: A query object. * * Checks whether the given query is already done. Being done means the initial * matching of objects have been finished, not that no more notifications about * changes will be sent. In fact, even after done, notifications will still be sent * if there are changes in the objects matching the query search expression. * * Returns: TRUE if the query is done, FALSE if still in progress. */ gboolean e_data_cal_view_is_done (EDataCalView *query) { EDataCalViewPrivate *priv; g_return_val_if_fail (IS_QUERY (query), FALSE); priv = query->priv; return priv->done; }
static int window_has_query(WINDOW_REC *window) { GSList *tmp; g_return_val_if_fail(window != NULL, FALSE); for (tmp = window->items; tmp != NULL; tmp = tmp->next) { if (IS_QUERY(tmp->data)) return TRUE; } return FALSE; }
/** * e_data_cal_view_object_matches: * @query: A query object. * @object: Object to match. * * Compares the given @object to the regular expression used for the * given query. * * Returns: TRUE if the object matches the expression, FALSE if not. */ gboolean e_data_cal_view_object_matches (EDataCalView *query, const gchar *object) { EDataCalViewPrivate *priv; g_return_val_if_fail (query != NULL, FALSE); g_return_val_if_fail (IS_QUERY (query), FALSE); g_return_val_if_fail (object != NULL, FALSE); priv = query->priv; return e_cal_backend_sexp_match_object (priv->sexp, object, priv->backend); }
void query_change_server(QUERY_REC *query, SERVER_REC *server) { g_return_if_fail(IS_QUERY(query)); if (query->server != NULL) { query->server->queries = g_slist_remove(query->server->queries, query); } if (server != NULL) server->queries = g_slist_append(server->queries, query); query->server = server; signal_emit("query server changed", 1, query); }
static void signal_query_destroyed(QUERY_REC *query) { WINDOW_REC *window; g_return_if_fail(IS_QUERY(query)); window = window_item_window((WI_ITEM_REC *) query); if (window != NULL) { window_item_destroy((WI_ITEM_REC *) query); if (window->items == NULL && windows->next != NULL && !query->unwanted && settings_get_bool("autoclose_windows")) window_destroy(window); } }
/* SYNTAX: VER [<nick> | <channel> | *] */ static void cmd_ver(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { char *str; g_return_if_fail(data != NULL); CMD_IRC_SERVER(server); if (*data == '\0' && !IS_QUERY(item)) cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); str = g_strdup_printf("%s VERSION", *data == '\0' ? window_item_get_target(item) : data); signal_emit("command ctcp", 3, str, server, item); g_free(str); }
static void signal_query_created(QUERY_REC *query, gpointer automatic) { TEXT_DEST_REC dest; g_return_if_fail(IS_QUERY(query)); if (window_item_window(query) == NULL) { window_item_create((WI_ITEM_REC *) query, GPOINTER_TO_INT(automatic)); } format_create_dest_tag(&dest, query->server, query->server_tag, query->name, MSGLEVEL_CLIENTNOTICE, NULL); printformat_dest(&dest, TXT_QUERY_START, query->name, query->server_tag); }
char * xmpp_get_dest(const char *cmd_dest, XMPP_SERVER_REC *server, WI_ITEM_REC *item) { NICK_REC *nick; char *dest; if (cmd_dest == NULL || *cmd_dest == '\0') return IS_QUERY(item) ? g_strdup(QUERY(item)->name) : g_strconcat(server->jid, "/", server->resource, (void *)NULL); if (IS_CHANNEL(item) && (nick = nicklist_find(CHANNEL(item), cmd_dest)) != NULL) return g_strdup(nick->host); if ((dest = rosters_resolve_name(server, cmd_dest)) != NULL) return dest; return g_strdup(cmd_dest); }
static void e_data_cal_view_finalize (GObject *object) { EDataCalView *query; EDataCalViewPrivate *priv; g_return_if_fail (object != NULL); g_return_if_fail (IS_QUERY (object)); query = QUERY (object); priv = query->priv; g_hash_table_destroy (priv->ids); g_mutex_free (priv->pending_mutex); (* G_OBJECT_CLASS (e_data_cal_view_parent_class)->finalize) (object); }
/* SYNTAX: PING [<nick> | <channel> | *] */ static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { GTimeVal tv; char *str; CMD_IRC_SERVER(server); if (*data == '\0') { if (!IS_QUERY(item)) cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); data = window_item_get_target(item); } g_get_current_time(&tv); str = g_strdup_printf("%s PING %ld %ld", data, tv.tv_sec, tv.tv_usec); signal_emit("command ctcp", 3, str, server, item); g_free(str); }
static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { char *line, *str, *target; g_return_if_fail(data != NULL); if (item == NULL) return; if (*data == '\0') { /* empty line, forget it. */ signal_stop(); return; } line = settings_get_bool("expand_escapes") ? expand_escapes(data, server, item) : g_strdup(data); /* check for automatic nick completion */ if (completion_auto && IS_CHANNEL(item)) { str = auto_complete(CHANNEL(item), line); if (str != NULL) { g_free(line); line = str; } } /* the nick is quoted in case it contains '-' character. also spaces should work too now :) The nick is also escaped in case it contains '\' characters */ target = escape_string(window_item_get_target(item)); str = g_strdup_printf(IS_CHANNEL(item) ? "-channel \"%s\" %s" : IS_QUERY(item) ? "-nick \"%s\" %s" : "%s %s", target, line); g_free(target); signal_emit("command msg", 3, str, server, item); g_free(str); g_free(line); signal_stop(); }
void query_destroy(QUERY_REC *query) { g_return_if_fail(IS_QUERY(query)); if (query->destroying) return; query->destroying = TRUE; queries = g_slist_remove(queries, query); if (query->server != NULL) { query->server->queries = g_slist_remove(query->server->queries, query); } signal_emit("query destroyed", 1, query); MODULE_DATA_DEINIT(query); g_free_not_null(query->server_tag); g_free_not_null(query->address); g_free(query->name); g_free(query); }
static void signal_query_destroyed(QUERY_REC *query) { WINDOW_REC *window; TEXT_DEST_REC dest; g_return_if_fail(IS_QUERY(query)); window = window_item_window((WI_ITEM_REC *) query); if (window == NULL) return; format_create_dest_tag(&dest, query->server, query->server_tag, query->name, MSGLEVEL_CLIENTNOTICE, NULL); printformat_dest(&dest, TXT_QUERY_STOP, query->name); window_item_destroy((WI_ITEM_REC *) query); if (!query->unwanted) window_auto_destroy(window); else { /* eg. connection lost to dcc chat */ window_bind_add(window, query->server_tag, query->name); } }
static void handle_exec(const char *args, GHashTable *optlist, WI_ITEM_REC *item) { PROCESS_REC *rec; char *target, *level; int notice, signum, interactive, target_nick, target_channel; /* check that there's no unknown options. we allowed them because signals can be used as options, but there should be only one unknown option: the signal name/number. */ signum = cmd_options_get_signal("exec", optlist); if (signum == -2) return; if (*args == '\0') { exec_show_list(); return; } target = NULL; notice = FALSE; if (g_hash_table_lookup(optlist, "in") != NULL) { rec = process_find(g_hash_table_lookup(optlist, "in"), TRUE); if (rec != NULL) { net_sendbuffer_send(rec->out, args, strlen(args)); net_sendbuffer_send(rec->out, "\n", 1); } return; } /* check if args is a process ID or name. if it's ID but not found, complain about it and fail immediately */ rec = process_find(args, *args == '%'); if (*args == '%' && rec == NULL) return; /* common options */ target_channel = target_nick = FALSE; if (g_hash_table_lookup(optlist, "out") != NULL) { /* redirect output to active channel/query */ if (item == NULL) cmd_return_error(CMDERR_NOT_JOINED); target = (char *) window_item_get_target(item); target_channel = IS_CHANNEL(item); target_nick = IS_QUERY(item); } else if (g_hash_table_lookup(optlist, "msg") != NULL) { /* redirect output to /msg <nick> */ target = g_hash_table_lookup(optlist, "msg"); } else if (g_hash_table_lookup(optlist, "notice") != NULL) { target = g_hash_table_lookup(optlist, "notice"); notice = TRUE; } /* options that require process ID/name as argument */ if (rec == NULL && (signum != -1 || g_hash_table_lookup(optlist, "close") != NULL)) { printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown process name: %s", args); return; } if (g_hash_table_lookup(optlist, "close") != NULL) { /* forcibly close the process */ process_destroy(rec, -1); return; } if (signum != -1) { /* send a signal to process */ kill(rec->pid, signum); return; } interactive = g_hash_table_lookup(optlist, "interactive") != NULL; if (*args == '%') { /* do something to already existing process */ char *name; if (target != NULL) { /* redirect output to target */ g_free_and_null(rec->target); rec->target = g_strdup(target); rec->notice = notice; } name = g_hash_table_lookup(optlist, "name"); if (name != NULL) { /* change window name */ g_free_not_null(rec->name); rec->name = *name == '\0' ? NULL : g_strdup(name); } else if (target == NULL && (rec->target_item == NULL || interactive)) { /* no parameters given, redirect output to the active window */ g_free_and_null(rec->target); rec->target_win = active_win; if (rec->target_item != NULL) exec_wi_destroy(rec->target_item); if (interactive) { rec->target_item = exec_wi_create(active_win, rec); } } return; } /* starting a new process */ rec = g_new0(PROCESS_REC, 1); rec->pid = -1; rec->shell = g_hash_table_lookup(optlist, "nosh") == NULL; process_exec(rec, args); if (rec->pid == -1) { /* pipe() or fork() failed */ g_free(rec); cmd_return_error(CMDERR_ERRNO); } rec->id = process_get_new_id(); rec->target = g_strdup(target); rec->target_win = active_win; rec->target_channel = target_channel; rec->target_nick = target_nick; rec->args = g_strdup(args); rec->notice = notice; rec->silent = g_hash_table_lookup(optlist, "-") != NULL; rec->quiet = g_hash_table_lookup(optlist, "quiet") != NULL; rec->name = g_strdup(g_hash_table_lookup(optlist, "name")); level = g_hash_table_lookup(optlist, "level"); rec->level = level == NULL ? MSGLEVEL_CLIENTCRAP : level2bits(level); rec->read_tag = g_input_add(rec->in, G_INPUT_READ, (GInputFunction) sig_exec_input_reader, rec); processes = g_slist_append(processes, rec); if (rec->target == NULL && interactive) rec->target_item = exec_wi_create(active_win, rec); signal_emit("exec new", 1, rec); }
static void signal_query_created_curwin(QUERY_REC *query) { g_return_if_fail(IS_QUERY(query)); window_item_add(active_win, (WI_ITEM_REC *) query, FALSE); }
/* nickname of whomever you are QUERYing */ static char *expando_query(SERVER_REC *server, void *item, int *free_ret) { return !IS_QUERY(item) ? "" : QUERY(item)->name; }
/* redraw channel */ static void statusbar_channel(SBAR_ITEM_REC *item, int ypos) { WINDOW_REC *window; WI_ITEM_REC *witem; CHANNEL_REC *channel; SERVER_REC *server; gchar channame[21], winnum[MAX_INT_STRLEN], *tmpname; int size_needed; int mode_size; window = item->bar->pos != STATUSBAR_POS_MIDDLE ? active_win : mainwindow_find_sbar(item); server = window == NULL ? NULL : window->active_server; ltoa(winnum, window == NULL ? 0 : window->refnum); witem = window != NULL && (IS_CHANNEL(window->active) || IS_QUERY(window->active)) ? window->active : NULL; if (witem == NULL) { /* display server tag */ channame[0] = '\0'; mode_size = 0; channel = NULL; size_needed = 3 + strlen(winnum) + (server == NULL ? 0 : (17+strlen(server->tag))); } else { /* display channel + mode */ tmpname = show_lowascii(witem->name); strncpy(channame, tmpname, 20); channame[20] = '\0'; g_free(tmpname); channel = CHANNEL(witem); if (channel == NULL) { mode_size = 0; } else { mode_size = strlen(channel->mode); if (mode_size > 0) mode_size += 3; /* (+) */ } size_needed = 3 + strlen(winnum) + strlen(channame) + mode_size; } if (item->size != size_needed) { /* we need more (or less..) space! */ statusbar_item_resize(item, size_needed); return; } move(ypos, item->xpos); set_color(stdscr, sbar_color_dim); addch('['); /* window number */ set_color(stdscr, sbar_color_normal); addstr(winnum); set_color(stdscr, sbar_color_dim); addch(':'); if (channame[0] == '\0' && server != NULL) { /* server tag */ set_color(stdscr, sbar_color_normal); addstr(server->tag); addstr(" (change with ^X)"); } else if (channame[0] != '\0') { /* channel + mode */ set_color(stdscr, sbar_color_normal); addstr(channame); if (mode_size) { set_color(stdscr, sbar_color_bold); addch('('); set_color(stdscr, sbar_color_dim); addch('+'); set_color(stdscr, sbar_color_normal); addstr(channel->mode); set_color(stdscr, sbar_color_bold); addch(')'); } } set_color(stdscr, sbar_color_dim); addch(']'); screen_refresh(NULL); }