1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-10-13 20:13:38 -04:00

Got rid of old naming convention on prof_autocomplete

This commit is contained in:
James Booth 2013-01-25 01:11:49 +00:00
parent 6b632625df
commit 527e739ac6
12 changed files with 247 additions and 247 deletions

View File

@ -1,8 +1,8 @@
bin_PROGRAMS = profanity bin_PROGRAMS = profanity
profanity_SOURCES = src/command.c src/contact.c src/history.c src/jabber.h \ profanity_SOURCES = src/command.c src/contact.c src/history.c src/jabber.h \
src/preferences.c src/prof_autocomplete.c src/status_bar.c \ src/preferences.c src/autocomplete.c src/status_bar.c \
src/command.h src/contact.h src/history.h src/log.c src/preferences.h \ src/command.h src/contact.h src/history.h src/log.c src/preferences.h \
src/prof_autocomplete.h src/title_bar.c src/windows.c src/common.c \ src/autocomplete.h src/title_bar.c src/windows.c src/common.c \
src/contact_list.c src/input_win.c src/log.h src/profanity.c \ src/contact_list.c src/input_win.c src/log.h src/profanity.c \
src/prof_history.c src/ui.h src/common.h src/ contact_list.h src/connection.c \ src/prof_history.c src/ui.h src/common.h src/ contact_list.h src/connection.c \
src/main.c src/profanity.h src/prof_history.h src/chat_log.c \ src/main.c src/profanity.h src/prof_history.h src/chat_log.c \
@ -17,7 +17,7 @@ TESTS = tests/testsuite
check_PROGRAMS = tests/testsuite check_PROGRAMS = tests/testsuite
tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \ tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \
tests/test_common.c tests/test_prof_history.c src/prof_history.c src/common.c \ tests/test_common.c tests/test_prof_history.c src/prof_history.c src/common.c \
tests/test_prof_autocomplete.c src/prof_autocomplete.c tests/testsuite.c \ tests/test_autocomplete.c src/autocomplete.c tests/testsuite.c \
tests/test_parser.c src/parser.c tests/test_jid.c src/jid.c tests/test_parser.c src/parser.c tests/test_jid.c src/jid.c
tests_testsuite_LDADD = -lheadunit -lstdc++ tests_testsuite_LDADD = -lheadunit -lstdc++

View File

@ -28,13 +28,13 @@
#include "accounts.h" #include "accounts.h"
#include "files.h" #include "files.h"
#include "log.h" #include "log.h"
#include "prof_autocomplete.h" #include "autocomplete.h"
static gchar *accounts_loc; static gchar *accounts_loc;
static GKeyFile *accounts; static GKeyFile *accounts;
static PAutocomplete all_ac; static Autocomplete all_ac;
static PAutocomplete enabled_ac; static Autocomplete enabled_ac;
static void _save_accounts(void); static void _save_accounts(void);
@ -42,8 +42,8 @@ void
accounts_load(void) accounts_load(void)
{ {
log_info("Loading accounts"); log_info("Loading accounts");
all_ac = p_autocomplete_new(); all_ac = autocomplete_new();
enabled_ac = p_autocomplete_new(); enabled_ac = autocomplete_new();
accounts_loc = files_get_accounts_file(); accounts_loc = files_get_accounts_file();
accounts = g_key_file_new(); accounts = g_key_file_new();
@ -58,9 +58,9 @@ accounts_load(void)
gsize i; gsize i;
for (i = 0; i < njids; i++) { for (i = 0; i < njids; i++) {
if (g_key_file_get_boolean(accounts, jids[i], "enabled", NULL)) { if (g_key_file_get_boolean(accounts, jids[i], "enabled", NULL)) {
p_autocomplete_add(enabled_ac, strdup(jids[i])); autocomplete_add(enabled_ac, strdup(jids[i]));
} }
p_autocomplete_add(all_ac, strdup(jids[i])); autocomplete_add(all_ac, strdup(jids[i]));
} }
for (i = 0; i < njids; i++) { for (i = 0; i < njids; i++) {
@ -72,33 +72,33 @@ accounts_load(void)
void void
accounts_close(void) accounts_close(void)
{ {
p_autocomplete_free(all_ac); autocomplete_free(all_ac);
p_autocomplete_free(enabled_ac); autocomplete_free(enabled_ac);
g_key_file_free(accounts); g_key_file_free(accounts);
} }
char * char *
accounts_find_enabled(char *prefix) accounts_find_enabled(char *prefix)
{ {
return p_autocomplete_complete(enabled_ac, prefix); return autocomplete_complete(enabled_ac, prefix);
} }
char * char *
accounts_find_all(char *prefix) accounts_find_all(char *prefix)
{ {
return p_autocomplete_complete(all_ac, prefix); return autocomplete_complete(all_ac, prefix);
} }
void void
accounts_reset_all_search(void) accounts_reset_all_search(void)
{ {
p_autocomplete_reset(all_ac); autocomplete_reset(all_ac);
} }
void void
accounts_reset_enabled_search(void) accounts_reset_enabled_search(void)
{ {
p_autocomplete_reset(enabled_ac); autocomplete_reset(enabled_ac);
} }
void void
@ -113,8 +113,8 @@ accounts_add_login(const char *jid, const char *altdomain)
} }
_save_accounts(); _save_accounts();
p_autocomplete_add(all_ac, strdup(jid)); autocomplete_add(all_ac, strdup(jid));
p_autocomplete_add(enabled_ac, strdup(jid)); autocomplete_add(enabled_ac, strdup(jid));
// already exists, update old style accounts // already exists, update old style accounts
} else { } else {
@ -184,7 +184,7 @@ accounts_enable(const char * const name)
if (g_key_file_has_group(accounts, name)) { if (g_key_file_has_group(accounts, name)) {
g_key_file_set_boolean(accounts, name, "enabled", TRUE); g_key_file_set_boolean(accounts, name, "enabled", TRUE);
_save_accounts(); _save_accounts();
p_autocomplete_add(enabled_ac, strdup(name)); autocomplete_add(enabled_ac, strdup(name));
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;
@ -197,7 +197,7 @@ accounts_disable(const char * const name)
if (g_key_file_has_group(accounts, name)) { if (g_key_file_has_group(accounts, name)) {
g_key_file_set_boolean(accounts, name, "enabled", FALSE); g_key_file_set_boolean(accounts, name, "enabled", FALSE);
_save_accounts(); _save_accounts();
p_autocomplete_remove(enabled_ac, strdup(name)); autocomplete_remove(enabled_ac, strdup(name));
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;
@ -233,11 +233,11 @@ accounts_rename(const char * const account_name, const char * const new_name)
g_key_file_remove_group(accounts, account_name, NULL); g_key_file_remove_group(accounts, account_name, NULL);
_save_accounts(); _save_accounts();
p_autocomplete_remove(all_ac, strdup(account_name)); autocomplete_remove(all_ac, strdup(account_name));
p_autocomplete_add(all_ac, strdup(new_name)); autocomplete_add(all_ac, strdup(new_name));
if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) { if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
p_autocomplete_remove(enabled_ac, strdup(account_name)); autocomplete_remove(enabled_ac, strdup(account_name));
p_autocomplete_add(enabled_ac, strdup(new_name)); autocomplete_add(enabled_ac, strdup(new_name));
} }
return TRUE; return TRUE;

View File

@ -1,5 +1,5 @@
/* /*
* prof_autocomplete.c * autocomplete.c
* *
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
* *
@ -23,20 +23,20 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "prof_autocomplete.h" #include "autocomplete.h"
struct p_autocomplete_t { struct autocomplete_t {
GSList *items; GSList *items;
GSList *last_found; GSList *last_found;
gchar *search_str; gchar *search_str;
}; };
static gchar * _search_from(PAutocomplete ac, GSList *curr); static gchar * _search_from(Autocomplete ac, GSList *curr);
PAutocomplete Autocomplete
p_autocomplete_new(void) autocomplete_new(void)
{ {
PAutocomplete new = malloc(sizeof(struct p_autocomplete_t)); Autocomplete new = malloc(sizeof(struct autocomplete_t));
new->items = NULL; new->items = NULL;
new->last_found = NULL; new->last_found = NULL;
new->search_str = NULL; new->search_str = NULL;
@ -45,16 +45,16 @@ p_autocomplete_new(void)
} }
void void
p_autocomplete_clear(PAutocomplete ac) autocomplete_clear(Autocomplete ac)
{ {
g_slist_free_full(ac->items, free); g_slist_free_full(ac->items, free);
ac->items = NULL; ac->items = NULL;
p_autocomplete_reset(ac); autocomplete_reset(ac);
} }
void void
p_autocomplete_reset(PAutocomplete ac) autocomplete_reset(Autocomplete ac)
{ {
ac->last_found = NULL; ac->last_found = NULL;
if (ac->search_str != NULL) { if (ac->search_str != NULL) {
@ -64,15 +64,15 @@ p_autocomplete_reset(PAutocomplete ac)
} }
void void
p_autocomplete_free(PAutocomplete ac) autocomplete_free(Autocomplete ac)
{ {
p_autocomplete_clear(ac); autocomplete_clear(ac);
g_free(ac); g_free(ac);
ac = NULL; ac = NULL;
} }
gboolean gboolean
p_autocomplete_add(PAutocomplete ac, void *item) autocomplete_add(Autocomplete ac, void *item)
{ {
if (ac->items == NULL) { if (ac->items == NULL) {
ac->items = g_slist_append(ac->items, item); ac->items = g_slist_append(ac->items, item);
@ -111,7 +111,7 @@ p_autocomplete_add(PAutocomplete ac, void *item)
} }
gboolean gboolean
p_autocomplete_remove(PAutocomplete ac, const char * const item) autocomplete_remove(Autocomplete ac, const char * const item)
{ {
// reset last found if it points to the item to be removed // reset last found if it points to the item to be removed
if (ac->last_found != NULL) if (ac->last_found != NULL)
@ -140,7 +140,7 @@ p_autocomplete_remove(PAutocomplete ac, const char * const item)
} }
GSList * GSList *
p_autocomplete_get_list(PAutocomplete ac) autocomplete_get_list(Autocomplete ac)
{ {
GSList *copy = NULL; GSList *copy = NULL;
GSList *curr = ac->items; GSList *curr = ac->items;
@ -154,7 +154,7 @@ p_autocomplete_get_list(PAutocomplete ac)
} }
gchar * gchar *
p_autocomplete_complete(PAutocomplete ac, gchar *search_str) autocomplete_complete(Autocomplete ac, gchar *search_str)
{ {
gchar *found = NULL; gchar *found = NULL;
@ -184,13 +184,13 @@ p_autocomplete_complete(PAutocomplete ac, gchar *search_str)
return found; return found;
// we found nothing, reset search // we found nothing, reset search
p_autocomplete_reset(ac); autocomplete_reset(ac);
return NULL; return NULL;
} }
} }
static gchar * static gchar *
_search_from(PAutocomplete ac, GSList *curr) _search_from(Autocomplete ac, GSList *curr)
{ {
while(curr) { while(curr) {

View File

@ -1,5 +1,5 @@
/* /*
* prof_autocomplete.h * autocomplete.h
* *
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
* *
@ -20,26 +20,26 @@
* *
*/ */
#ifndef PROF_AUTOCOMPLETE_H #ifndef AUTOCOMPLETE_H
#define PROF_AUTOCOMPLETE_H #define AUTOCOMPLETE_H
#include <glib.h> #include <glib.h>
typedef struct p_autocomplete_t *PAutocomplete; typedef struct autocomplete_t *Autocomplete;
typedef const char * (*PStrFunc)(const void *obj); typedef const char * (*PStrFunc)(const void *obj);
typedef void * (*PCopyFunc)(const void *obj); typedef void * (*PCopyFunc)(const void *obj);
typedef int (*PEqualFunc)(const void *o1, const void *o2); typedef int (*PEqualFunc)(const void *o1, const void *o2);
typedef int (*PEqualDeepFunc)(const void *o1, const void *o2); typedef int (*PEqualDeepFunc)(const void *o1, const void *o2);
PAutocomplete p_autocomplete_new(void); Autocomplete autocomplete_new(void);
PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func, Autocomplete obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
PEqualDeepFunc equal_deep_func, GDestroyNotify free_func); PEqualDeepFunc equal_deep_func, GDestroyNotify free_func);
void p_autocomplete_clear(PAutocomplete ac); void autocomplete_clear(Autocomplete ac);
void p_autocomplete_reset(PAutocomplete ac); void autocomplete_reset(Autocomplete ac);
void p_autocomplete_free(PAutocomplete ac); void autocomplete_free(Autocomplete ac);
gboolean p_autocomplete_add(PAutocomplete ac, void *item); gboolean autocomplete_add(Autocomplete ac, void *item);
gboolean p_autocomplete_remove(PAutocomplete ac, const char * const item); gboolean autocomplete_remove(Autocomplete ac, const char * const item);
GSList * p_autocomplete_get_list(PAutocomplete ac); GSList * autocomplete_get_list(Autocomplete ac);
gchar * p_autocomplete_complete(PAutocomplete ac, gchar *search_str); gchar * autocomplete_complete(Autocomplete ac, gchar *search_str);
#endif #endif

View File

@ -40,7 +40,7 @@
#include "log.h" #include "log.h"
#include "parser.h" #include "parser.h"
#include "preferences.h" #include "preferences.h"
#include "prof_autocomplete.h" #include "autocomplete.h"
#include "profanity.h" #include "profanity.h"
#include "muc.h" #include "muc.h"
#include "theme.h" #include "theme.h"
@ -84,7 +84,7 @@ static void _account_autocomplete(char *input, int *size);
static void _parameter_autocomplete(char *input, int *size, char *command, static void _parameter_autocomplete(char *input, int *size, char *command,
autocomplete_func func); autocomplete_func func);
static void _parameter_autocomplete_with_ac(char *input, int *size, char *command, static void _parameter_autocomplete_with_ac(char *input, int *size, char *command,
PAutocomplete ac); Autocomplete ac);
static int _strtoi(char *str, int *saveptr, int min, int max); static int _strtoi(char *str, int *saveptr, int min, int max);
gchar** _cmd_parse_args(const char * const inp, int min, int max, int *num); gchar** _cmd_parse_args(const char * const inp, int min, int max, int *num);
@ -632,19 +632,19 @@ static struct cmd_t presence_commands[] =
NULL } } }, NULL } } },
}; };
static PAutocomplete commands_ac; static Autocomplete commands_ac;
static PAutocomplete who_ac; static Autocomplete who_ac;
static PAutocomplete help_ac; static Autocomplete help_ac;
static PAutocomplete notify_ac; static Autocomplete notify_ac;
static PAutocomplete prefs_ac; static Autocomplete prefs_ac;
static PAutocomplete sub_ac; static Autocomplete sub_ac;
static PAutocomplete log_ac; static Autocomplete log_ac;
static PAutocomplete autoaway_ac; static Autocomplete autoaway_ac;
static PAutocomplete autoaway_mode_ac; static Autocomplete autoaway_mode_ac;
static PAutocomplete titlebar_ac; static Autocomplete titlebar_ac;
static PAutocomplete theme_ac; static Autocomplete theme_ac;
static PAutocomplete theme_load_ac; static Autocomplete theme_load_ac;
static PAutocomplete account_ac; static Autocomplete account_ac;
/* /*
* Initialise command autocompleter and history * Initialise command autocompleter and history
@ -654,93 +654,93 @@ cmd_init(void)
{ {
log_info("Initialising commands"); log_info("Initialising commands");
commands_ac = p_autocomplete_new(); commands_ac = autocomplete_new();
who_ac = p_autocomplete_new(); who_ac = autocomplete_new();
prefs_ac = p_autocomplete_new(); prefs_ac = autocomplete_new();
p_autocomplete_add(prefs_ac, strdup("ui")); autocomplete_add(prefs_ac, strdup("ui"));
p_autocomplete_add(prefs_ac, strdup("desktop")); autocomplete_add(prefs_ac, strdup("desktop"));
p_autocomplete_add(prefs_ac, strdup("chat")); autocomplete_add(prefs_ac, strdup("chat"));
p_autocomplete_add(prefs_ac, strdup("log")); autocomplete_add(prefs_ac, strdup("log"));
p_autocomplete_add(prefs_ac, strdup("conn")); autocomplete_add(prefs_ac, strdup("conn"));
p_autocomplete_add(prefs_ac, strdup("presence")); autocomplete_add(prefs_ac, strdup("presence"));
help_ac = p_autocomplete_new(); help_ac = autocomplete_new();
p_autocomplete_add(help_ac, strdup("list")); autocomplete_add(help_ac, strdup("list"));
p_autocomplete_add(help_ac, strdup("basic")); autocomplete_add(help_ac, strdup("basic"));
p_autocomplete_add(help_ac, strdup("presence")); autocomplete_add(help_ac, strdup("presence"));
p_autocomplete_add(help_ac, strdup("settings")); autocomplete_add(help_ac, strdup("settings"));
p_autocomplete_add(help_ac, strdup("navigation")); autocomplete_add(help_ac, strdup("navigation"));
notify_ac = p_autocomplete_new(); notify_ac = autocomplete_new();
p_autocomplete_add(notify_ac, strdup("message")); autocomplete_add(notify_ac, strdup("message"));
p_autocomplete_add(notify_ac, strdup("typing")); autocomplete_add(notify_ac, strdup("typing"));
p_autocomplete_add(notify_ac, strdup("remind")); autocomplete_add(notify_ac, strdup("remind"));
p_autocomplete_add(notify_ac, strdup("status")); autocomplete_add(notify_ac, strdup("status"));
sub_ac = p_autocomplete_new(); sub_ac = autocomplete_new();
p_autocomplete_add(sub_ac, strdup("request")); autocomplete_add(sub_ac, strdup("request"));
p_autocomplete_add(sub_ac, strdup("allow")); autocomplete_add(sub_ac, strdup("allow"));
p_autocomplete_add(sub_ac, strdup("deny")); autocomplete_add(sub_ac, strdup("deny"));
p_autocomplete_add(sub_ac, strdup("show")); autocomplete_add(sub_ac, strdup("show"));
p_autocomplete_add(sub_ac, strdup("sent")); autocomplete_add(sub_ac, strdup("sent"));
p_autocomplete_add(sub_ac, strdup("received")); autocomplete_add(sub_ac, strdup("received"));
titlebar_ac = p_autocomplete_new(); titlebar_ac = autocomplete_new();
p_autocomplete_add(titlebar_ac, strdup("version")); autocomplete_add(titlebar_ac, strdup("version"));
log_ac = p_autocomplete_new(); log_ac = autocomplete_new();
p_autocomplete_add(log_ac, strdup("maxsize")); autocomplete_add(log_ac, strdup("maxsize"));
autoaway_ac = p_autocomplete_new(); autoaway_ac = autocomplete_new();
p_autocomplete_add(autoaway_ac, strdup("mode")); autocomplete_add(autoaway_ac, strdup("mode"));
p_autocomplete_add(autoaway_ac, strdup("time")); autocomplete_add(autoaway_ac, strdup("time"));
p_autocomplete_add(autoaway_ac, strdup("message")); autocomplete_add(autoaway_ac, strdup("message"));
p_autocomplete_add(autoaway_ac, strdup("check")); autocomplete_add(autoaway_ac, strdup("check"));
autoaway_mode_ac = p_autocomplete_new(); autoaway_mode_ac = autocomplete_new();
p_autocomplete_add(autoaway_mode_ac, strdup("away")); autocomplete_add(autoaway_mode_ac, strdup("away"));
p_autocomplete_add(autoaway_mode_ac, strdup("idle")); autocomplete_add(autoaway_mode_ac, strdup("idle"));
p_autocomplete_add(autoaway_mode_ac, strdup("off")); autocomplete_add(autoaway_mode_ac, strdup("off"));
theme_ac = p_autocomplete_new(); theme_ac = autocomplete_new();
p_autocomplete_add(theme_ac, strdup("list")); autocomplete_add(theme_ac, strdup("list"));
p_autocomplete_add(theme_ac, strdup("set")); autocomplete_add(theme_ac, strdup("set"));
account_ac = p_autocomplete_new(); account_ac = autocomplete_new();
p_autocomplete_add(account_ac, strdup("list")); autocomplete_add(account_ac, strdup("list"));
p_autocomplete_add(account_ac, strdup("show")); autocomplete_add(account_ac, strdup("show"));
p_autocomplete_add(account_ac, strdup("add")); autocomplete_add(account_ac, strdup("add"));
p_autocomplete_add(account_ac, strdup("enable")); autocomplete_add(account_ac, strdup("enable"));
p_autocomplete_add(account_ac, strdup("disable")); autocomplete_add(account_ac, strdup("disable"));
p_autocomplete_add(account_ac, strdup("rename")); autocomplete_add(account_ac, strdup("rename"));
p_autocomplete_add(account_ac, strdup("set")); autocomplete_add(account_ac, strdup("set"));
theme_load_ac = NULL; theme_load_ac = NULL;
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(main_commands); i++) { for (i = 0; i < ARRAY_SIZE(main_commands); i++) {
struct cmd_t *pcmd = main_commands+i; struct cmd_t *pcmd = main_commands+i;
p_autocomplete_add(commands_ac, (gchar *)strdup(pcmd->cmd)); autocomplete_add(commands_ac, (gchar *)strdup(pcmd->cmd));
p_autocomplete_add(help_ac, (gchar *)strdup(pcmd->cmd+1)); autocomplete_add(help_ac, (gchar *)strdup(pcmd->cmd+1));
} }
for (i = 0; i < ARRAY_SIZE(setting_commands); i++) { for (i = 0; i < ARRAY_SIZE(setting_commands); i++) {
struct cmd_t *pcmd = setting_commands+i; struct cmd_t *pcmd = setting_commands+i;
p_autocomplete_add(commands_ac, (gchar *)strdup(pcmd->cmd)); autocomplete_add(commands_ac, (gchar *)strdup(pcmd->cmd));
p_autocomplete_add(help_ac, (gchar *)strdup(pcmd->cmd+1)); autocomplete_add(help_ac, (gchar *)strdup(pcmd->cmd+1));
} }
for (i = 0; i < ARRAY_SIZE(presence_commands); i++) { for (i = 0; i < ARRAY_SIZE(presence_commands); i++) {
struct cmd_t *pcmd = presence_commands+i; struct cmd_t *pcmd = presence_commands+i;
p_autocomplete_add(commands_ac, (gchar *)strdup(pcmd->cmd)); autocomplete_add(commands_ac, (gchar *)strdup(pcmd->cmd));
p_autocomplete_add(help_ac, (gchar *)strdup(pcmd->cmd+1)); autocomplete_add(help_ac, (gchar *)strdup(pcmd->cmd+1));
p_autocomplete_add(who_ac, (gchar *)strdup(pcmd->cmd+1)); autocomplete_add(who_ac, (gchar *)strdup(pcmd->cmd+1));
} }
p_autocomplete_add(who_ac, strdup("offline")); autocomplete_add(who_ac, strdup("offline"));
p_autocomplete_add(who_ac, strdup("available")); autocomplete_add(who_ac, strdup("available"));
p_autocomplete_add(who_ac, strdup("unavailable")); autocomplete_add(who_ac, strdup("unavailable"));
history_init(); history_init();
} }
@ -748,20 +748,20 @@ cmd_init(void)
void void
cmd_close(void) cmd_close(void)
{ {
p_autocomplete_free(commands_ac); autocomplete_free(commands_ac);
p_autocomplete_free(who_ac); autocomplete_free(who_ac);
p_autocomplete_free(help_ac); autocomplete_free(help_ac);
p_autocomplete_free(notify_ac); autocomplete_free(notify_ac);
p_autocomplete_free(sub_ac); autocomplete_free(sub_ac);
p_autocomplete_free(log_ac); autocomplete_free(log_ac);
p_autocomplete_free(prefs_ac); autocomplete_free(prefs_ac);
p_autocomplete_free(autoaway_ac); autocomplete_free(autoaway_ac);
p_autocomplete_free(autoaway_mode_ac); autocomplete_free(autoaway_mode_ac);
p_autocomplete_free(theme_ac); autocomplete_free(theme_ac);
if (theme_load_ac != NULL) { if (theme_load_ac != NULL) {
p_autocomplete_free(theme_load_ac); autocomplete_free(theme_load_ac);
} }
p_autocomplete_free(account_ac); autocomplete_free(account_ac);
} }
// Command autocompletion functions // Command autocompletion functions
@ -779,7 +779,7 @@ cmd_autocomplete(char *input, int *size)
inp_cpy[i] = input[i]; inp_cpy[i] = input[i];
} }
inp_cpy[i] = '\0'; inp_cpy[i] = '\0';
found = p_autocomplete_complete(commands_ac, inp_cpy); found = autocomplete_complete(commands_ac, inp_cpy);
if (found != NULL) { if (found != NULL) {
auto_msg = (char *) malloc((strlen(found) + 1) * sizeof(char)); auto_msg = (char *) malloc((strlen(found) + 1) * sizeof(char));
strcpy(auto_msg, found); strcpy(auto_msg, found);
@ -801,29 +801,29 @@ cmd_reset_autocomplete()
accounts_reset_all_search(); accounts_reset_all_search();
accounts_reset_enabled_search(); accounts_reset_enabled_search();
prefs_reset_boolean_choice(); prefs_reset_boolean_choice();
p_autocomplete_reset(help_ac); autocomplete_reset(help_ac);
p_autocomplete_reset(notify_ac); autocomplete_reset(notify_ac);
p_autocomplete_reset(sub_ac); autocomplete_reset(sub_ac);
if (win_current_is_groupchat()) { if (win_current_is_groupchat()) {
PAutocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient()); Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient());
if (nick_ac != NULL) { if (nick_ac != NULL) {
p_autocomplete_reset(nick_ac); autocomplete_reset(nick_ac);
} }
} }
p_autocomplete_reset(who_ac); autocomplete_reset(who_ac);
p_autocomplete_reset(prefs_ac); autocomplete_reset(prefs_ac);
p_autocomplete_reset(log_ac); autocomplete_reset(log_ac);
p_autocomplete_reset(commands_ac); autocomplete_reset(commands_ac);
p_autocomplete_reset(autoaway_ac); autocomplete_reset(autoaway_ac);
p_autocomplete_reset(autoaway_mode_ac); autocomplete_reset(autoaway_mode_ac);
p_autocomplete_reset(theme_ac); autocomplete_reset(theme_ac);
if (theme_load_ac != NULL) { if (theme_load_ac != NULL) {
p_autocomplete_reset(theme_load_ac); autocomplete_reset(theme_load_ac);
theme_load_ac = NULL; theme_load_ac = NULL;
} }
p_autocomplete_reset(account_ac); autocomplete_reset(account_ac);
} }
GSList * GSList *
@ -954,7 +954,7 @@ _cmd_complete_parameters(char *input, int *size)
prefs_autocomplete_boolean_choice); prefs_autocomplete_boolean_choice);
if (win_current_is_groupchat()) { if (win_current_is_groupchat()) {
PAutocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient()); Autocomplete nick_ac = muc_get_roster_ac(win_current_get_recipient());
if (nick_ac != NULL) { if (nick_ac != NULL) {
_parameter_autocomplete_with_ac(input, size, "/msg", nick_ac); _parameter_autocomplete_with_ac(input, size, "/msg", nick_ac);
_parameter_autocomplete_with_ac(input, size, "/info", nick_ac); _parameter_autocomplete_with_ac(input, size, "/info", nick_ac);
@ -2394,7 +2394,7 @@ _parameter_autocomplete(char *input, int *size, char *command,
static void static void
_parameter_autocomplete_with_ac(char *input, int *size, char *command, _parameter_autocomplete_with_ac(char *input, int *size, char *command,
PAutocomplete ac) Autocomplete ac)
{ {
char *found = NULL; char *found = NULL;
char *auto_msg = NULL; char *auto_msg = NULL;
@ -2408,7 +2408,7 @@ _parameter_autocomplete_with_ac(char *input, int *size, char *command,
inp_cpy[i-len] = input[i]; inp_cpy[i-len] = input[i];
} }
inp_cpy[(*size) - len] = '\0'; inp_cpy[(*size) - len] = '\0';
found = p_autocomplete_complete(ac, inp_cpy); found = autocomplete_complete(ac, inp_cpy);
if (found != NULL) { if (found != NULL) {
auto_msg = (char *) malloc((len + (strlen(found) + 1)) * sizeof(char)); auto_msg = (char *) malloc((len + (strlen(found) + 1)) * sizeof(char));
strcpy(auto_msg, command_cpy); strcpy(auto_msg, command_cpy);
@ -2523,14 +2523,14 @@ _theme_autocomplete(char *input, int *size)
{ {
if ((strncmp(input, "/theme set ", 11) == 0) && (*size > 11)) { if ((strncmp(input, "/theme set ", 11) == 0) && (*size > 11)) {
if (theme_load_ac == NULL) { if (theme_load_ac == NULL) {
theme_load_ac = p_autocomplete_new(); theme_load_ac = autocomplete_new();
GSList *themes = theme_list(); GSList *themes = theme_list();
while (themes != NULL) { while (themes != NULL) {
p_autocomplete_add(theme_load_ac, strdup(themes->data)); autocomplete_add(theme_load_ac, strdup(themes->data));
themes = g_slist_next(themes); themes = g_slist_next(themes);
} }
g_slist_free(themes); g_slist_free(themes);
p_autocomplete_add(theme_load_ac, "default"); autocomplete_add(theme_load_ac, "default");
} }
_parameter_autocomplete_with_ac(input, size, "/theme set", theme_load_ac); _parameter_autocomplete_with_ac(input, size, "/theme set", theme_load_ac);
} else if ((strncmp(input, "/theme ", 7) == 0) && (*size > 7)) { } else if ((strncmp(input, "/theme ", 7) == 0) && (*size > 7)) {

View File

@ -25,9 +25,9 @@
#include <glib.h> #include <glib.h>
#include "contact.h" #include "contact.h"
#include "prof_autocomplete.h" #include "autocomplete.h"
static PAutocomplete ac; static Autocomplete ac;
static GHashTable *contacts; static GHashTable *contacts;
static gboolean _key_equals(void *key1, void *key2); static gboolean _key_equals(void *key1, void *key2);
@ -36,7 +36,7 @@ static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
void void
contact_list_init(void) contact_list_init(void)
{ {
ac = p_autocomplete_new(); ac = autocomplete_new();
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free, contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
(GDestroyNotify)p_contact_free); (GDestroyNotify)p_contact_free);
} }
@ -44,20 +44,20 @@ contact_list_init(void)
void void
contact_list_clear(void) contact_list_clear(void)
{ {
p_autocomplete_clear(ac); autocomplete_clear(ac);
g_hash_table_remove_all(contacts); g_hash_table_remove_all(contacts);
} }
void void
contact_list_free() contact_list_free()
{ {
p_autocomplete_free(ac); autocomplete_free(ac);
} }
void void
contact_list_reset_search_attempts(void) contact_list_reset_search_attempts(void)
{ {
p_autocomplete_reset(ac); autocomplete_reset(ac);
} }
gboolean gboolean
@ -72,7 +72,7 @@ contact_list_add(const char * const jid, const char * const name,
contact = p_contact_new(jid, name, presence, status, subscription, contact = p_contact_new(jid, name, presence, status, subscription,
pending_out, NULL); pending_out, NULL);
g_hash_table_insert(contacts, strdup(jid), contact); g_hash_table_insert(contacts, strdup(jid), contact);
p_autocomplete_add(ac, strdup(jid)); autocomplete_add(ac, strdup(jid));
added = TRUE; added = TRUE;
} }
@ -172,7 +172,7 @@ get_contact_list(void)
char * char *
contact_list_find_contact(char *search_str) contact_list_find_contact(char *search_str)
{ {
return p_autocomplete_complete(ac, search_str); return autocomplete_complete(ac, search_str);
} }
PContact PContact

View File

@ -27,7 +27,7 @@
#include "contact.h" #include "contact.h"
#include "jid.h" #include "jid.h"
#include "prof_autocomplete.h" #include "autocomplete.h"
typedef struct _muc_room_t { typedef struct _muc_room_t {
char *room; // e.g. test@conference.server char *room; // e.g. test@conference.server
@ -35,7 +35,7 @@ typedef struct _muc_room_t {
char *subject; char *subject;
gboolean pending_nick_change; gboolean pending_nick_change;
GHashTable *roster; GHashTable *roster;
PAutocomplete nick_ac; Autocomplete nick_ac;
GHashTable *nick_changes; GHashTable *nick_changes;
gboolean roster_received; gboolean roster_received;
} ChatRoom; } ChatRoom;
@ -61,7 +61,7 @@ muc_join_room(const char * const room, const char * const nick)
new_room->subject = NULL; new_room->subject = NULL;
new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
(GDestroyNotify)p_contact_free); (GDestroyNotify)p_contact_free);
new_room->nick_ac = p_autocomplete_new(); new_room->nick_ac = autocomplete_new();
new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal, new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, g_free); g_free, g_free);
new_room->roster_received = FALSE; new_room->roster_received = FALSE;
@ -215,7 +215,7 @@ muc_add_to_roster(const char * const room, const char * const nick,
if (old == NULL) { if (old == NULL) {
updated = TRUE; updated = TRUE;
p_autocomplete_add(chat_room->nick_ac, strdup(nick)); autocomplete_add(chat_room->nick_ac, strdup(nick));
} else if ((g_strcmp0(p_contact_presence(old), show) != 0) || } else if ((g_strcmp0(p_contact_presence(old), show) != 0) ||
(g_strcmp0(p_contact_status(old), status) != 0)) { (g_strcmp0(p_contact_status(old), status) != 0)) {
updated = TRUE; updated = TRUE;
@ -237,7 +237,7 @@ muc_remove_from_roster(const char * const room, const char * const nick)
if (chat_room != NULL) { if (chat_room != NULL) {
g_hash_table_remove(chat_room->roster, nick); g_hash_table_remove(chat_room->roster, nick);
p_autocomplete_remove(chat_room->nick_ac, nick); autocomplete_remove(chat_room->nick_ac, nick);
} }
} }
@ -271,9 +271,9 @@ muc_get_roster(const char * const room)
} }
/* /*
* Return a PAutocomplete representing the room member's in the roster * Return a Autocomplete representing the room member's in the roster
*/ */
PAutocomplete Autocomplete
muc_get_roster_ac(const char * const room) muc_get_roster_ac(const char * const room)
{ {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room); ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
@ -377,7 +377,7 @@ _free_room(ChatRoom *room)
room->roster = NULL; room->roster = NULL;
} }
if (room->nick_ac != NULL) { if (room->nick_ac != NULL) {
p_autocomplete_free(room->nick_ac); autocomplete_free(room->nick_ac);
} }
if (room->nick_changes != NULL) { if (room->nick_changes != NULL) {
g_hash_table_remove_all(room->nick_changes); g_hash_table_remove_all(room->nick_changes);

View File

@ -25,7 +25,7 @@
#include <glib.h> #include <glib.h>
#include "prof_autocomplete.h" #include "autocomplete.h"
void muc_join_room(const char * const room, const char * const nick); void muc_join_room(const char * const room, const char * const nick);
void muc_leave_room(const char * const room); void muc_leave_room(const char * const room);
@ -43,7 +43,7 @@ gboolean muc_add_to_roster(const char * const room, const char * const nick,
const char * const caps_str); const char * const caps_str);
void muc_remove_from_roster(const char * const room, const char * const nick); void muc_remove_from_roster(const char * const room, const char * const nick);
GList * muc_get_roster(const char * const room); GList * muc_get_roster(const char * const room);
PAutocomplete muc_get_roster_ac(const char * const room); Autocomplete muc_get_roster_ac(const char * const room);
gboolean muc_nick_in_roster(const char * const room, const char * const nick); gboolean muc_nick_in_roster(const char * const room, const char * const nick);
PContact muc_get_participant(const char * const room, const char * const nick); PContact muc_get_participant(const char * const room, const char * const nick);
void muc_set_roster_received(const char * const room); void muc_set_roster_received(const char * const room);

View File

@ -35,13 +35,13 @@
#include "files.h" #include "files.h"
#include "log.h" #include "log.h"
#include "preferences.h" #include "preferences.h"
#include "prof_autocomplete.h" #include "autocomplete.h"
static gchar *prefs_loc; static gchar *prefs_loc;
static GKeyFile *prefs; static GKeyFile *prefs;
gint log_maxsize = 0; gint log_maxsize = 0;
static PAutocomplete boolean_choice_ac; static Autocomplete boolean_choice_ac;
static void _save_prefs(void); static void _save_prefs(void);
@ -64,28 +64,28 @@ prefs_load(void)
g_error_free(err); g_error_free(err);
} }
boolean_choice_ac = p_autocomplete_new(); boolean_choice_ac = autocomplete_new();
p_autocomplete_add(boolean_choice_ac, strdup("on")); autocomplete_add(boolean_choice_ac, strdup("on"));
p_autocomplete_add(boolean_choice_ac, strdup("off")); autocomplete_add(boolean_choice_ac, strdup("off"));
} }
void void
prefs_close(void) prefs_close(void)
{ {
p_autocomplete_free(boolean_choice_ac); autocomplete_free(boolean_choice_ac);
g_key_file_free(prefs); g_key_file_free(prefs);
} }
char * char *
prefs_autocomplete_boolean_choice(char *prefix) prefs_autocomplete_boolean_choice(char *prefix)
{ {
return p_autocomplete_complete(boolean_choice_ac, prefix); return autocomplete_complete(boolean_choice_ac, prefix);
} }
void void
prefs_reset_boolean_choice(void) prefs_reset_boolean_choice(void)
{ {
p_autocomplete_reset(boolean_choice_ac); autocomplete_reset(boolean_choice_ac);
} }
gboolean gboolean

View File

@ -5,115 +5,115 @@
#include <glib.h> #include <glib.h>
#include "contact.h" #include "contact.h"
#include "prof_autocomplete.h" #include "autocomplete.h"
static void clear_empty(void) static void clear_empty(void)
{ {
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void reset_after_create(void) static void reset_after_create(void)
{ {
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_reset(ac); autocomplete_reset(ac);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void find_after_create(void) static void find_after_create(void)
{ {
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_complete(ac, "hello"); autocomplete_complete(ac, "hello");
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void get_after_create_returns_null(void) static void get_after_create_returns_null(void)
{ {
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
GSList *result = p_autocomplete_get_list(ac); GSList *result = autocomplete_get_list(ac);
assert_is_null(result); assert_is_null(result);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_one_and_complete(void) static void add_one_and_complete(void)
{ {
char *item = strdup("Hello"); char *item = strdup("Hello");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_add(ac, item); autocomplete_add(ac, item);
char *result = p_autocomplete_complete(ac, "Hel"); char *result = autocomplete_complete(ac, "Hel");
assert_string_equals("Hello", result); assert_string_equals("Hello", result);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_and_complete_returns_first(void) static void add_two_and_complete_returns_first(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Help"); char *item2 = strdup("Help");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_add(ac, item1); autocomplete_add(ac, item1);
p_autocomplete_add(ac, item2); autocomplete_add(ac, item2);
char *result = p_autocomplete_complete(ac, "Hel"); char *result = autocomplete_complete(ac, "Hel");
assert_string_equals("Hello", result); assert_string_equals("Hello", result);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_and_complete_returns_second(void) static void add_two_and_complete_returns_second(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Help"); char *item2 = strdup("Help");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_add(ac, item1); autocomplete_add(ac, item1);
p_autocomplete_add(ac, item2); autocomplete_add(ac, item2);
char *result1 = p_autocomplete_complete(ac, "Hel"); char *result1 = autocomplete_complete(ac, "Hel");
char *result2 = p_autocomplete_complete(ac, result1); char *result2 = autocomplete_complete(ac, result1);
assert_string_equals("Help", result2); assert_string_equals("Help", result2);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_adds_two(void) static void add_two_adds_two(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Help"); char *item2 = strdup("Help");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_add(ac, item1); autocomplete_add(ac, item1);
p_autocomplete_add(ac, item2); autocomplete_add(ac, item2);
GSList *result = p_autocomplete_get_list(ac); GSList *result = autocomplete_get_list(ac);
assert_int_equals(2, g_slist_length(result)); assert_int_equals(2, g_slist_length(result));
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_same_adds_one(void) static void add_two_same_adds_one(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Hello"); char *item2 = strdup("Hello");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_add(ac, item1); autocomplete_add(ac, item1);
p_autocomplete_add(ac, item2); autocomplete_add(ac, item2);
GSList *result = p_autocomplete_get_list(ac); GSList *result = autocomplete_get_list(ac);
assert_int_equals(1, g_slist_length(result)); assert_int_equals(1, g_slist_length(result));
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_same_updates(void) static void add_two_same_updates(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Hello"); char *item2 = strdup("Hello");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
p_autocomplete_add(ac, item1); autocomplete_add(ac, item1);
p_autocomplete_add(ac, item2); autocomplete_add(ac, item2);
GSList *result = p_autocomplete_get_list(ac); GSList *result = autocomplete_get_list(ac);
GSList *first = g_slist_nth(result, 0); GSList *first = g_slist_nth(result, 0);
@ -121,51 +121,51 @@ static void add_two_same_updates(void)
assert_string_equals("Hello", str); assert_string_equals("Hello", str);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_one_returns_true(void) static void add_one_returns_true(void)
{ {
char *item = strdup("Hello"); char *item = strdup("Hello");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
int result = p_autocomplete_add(ac, item); int result = autocomplete_add(ac, item);
assert_true(result); assert_true(result);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_different_returns_true(void) static void add_two_different_returns_true(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Hello there"); char *item2 = strdup("Hello there");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
int result1 = p_autocomplete_add(ac, item1); int result1 = autocomplete_add(ac, item1);
int result2 = p_autocomplete_add(ac, item2); int result2 = autocomplete_add(ac, item2);
assert_true(result1); assert_true(result1);
assert_true(result2); assert_true(result2);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
static void add_two_same_returns_false(void) static void add_two_same_returns_false(void)
{ {
char *item1 = strdup("Hello"); char *item1 = strdup("Hello");
char *item2 = strdup("Hello"); char *item2 = strdup("Hello");
PAutocomplete ac = p_autocomplete_new(); Autocomplete ac = autocomplete_new();
int result1 = p_autocomplete_add(ac, item1); int result1 = autocomplete_add(ac, item1);
int result2 = p_autocomplete_add(ac, item2); int result2 = autocomplete_add(ac, item2);
assert_true(result1); assert_true(result1);
assert_false(result2); assert_false(result2);
p_autocomplete_clear(ac); autocomplete_clear(ac);
} }
void register_prof_autocomplete_tests(void) void register_autocomplete_tests(void)
{ {
TEST_MODULE("prof_autocomplete tests"); TEST_MODULE("autocomplete tests");
TEST(clear_empty); TEST(clear_empty);
TEST(reset_after_create); TEST(reset_after_create);
TEST(find_after_create); TEST(find_after_create);

View File

@ -6,7 +6,7 @@ int main(void)
register_prof_history_tests(); register_prof_history_tests();
register_contact_list_tests(); register_contact_list_tests();
register_common_tests(); register_common_tests();
register_prof_autocomplete_tests(); register_autocomplete_tests();
register_parser_tests(); register_parser_tests();
register_jid_tests(); register_jid_tests();
run_suite(); run_suite();

View File

@ -4,7 +4,7 @@
void register_prof_history_tests(void); void register_prof_history_tests(void);
void register_contact_list_tests(void); void register_contact_list_tests(void);
void register_common_tests(void); void register_common_tests(void);
void register_prof_autocomplete_tests(void); void register_autocomplete_tests(void);
void register_parser_tests(void); void register_parser_tests(void);
void register_jid_tests(void); void register_jid_tests(void);