mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added parameter to /close
2,3,4,5,6,7,8,9,0 will close specified window. 'all' will close all windows. closes #159
This commit is contained in:
parent
c1ee75da40
commit
57e64bebe5
@ -481,12 +481,14 @@ static struct cmd_t main_commands[] =
|
|||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/close",
|
{ "/close",
|
||||||
_cmd_close, parse_args, 0, 0,
|
_cmd_close, parse_args, 0, 1,
|
||||||
{ "/close", "Close current chat window.",
|
{ "/close [win|all]", "Close a window window.",
|
||||||
{ "/close",
|
{ "/close [win|all]",
|
||||||
"------",
|
"----------------",
|
||||||
"Close the current chat window, no message is sent to the recipient,",
|
"Passing no argument will close the current window.",
|
||||||
"The chat window will become available for new chats.",
|
"Passing 2,3,4,5,6,7,8,9 or 0 will close the specified window.",
|
||||||
|
"Passing 'all' will close all currently open windows.",
|
||||||
|
"The console window cannot be closed.",
|
||||||
"If in a chat room, you will leave the room.",
|
"If in a chat room, you will leave the room.",
|
||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
@ -2476,27 +2478,16 @@ _cmd_clear(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void _close_connected_win(index)
|
||||||
_cmd_close(gchar **args, struct cmd_help_t help)
|
|
||||||
{
|
{
|
||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
win_type_t win_type = ui_win_type(index);
|
||||||
win_type_t win_type = ui_current_win_type();
|
|
||||||
|
|
||||||
// cannot close console window
|
|
||||||
if (win_type == WIN_CONSOLE) {
|
|
||||||
cons_show("Cannot close console window.");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle leaving rooms, or chat
|
|
||||||
if (conn_status == JABBER_CONNECTED) {
|
|
||||||
if (win_type == WIN_MUC) {
|
if (win_type == WIN_MUC) {
|
||||||
char *room_jid = ui_current_recipient();
|
char *room_jid = ui_recipient(index);
|
||||||
presence_leave_chat_room(room_jid);
|
presence_leave_chat_room(room_jid);
|
||||||
} else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) {
|
} else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) {
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_STATES)) {
|
if (prefs_get_boolean(PREF_STATES)) {
|
||||||
char *recipient = ui_current_recipient();
|
char *recipient = ui_recipient(index);
|
||||||
|
|
||||||
// send <gone/> chat state before closing
|
// send <gone/> chat state before closing
|
||||||
if (chat_session_get_recipient_supports(recipient)) {
|
if (chat_session_get_recipient_supports(recipient)) {
|
||||||
@ -2508,8 +2499,60 @@ _cmd_close(gchar **args, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_cmd_close(gchar **args, struct cmd_help_t help)
|
||||||
|
{
|
||||||
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
|
int index = 0;
|
||||||
|
int curr = 0;
|
||||||
|
|
||||||
|
if (args[0] == NULL) {
|
||||||
|
index = ui_current_win_index();
|
||||||
|
} else if (strcmp(args[0], "all") == 0) {
|
||||||
|
for (curr = 1; curr <= 9; curr++) {
|
||||||
|
if (ui_win_exists(curr)) {
|
||||||
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
|
_close_connected_win(curr);
|
||||||
|
}
|
||||||
|
ui_close_win(curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cons_show("Closed all windows.");
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
index = atoi(args[0]);
|
||||||
|
if (index == 0) {
|
||||||
|
index = 9;
|
||||||
|
} else {
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == 0) {
|
||||||
|
cons_show("Cannot close console window.");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > 9 || index < 0) {
|
||||||
|
cons_show("No such window exists.");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ui_win_exists(index)) {
|
||||||
|
cons_show("Window is not open.");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// handle leaving rooms, or chat
|
||||||
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
|
_close_connected_win(index);
|
||||||
|
}
|
||||||
|
|
||||||
// close the window
|
// close the window
|
||||||
ui_close_current();
|
ui_close_win(index);
|
||||||
|
cons_show("Closed window %d", index + 1);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -205,6 +205,11 @@ ui_windows_full(void)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean ui_win_exists(int index)
|
||||||
|
{
|
||||||
|
return (windows[index] != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ui_duck_exists(void)
|
ui_duck_exists(void)
|
||||||
{
|
{
|
||||||
@ -550,12 +555,46 @@ ui_close_current(void)
|
|||||||
current_win_dirty = TRUE;
|
current_win_dirty = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_close_win(int index)
|
||||||
|
{
|
||||||
|
win_free(windows[index]);
|
||||||
|
windows[index] = NULL;
|
||||||
|
status_bar_inactive(index);
|
||||||
|
|
||||||
|
if (index == current_index) {
|
||||||
|
_set_current(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_bar_active(0);
|
||||||
|
title_bar_title();
|
||||||
|
|
||||||
|
current_win_dirty = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
win_type_t
|
win_type_t
|
||||||
ui_current_win_type(void)
|
ui_current_win_type(void)
|
||||||
{
|
{
|
||||||
return current->type;
|
return current->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ui_current_win_index(void)
|
||||||
|
{
|
||||||
|
return current_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
win_type_t
|
||||||
|
ui_win_type(int index)
|
||||||
|
{
|
||||||
|
return windows[index]->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
ui_recipient(int index)
|
||||||
|
{
|
||||||
|
return strdup(windows[index]->from);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
ui_current_recipient(void)
|
ui_current_recipient(void)
|
||||||
{
|
{
|
||||||
|
@ -69,11 +69,17 @@ void ui_console_dirty(void);
|
|||||||
void ui_close_current(void);
|
void ui_close_current(void);
|
||||||
void ui_clear_current(void);
|
void ui_clear_current(void);
|
||||||
win_type_t ui_current_win_type(void);
|
win_type_t ui_current_win_type(void);
|
||||||
|
int ui_current_win_index(void);
|
||||||
char* ui_current_recipient(void);
|
char* ui_current_recipient(void);
|
||||||
void ui_current_print_line(const char * const msg, ...);
|
void ui_current_print_line(const char * const msg, ...);
|
||||||
void ui_current_error_line(const char * const msg);
|
void ui_current_error_line(const char * const msg);
|
||||||
void ui_current_page_off(void);
|
void ui_current_page_off(void);
|
||||||
|
|
||||||
|
win_type_t ui_win_type(int index);
|
||||||
|
char * ui_recipient(int index);
|
||||||
|
void ui_close_win(int index);
|
||||||
|
gboolean ui_win_exists(int index);
|
||||||
|
|
||||||
// ui events
|
// ui events
|
||||||
void ui_contact_typing(const char * const from);
|
void ui_contact_typing(const char * const from);
|
||||||
void ui_incoming_msg(const char * const from, const char * const message,
|
void ui_incoming_msg(const char * const from, const char * const message,
|
||||||
|
Loading…
Reference in New Issue
Block a user