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

Added /resource autocompletion

This commit is contained in:
James Booth 2014-12-04 00:16:42 +00:00
parent eeb6e6b8fc
commit 5314e59703
3 changed files with 72 additions and 1 deletions

View File

@ -95,6 +95,7 @@ static char * _kick_autocomplete(char *input, int *size);
static char * _ban_autocomplete(char *input, int *size);
static char * _affiliation_autocomplete(char *input, int *size);
static char * _role_autocomplete(char *input, int *size);
static char * _resource_autocomplete(char *input, int *size);
GHashTable *commands = NULL;
@ -1092,6 +1093,7 @@ static Autocomplete form_field_multi_ac;
static Autocomplete occupants_ac;
static Autocomplete occupants_default_ac;
static Autocomplete time_ac;
static Autocomplete resource_ac;
/*
* Initialise command autocompleter and history
@ -1426,6 +1428,14 @@ cmd_init(void)
autocomplete_add(time_ac, "seconds");
autocomplete_add(time_ac, "off");
time_ac = autocomplete_new();
autocomplete_add(time_ac, "minutes");
autocomplete_add(time_ac, "seconds");
resource_ac = autocomplete_new();
autocomplete_add(resource_ac, "set");
autocomplete_add(resource_ac, "off");
cmd_history_init();
}
@ -1480,6 +1490,7 @@ cmd_uninit(void)
autocomplete_free(occupants_ac);
autocomplete_free(occupants_default_ac);
autocomplete_free(time_ac);
autocomplete_free(resource_ac);
}
gboolean
@ -1651,6 +1662,7 @@ cmd_reset_autocomplete()
autocomplete_reset(occupants_ac);
autocomplete_reset(occupants_default_ac);
autocomplete_reset(time_ac);
autocomplete_reset(resource_ac);
if (ui_current_win_type() == WIN_MUC_CONFIG) {
ProfWin *window = wins_get_current();
@ -1659,6 +1671,14 @@ cmd_reset_autocomplete()
}
}
if (ui_current_win_type() == WIN_CHAT) {
char *recipient = ui_current_recipient();
PContact contact = roster_get_contact(recipient);
if (contact) {
p_contact_resource_ac_reset(contact);
}
}
bookmark_autocomplete_reset();
}
@ -1959,6 +1979,7 @@ _cmd_complete_parameters(char *input, int *size)
g_hash_table_insert(ac_funcs, "/ban", _ban_autocomplete);
g_hash_table_insert(ac_funcs, "/affiliation", _affiliation_autocomplete);
g_hash_table_insert(ac_funcs, "/role", _role_autocomplete);
g_hash_table_insert(ac_funcs, "/resource", _resource_autocomplete);
char parsed[*size+1];
i = 0;
@ -2405,6 +2426,32 @@ _theme_autocomplete(char *input, int *size)
return NULL;
}
static char *
_resource_autocomplete(char *input, int *size)
{
char *found = NULL;
ProfWin *current = wins_get_current();
if (current && current->type == WIN_CHAT) {
char *recipient = ui_current_recipient();
PContact contact = roster_get_contact(recipient);
if (contact) {
Autocomplete ac = p_contact_resource_ac(contact);
found = autocomplete_param_with_ac(input, size, "/resource set", ac, FALSE);
if (found != NULL) {
return found;
}
}
}
found = autocomplete_param_with_ac(input, size, "/resource", resource_ac, FALSE);
if (found != NULL) {
return found;
}
return NULL;
}
static char *
_form_autocomplete(char *input, int *size)
{

View File

@ -41,6 +41,7 @@
#include "contact.h"
#include "common.h"
#include "resource.h"
#include "tools/autocomplete.h"
struct p_contact_t {
char *barejid;
@ -51,6 +52,7 @@ struct p_contact_t {
gboolean pending_out;
GDateTime *last_activity;
GHashTable *available_resources;
Autocomplete resource_ac;
};
PContact
@ -85,6 +87,8 @@ p_contact_new(const char * const barejid, const char * const name,
contact->available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free,
(GDestroyNotify)resource_destroy);
contact->resource_ac = autocomplete_new();
return contact;
}
@ -131,7 +135,10 @@ p_contact_groups(const PContact contact)
gboolean
p_contact_remove_resource(PContact contact, const char * const resource)
{
return g_hash_table_remove(contact->available_resources, resource);
gboolean result = g_hash_table_remove(contact->available_resources, resource);
autocomplete_remove(contact->resource_ac, resource);
return result;
}
void
@ -152,6 +159,7 @@ p_contact_free(PContact contact)
}
g_hash_table_destroy(contact->available_resources);
autocomplete_free(contact->resource_ac);
free(contact);
}
}
@ -373,6 +381,7 @@ void
p_contact_set_presence(const PContact contact, Resource *resource)
{
g_hash_table_replace(contact->available_resources, strdup(resource->name), resource);
autocomplete_add(contact->resource_ac, strdup(resource->name));
}
void
@ -402,3 +411,15 @@ p_contact_set_last_activity(const PContact contact, GDateTime *last_activity)
contact->last_activity = g_date_time_ref(last_activity);
}
}
Autocomplete
p_contact_resource_ac(const PContact contact)
{
return contact->resource_ac;
}
void
p_contact_resource_ac_reset(const PContact contact)
{
autocomplete_reset(contact->resource_ac);
}

View File

@ -36,6 +36,7 @@
#define CONTACT_H
#include "resource.h"
#include "tools/autocomplete.h"
typedef struct p_contact_t *PContact;
@ -68,5 +69,7 @@ GSList * p_contact_groups(const PContact contact);
gboolean p_contact_in_group(const PContact contact, const char * const group);
gboolean p_contact_subscribed(const PContact contact);
char * p_contact_create_display_string(const PContact contact, const char * const resource);
Autocomplete p_contact_resource_ac(const PContact contact);
void p_contact_resource_ac_reset(const PContact contact);
#endif