1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00
profanity/src/command/cmd_ac.c

3037 lines
98 KiB
C
Raw Normal View History

2016-05-19 19:19:03 -04:00
/*
2016-05-22 19:06:01 -04:00
* cmd_ac.c
2016-05-19 19:19:03 -04:00
*
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2016-07-23 20:14:49 -04:00
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
2016-05-19 19:19:03 -04:00
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
*/
#define _GNU_SOURCE 1
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <libgen.h>
2016-05-22 18:59:52 -04:00
#include <dirent.h>
2016-05-19 19:19:03 -04:00
#include "common.h"
#include "config/preferences.h"
#include "config/scripts.h"
2016-07-24 10:43:51 -04:00
#include "command/cmd_ac.h"
#include "command/cmd_funcs.h"
#include "tools/parser.h"
#include "plugins/plugins.h"
#include "ui/win_types.h"
#include "ui/window_list.h"
2016-07-24 10:02:43 -04:00
#include "xmpp/muc.h"
2016-05-19 19:19:03 -04:00
#include "xmpp/xmpp.h"
2016-07-24 10:08:47 -04:00
#include "xmpp/roster_list.h"
2016-05-19 19:19:03 -04:00
#ifdef HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif
2016-07-12 18:50:21 -04:00
static char* _complete_filepath(const char *const input, char *const startstr);
2016-05-19 19:19:03 -04:00
static char* _sub_autocomplete(ProfWin *window, const char *const input);
static char* _notify_autocomplete(ProfWin *window, const char *const input);
static char* _theme_autocomplete(ProfWin *window, const char *const input);
static char* _autoaway_autocomplete(ProfWin *window, const char *const input);
static char* _autoconnect_autocomplete(ProfWin *window, const char *const input);
static char* _account_autocomplete(ProfWin *window, const char *const input);
static char* _who_autocomplete(ProfWin *window, const char *const input);
static char* _roster_autocomplete(ProfWin *window, const char *const input);
static char* _group_autocomplete(ProfWin *window, const char *const input);
static char* _bookmark_autocomplete(ProfWin *window, const char *const input);
static char* _otr_autocomplete(ProfWin *window, const char *const input);
static char* _pgp_autocomplete(ProfWin *window, const char *const input);
static char* _connect_autocomplete(ProfWin *window, const char *const input);
static char* _alias_autocomplete(ProfWin *window, const char *const input);
static char* _join_autocomplete(ProfWin *window, const char *const input);
static char* _log_autocomplete(ProfWin *window, const char *const input);
static char* _form_autocomplete(ProfWin *window, const char *const input);
static char* _form_field_autocomplete(ProfWin *window, const char *const input);
static char* _occupants_autocomplete(ProfWin *window, const char *const input);
static char* _kick_autocomplete(ProfWin *window, const char *const input);
static char* _ban_autocomplete(ProfWin *window, const char *const input);
static char* _affiliation_autocomplete(ProfWin *window, const char *const input);
static char* _role_autocomplete(ProfWin *window, const char *const input);
static char* _resource_autocomplete(ProfWin *window, const char *const input);
static char* _titlebar_autocomplete(ProfWin *window, const char *const input);
static char* _inpblock_autocomplete(ProfWin *window, const char *const input);
static char* _time_autocomplete(ProfWin *window, const char *const input);
static char* _receipts_autocomplete(ProfWin *window, const char *const input);
static char* _help_autocomplete(ProfWin *window, const char *const input);
static char* _wins_autocomplete(ProfWin *window, const char *const input);
static char* _tls_autocomplete(ProfWin *window, const char *const input);
static char* _script_autocomplete(ProfWin *window, const char *const input);
static char* _subject_autocomplete(ProfWin *window, const char *const input);
static char* _console_autocomplete(ProfWin *window, const char *const input);
static char* _win_autocomplete(ProfWin *window, const char *const input);
static char* _close_autocomplete(ProfWin *window, const char *const input);
static char* _plugins_autocomplete(ProfWin *window, const char *const input);
static char* _sendfile_autocomplete(ProfWin *window, const char *const input);
static char* _blocked_autocomplete(ProfWin *window, const char *const input);
2016-05-31 17:46:03 -04:00
static char* _tray_autocomplete(ProfWin *window, const char *const input);
static char* _presence_autocomplete(ProfWin *window, const char *const input);
2016-05-19 19:19:03 -04:00
static char* _script_autocomplete_func(const char *const prefix);
static char* _cmd_ac_complete_params(ProfWin *window, const char *const input);
static Autocomplete commands_ac;
static Autocomplete who_room_ac;
static Autocomplete who_roster_ac;
static Autocomplete help_ac;
static Autocomplete help_commands_ac;
static Autocomplete notify_ac;
static Autocomplete notify_chat_ac;
static Autocomplete notify_room_ac;
static Autocomplete notify_typing_ac;
static Autocomplete notify_mention_ac;
static Autocomplete notify_trigger_ac;
static Autocomplete prefs_ac;
static Autocomplete sub_ac;
static Autocomplete log_ac;
static Autocomplete autoaway_ac;
static Autocomplete autoaway_mode_ac;
static Autocomplete autoaway_presence_ac;
static Autocomplete autoconnect_ac;
static Autocomplete titlebar_ac;
static Autocomplete theme_ac;
static Autocomplete theme_load_ac;
static Autocomplete account_ac;
static Autocomplete account_set_ac;
static Autocomplete account_clear_ac;
static Autocomplete account_default_ac;
static Autocomplete account_status_ac;
static Autocomplete disco_ac;
static Autocomplete wins_ac;
static Autocomplete roster_ac;
static Autocomplete roster_show_ac;
static Autocomplete roster_by_ac;
static Autocomplete roster_count_ac;
static Autocomplete roster_order_ac;
static Autocomplete roster_header_ac;
static Autocomplete roster_contact_ac;
static Autocomplete roster_resource_ac;
static Autocomplete roster_presence_ac;
static Autocomplete roster_char_ac;
static Autocomplete roster_remove_all_ac;
static Autocomplete roster_room_ac;
static Autocomplete roster_room_position_ac;
static Autocomplete roster_room_by_ac;
static Autocomplete roster_room_order_ac;
static Autocomplete roster_unread_ac;
static Autocomplete roster_private_ac;
static Autocomplete group_ac;
static Autocomplete bookmark_ac;
static Autocomplete bookmark_property_ac;
static Autocomplete otr_ac;
static Autocomplete otr_log_ac;
static Autocomplete otr_policy_ac;
static Autocomplete connect_property_ac;
static Autocomplete tls_property_ac;
static Autocomplete alias_ac;
static Autocomplete aliases_ac;
static Autocomplete join_property_ac;
static Autocomplete room_ac;
static Autocomplete affiliation_ac;
static Autocomplete role_ac;
static Autocomplete privilege_cmd_ac;
static Autocomplete subject_ac;
static Autocomplete form_ac;
static Autocomplete form_field_multi_ac;
static Autocomplete occupants_ac;
static Autocomplete occupants_default_ac;
static Autocomplete occupants_show_ac;
static Autocomplete time_ac;
static Autocomplete time_format_ac;
static Autocomplete resource_ac;
static Autocomplete inpblock_ac;
static Autocomplete receipts_ac;
static Autocomplete pgp_ac;
static Autocomplete pgp_log_ac;
static Autocomplete tls_ac;
static Autocomplete tls_certpath_ac;
static Autocomplete script_ac;
static Autocomplete script_show_ac;
static Autocomplete console_ac;
static Autocomplete console_msg_ac;
static Autocomplete autoping_ac;
static Autocomplete plugins_ac;
static Autocomplete plugins_load_ac;
2016-06-30 18:14:05 -04:00
static Autocomplete plugins_unload_ac;
2016-07-09 20:07:41 -04:00
static Autocomplete plugins_reload_ac;
2016-07-12 18:50:21 -04:00
static Autocomplete filepath_ac;
2016-05-19 19:19:03 -04:00
static Autocomplete blocked_ac;
static Autocomplete tray_ac;
2016-05-31 17:46:03 -04:00
static Autocomplete presence_ac;
static Autocomplete presence_setting_ac;
2016-05-19 19:19:03 -04:00
void
cmd_ac_init(void)
{
commands_ac = autocomplete_new();
aliases_ac = autocomplete_new();
help_ac = autocomplete_new();
autocomplete_add(help_ac, "commands");
autocomplete_add(help_ac, "navigation");
help_commands_ac = autocomplete_new();
autocomplete_add(help_commands_ac, "chat");
autocomplete_add(help_commands_ac, "groupchat");
autocomplete_add(help_commands_ac, "roster");
autocomplete_add(help_commands_ac, "presence");
autocomplete_add(help_commands_ac, "discovery");
autocomplete_add(help_commands_ac, "connection");
autocomplete_add(help_commands_ac, "ui");
autocomplete_add(help_commands_ac, "plugins");
prefs_ac = autocomplete_new();
autocomplete_add(prefs_ac, "ui");
autocomplete_add(prefs_ac, "desktop");
autocomplete_add(prefs_ac, "chat");
autocomplete_add(prefs_ac, "log");
autocomplete_add(prefs_ac, "conn");
autocomplete_add(prefs_ac, "presence");
autocomplete_add(prefs_ac, "otr");
autocomplete_add(prefs_ac, "pgp");
notify_ac = autocomplete_new();
autocomplete_add(notify_ac, "chat");
autocomplete_add(notify_ac, "room");
autocomplete_add(notify_ac, "typing");
autocomplete_add(notify_ac, "remind");
autocomplete_add(notify_ac, "invite");
autocomplete_add(notify_ac, "sub");
autocomplete_add(notify_ac, "on");
autocomplete_add(notify_ac, "off");
autocomplete_add(notify_ac, "mention");
autocomplete_add(notify_ac, "trigger");
autocomplete_add(notify_ac, "reset");
notify_chat_ac = autocomplete_new();
autocomplete_add(notify_chat_ac, "on");
autocomplete_add(notify_chat_ac, "off");
autocomplete_add(notify_chat_ac, "current");
autocomplete_add(notify_chat_ac, "text");
notify_room_ac = autocomplete_new();
autocomplete_add(notify_room_ac, "on");
autocomplete_add(notify_room_ac, "off");
autocomplete_add(notify_room_ac, "mention");
autocomplete_add(notify_room_ac, "current");
autocomplete_add(notify_room_ac, "text");
autocomplete_add(notify_room_ac, "trigger");
notify_typing_ac = autocomplete_new();
autocomplete_add(notify_typing_ac, "on");
autocomplete_add(notify_typing_ac, "off");
autocomplete_add(notify_typing_ac, "current");
notify_mention_ac = autocomplete_new();
autocomplete_add(notify_mention_ac, "on");
autocomplete_add(notify_mention_ac, "off");
autocomplete_add(notify_mention_ac, "case_sensitive");
autocomplete_add(notify_mention_ac, "case_insensitive");
autocomplete_add(notify_mention_ac, "word_whole");
autocomplete_add(notify_mention_ac, "word_part");
notify_trigger_ac = autocomplete_new();
autocomplete_add(notify_trigger_ac, "add");
autocomplete_add(notify_trigger_ac, "remove");
autocomplete_add(notify_trigger_ac, "list");
autocomplete_add(notify_trigger_ac, "on");
autocomplete_add(notify_trigger_ac, "off");
sub_ac = autocomplete_new();
autocomplete_add(sub_ac, "request");
autocomplete_add(sub_ac, "allow");
autocomplete_add(sub_ac, "deny");
autocomplete_add(sub_ac, "show");
autocomplete_add(sub_ac, "sent");
autocomplete_add(sub_ac, "received");
titlebar_ac = autocomplete_new();
autocomplete_add(titlebar_ac, "show");
autocomplete_add(titlebar_ac, "goodbye");
log_ac = autocomplete_new();
autocomplete_add(log_ac, "maxsize");
autocomplete_add(log_ac, "rotate");
autocomplete_add(log_ac, "shared");
autocomplete_add(log_ac, "where");
autoaway_ac = autocomplete_new();
autocomplete_add(autoaway_ac, "mode");
autocomplete_add(autoaway_ac, "time");
autocomplete_add(autoaway_ac, "message");
autocomplete_add(autoaway_ac, "check");
autoaway_mode_ac = autocomplete_new();
autocomplete_add(autoaway_mode_ac, "away");
autocomplete_add(autoaway_mode_ac, "idle");
autocomplete_add(autoaway_mode_ac, "off");
autoaway_presence_ac = autocomplete_new();
autocomplete_add(autoaway_presence_ac, "away");
autocomplete_add(autoaway_presence_ac, "xa");
autoconnect_ac = autocomplete_new();
autocomplete_add(autoconnect_ac, "set");
autocomplete_add(autoconnect_ac, "off");
theme_ac = autocomplete_new();
autocomplete_add(theme_ac, "load");
autocomplete_add(theme_ac, "list");
autocomplete_add(theme_ac, "colours");
autocomplete_add(theme_ac, "properties");
disco_ac = autocomplete_new();
autocomplete_add(disco_ac, "info");
autocomplete_add(disco_ac, "items");
account_ac = autocomplete_new();
autocomplete_add(account_ac, "list");
autocomplete_add(account_ac, "show");
autocomplete_add(account_ac, "add");
autocomplete_add(account_ac, "remove");
autocomplete_add(account_ac, "enable");
autocomplete_add(account_ac, "disable");
autocomplete_add(account_ac, "default");
autocomplete_add(account_ac, "rename");
autocomplete_add(account_ac, "set");
autocomplete_add(account_ac, "clear");
account_set_ac = autocomplete_new();
autocomplete_add(account_set_ac, "jid");
autocomplete_add(account_set_ac, "server");
autocomplete_add(account_set_ac, "port");
autocomplete_add(account_set_ac, "status");
autocomplete_add(account_set_ac, "online");
autocomplete_add(account_set_ac, "chat");
autocomplete_add(account_set_ac, "away");
autocomplete_add(account_set_ac, "xa");
autocomplete_add(account_set_ac, "dnd");
autocomplete_add(account_set_ac, "resource");
autocomplete_add(account_set_ac, "password");
autocomplete_add(account_set_ac, "eval_password");
autocomplete_add(account_set_ac, "muc");
autocomplete_add(account_set_ac, "nick");
autocomplete_add(account_set_ac, "otr");
autocomplete_add(account_set_ac, "pgpkeyid");
autocomplete_add(account_set_ac, "startscript");
autocomplete_add(account_set_ac, "tls");
autocomplete_add(account_set_ac, "theme");
account_clear_ac = autocomplete_new();
autocomplete_add(account_clear_ac, "password");
autocomplete_add(account_clear_ac, "eval_password");
autocomplete_add(account_clear_ac, "server");
autocomplete_add(account_clear_ac, "port");
autocomplete_add(account_clear_ac, "otr");
autocomplete_add(account_clear_ac, "pgpkeyid");
autocomplete_add(account_clear_ac, "startscript");
autocomplete_add(account_clear_ac, "theme");
account_default_ac = autocomplete_new();
autocomplete_add(account_default_ac, "set");
autocomplete_add(account_default_ac, "off");
account_status_ac = autocomplete_new();
autocomplete_add(account_status_ac, "online");
autocomplete_add(account_status_ac, "chat");
autocomplete_add(account_status_ac, "away");
autocomplete_add(account_status_ac, "xa");
autocomplete_add(account_status_ac, "dnd");
autocomplete_add(account_status_ac, "last");
wins_ac = autocomplete_new();
autocomplete_add(wins_ac, "unread");
autocomplete_add(wins_ac, "prune");
autocomplete_add(wins_ac, "tidy");
autocomplete_add(wins_ac, "autotidy");
autocomplete_add(wins_ac, "swap");
roster_ac = autocomplete_new();
autocomplete_add(roster_ac, "add");
autocomplete_add(roster_ac, "online");
autocomplete_add(roster_ac, "nick");
autocomplete_add(roster_ac, "clearnick");
autocomplete_add(roster_ac, "remove");
autocomplete_add(roster_ac, "remove_all");
autocomplete_add(roster_ac, "show");
autocomplete_add(roster_ac, "hide");
autocomplete_add(roster_ac, "by");
autocomplete_add(roster_ac, "count");
autocomplete_add(roster_ac, "order");
autocomplete_add(roster_ac, "unread");
autocomplete_add(roster_ac, "room");
autocomplete_add(roster_ac, "size");
autocomplete_add(roster_ac, "wrap");
autocomplete_add(roster_ac, "header");
autocomplete_add(roster_ac, "contact");
autocomplete_add(roster_ac, "resource");
autocomplete_add(roster_ac, "presence");
autocomplete_add(roster_ac, "private");
roster_private_ac = autocomplete_new();
autocomplete_add(roster_private_ac, "room");
autocomplete_add(roster_private_ac, "group");
autocomplete_add(roster_private_ac, "off");
autocomplete_add(roster_private_ac, "char");
roster_header_ac = autocomplete_new();
autocomplete_add(roster_header_ac, "char");
roster_contact_ac = autocomplete_new();
autocomplete_add(roster_contact_ac, "char");
autocomplete_add(roster_contact_ac, "indent");
roster_resource_ac = autocomplete_new();
autocomplete_add(roster_resource_ac, "char");
autocomplete_add(roster_resource_ac, "indent");
autocomplete_add(roster_resource_ac, "join");
roster_presence_ac = autocomplete_new();
autocomplete_add(roster_presence_ac, "indent");
roster_char_ac = autocomplete_new();
autocomplete_add(roster_char_ac, "none");
roster_show_ac = autocomplete_new();
autocomplete_add(roster_show_ac, "offline");
autocomplete_add(roster_show_ac, "resource");
autocomplete_add(roster_show_ac, "presence");
autocomplete_add(roster_show_ac, "status");
autocomplete_add(roster_show_ac, "empty");
autocomplete_add(roster_show_ac, "priority");
autocomplete_add(roster_show_ac, "contacts");
autocomplete_add(roster_show_ac, "unsubscribed");
autocomplete_add(roster_show_ac, "rooms");
roster_by_ac = autocomplete_new();
autocomplete_add(roster_by_ac, "group");
autocomplete_add(roster_by_ac, "presence");
autocomplete_add(roster_by_ac, "none");
roster_count_ac = autocomplete_new();
autocomplete_add(roster_count_ac, "unread");
autocomplete_add(roster_count_ac, "items");
autocomplete_add(roster_count_ac, "off");
autocomplete_add(roster_count_ac, "zero");
roster_order_ac = autocomplete_new();
autocomplete_add(roster_order_ac, "name");
autocomplete_add(roster_order_ac, "presence");
roster_unread_ac = autocomplete_new();
autocomplete_add(roster_unread_ac, "before");
autocomplete_add(roster_unread_ac, "after");
autocomplete_add(roster_unread_ac, "off");
roster_room_ac = autocomplete_new();
autocomplete_add(roster_room_ac, "char");
autocomplete_add(roster_room_ac, "position");
autocomplete_add(roster_room_ac, "by");
autocomplete_add(roster_room_ac, "order");
autocomplete_add(roster_room_ac, "unread");
autocomplete_add(roster_room_ac, "private");
roster_room_by_ac = autocomplete_new();
autocomplete_add(roster_room_by_ac, "service");
autocomplete_add(roster_room_by_ac, "none");
roster_room_order_ac = autocomplete_new();
autocomplete_add(roster_room_order_ac, "name");
autocomplete_add(roster_room_order_ac, "unread");
roster_room_position_ac = autocomplete_new();
autocomplete_add(roster_room_position_ac, "first");
autocomplete_add(roster_room_position_ac, "last");
roster_remove_all_ac = autocomplete_new();
autocomplete_add(roster_remove_all_ac, "contacts");
group_ac = autocomplete_new();
autocomplete_add(group_ac, "show");
autocomplete_add(group_ac, "add");
autocomplete_add(group_ac, "remove");
theme_load_ac = NULL;
plugins_load_ac = NULL;
2016-06-30 18:14:05 -04:00
plugins_unload_ac = NULL;
2016-07-09 20:07:41 -04:00
plugins_reload_ac = NULL;
2016-05-19 19:19:03 -04:00
who_roster_ac = autocomplete_new();
autocomplete_add(who_roster_ac, "chat");
autocomplete_add(who_roster_ac, "online");
autocomplete_add(who_roster_ac, "away");
autocomplete_add(who_roster_ac, "xa");
autocomplete_add(who_roster_ac, "dnd");
autocomplete_add(who_roster_ac, "offline");
autocomplete_add(who_roster_ac, "available");
autocomplete_add(who_roster_ac, "unavailable");
autocomplete_add(who_roster_ac, "any");
who_room_ac = autocomplete_new();
autocomplete_add(who_room_ac, "chat");
autocomplete_add(who_room_ac, "online");
autocomplete_add(who_room_ac, "away");
autocomplete_add(who_room_ac, "xa");
autocomplete_add(who_room_ac, "dnd");
autocomplete_add(who_room_ac, "available");
autocomplete_add(who_room_ac, "unavailable");
autocomplete_add(who_room_ac, "moderator");
autocomplete_add(who_room_ac, "participant");
autocomplete_add(who_room_ac, "visitor");
autocomplete_add(who_room_ac, "owner");
autocomplete_add(who_room_ac, "admin");
autocomplete_add(who_room_ac, "member");
bookmark_ac = autocomplete_new();
autocomplete_add(bookmark_ac, "list");
autocomplete_add(bookmark_ac, "add");
autocomplete_add(bookmark_ac, "update");
autocomplete_add(bookmark_ac, "remove");
autocomplete_add(bookmark_ac, "join");
autocomplete_add(bookmark_ac, "invites");
2016-05-19 19:19:03 -04:00
bookmark_property_ac = autocomplete_new();
autocomplete_add(bookmark_property_ac, "nick");
autocomplete_add(bookmark_property_ac, "password");
autocomplete_add(bookmark_property_ac, "autojoin");
otr_ac = autocomplete_new();
autocomplete_add(otr_ac, "gen");
autocomplete_add(otr_ac, "start");
autocomplete_add(otr_ac, "end");
autocomplete_add(otr_ac, "myfp");
autocomplete_add(otr_ac, "theirfp");
autocomplete_add(otr_ac, "trust");
autocomplete_add(otr_ac, "untrust");
autocomplete_add(otr_ac, "secret");
autocomplete_add(otr_ac, "log");
autocomplete_add(otr_ac, "libver");
autocomplete_add(otr_ac, "policy");
autocomplete_add(otr_ac, "question");
autocomplete_add(otr_ac, "answer");
autocomplete_add(otr_ac, "char");
otr_log_ac = autocomplete_new();
autocomplete_add(otr_log_ac, "on");
autocomplete_add(otr_log_ac, "off");
autocomplete_add(otr_log_ac, "redact");
otr_policy_ac = autocomplete_new();
autocomplete_add(otr_policy_ac, "manual");
autocomplete_add(otr_policy_ac, "opportunistic");
autocomplete_add(otr_policy_ac, "always");
connect_property_ac = autocomplete_new();
autocomplete_add(connect_property_ac, "server");
autocomplete_add(connect_property_ac, "port");
autocomplete_add(connect_property_ac, "tls");
tls_property_ac = autocomplete_new();
autocomplete_add(tls_property_ac, "force");
autocomplete_add(tls_property_ac, "allow");
autocomplete_add(tls_property_ac, "disable");
join_property_ac = autocomplete_new();
autocomplete_add(join_property_ac, "nick");
autocomplete_add(join_property_ac, "password");
alias_ac = autocomplete_new();
autocomplete_add(alias_ac, "add");
autocomplete_add(alias_ac, "remove");
autocomplete_add(alias_ac, "list");
room_ac = autocomplete_new();
autocomplete_add(room_ac, "accept");
autocomplete_add(room_ac, "destroy");
autocomplete_add(room_ac, "config");
affiliation_ac = autocomplete_new();
autocomplete_add(affiliation_ac, "owner");
autocomplete_add(affiliation_ac, "admin");
autocomplete_add(affiliation_ac, "member");
autocomplete_add(affiliation_ac, "none");
autocomplete_add(affiliation_ac, "outcast");
role_ac = autocomplete_new();
autocomplete_add(role_ac, "moderator");
autocomplete_add(role_ac, "participant");
autocomplete_add(role_ac, "visitor");
autocomplete_add(role_ac, "none");
privilege_cmd_ac = autocomplete_new();
autocomplete_add(privilege_cmd_ac, "list");
autocomplete_add(privilege_cmd_ac, "set");
subject_ac = autocomplete_new();
autocomplete_add(subject_ac, "set");
autocomplete_add(subject_ac, "edit");
autocomplete_add(subject_ac, "prepend");
autocomplete_add(subject_ac, "append");
autocomplete_add(subject_ac, "clear");
form_ac = autocomplete_new();
autocomplete_add(form_ac, "submit");
autocomplete_add(form_ac, "cancel");
autocomplete_add(form_ac, "show");
autocomplete_add(form_ac, "help");
form_field_multi_ac = autocomplete_new();
autocomplete_add(form_field_multi_ac, "add");
autocomplete_add(form_field_multi_ac, "remove");
occupants_ac = autocomplete_new();
autocomplete_add(occupants_ac, "show");
autocomplete_add(occupants_ac, "hide");
autocomplete_add(occupants_ac, "default");
autocomplete_add(occupants_ac, "size");
occupants_default_ac = autocomplete_new();
autocomplete_add(occupants_default_ac, "show");
autocomplete_add(occupants_default_ac, "hide");
occupants_show_ac = autocomplete_new();
autocomplete_add(occupants_show_ac, "jid");
time_ac = autocomplete_new();
autocomplete_add(time_ac, "console");
autocomplete_add(time_ac, "chat");
autocomplete_add(time_ac, "muc");
autocomplete_add(time_ac, "mucconfig");
autocomplete_add(time_ac, "private");
autocomplete_add(time_ac, "xml");
autocomplete_add(time_ac, "statusbar");
autocomplete_add(time_ac, "lastactivity");
time_format_ac = autocomplete_new();
autocomplete_add(time_format_ac, "set");
autocomplete_add(time_format_ac, "off");
resource_ac = autocomplete_new();
autocomplete_add(resource_ac, "set");
autocomplete_add(resource_ac, "off");
autocomplete_add(resource_ac, "title");
autocomplete_add(resource_ac, "message");
inpblock_ac = autocomplete_new();
autocomplete_add(inpblock_ac, "timeout");
autocomplete_add(inpblock_ac, "dynamic");
receipts_ac = autocomplete_new();
autocomplete_add(receipts_ac, "send");
autocomplete_add(receipts_ac, "request");
pgp_ac = autocomplete_new();
autocomplete_add(pgp_ac, "keys");
autocomplete_add(pgp_ac, "contacts");
autocomplete_add(pgp_ac, "setkey");
autocomplete_add(pgp_ac, "libver");
autocomplete_add(pgp_ac, "start");
autocomplete_add(pgp_ac, "end");
autocomplete_add(pgp_ac, "log");
autocomplete_add(pgp_ac, "char");
pgp_log_ac = autocomplete_new();
autocomplete_add(pgp_log_ac, "on");
autocomplete_add(pgp_log_ac, "off");
autocomplete_add(pgp_log_ac, "redact");
tls_ac = autocomplete_new();
autocomplete_add(tls_ac, "allow");
autocomplete_add(tls_ac, "always");
autocomplete_add(tls_ac, "deny");
autocomplete_add(tls_ac, "cert");
autocomplete_add(tls_ac, "trust");
autocomplete_add(tls_ac, "trusted");
autocomplete_add(tls_ac, "revoke");
autocomplete_add(tls_ac, "certpath");
autocomplete_add(tls_ac, "show");
tls_certpath_ac = autocomplete_new();
autocomplete_add(tls_certpath_ac, "set");
autocomplete_add(tls_certpath_ac, "clear");
script_ac = autocomplete_new();
autocomplete_add(script_ac, "run");
autocomplete_add(script_ac, "list");
autocomplete_add(script_ac, "show");
script_show_ac = NULL;
console_ac = autocomplete_new();
autocomplete_add(console_ac, "chat");
autocomplete_add(console_ac, "muc");
autocomplete_add(console_ac, "private");
console_msg_ac = autocomplete_new();
autocomplete_add(console_msg_ac, "all");
autocomplete_add(console_msg_ac, "first");
autocomplete_add(console_msg_ac, "none");
autoping_ac = autocomplete_new();
autocomplete_add(autoping_ac, "set");
autocomplete_add(autoping_ac, "timeout");
plugins_ac = autocomplete_new();
2016-07-12 18:50:21 -04:00
autocomplete_add(plugins_ac, "install");
2016-05-19 19:19:03 -04:00
autocomplete_add(plugins_ac, "load");
2016-06-30 18:14:05 -04:00
autocomplete_add(plugins_ac, "unload");
2016-07-09 20:07:41 -04:00
autocomplete_add(plugins_ac, "reload");
2016-07-23 21:12:56 -04:00
autocomplete_add(plugins_ac, "python_version");
2016-05-19 19:19:03 -04:00
2016-07-12 18:50:21 -04:00
filepath_ac = autocomplete_new();
2016-05-19 19:19:03 -04:00
blocked_ac = autocomplete_new();
autocomplete_add(blocked_ac, "add");
autocomplete_add(blocked_ac, "remove");
tray_ac = autocomplete_new();
autocomplete_add(tray_ac, "on");
autocomplete_add(tray_ac, "off");
autocomplete_add(tray_ac, "read");
autocomplete_add(tray_ac, "timer");
2016-05-31 17:46:03 -04:00
presence_ac = autocomplete_new();
autocomplete_add(presence_ac, "titlebar");
autocomplete_add(presence_ac, "console");
autocomplete_add(presence_ac, "chat");
autocomplete_add(presence_ac, "room");
presence_setting_ac = autocomplete_new();
autocomplete_add(presence_setting_ac, "all");
autocomplete_add(presence_setting_ac, "online");
autocomplete_add(presence_setting_ac, "none");
2016-05-19 19:19:03 -04:00
}
void
cmd_ac_add(const char *const value)
{
if (commands_ac) {
autocomplete_add(commands_ac, value);
}
}
void
cmd_ac_add_help(const char *const value)
{
if (help_ac) {
autocomplete_add(help_ac, value);
}
}
void
cmd_ac_add_cmd(Command *command)
{
autocomplete_add(commands_ac, command->cmd);
autocomplete_add(help_ac, command->cmd+1);
}
void
cmd_ac_add_alias(ProfAlias *alias)
{
GString *ac_alias = g_string_new("/");
g_string_append(ac_alias, alias->name);
autocomplete_add(commands_ac, ac_alias->str);
autocomplete_add(aliases_ac, alias->name);
g_string_free(ac_alias, TRUE);
}
void
cmd_ac_add_alias_value(char *value)
{
if (aliases_ac) {
autocomplete_add(aliases_ac, value);
}
}
void
cmd_ac_remove_alias_value(char *value)
{
if (aliases_ac) {
autocomplete_remove(aliases_ac, value);
}
}
void
cmd_ac_remove(const char *const value)
{
if (commands_ac) {
autocomplete_remove(commands_ac, value);
}
}
void
cmd_ac_remove_help(const char *const value)
{
if (help_ac) {
autocomplete_remove(help_ac, value);
}
}
2016-05-19 19:19:03 -04:00
gboolean
cmd_ac_exists(char *cmd)
{
if (commands_ac == NULL) {
return FALSE;
} else {
return autocomplete_contains(commands_ac, cmd);
}
}
void
cmd_ac_add_form_fields(DataForm *form)
{
if (form == NULL) {
return;
}
GSList *fields = autocomplete_create_list(form->tag_ac);
GSList *curr_field = fields;
while (curr_field) {
GString *field_str = g_string_new("/");
g_string_append(field_str, curr_field->data);
cmd_ac_add(field_str->str);
g_string_free(field_str, TRUE);
curr_field = g_slist_next(curr_field);
}
g_slist_free_full(fields, free);
}
void
cmd_ac_remove_form_fields(DataForm *form)
{
if (form == NULL) {
return;
}
GSList *fields = autocomplete_create_list(form->tag_ac);
GSList *curr_field = fields;
while (curr_field) {
GString *field_str = g_string_new("/");
g_string_append(field_str, curr_field->data);
cmd_ac_remove(field_str->str);
g_string_free(field_str, TRUE);
curr_field = g_slist_next(curr_field);
}
g_slist_free_full(fields, free);
}
char*
cmd_ac_complete(ProfWin *window, const char *const input)
{
// autocomplete command
if ((strncmp(input, "/", 1) == 0) && (!str_contains(input, strlen(input), ' '))) {
char *found = NULL;
found = autocomplete_complete(commands_ac, input, TRUE);
if (found) {
return found;
}
// autocomplete parameters
} else {
char *found = _cmd_ac_complete_params(window, input);
if (found) {
return found;
}
}
return NULL;
}
void
cmd_ac_reset(ProfWin *window)
{
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
roster_reset_search_attempts();
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
PContact contact = roster_get_contact(chatwin->barejid);
if (contact) {
p_contact_resource_ac_reset(contact);
}
}
}
muc_invites_reset_ac();
accounts_reset_all_search();
accounts_reset_enabled_search();
tlscerts_reset_ac();
prefs_reset_boolean_choice();
presence_reset_sub_request_search();
#ifdef HAVE_LIBGPGME
p_gpg_autocomplete_key_reset();
#endif
autocomplete_reset(help_ac);
autocomplete_reset(help_commands_ac);
autocomplete_reset(notify_ac);
autocomplete_reset(notify_chat_ac);
autocomplete_reset(notify_room_ac);
autocomplete_reset(notify_typing_ac);
autocomplete_reset(notify_mention_ac);
autocomplete_reset(notify_trigger_ac);
autocomplete_reset(sub_ac);
2016-07-12 18:50:21 -04:00
autocomplete_reset(filepath_ac);
2016-05-19 19:19:03 -04:00
autocomplete_reset(who_room_ac);
autocomplete_reset(who_roster_ac);
autocomplete_reset(prefs_ac);
autocomplete_reset(log_ac);
autocomplete_reset(commands_ac);
autocomplete_reset(autoaway_ac);
autocomplete_reset(autoaway_mode_ac);
autocomplete_reset(autoaway_presence_ac);
autocomplete_reset(autoconnect_ac);
autocomplete_reset(theme_ac);
if (theme_load_ac) {
autocomplete_free(theme_load_ac);
theme_load_ac = NULL;
}
if (plugins_load_ac) {
autocomplete_free(plugins_load_ac);
plugins_load_ac = NULL;
}
2016-06-30 18:14:05 -04:00
if (plugins_unload_ac) {
autocomplete_free(plugins_unload_ac);
plugins_unload_ac = NULL;
}
2016-07-09 20:07:41 -04:00
if (plugins_reload_ac) {
autocomplete_free(plugins_reload_ac);
plugins_reload_ac = NULL;
}
2016-05-19 19:19:03 -04:00
autocomplete_reset(account_ac);
autocomplete_reset(account_set_ac);
autocomplete_reset(account_clear_ac);
autocomplete_reset(account_default_ac);
autocomplete_reset(account_status_ac);
autocomplete_reset(disco_ac);
autocomplete_reset(wins_ac);
autocomplete_reset(roster_ac);
autocomplete_reset(roster_header_ac);
autocomplete_reset(roster_contact_ac);
autocomplete_reset(roster_resource_ac);
autocomplete_reset(roster_presence_ac);
autocomplete_reset(roster_char_ac);
autocomplete_reset(roster_show_ac);
autocomplete_reset(roster_by_ac);
autocomplete_reset(roster_count_ac);
autocomplete_reset(roster_order_ac);
autocomplete_reset(roster_room_ac);
autocomplete_reset(roster_room_by_ac);
autocomplete_reset(roster_unread_ac);
autocomplete_reset(roster_room_position_ac);
autocomplete_reset(roster_room_order_ac);
autocomplete_reset(roster_remove_all_ac);
autocomplete_reset(roster_private_ac);
autocomplete_reset(group_ac);
autocomplete_reset(titlebar_ac);
autocomplete_reset(bookmark_ac);
autocomplete_reset(bookmark_property_ac);
autocomplete_reset(otr_ac);
autocomplete_reset(otr_log_ac);
autocomplete_reset(otr_policy_ac);
autocomplete_reset(connect_property_ac);
autocomplete_reset(tls_property_ac);
autocomplete_reset(alias_ac);
autocomplete_reset(aliases_ac);
autocomplete_reset(join_property_ac);
autocomplete_reset(room_ac);
autocomplete_reset(affiliation_ac);
autocomplete_reset(role_ac);
autocomplete_reset(privilege_cmd_ac);
autocomplete_reset(subject_ac);
autocomplete_reset(form_ac);
autocomplete_reset(form_field_multi_ac);
autocomplete_reset(occupants_ac);
autocomplete_reset(occupants_default_ac);
autocomplete_reset(occupants_show_ac);
autocomplete_reset(time_ac);
autocomplete_reset(time_format_ac);
autocomplete_reset(resource_ac);
autocomplete_reset(inpblock_ac);
autocomplete_reset(receipts_ac);
autocomplete_reset(pgp_ac);
autocomplete_reset(pgp_log_ac);
autocomplete_reset(tls_ac);
autocomplete_reset(tls_certpath_ac);
autocomplete_reset(console_ac);
autocomplete_reset(console_msg_ac);
autocomplete_reset(autoping_ac);
autocomplete_reset(plugins_ac);
autocomplete_reset(blocked_ac);
autocomplete_reset(tray_ac);
2016-05-31 17:46:03 -04:00
autocomplete_reset(presence_ac);
autocomplete_reset(presence_setting_ac);
2016-05-31 17:46:03 -04:00
2016-05-19 19:19:03 -04:00
autocomplete_reset(script_ac);
if (script_show_ac) {
autocomplete_free(script_show_ac);
script_show_ac = NULL;
}
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
muc_autocomplete_reset(mucwin->roomjid);
muc_jid_autocomplete_reset(mucwin->roomjid);
}
if (window->type == WIN_MUC_CONFIG) {
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
if (confwin->form) {
form_reset_autocompleters(confwin->form);
}
}
bookmark_autocomplete_reset();
blocked_ac_reset();
prefs_reset_room_trigger_ac();
win_reset_search_attempts();
win_close_reset_search_attempts();
plugins_reset_autocomplete();
}
void
cmd_ac_uninit(void)
{