Add /getbool command
This commit is contained in:
parent
3a7fb4d8e1
commit
10d3c15143
|
@ -122,6 +122,7 @@ void fe_set_lag (server *serv, long lag);
|
||||||
void fe_set_throttle (server *serv);
|
void fe_set_throttle (server *serv);
|
||||||
void fe_set_away (server *serv);
|
void fe_set_away (server *serv);
|
||||||
void fe_serverlist_open (session *sess);
|
void fe_serverlist_open (session *sess);
|
||||||
|
void fe_get_bool (char *title, char *prompt, void *callback, void *userdata);
|
||||||
void fe_get_str (char *prompt, char *def, void *callback, void *ud);
|
void fe_get_str (char *prompt, char *def, void *callback, void *ud);
|
||||||
void fe_get_int (char *prompt, int def, void *callback, void *ud);
|
void fe_get_int (char *prompt, int def, void *callback, void *ud);
|
||||||
#define FRF_WRITE 1 /* save file */
|
#define FRF_WRITE 1 /* save file */
|
||||||
|
|
|
@ -1940,6 +1940,36 @@ typedef struct
|
||||||
session *sess;
|
session *sess;
|
||||||
} getvalinfo;
|
} getvalinfo;
|
||||||
|
|
||||||
|
static void
|
||||||
|
get_bool_cb (int val, getvalinfo *info)
|
||||||
|
{
|
||||||
|
char buf[512];
|
||||||
|
|
||||||
|
snprintf (buf, sizeof (buf), "%s %d", info->cmd, val);
|
||||||
|
if (is_session (info->sess))
|
||||||
|
handle_command (info->sess, buf, FALSE);
|
||||||
|
|
||||||
|
free (info->cmd);
|
||||||
|
free (info);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmd_getbool (struct session *sess, char *tbuf, char *word[], char *word_eol[])
|
||||||
|
{
|
||||||
|
getvalinfo *info;
|
||||||
|
|
||||||
|
if (!word[4][0])
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
info = malloc (sizeof (*info));
|
||||||
|
info->cmd = strdup (word[2]);
|
||||||
|
info->sess = sess;
|
||||||
|
|
||||||
|
fe_get_bool (word[3], word_eol[4], get_bool_cb, info);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_int_cb (int cancel, int val, getvalinfo *info)
|
get_int_cb (int cancel, int val, getvalinfo *info)
|
||||||
{
|
{
|
||||||
|
@ -3934,6 +3964,7 @@ const struct commands xc_cmds[] = {
|
||||||
N_("FLUSHQ, flushes the current server's send queue")},
|
N_("FLUSHQ, flushes the current server's send queue")},
|
||||||
{"GATE", cmd_gate, 0, 0, 1,
|
{"GATE", cmd_gate, 0, 0, 1,
|
||||||
N_("GATE <host> [<port>], proxies through a host, port defaults to 23")},
|
N_("GATE <host> [<port>], proxies through a host, port defaults to 23")},
|
||||||
|
{"GETBOOL", cmd_getbool, 0, 0, 1, "GETBOOL <command> <title> <text>"},
|
||||||
{"GETFILE", cmd_getfile, 0, 0, 1, "GETFILE [-folder] [-multi] [-save] <command> <title> [<initial>]"},
|
{"GETFILE", cmd_getfile, 0, 0, 1, "GETFILE [-folder] [-multi] [-save] <command> <title> [<initial>]"},
|
||||||
{"GETINT", cmd_getint, 0, 0, 1, "GETINT <default> <command> <prompt>"},
|
{"GETINT", cmd_getint, 0, 0, 1, "GETINT <default> <command> <prompt>"},
|
||||||
{"GETSTR", cmd_getstr, 0, 0, 1, "GETSTR <default> <command> <prompt>"},
|
{"GETSTR", cmd_getstr, 0, 0, 1, "GETSTR <default> <command> <prompt>"},
|
||||||
|
|
|
@ -374,6 +374,28 @@ gtkutil_get_number_response (GtkDialog *dialog, gint arg1, gpointer spin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtkutil_get_bool_response (GtkDialog *dialog, gint arg1, gpointer spin)
|
||||||
|
{
|
||||||
|
void (*callback) (int value, void *user_data);
|
||||||
|
void *user_data;
|
||||||
|
|
||||||
|
callback = g_object_get_data (G_OBJECT (dialog), "cb");
|
||||||
|
user_data = g_object_get_data (G_OBJECT (dialog), "ud");
|
||||||
|
|
||||||
|
switch (arg1)
|
||||||
|
{
|
||||||
|
case GTK_RESPONSE_REJECT:
|
||||||
|
callback (0, user_data);
|
||||||
|
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||||
|
break;
|
||||||
|
case GTK_RESPONSE_ACCEPT:
|
||||||
|
callback (1, user_data);
|
||||||
|
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fe_get_int (char *msg, int def, void *callback, void *userdata)
|
fe_get_int (char *msg, int def, void *callback, void *userdata)
|
||||||
{
|
{
|
||||||
|
@ -417,6 +439,35 @@ fe_get_int (char *msg, int def, void *callback, void *userdata)
|
||||||
gtk_widget_show_all (dialog);
|
gtk_widget_show_all (dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fe_get_bool (char *title, char *prompt, void *callback, void *userdata)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GtkWidget *prompt_label;
|
||||||
|
extern GtkWidget *parent_window;
|
||||||
|
|
||||||
|
dialog = gtk_dialog_new_with_buttons (title, NULL, 0,
|
||||||
|
GTK_STOCK_NO, GTK_RESPONSE_REJECT,
|
||||||
|
GTK_STOCK_YES, GTK_RESPONSE_ACCEPT,
|
||||||
|
NULL);
|
||||||
|
gtk_box_set_homogeneous (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), TRUE);
|
||||||
|
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||||
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent_window));
|
||||||
|
|
||||||
|
|
||||||
|
g_object_set_data (G_OBJECT (dialog), "cb", callback);
|
||||||
|
g_object_set_data (G_OBJECT (dialog), "ud", userdata);
|
||||||
|
|
||||||
|
prompt_label = gtk_label_new (prompt);
|
||||||
|
|
||||||
|
g_signal_connect (G_OBJECT (dialog), "response",
|
||||||
|
G_CALLBACK (gtkutil_get_bool_response), NULL);
|
||||||
|
|
||||||
|
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), prompt_label);
|
||||||
|
|
||||||
|
gtk_widget_show_all (dialog);
|
||||||
|
}
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback,
|
gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback,
|
||||||
void *userdata, char *labeltext)
|
void *userdata, char *labeltext)
|
||||||
|
|
|
@ -818,6 +818,10 @@ fe_serverlist_open (session *sess)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
|
fe_get_bool (char *title, char *prompt, void *callback, void *userdata)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void
|
||||||
fe_get_str (char *prompt, char *def, void *callback, void *ud)
|
fe_get_str (char *prompt, char *def, void *callback, void *ud)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue