mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Remaining Lua window api
This commit is contained in:
parent
06a6dcc137
commit
ab1c140935
@ -132,8 +132,7 @@ fi
|
||||
AM_CFLAGS="-Wall -export-dynamic"
|
||||
|
||||
if test "x$PACKAGE_STATUS" = xdevelopment; then
|
||||
# AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wunused"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"
|
||||
fi
|
||||
|
||||
LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS"
|
||||
|
@ -85,7 +85,7 @@ api_notify(const char *message, const char *category, int timeout_ms)
|
||||
}
|
||||
|
||||
void
|
||||
api_send_line(char *line)
|
||||
api_send_line(const char *line)
|
||||
{
|
||||
prof_process_input(line);
|
||||
}
|
||||
@ -127,14 +127,14 @@ api_log_error(const char *message)
|
||||
}
|
||||
|
||||
int
|
||||
api_win_exists(char *tag)
|
||||
api_win_exists(const char *tag)
|
||||
{
|
||||
return (wins_get_by_recipient(tag) != NULL);
|
||||
}
|
||||
|
||||
void
|
||||
api_win_create(char *tag, void *callback,
|
||||
void(*callback_func)(PluginWindowCallback *window_callback, char *tag, const char * const line))
|
||||
api_win_create(const char *tag, void *callback,
|
||||
void(*callback_func)(PluginWindowCallback *window_callback, const char *tag, const char * const line))
|
||||
{
|
||||
PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback));
|
||||
window->callback = callback;
|
||||
@ -144,7 +144,7 @@ api_win_create(char *tag, void *callback,
|
||||
}
|
||||
|
||||
void
|
||||
api_win_focus(char *tag)
|
||||
api_win_focus(const char *tag)
|
||||
{
|
||||
ProfWin *win = wins_get_by_recipient(tag);
|
||||
int num = wins_get_num(win);
|
||||
@ -152,14 +152,14 @@ api_win_focus(char *tag)
|
||||
}
|
||||
|
||||
void
|
||||
api_win_process_line(char *tag, const char * const line)
|
||||
api_win_process_line(const char *tag, const char * const line)
|
||||
{
|
||||
PluginWindowCallback *window = callbacks_get_window_handler(tag);
|
||||
window->callback_func(window, tag, line);
|
||||
}
|
||||
|
||||
void
|
||||
api_win_show(char *tag, char *line)
|
||||
api_win_show(const char *tag, const char *line)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(tag);
|
||||
win_print_time(window, '-');
|
||||
|
@ -28,7 +28,7 @@
|
||||
void api_cons_alert(void);
|
||||
void api_cons_show(const char * const message);
|
||||
void api_notify(const char *message, const char *category, int timeout_ms);
|
||||
void api_send_line(char *line);
|
||||
void api_send_line(const char *line);
|
||||
char * api_get_current_recipient(void);
|
||||
|
||||
void api_register_command(const char *command_name, int min_args, int max_args,
|
||||
@ -42,11 +42,11 @@ void api_log_info(const char *message);
|
||||
void api_log_warning(const char *message);
|
||||
void api_log_error(const char *message);
|
||||
|
||||
int api_win_exists(char *tag);
|
||||
void api_win_create(char *tag, void *callback,
|
||||
int api_win_exists(const char *tag);
|
||||
void api_win_create(const char *tag, void *callback,
|
||||
void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line));
|
||||
void api_win_focus(char *tag);
|
||||
void api_win_process_line(char *tag, const char * const line);
|
||||
void api_win_show(char *tag, char *line);
|
||||
void api_win_focus(const char *tag);
|
||||
void api_win_process_line(const char *tag, const char * const line);
|
||||
void api_win_show(const char *tag, const char *line);
|
||||
|
||||
#endif
|
||||
|
@ -48,17 +48,17 @@ callbacks_add_timed(PluginTimedFunction *timed_function)
|
||||
}
|
||||
|
||||
void
|
||||
callbacks_add_window_handler(char *tag, PluginWindowCallback *window_callback)
|
||||
callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback)
|
||||
{
|
||||
if (p_window_callbacks == NULL) {
|
||||
p_window_callbacks = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
}
|
||||
|
||||
g_hash_table_insert(p_window_callbacks, tag, window_callback);
|
||||
g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback);
|
||||
}
|
||||
|
||||
void *
|
||||
callbacks_get_window_handler(char *tag)
|
||||
callbacks_get_window_handler(const char *tag)
|
||||
{
|
||||
if (p_window_callbacks != NULL) {
|
||||
return g_hash_table_lookup(p_window_callbacks, tag);
|
||||
|
@ -45,12 +45,12 @@ typedef struct p_timed_function {
|
||||
|
||||
typedef struct p_window_input_callback {
|
||||
void *callback;
|
||||
void (*callback_func)(struct p_window_input_callback *window_callback, char *tag, const char * const line);
|
||||
void (*callback_func)(struct p_window_input_callback *window_callback, const char *tag, const char * const line);
|
||||
} PluginWindowCallback;
|
||||
|
||||
void callbacks_add_command(PluginCommand *command);
|
||||
void callbacks_add_timed(PluginTimedFunction *timed_function);
|
||||
void callbacks_add_window_handler(char *tag, PluginWindowCallback *window_callback);
|
||||
void * callbacks_get_window_handler(char *tag);
|
||||
void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback);
|
||||
void * callbacks_get_window_handler(const char *tag);
|
||||
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@ lua_api_cons_alert(lua_State *L)
|
||||
static int
|
||||
lua_api_cons_show(lua_State *L)
|
||||
{
|
||||
const char *message = lua_tostring(L, 1);
|
||||
const char *message = lua_tostring(L, -1);
|
||||
api_cons_show(message);
|
||||
return 0;
|
||||
}
|
||||
@ -105,7 +105,7 @@ lua_api_notify(lua_State *L)
|
||||
static int
|
||||
lua_api_send_line(lua_State *L)
|
||||
{
|
||||
const char *line = lua_tostring(L, 1);
|
||||
const char *line = lua_tostring(L, -1);
|
||||
api_send_line(line);
|
||||
return 0;
|
||||
}
|
||||
@ -127,7 +127,7 @@ lua_api_get_current_recipient(lua_State *L)
|
||||
static int
|
||||
lua_api_log_debug(lua_State *L)
|
||||
{
|
||||
const char *message = lua_tostring(L, 1);
|
||||
const char *message = lua_tostring(L, -1);
|
||||
api_log_debug(message);
|
||||
return 0;
|
||||
}
|
||||
@ -135,7 +135,7 @@ lua_api_log_debug(lua_State *L)
|
||||
static int
|
||||
lua_api_log_info(lua_State *L)
|
||||
{
|
||||
const char *message = lua_tostring(L, 1);
|
||||
const char *message = lua_tostring(L, -1);
|
||||
api_log_info(message);
|
||||
return 0;
|
||||
}
|
||||
@ -143,7 +143,7 @@ lua_api_log_info(lua_State *L)
|
||||
static int
|
||||
lua_api_log_warning(lua_State *L)
|
||||
{
|
||||
const char *message = lua_tostring(L, 1);
|
||||
const char *message = lua_tostring(L, -1);
|
||||
api_log_warning(message);
|
||||
return 0;
|
||||
}
|
||||
@ -151,7 +151,7 @@ lua_api_log_warning(lua_State *L)
|
||||
static int
|
||||
lua_api_log_error(lua_State *L)
|
||||
{
|
||||
const char *message = lua_tostring(L, 1);
|
||||
const char *message = lua_tostring(L, -1);
|
||||
api_log_error(message);
|
||||
return 0;
|
||||
}
|
||||
@ -159,7 +159,7 @@ lua_api_log_error(lua_State *L)
|
||||
static int
|
||||
lua_api_win_exists(lua_State *L)
|
||||
{
|
||||
const char *tag = lua_tostring(L, 1);
|
||||
const char *tag = lua_tostring(L, -1);
|
||||
|
||||
if (api_win_exists(tag)) {
|
||||
lua_pushboolean(L, 1);
|
||||
@ -193,50 +193,26 @@ lua_api_win_create(lua_State *L)
|
||||
static int
|
||||
lua_api_win_focus(lua_State *L)
|
||||
{
|
||||
/*
|
||||
char *tag = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &tag)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
const char *tag = lua_tostring(L, -1);
|
||||
api_win_focus(tag);
|
||||
return Py_BuildValue("");
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_api_win_process_line(lua_State *L)
|
||||
{
|
||||
/*
|
||||
char *tag = NULL;
|
||||
char *line = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &tag, &line)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
const char *tag = lua_tostring(L, -2);
|
||||
const char *line = lua_tostring(L, -1);
|
||||
api_win_process_line(tag, line);
|
||||
return Py_BuildValue("");
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_api_win_show(lua_State *L)
|
||||
{
|
||||
/*
|
||||
char *tag = NULL;
|
||||
char *line = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &tag, &line)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
const char *tag = lua_tostring(L, -2);
|
||||
const char *line = lua_tostring(L, -1);
|
||||
api_win_show(tag, line);
|
||||
return Py_BuildValue("");
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -549,37 +549,40 @@ prof_handle_disco_info(const char *from, GSList *identities, GSList *features)
|
||||
* continue, FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
prof_process_input(char *inp)
|
||||
prof_process_input(const char *inp)
|
||||
{
|
||||
log_debug("Input recieved: %s", inp);
|
||||
gboolean result = FALSE;
|
||||
g_strstrip(inp);
|
||||
gchar *inp_cpy = strdup(inp);
|
||||
g_strstrip(inp_cpy);
|
||||
|
||||
// add line to history if something typed
|
||||
if (strlen(inp) > 0) {
|
||||
cmd_history_append(inp);
|
||||
if (strlen(inp_cpy) > 0) {
|
||||
cmd_history_append(inp_cpy);
|
||||
}
|
||||
|
||||
// just carry on if no input
|
||||
if (strlen(inp) == 0) {
|
||||
if (strlen(inp_cpy) == 0) {
|
||||
result = TRUE;
|
||||
|
||||
// habdle command if input starts with a '/'
|
||||
} else if (inp[0] == '/') {
|
||||
char inp_cpy[strlen(inp) + 1];
|
||||
strcpy(inp_cpy, inp);
|
||||
} else if (inp_cpy[0] == '/') {
|
||||
char inp_cpy[strlen(inp_cpy) + 1];
|
||||
strcpy(inp_cpy, inp_cpy);
|
||||
char *command = strtok(inp_cpy, " ");
|
||||
result = cmd_execute(command, inp);
|
||||
result = cmd_execute(command, inp_cpy);
|
||||
|
||||
// call a default handler if input didn't start with '/'
|
||||
} else {
|
||||
result = cmd_execute_default(inp);
|
||||
result = cmd_execute_default(inp_cpy);
|
||||
}
|
||||
|
||||
inp_win_reset();
|
||||
roster_reset_search_attempts();
|
||||
ui_current_page_off();
|
||||
|
||||
g_free(inp_cpy);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,6 @@ void prof_handle_already_in_group(const char * const contact, const char * const
|
||||
void prof_handle_not_in_group(const char * const contact, const char * const group);
|
||||
void prof_handle_group_add(const char * const contact, const char * const group);
|
||||
void prof_handle_group_remove(const char * const contact, const char * const group);
|
||||
gboolean prof_process_input(char *inp);
|
||||
gboolean prof_process_input(const char *inp);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user