From 86adbc497361da1bf2a54201e3bdc07f3eca401b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 28 Oct 2012 00:12:39 +0100 Subject: Added autocomplete for second /notify parameter --- src/input_win.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'src/input_win.c') diff --git a/src/input_win.c b/src/input_win.c index b69e3feb..330b6443 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -68,6 +68,7 @@ static int _printable(const int ch); static void _replace_input(char *input, const char * const new_input, int *size); static void _parameter_autocomplete(char *input, int *size, char *command, autocomplete_func func); +static void _notify_autocomplete(char *input, int *size); void create_input_window(void) @@ -361,8 +362,6 @@ _handle_edit(const int ch, char *input, int *size) cmd_help_complete); _parameter_autocomplete(input, size, "/beep", prefs_autocomplete_boolean_choice); - _parameter_autocomplete(input, size, "/notify", - cmd_notify_complete); _parameter_autocomplete(input, size, "/flash", prefs_autocomplete_boolean_choice); _parameter_autocomplete(input, size, "/showsplash", @@ -374,6 +373,8 @@ _handle_edit(const int ch, char *input, int *size) _parameter_autocomplete(input, size, "/vercheck", prefs_autocomplete_boolean_choice); + _notify_autocomplete(input, size); + return 1; default: @@ -433,3 +434,56 @@ _parameter_autocomplete(char *input, int *size, char *command, } free(command_cpy); } + +static void +_notify_autocomplete(char *input, int *size) +{ + char *found = NULL; + char *auto_msg = NULL; + char inp_cpy[*size]; + int i; + + if ((strncmp(input, "/notify message ", 16) == 0) && (*size > 16)) { + for(i = 16; i < *size; i++) { + inp_cpy[i-16] = input[i]; + } + inp_cpy[(*size) - 16] = '\0'; + found = prefs_autocomplete_boolean_choice(inp_cpy); + if (found != NULL) { + auto_msg = (char *) malloc((16 + (strlen(found) + 1)) * sizeof(char)); + strcpy(auto_msg, "/notify message "); + strcat(auto_msg, found); + _replace_input(input, auto_msg, size); + free(auto_msg); + free(found); + } + } else if ((strncmp(input, "/notify typing ", 15) == 0) && (*size > 15)) { + for(i = 15; i < *size; i++) { + inp_cpy[i-15] = input[i]; + } + inp_cpy[(*size) - 15] = '\0'; + found = prefs_autocomplete_boolean_choice(inp_cpy); + if (found != NULL) { + auto_msg = (char *) malloc((15 + (strlen(found) + 1)) * sizeof(char)); + strcpy(auto_msg, "/notify typing "); + strcat(auto_msg, found); + _replace_input(input, auto_msg, size); + free(auto_msg); + free(found); + } + } else if ((strncmp(input, "/notify ", 8) == 0) && (*size > 8)) { + for(i = 8; i < *size; i++) { + inp_cpy[i-8] = input[i]; + } + inp_cpy[(*size) - 8] = '\0'; + found = cmd_notify_complete(inp_cpy); + if (found != NULL) { + auto_msg = (char *) malloc((8 + (strlen(found) + 1)) * sizeof(char)); + strcpy(auto_msg, "/notify "); + strcat(auto_msg, found); + _replace_input(input, auto_msg, size); + free(auto_msg); + free(found); + } + } +} -- cgit 1.4.1-2-gfad0 n19' href='#n19'>19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74