mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add conf win callback
This commit is contained in:
parent
a952776b89
commit
b11d3a79df
@ -3899,11 +3899,11 @@ cmd_form(ProfWin *window, const char *const command, gchar **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "submit") == 0) {
|
if (g_strcmp0(args[0], "submit") == 0) {
|
||||||
iq_submit_room_config(confwin->roomjid, confwin->form);
|
confwin->submit(confwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "cancel") == 0) {
|
if (g_strcmp0(args[0], "cancel") == 0) {
|
||||||
iq_room_config_cancel(confwin->roomjid);
|
confwin->cancel(confwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
|
if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
|
||||||
|
@ -346,7 +346,7 @@ ProfWin* win_create_console(void);
|
|||||||
ProfWin* win_create_xmlconsole(void);
|
ProfWin* win_create_xmlconsole(void);
|
||||||
ProfWin* win_create_chat(const char *const barejid);
|
ProfWin* win_create_chat(const char *const barejid);
|
||||||
ProfWin* win_create_muc(const char *const roomjid);
|
ProfWin* win_create_muc(const char *const roomjid);
|
||||||
ProfWin* win_create_config(const char *const title, DataForm *form);
|
ProfWin* win_create_config(const char *const title, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel);
|
||||||
ProfWin* win_create_private(const char *const fulljid);
|
ProfWin* win_create_private(const char *const fulljid);
|
||||||
ProfWin* win_create_plugin(const char *const plugin_name, const char *const tag);
|
ProfWin* win_create_plugin(const char *const plugin_name, const char *const tag);
|
||||||
void win_update_virtual(ProfWin *window);
|
void win_update_virtual(ProfWin *window);
|
||||||
@ -380,6 +380,7 @@ char* win_to_string(ProfWin *window);
|
|||||||
void win_command_list_error(ProfWin *window, const char *const error);
|
void win_command_list_error(ProfWin *window, const char *const error);
|
||||||
void win_command_exec_error(ProfWin *window, const char *const command, const char *const error, ...);
|
void win_command_exec_error(ProfWin *window, const char *const command, const char *const error, ...);
|
||||||
void win_handle_command_list(ProfWin *window, GSList *cmds);
|
void win_handle_command_list(ProfWin *window, GSList *cmds);
|
||||||
|
void win_handle_command_exec_status(ProfWin *window, const char *const type, const char *const value);
|
||||||
void win_handle_command_exec_result_note(ProfWin *window, const char *const type, const char *const value);
|
void win_handle_command_exec_result_note(ProfWin *window, const char *const type, const char *const value);
|
||||||
|
|
||||||
// desktop notifications
|
// desktop notifications
|
||||||
|
@ -172,12 +172,17 @@ typedef struct prof_muc_win_t {
|
|||||||
char *message_char;
|
char *message_char;
|
||||||
} ProfMucWin;
|
} ProfMucWin;
|
||||||
|
|
||||||
typedef struct prof_conf_win_t {
|
typedef struct prof_conf_win_t ProfConfWin;
|
||||||
|
typedef void (*ProfConfWinCallback)(ProfConfWin *);
|
||||||
|
|
||||||
|
struct prof_conf_win_t {
|
||||||
ProfWin window;
|
ProfWin window;
|
||||||
char *roomjid;
|
char *roomjid;
|
||||||
DataForm *form;
|
DataForm *form;
|
||||||
unsigned long memcheck;
|
unsigned long memcheck;
|
||||||
} ProfConfWin;
|
ProfConfWinCallback submit;
|
||||||
|
ProfConfWinCallback cancel;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct prof_private_win_t {
|
typedef struct prof_private_win_t {
|
||||||
ProfWin window;
|
ProfWin window;
|
||||||
|
@ -203,13 +203,15 @@ win_create_muc(const char *const roomjid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProfWin*
|
ProfWin*
|
||||||
win_create_config(const char *const roomjid, DataForm *form)
|
win_create_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel)
|
||||||
{
|
{
|
||||||
ProfConfWin *new_win = malloc(sizeof(ProfConfWin));
|
ProfConfWin *new_win = malloc(sizeof(ProfConfWin));
|
||||||
new_win->window.type = WIN_CONFIG;
|
new_win->window.type = WIN_CONFIG;
|
||||||
new_win->window.layout = _win_create_simple_layout();
|
new_win->window.layout = _win_create_simple_layout();
|
||||||
new_win->roomjid = strdup(roomjid);
|
new_win->roomjid = strdup(roomjid);
|
||||||
new_win->form = form;
|
new_win->form = form;
|
||||||
|
new_win->submit = submit;
|
||||||
|
new_win->cancel = cancel;
|
||||||
|
|
||||||
new_win->memcheck = PROFCONFWIN_MEMCHECK;
|
new_win->memcheck = PROFCONFWIN_MEMCHECK;
|
||||||
|
|
||||||
@ -1768,6 +1770,13 @@ win_handle_command_list(ProfWin *window, GSList *cmds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
win_handle_command_exec_status(ProfWin *window, const char *const command, const char *const value)
|
||||||
|
{
|
||||||
|
assert(window != NULL);
|
||||||
|
win_println(window, THEME_DEFAULT, '!', "%s %s", command, value);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win_handle_command_exec_result_note(ProfWin *window, const char *const type, const char *const value)
|
win_handle_command_exec_result_note(ProfWin *window, const char *const type, const char *const value)
|
||||||
{
|
{
|
||||||
|
@ -657,12 +657,12 @@ wins_new_muc(const char *const roomjid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProfWin*
|
ProfWin*
|
||||||
wins_new_config(const char *const roomjid, DataForm *form)
|
wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel)
|
||||||
{
|
{
|
||||||
GList *keys = g_hash_table_get_keys(windows);
|
GList *keys = g_hash_table_get_keys(windows);
|
||||||
int result = _wins_get_next_available_num(keys);
|
int result = _wins_get_next_available_num(keys);
|
||||||
g_list_free(keys);
|
g_list_free(keys);
|
||||||
ProfWin *newwin = win_create_config(roomjid, form);
|
ProfWin *newwin = win_create_config(roomjid, form, submit, cancel);
|
||||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||||
return newwin;
|
return newwin;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ void wins_init(void);
|
|||||||
ProfWin* wins_new_xmlconsole(void);
|
ProfWin* wins_new_xmlconsole(void);
|
||||||
ProfWin* wins_new_chat(const char *const barejid);
|
ProfWin* wins_new_chat(const char *const barejid);
|
||||||
ProfWin* wins_new_muc(const char *const roomjid);
|
ProfWin* wins_new_muc(const char *const roomjid);
|
||||||
ProfWin* wins_new_config(const char *const roomjid, DataForm *form);
|
ProfWin* wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback submit, ProfConfWinCallback cancel);
|
||||||
ProfWin* wins_new_private(const char *const fulljid);
|
ProfWin* wins_new_private(const char *const fulljid);
|
||||||
ProfWin* wins_new_plugin(const char *const plugin_name, const char *const tag);
|
ProfWin* wins_new_plugin(const char *const plugin_name, const char *const tag);
|
||||||
|
|
||||||
|
@ -586,10 +586,10 @@ iq_request_room_config_form(const char *const room_jid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
iq_submit_room_config(const char *const room, DataForm *form)
|
iq_submit_room_config(ProfConfWin *confwin)
|
||||||
{
|
{
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_room_config_submit_iq(ctx, room, form);
|
xmpp_stanza_t *iq = stanza_create_room_config_submit_iq(ctx, confwin->roomjid, confwin->form);
|
||||||
|
|
||||||
const char *id = xmpp_stanza_get_id(iq);
|
const char *id = xmpp_stanza_get_id(iq);
|
||||||
iq_id_handler_add(id, _room_config_submit_id_handler, NULL, NULL);
|
iq_id_handler_add(id, _room_config_submit_id_handler, NULL, NULL);
|
||||||
@ -599,10 +599,10 @@ iq_submit_room_config(const char *const room, DataForm *form)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
iq_room_config_cancel(const char *const room_jid)
|
iq_room_config_cancel(ProfConfWin *confwin)
|
||||||
{
|
{
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_room_config_cancel_iq(ctx, room_jid);
|
xmpp_stanza_t *iq = stanza_create_room_config_cancel_iq(ctx, confwin->roomjid);
|
||||||
iq_send_stanza(iq);
|
iq_send_stanza(iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
}
|
}
|
||||||
@ -1106,61 +1106,71 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata
|
|||||||
log_debug("IQ command exec response handler fired.");
|
log_debug("IQ command exec response handler fired.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProfWin *win = wins_get_by_string(from);
|
||||||
|
if (win == NULL) {
|
||||||
|
/* No more window associated with this command.
|
||||||
|
* Fallback to console. */
|
||||||
|
win = wins_get_console();
|
||||||
|
}
|
||||||
|
|
||||||
// handle error responses
|
// handle error responses
|
||||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||||
char *error_message = stanza_get_error_message(stanza);
|
char *error_message = stanza_get_error_message(stanza);
|
||||||
log_debug("Error executing command %s for %s: %s", command, from, error_message);
|
log_debug("Error executing command %s for %s: %s", command, from, error_message);
|
||||||
ProfWin *win = wins_get_by_string(from);
|
|
||||||
if (win) {
|
|
||||||
win_command_exec_error(win, command, error_message);
|
win_command_exec_error(win, command, error_message);
|
||||||
}
|
|
||||||
free(error_message);
|
free(error_message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *cmd = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_COMMAND);
|
xmpp_stanza_t *cmd = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_COMMAND);
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
/* TODO */
|
log_error("No command element for command response");
|
||||||
|
win_command_exec_error(win, command, "Malformed command response");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfWin *win = wins_get_by_string(from);
|
|
||||||
|
|
||||||
const char *status = xmpp_stanza_get_attribute(cmd, STANZA_ATTR_STATUS);
|
const char *status = xmpp_stanza_get_attribute(cmd, STANZA_ATTR_STATUS);
|
||||||
if (g_strcmp0(status, "completed") == 0) {
|
if (g_strcmp0(status, "completed") == 0) {
|
||||||
if (win) {
|
win_handle_command_exec_status(win, command, "completed");
|
||||||
xmpp_stanza_t *note = xmpp_stanza_get_child_by_name(cmd, "note");
|
xmpp_stanza_t *note = xmpp_stanza_get_child_by_name(cmd, "note");
|
||||||
if (note) {
|
if (note) {
|
||||||
const char *type = xmpp_stanza_get_attribute(note, "type");
|
const char *type = xmpp_stanza_get_attribute(note, "type");
|
||||||
const char *value = xmpp_stanza_get_text(note);
|
const char *value = xmpp_stanza_get_text(note);
|
||||||
win_handle_command_exec_result_note(win, type, value);
|
win_handle_command_exec_result_note(win, type, value);
|
||||||
}
|
}
|
||||||
}
|
} else if (g_strcmp0(status, "executing") == 0) {
|
||||||
return 0;
|
win_handle_command_exec_status(win, command, "executing");
|
||||||
}
|
|
||||||
|
|
||||||
if (g_strcmp0(status, "executing") == 0) {
|
/* Looking for a jabber:x:data type form */
|
||||||
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(cmd, STANZA_NS_DATA);
|
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(cmd, STANZA_NS_DATA);
|
||||||
if (x == NULL) {
|
if (x == NULL) {
|
||||||
/* TODO */
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *form_type = xmpp_stanza_get_type(x);
|
const char *form_type = xmpp_stanza_get_type(x);
|
||||||
if (g_strcmp0(form_type, "form") != 0) {
|
if (g_strcmp0(form_type, "form") != 0) {
|
||||||
/* TODO */
|
log_error("Unsupported payload in command response");
|
||||||
|
win_command_exec_error(win, command, "Unsupported command response");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataForm *form = form_create(x);
|
DataForm *form = form_create(x);
|
||||||
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form);
|
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, NULL, NULL);
|
||||||
confwin_handle_configuration(confwin, form);
|
confwin_handle_configuration(confwin, form);
|
||||||
|
} else if (g_strcmp0(status, "canceled") == 0) {
|
||||||
|
win_handle_command_exec_status(win, command, "canceled");
|
||||||
|
xmpp_stanza_t *note = xmpp_stanza_get_child_by_name(cmd, "note");
|
||||||
|
if (note) {
|
||||||
|
const char *type = xmpp_stanza_get_attribute(note, "type");
|
||||||
|
const char *value = xmpp_stanza_get_text(note);
|
||||||
|
win_handle_command_exec_result_note(win, type, value);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (g_strcmp0(status, "canceled") == 0) {
|
log_error("Unsupported command status %s", status);
|
||||||
|
win_command_exec_error(win, command, "Malformed command response");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO */
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1693,7 +1703,7 @@ _room_config_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataForm *form = form_create(x);
|
DataForm *form = form_create(x);
|
||||||
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form);
|
ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, iq_submit_room_config, iq_room_config_cancel);
|
||||||
confwin_handle_configuration(confwin, form);
|
confwin_handle_configuration(confwin, form);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -171,8 +171,8 @@ void iq_set_autoping(int seconds);
|
|||||||
void iq_confirm_instant_room(const char *const room_jid);
|
void iq_confirm_instant_room(const char *const room_jid);
|
||||||
void iq_destroy_room(const char *const room_jid);
|
void iq_destroy_room(const char *const room_jid);
|
||||||
void iq_request_room_config_form(const char *const room_jid);
|
void iq_request_room_config_form(const char *const room_jid);
|
||||||
void iq_submit_room_config(const char *const room, DataForm *form);
|
void iq_submit_room_config(ProfConfWin *confwin);
|
||||||
void iq_room_config_cancel(const char *const room_jid);
|
void iq_room_config_cancel(ProfConfWin *confwin);
|
||||||
void iq_send_ping(const char *const target);
|
void iq_send_ping(const char *const target);
|
||||||
void iq_room_info_request(const char *const room, gboolean display_result);
|
void iq_room_info_request(const char *const room, gboolean display_result);
|
||||||
void iq_room_affiliation_list(const char *const room, char *affiliation);
|
void iq_room_affiliation_list(const char *const room, char *affiliation);
|
||||||
|
@ -185,8 +185,8 @@ void iq_http_upload_request(HTTPUpload *upload) {}
|
|||||||
void iq_confirm_instant_room(const char * const room_jid) {}
|
void iq_confirm_instant_room(const char * const room_jid) {}
|
||||||
void iq_destroy_room(const char * const room_jid) {}
|
void iq_destroy_room(const char * const room_jid) {}
|
||||||
void iq_request_room_config_form(const char * const room_jid) {}
|
void iq_request_room_config_form(const char * const room_jid) {}
|
||||||
void iq_submit_room_config(const char * const room, DataForm *form) {}
|
void iq_submit_room_config(ProfConfWin *confwin) {}
|
||||||
void iq_room_config_cancel(const char * const room_jid) {}
|
void iq_room_config_cancel(ProfConfWin *confwin) {}
|
||||||
void iq_send_ping(const char * const target) {}
|
void iq_send_ping(const char * const target) {}
|
||||||
void iq_send_caps_request(const char * const to, const char * const id,
|
void iq_send_caps_request(const char * const to, const char * const id,
|
||||||
const char * const node, const char * const ver) {}
|
const char * const node, const char * const ver) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user