Added auto xa option, tidied autoaway code
This commit is contained in:
@@ -1374,28 +1374,33 @@ static struct cmd_t command_defs[] =
|
||||
},
|
||||
|
||||
{ "/autoaway",
|
||||
cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting,
|
||||
cmd_autoaway, parse_args_with_freetext, 2, 3, &cons_autoaway_setting,
|
||||
CMD_TAGS(
|
||||
CMD_TAG_PRESENCE)
|
||||
CMD_SYN(
|
||||
"/autoaway mode idle|away|off",
|
||||
"/autoaway time <minutes>",
|
||||
"/autoaway message <message>|off",
|
||||
"/autoaway time away|xa <minutes>",
|
||||
"/autoaway message away|xa <message>|off",
|
||||
"/autoaway check on|off")
|
||||
CMD_DESC(
|
||||
"Manage autoway settings for idle time.")
|
||||
CMD_ARGS(
|
||||
{ "mode idle", "Sends idle time, status remains online." },
|
||||
{ "mode away", "Sends an away presence." },
|
||||
{ "mode off", "Disabled (default)." },
|
||||
{ "time <minutes>", "Number of minutes before the presence change is sent, default: 15." },
|
||||
{ "message <message>", "Optional message to send with the presence change, default: off (disabled)." },
|
||||
{ "message off", "Send no message with autoaway presence." },
|
||||
{ "check on|off", "When enabled, checks for activity and sends online presence, default: on." })
|
||||
{ "mode idle", "Sends idle time, status remains online." },
|
||||
{ "mode away", "Sends away and xa presence as well as idle time." },
|
||||
{ "mode off", "Disabled (default)." },
|
||||
{ "time away <minutes>", "Number of minutes before the away presence is sent, default: 15." },
|
||||
{ "time xa <minutes>", "Number of minutes before the xa presence is sent, default: 0 (disabled)." },
|
||||
{ "message away <message>", "Optional message to send with the away presence, default: off (disabled)." },
|
||||
{ "message xa <message>", "Optional message to send with the xa presence, default: off (disabled)." },
|
||||
{ "message away off", "Send no message with away presence." },
|
||||
{ "message xa off", "Send no message with xa presence." },
|
||||
{ "check on|off", "When enabled, checks for activity and sends online presence, default: on." })
|
||||
CMD_EXAMPLES(
|
||||
"/autoaway mode idle",
|
||||
"/autoaway time 30",
|
||||
"/autoaway message I'm not really doing much",
|
||||
"/autoaway mode away",
|
||||
"/autoaway time away 30",
|
||||
"/autoaway message away Away from computer for a while",
|
||||
"/autoaway time xa 120",
|
||||
"/autoaway message xa Away from computer for a very long time",
|
||||
"/autoaway check off")
|
||||
},
|
||||
|
||||
@@ -1658,6 +1663,7 @@ static Autocomplete sub_ac;
|
||||
static Autocomplete log_ac;
|
||||
static Autocomplete autoaway_ac;
|
||||
static Autocomplete autoaway_mode_ac;
|
||||
static Autocomplete autoaway_presence_ac;
|
||||
static Autocomplete autoconnect_ac;
|
||||
static Autocomplete titlebar_ac;
|
||||
static Autocomplete theme_ac;
|
||||
@@ -1823,6 +1829,10 @@ cmd_init(void)
|
||||
autocomplete_add(autoaway_mode_ac, "idle");
|
||||
autocomplete_add(autoaway_mode_ac, "off");
|
||||
|
||||
autoaway_presence_ac = autocomplete_new();
|
||||
autocomplete_add(autoaway_presence_ac, "away");
|
||||
autocomplete_add(autoaway_presence_ac, "xa");
|
||||
|
||||
autoconnect_ac = autocomplete_new();
|
||||
autocomplete_add(autoconnect_ac, "set");
|
||||
autocomplete_add(autoconnect_ac, "off");
|
||||
@@ -2132,6 +2142,7 @@ cmd_uninit(void)
|
||||
autocomplete_free(prefs_ac);
|
||||
autocomplete_free(autoaway_ac);
|
||||
autocomplete_free(autoaway_mode_ac);
|
||||
autocomplete_free(autoaway_presence_ac);
|
||||
autocomplete_free(autoconnect_ac);
|
||||
autocomplete_free(theme_ac);
|
||||
autocomplete_free(theme_load_ac);
|
||||
@@ -2311,6 +2322,7 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
autocomplete_reset(commands_ac);
|
||||
autocomplete_reset(autoaway_ac);
|
||||
autocomplete_reset(autoaway_mode_ac);
|
||||
autocomplete_reset(autoaway_presence_ac);
|
||||
autocomplete_reset(autoconnect_ac);
|
||||
autocomplete_reset(theme_ac);
|
||||
if (theme_load_ac) {
|
||||
@@ -2925,8 +2937,18 @@ _autoaway_autocomplete(ProfWin *window, const char * const input)
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/autoaway check",
|
||||
prefs_autocomplete_boolean_choice);
|
||||
|
||||
result = autocomplete_param_with_ac(input, "/autoaway time", autoaway_presence_ac, TRUE);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_ac(input, "/autoaway message", autoaway_presence_ac, TRUE);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_func(input, "/autoaway check", prefs_autocomplete_boolean_choice);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3973,56 +3973,101 @@ cmd_ping(ProfWin *window, const char * const command, gchar **args)
|
||||
gboolean
|
||||
cmd_autoaway(ProfWin *window, const char * const command, gchar **args)
|
||||
{
|
||||
char *setting = args[0];
|
||||
char *value = args[1];
|
||||
|
||||
if ((strcmp(setting, "mode") != 0) && (strcmp(setting, "time") != 0) &&
|
||||
(strcmp(setting, "message") != 0) && (strcmp(setting, "check") != 0)) {
|
||||
if ((strcmp(args[0], "mode") != 0) && (strcmp(args[0], "time") != 0) &&
|
||||
(strcmp(args[0], "message") != 0) && (strcmp(args[0], "check") != 0)) {
|
||||
cons_show("Setting must be one of 'mode', 'time', 'message' or 'check'");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(setting, "mode") == 0) {
|
||||
if ((strcmp(value, "idle") != 0) && (strcmp(value, "away") != 0) &&
|
||||
(strcmp(value, "off") != 0)) {
|
||||
if (strcmp(args[0], "mode") == 0) {
|
||||
if ((strcmp(args[1], "idle") != 0) && (strcmp(args[1], "away") != 0) &&
|
||||
(strcmp(args[1], "off") != 0)) {
|
||||
cons_show("Mode must be one of 'idle', 'away' or 'off'");
|
||||
} else {
|
||||
prefs_set_string(PREF_AUTOAWAY_MODE, value);
|
||||
cons_show("Auto away mode set to: %s.", value);
|
||||
prefs_set_string(PREF_AUTOAWAY_MODE, args[1]);
|
||||
cons_show("Auto away mode set to: %s.", args[1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(setting, "time") == 0) {
|
||||
int minutesval = 0;
|
||||
char *err_msg = NULL;
|
||||
gboolean res = strtoi_range(value, &minutesval, 1, INT_MAX, &err_msg);
|
||||
if (res) {
|
||||
prefs_set_autoaway_time(minutesval);
|
||||
cons_show("Auto away time set to: %d minutes.", minutesval);
|
||||
if (strcmp(args[0], "time") == 0) {
|
||||
if (g_strcmp0(args[1], "away") == 0) {
|
||||
int minutesval = 0;
|
||||
char *err_msg = NULL;
|
||||
gboolean res = strtoi_range(args[2], &minutesval, 1, INT_MAX, &err_msg);
|
||||
if (res) {
|
||||
prefs_set_autoaway_time(minutesval);
|
||||
if (minutesval == 1) {
|
||||
cons_show("Auto away time set to: 1 minute.");
|
||||
} else {
|
||||
cons_show("Auto away time set to: %d minutes.", minutesval);
|
||||
}
|
||||
} else {
|
||||
cons_show(err_msg);
|
||||
free(err_msg);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[1], "xa") == 0) {
|
||||
int minutesval = 0;
|
||||
char *err_msg = NULL;
|
||||
gboolean res = strtoi_range(args[2], &minutesval, 0, INT_MAX, &err_msg);
|
||||
if (res) {
|
||||
int away_time = prefs_get_autoaway_time();
|
||||
if (minutesval != 0 && minutesval <= away_time) {
|
||||
cons_show("Auto xa time must be larger than auto away time.");
|
||||
} else {
|
||||
prefs_set_autoxa_time(minutesval);
|
||||
if (minutesval == 0) {
|
||||
cons_show("Auto xa time disabled.");
|
||||
} else if (minutesval == 1) {
|
||||
cons_show("Auto xa time set to: 1 minute.");
|
||||
} else {
|
||||
cons_show("Auto xa time set to: %d minutes.", minutesval);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cons_show(err_msg);
|
||||
free(err_msg);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
cons_show(err_msg);
|
||||
free(err_msg);
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(setting, "message") == 0) {
|
||||
if (strcmp(value, "off") == 0) {
|
||||
prefs_set_string(PREF_AUTOAWAY_MESSAGE, NULL);
|
||||
cons_show("Auto away message cleared.");
|
||||
if (strcmp(args[0], "message") == 0) {
|
||||
if (g_strcmp0(args[1], "away") == 0) {
|
||||
if (strcmp(args[2], "off") == 0) {
|
||||
prefs_set_string(PREF_AUTOAWAY_MESSAGE, NULL);
|
||||
cons_show("Auto away message cleared.");
|
||||
} else {
|
||||
prefs_set_string(PREF_AUTOAWAY_MESSAGE, args[2]);
|
||||
cons_show("Auto away message set to: \"%s\".", args[2]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[1], "xa") == 0) {
|
||||
if (strcmp(args[2], "off") == 0) {
|
||||
prefs_set_string(PREF_AUTOXA_MESSAGE, NULL);
|
||||
cons_show("Auto xa message cleared.");
|
||||
} else {
|
||||
prefs_set_string(PREF_AUTOXA_MESSAGE, args[2]);
|
||||
cons_show("Auto xa message set to: \"%s\".", args[2]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
prefs_set_string(PREF_AUTOAWAY_MESSAGE, value);
|
||||
cons_show("Auto away message set to: \"%s\".", value);
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(setting, "check") == 0) {
|
||||
return _cmd_set_boolean_preference(value, command, "Online check", PREF_AUTOAWAY_CHECK);
|
||||
if (strcmp(args[0], "check") == 0) {
|
||||
return _cmd_set_boolean_preference(args[1], command, "Online check", PREF_AUTOAWAY_CHECK);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -4879,51 +4924,3 @@ _cmd_set_boolean_preference(gchar *arg, const char * const command,
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//static void
|
||||
//_cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size)
|
||||
//{
|
||||
// ProfWin *console = wins_get_console();
|
||||
// cons_show("");
|
||||
// win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", heading);
|
||||
//
|
||||
// GList *ordered_commands = NULL;
|
||||
// int i;
|
||||
// for (i = 0; i < filter_size; i++) {
|
||||
// Command *pcmd = g_hash_table_lookup(commands, cmd_filter[i]);
|
||||
// ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
|
||||
// }
|
||||
//
|
||||
// int maxlen = 0;
|
||||
// GList *curr = ordered_commands;
|
||||
// while (curr) {
|
||||
// gchar *cmd = curr->data;
|
||||
// int len = strlen(cmd);
|
||||
// if (len > maxlen) maxlen = len;
|
||||
// curr = g_list_next(curr);
|
||||
// }
|
||||
//
|
||||
// GString *cmds = g_string_new("");
|
||||
// curr = ordered_commands;
|
||||
// int count = 0;
|
||||
// while (curr) {
|
||||
// gchar *cmd = curr->data;
|
||||
// if (count == 5) {
|
||||
// cons_show(cmds->str);
|
||||
// g_string_free(cmds, TRUE);
|
||||
// cmds = g_string_new("");
|
||||
// count = 0;
|
||||
// }
|
||||
// g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd);
|
||||
// curr = g_list_next(curr);
|
||||
// count++;
|
||||
// }
|
||||
// cons_show(cmds->str);
|
||||
// g_string_free(cmds, TRUE);
|
||||
// g_list_free(ordered_commands);
|
||||
// g_list_free(curr);
|
||||
//
|
||||
// cons_show("");
|
||||
// cons_show("Use /help [command] without the leading slash, for help on a specific command");
|
||||
// cons_show("");
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user