mirror of
https://github.com/irssi/irssi.git
synced 2024-09-01 04:14:16 -04:00
Added keyboard_entry_redirect() function to keyboard.[ch] which sends
the signal "gui entry redirect" signal. Added possibility to keep the entry hidden. /OPER [<nick> [<password>]] - syntax changed. If password isn't given, it's asked. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1063 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
d844880515
commit
596ef586b2
@ -29,6 +29,7 @@
|
||||
|
||||
#include "levels.h"
|
||||
#include "printtext.h"
|
||||
#include "keyboard.h"
|
||||
|
||||
static void set_print(SETTINGS_REC *rec)
|
||||
{
|
||||
@ -274,10 +275,9 @@ static void cmd_save(const char *data)
|
||||
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
IRCTXT_CONFIG_MODIFIED, data);
|
||||
signal_emit("gui entry redirect", 4,
|
||||
settings_save_confirm,
|
||||
_("Overwrite config (y/N)?"),
|
||||
GINT_TO_POINTER(FALSE), g_strdup(data));
|
||||
keyboard_entry_redirect((SIGNAL_FUNC) settings_save_confirm,
|
||||
_("Overwrite config (y/N)?"),
|
||||
0, g_strdup(data));
|
||||
}
|
||||
|
||||
void fe_settings_init(void)
|
||||
|
@ -234,6 +234,13 @@ int key_pressed(const char *key, void *data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void keyboard_entry_redirect(SIGNAL_FUNC func, const char *entry,
|
||||
int flags, void *data)
|
||||
{
|
||||
signal_emit("gui entry redirect", 4, func, entry,
|
||||
GINT_TO_POINTER(flags), data);
|
||||
}
|
||||
|
||||
static void sig_command(const char *data)
|
||||
{
|
||||
const char *cmdchars;
|
||||
|
@ -29,6 +29,12 @@ void key_configure_remove(const char *key);
|
||||
KEYINFO_REC *key_info_find(const char *id);
|
||||
int key_pressed(const char *key, void *data);
|
||||
|
||||
#define ENTRY_REDIRECT_FLAG_HOTKEY 0x01
|
||||
#define ENTRY_REDIRECT_FLAG_HIDDEN 0x02
|
||||
|
||||
void keyboard_entry_redirect(SIGNAL_FUNC func, const char *entry,
|
||||
int flags, void *data);
|
||||
|
||||
void keyboard_init(void);
|
||||
void keyboard_deinit(void);
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "fe-windows.h"
|
||||
#include "window-items.h"
|
||||
#include "printtext.h"
|
||||
#include "keyboard.h"
|
||||
|
||||
/* SYNTAX: ME <message> */
|
||||
static void cmd_me(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
|
||||
@ -371,6 +372,50 @@ static void cmd_ts(const char *data)
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
IRC_SERVER_REC *server;
|
||||
char *nick;
|
||||
} OPER_PASS_REC;
|
||||
|
||||
static void cmd_oper_got_pass(const char *password, OPER_PASS_REC *rec)
|
||||
{
|
||||
if (*password != '\0')
|
||||
irc_send_cmdv(rec->server, "OPER %s %s", rec->nick, password);
|
||||
g_free(rec->nick);
|
||||
g_free(rec);
|
||||
}
|
||||
|
||||
/* SYNTAX: OPER [<nick> [<password>]] */
|
||||
static void cmd_oper(const char *data, IRC_SERVER_REC *server)
|
||||
{
|
||||
char *nick, *password;
|
||||
void *free_arg;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
if (!IS_IRC_SERVER(server) || !server->connected)
|
||||
cmd_return_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2, &nick, &password))
|
||||
return;
|
||||
if (*password == '\0') {
|
||||
/* password not given, ask it.
|
||||
irc/core handles the /OPER when password is given */
|
||||
OPER_PASS_REC *rec;
|
||||
|
||||
rec = g_new(OPER_PASS_REC, 1);
|
||||
rec->server = server;
|
||||
rec->nick = g_strdup(*nick != '\0' ? nick : server->nick);
|
||||
|
||||
keyboard_entry_redirect((SIGNAL_FUNC) cmd_oper_got_pass,
|
||||
_("Operator password:"),
|
||||
ENTRY_REDIRECT_FLAG_HIDDEN, rec);
|
||||
|
||||
signal_stop();
|
||||
}
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
void fe_irc_commands_init(void)
|
||||
{
|
||||
command_bind_last("me", NULL, (SIGNAL_FUNC) cmd_me);
|
||||
@ -386,6 +431,7 @@ void fe_irc_commands_init(void)
|
||||
command_bind("ver", NULL, (SIGNAL_FUNC) cmd_ver);
|
||||
command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic);
|
||||
command_bind("ts", NULL, (SIGNAL_FUNC) cmd_ts);
|
||||
command_bind("oper", NULL, (SIGNAL_FUNC) cmd_oper);
|
||||
}
|
||||
|
||||
void fe_irc_commands_deinit(void)
|
||||
@ -403,4 +449,5 @@ void fe_irc_commands_deinit(void)
|
||||
command_unbind("ver", (SIGNAL_FUNC) cmd_ver);
|
||||
command_unbind("topic", (SIGNAL_FUNC) cmd_topic);
|
||||
command_unbind("ts", (SIGNAL_FUNC) cmd_ts);
|
||||
command_unbind("oper", (SIGNAL_FUNC) cmd_oper);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
static GString *entry;
|
||||
static int promptlen, permanent_prompt, pos, scrstart, scrpos;
|
||||
static int prompt_hidden;
|
||||
static char *prompt;
|
||||
|
||||
static void entry_screenpos(void)
|
||||
@ -54,7 +55,9 @@ static void entry_update(void)
|
||||
move(LINES-1, promptlen);
|
||||
|
||||
for (p = entry->str+scrstart, n = 0; n < len; n++, p++) {
|
||||
if ((unsigned char) *p >= 32)
|
||||
if (prompt_hidden)
|
||||
addch(' ');
|
||||
else if ((unsigned char) *p >= 32)
|
||||
addch((unsigned char) *p);
|
||||
else {
|
||||
set_color(stdscr, ATTR_REVERSE);
|
||||
@ -97,6 +100,11 @@ void gui_entry_set_perm_prompt(const char *str)
|
||||
gui_entry_set_prompt(NULL);
|
||||
}
|
||||
|
||||
void gui_entry_set_hidden(int hidden)
|
||||
{
|
||||
prompt_hidden = hidden;
|
||||
}
|
||||
|
||||
void gui_entry_remove_perm_prompt(void)
|
||||
{
|
||||
permanent_prompt = FALSE;
|
||||
@ -248,6 +256,7 @@ void gui_entry_init(void)
|
||||
pos = scrpos = 0;
|
||||
prompt = NULL; promptlen = 0;
|
||||
permanent_prompt = FALSE;
|
||||
prompt_hidden = FALSE;
|
||||
}
|
||||
|
||||
void gui_entry_deinit(void)
|
||||
|
@ -6,6 +6,7 @@ void gui_entry_set_prompt(const char *str);
|
||||
/* permanent prompt can't be overwritten with gui_entry_set_prompt() */
|
||||
void gui_entry_set_perm_prompt(const char *str);
|
||||
void gui_entry_remove_perm_prompt(void);
|
||||
void gui_entry_set_hidden(int hidden);
|
||||
|
||||
void gui_entry_set_text(const char *str);
|
||||
char *gui_entry_get_text(void);
|
||||
|
@ -44,7 +44,7 @@ typedef void (*ENTRY_REDIRECT_ENTRY_FUNC) (const char *line, void *data, SERVER_
|
||||
|
||||
typedef struct {
|
||||
SIGNAL_FUNC func;
|
||||
int key;
|
||||
int flags;
|
||||
void *data;
|
||||
} ENTRY_REDIRECT_REC;
|
||||
|
||||
@ -75,12 +75,16 @@ static void handle_entry_redirect(const char *line)
|
||||
ENTRY_REDIRECT_ENTRY_FUNC func;
|
||||
void *data;
|
||||
|
||||
gui_entry_set_hidden(FALSE);
|
||||
|
||||
func = (ENTRY_REDIRECT_ENTRY_FUNC) redir->func;
|
||||
data = redir->data;
|
||||
g_free_and_null(redir);
|
||||
|
||||
if (func != NULL)
|
||||
func(line, data, active_win->active_server, active_win->active);
|
||||
if (func != NULL) {
|
||||
func(line, data, active_win->active_server,
|
||||
active_win->active);
|
||||
}
|
||||
|
||||
gui_entry_remove_perm_prompt();
|
||||
window_update_prompt();
|
||||
@ -158,6 +162,7 @@ void handle_key(int key)
|
||||
{
|
||||
const char *keyname;
|
||||
char *str;
|
||||
int add_history;
|
||||
|
||||
/* Quit if we get 5 CTRL-C's in a row. */
|
||||
if (key != CTRL('c'))
|
||||
@ -167,7 +172,7 @@ void handle_key(int key)
|
||||
|
||||
idle_time = time(NULL);
|
||||
|
||||
if (redir != NULL && redir->key) {
|
||||
if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) {
|
||||
handle_key_redirect(key);
|
||||
return;
|
||||
}
|
||||
@ -218,12 +223,21 @@ void handle_key(int key)
|
||||
|
||||
translate_output(str);
|
||||
|
||||
if (redir == NULL)
|
||||
signal_emit("send command", 3, str, active_win->active_server, active_win->active);
|
||||
else
|
||||
add_history = TRUE;
|
||||
if (redir == NULL) {
|
||||
signal_emit("send command", 3, str,
|
||||
active_win->active_server,
|
||||
active_win->active);
|
||||
} else {
|
||||
if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
|
||||
add_history = FALSE;
|
||||
handle_entry_redirect(str);
|
||||
}
|
||||
|
||||
command_history_add(active_win, gui_entry_get_text(), FALSE);
|
||||
if (add_history) {
|
||||
command_history_add(active_win, gui_entry_get_text(),
|
||||
FALSE);
|
||||
}
|
||||
gui_entry_set_text("");
|
||||
command_history_clear_pos(active_win);
|
||||
break;
|
||||
@ -531,13 +545,16 @@ static void sig_window_auto_changed(void)
|
||||
gui_entry_set_text("");
|
||||
}
|
||||
|
||||
static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry, gpointer key, void *data)
|
||||
static void sig_gui_entry_redirect(SIGNAL_FUNC func, const char *entry,
|
||||
void *flags, void *data)
|
||||
{
|
||||
redir = g_new0(ENTRY_REDIRECT_REC, 1);
|
||||
redir->func = func;
|
||||
redir->key = key != NULL;
|
||||
redir->flags = GPOINTER_TO_INT(flags);
|
||||
redir->data = data;
|
||||
|
||||
if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
|
||||
gui_entry_set_hidden(TRUE);
|
||||
gui_entry_set_perm_prompt(entry);
|
||||
}
|
||||
|
||||
|
@ -1000,7 +1000,7 @@ static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: OPER [<nick>] <password> */
|
||||
/* SYNTAX: OPER [<nick> [<password>]] */
|
||||
static void cmd_oper(const char *data, IRC_SERVER_REC *server)
|
||||
{
|
||||
char *nick, *password;
|
||||
@ -1010,13 +1010,10 @@ static void cmd_oper(const char *data, IRC_SERVER_REC *server)
|
||||
if (!IS_IRC_SERVER(server) || !server->connected)
|
||||
cmd_return_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
/* asking for password is handled by fe-common */
|
||||
if (!cmd_get_params(data, &free_arg, 2, &nick, &password))
|
||||
return;
|
||||
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
if (*password == '\0') {
|
||||
password = nick;
|
||||
nick = server->nick;
|
||||
}
|
||||
if (*password == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
irc_send_cmdv(server, "OPER %s %s", nick, password);
|
||||
cmd_params_free(free_arg);
|
||||
|
Loading…
Reference in New Issue
Block a user