@@ -304,9 +304,9 @@ static struct cmd_t command_defs[] =
|
|||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/bookmark",
|
{ "/bookmark",
|
||||||
cmd_bookmark, parse_args, 1, 8, NULL,
|
cmd_bookmark, parse_args, 0, 8, NULL,
|
||||||
{ "/bookmark list|add|update|remove|join [room@server] [nick value] [password value] [autojoin on|off]", "Manage bookmarks.",
|
{ "/bookmark [list|add|update|remove|join] [room@server] [nick value] [password value] [autojoin on|off]", "Manage bookmarks.",
|
||||||
{ "/bookmark list|add|update|remove|join [room@server] [nick value] [password value] [autojoin on|off]",
|
{ "/bookmark [list|add|update|remove|join] [room@server] [nick value] [password value] [autojoin on|off]",
|
||||||
"---------------------------------------------------------------------------------------------------",
|
"---------------------------------------------------------------------------------------------------",
|
||||||
"Manage bookmarks.",
|
"Manage bookmarks.",
|
||||||
"list: List all bookmarks.",
|
"list: List all bookmarks.",
|
||||||
@@ -317,6 +317,7 @@ static struct cmd_t command_defs[] =
|
|||||||
"update: Update any of the above properties associated with the bookmark.",
|
"update: Update any of the above properties associated with the bookmark.",
|
||||||
"remove: Remove the bookmark for room@server.",
|
"remove: Remove the bookmark for room@server.",
|
||||||
"join: Join room@server using the properties associated with the bookmark.",
|
"join: Join room@server using the properties associated with the bookmark.",
|
||||||
|
"When in a chat room, the /bookmark command with no arguments will bookmark the current room with the current settings, and set autojoin to \"on\".",
|
||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/disco",
|
{ "/disco",
|
||||||
|
|||||||
@@ -1807,86 +1807,110 @@ cmd_bookmark(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *cmd = args[0];
|
win_type_t win_type = ui_current_win_type();
|
||||||
if (cmd == NULL) {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(cmd, "list") == 0) {
|
if (win_type == WIN_MUC) {
|
||||||
const GList *bookmarks = bookmark_get_list();
|
gchar *cmd = args[0];
|
||||||
cons_show_bookmarks(bookmarks);
|
|
||||||
} else {
|
|
||||||
char *jid = args[1];
|
|
||||||
if (jid == NULL) {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
cons_show("");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(cmd, "remove") == 0) {
|
// default to current nickname, password, and autojoin "on"
|
||||||
gboolean removed = bookmark_remove(jid);
|
if (cmd == NULL) {
|
||||||
if (removed) {
|
char *jid = ui_current_recipient();
|
||||||
cons_show("Bookmark removed for %s.", jid);
|
char *nick = muc_get_room_nick(jid);
|
||||||
|
char *password = muc_get_room_password(jid);
|
||||||
|
gboolean added = bookmark_add(jid, nick, password, "on");
|
||||||
|
if (added) {
|
||||||
|
ui_current_print_formatted_line('!', 0, "Bookmark added for %s.", jid);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No bookmark exists for %s.", jid);
|
ui_current_print_formatted_line('!', 0, "Bookmark already exists for %s.", jid);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
ui_current_print_formatted_line('!', 0, "No arguments required for /bookmark in a chat room");
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cmd, "join") == 0) {
|
} else {
|
||||||
gboolean joined = bookmark_join(jid);
|
gchar *cmd = args[0];
|
||||||
if (!joined) {
|
if (cmd == NULL) {
|
||||||
cons_show("No bookmark exists for %s.", jid);
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
|
|
||||||
gboolean parsed;
|
|
||||||
|
|
||||||
GHashTable *options = parse_options(&args[2], opt_keys, &parsed);
|
|
||||||
if (!parsed) {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
cons_show("");
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *nick = g_hash_table_lookup(options, "nick");
|
if (strcmp(cmd, "list") == 0) {
|
||||||
char *password = g_hash_table_lookup(options, "password");
|
const GList *bookmarks = bookmark_get_list();
|
||||||
char *autojoin = g_hash_table_lookup(options, "autojoin");
|
cons_show_bookmarks(bookmarks);
|
||||||
|
} else {
|
||||||
if (autojoin != NULL) {
|
char *jid = args[1];
|
||||||
if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
|
if (jid == NULL) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
cons_show("");
|
cons_show("");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(cmd, "add") == 0) {
|
if (strcmp(cmd, "remove") == 0) {
|
||||||
if (strchr(jid, '@')==NULL) {
|
gboolean removed = bookmark_remove(jid);
|
||||||
cons_show("Can't add bookmark with JID '%s'; should be '%s@domain.tld'", jid, jid);
|
if (removed) {
|
||||||
} else {
|
cons_show("Bookmark removed for %s.", jid);
|
||||||
gboolean added = bookmark_add(jid, nick, password, autojoin);
|
|
||||||
if (added) {
|
|
||||||
cons_show("Bookmark added for %s.", jid);
|
|
||||||
} else {
|
} else {
|
||||||
cons_show("Bookmark already exists, use /bookmark update to edit.");
|
cons_show("No bookmark exists for %s.", jid);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(cmd, "join") == 0) {
|
||||||
|
gboolean joined = bookmark_join(jid);
|
||||||
|
if (!joined) {
|
||||||
|
cons_show("No bookmark exists for %s.", jid);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
|
||||||
|
gboolean parsed;
|
||||||
|
|
||||||
|
GHashTable *options = parse_options(&args[2], opt_keys, &parsed);
|
||||||
|
if (!parsed) {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
cons_show("");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *nick = g_hash_table_lookup(options, "nick");
|
||||||
|
char *password = g_hash_table_lookup(options, "password");
|
||||||
|
char *autojoin = g_hash_table_lookup(options, "autojoin");
|
||||||
|
|
||||||
|
if (autojoin != NULL) {
|
||||||
|
if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
cons_show("");
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (strcmp(cmd, "update") == 0) {
|
|
||||||
gboolean updated = bookmark_update(jid, nick, password, autojoin);
|
|
||||||
if (updated) {
|
|
||||||
cons_show("Bookmark updated.");
|
|
||||||
} else {
|
|
||||||
cons_show("No bookmark exists for %s.", jid);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
options_destroy(options);
|
if (strcmp(cmd, "add") == 0) {
|
||||||
|
if (strchr(jid, '@')==NULL) {
|
||||||
|
cons_show("Can't add bookmark with JID '%s'; should be '%s@domain.tld'", jid, jid);
|
||||||
|
} else {
|
||||||
|
gboolean added = bookmark_add(jid, nick, password, autojoin);
|
||||||
|
if (added) {
|
||||||
|
cons_show("Bookmark added for %s.", jid);
|
||||||
|
} else {
|
||||||
|
cons_show("Bookmark already exists, use /bookmark update to edit.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (strcmp(cmd, "update") == 0) {
|
||||||
|
gboolean updated = bookmark_update(jid, nick, password, autojoin);
|
||||||
|
if (updated) {
|
||||||
|
cons_show("Bookmark updated.");
|
||||||
|
} else {
|
||||||
|
cons_show("No bookmark exists for %s.", jid);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
options_destroy(options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ void cmd_bookmark_shows_message_when_undefined(void **state)
|
|||||||
void cmd_bookmark_shows_usage_when_no_args(void **state)
|
void cmd_bookmark_shows_usage_when_no_args(void **state)
|
||||||
{
|
{
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
help->usage = "some usage";
|
help->usage = "some usage";
|
||||||
gchar *args[] = { NULL };
|
gchar *args[] = { NULL };
|
||||||
@@ -83,6 +84,7 @@ static void _free_bookmark(Bookmark *bookmark)
|
|||||||
void cmd_bookmark_list_shows_bookmarks(void **state)
|
void cmd_bookmark_list_shows_bookmarks(void **state)
|
||||||
{
|
{
|
||||||
mock_cons_show_bookmarks();
|
mock_cons_show_bookmarks();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "list", NULL };
|
gchar *args[] = { "list", NULL };
|
||||||
GList *bookmarks = NULL;
|
GList *bookmarks = NULL;
|
||||||
@@ -130,6 +132,7 @@ void cmd_bookmark_add_shows_message_when_invalid_jid(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_add();
|
mock_bookmark_add();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room";
|
char *jid = "room";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "add", jid, NULL };
|
gchar *args[] = { "add", jid, NULL };
|
||||||
@@ -148,6 +151,7 @@ void cmd_bookmark_add_adds_bookmark_with_jid(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_add();
|
mock_bookmark_add();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room@conf.server";
|
char *jid = "room@conf.server";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "add", jid, NULL };
|
gchar *args[] = { "add", jid, NULL };
|
||||||
@@ -167,6 +171,7 @@ void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_add();
|
mock_bookmark_add();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room@conf.server";
|
char *jid = "room@conf.server";
|
||||||
char *nick = "bob";
|
char *nick = "bob";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
@@ -187,6 +192,7 @@ void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_add();
|
mock_bookmark_add();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room@conf.server";
|
char *jid = "room@conf.server";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "add", jid, "autojoin", "on", NULL };
|
gchar *args[] = { "add", jid, "autojoin", "on", NULL };
|
||||||
@@ -206,6 +212,7 @@ void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_add();
|
mock_bookmark_add();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room@conf.server";
|
char *jid = "room@conf.server";
|
||||||
char *nick = "bob";
|
char *nick = "bob";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
@@ -226,6 +233,7 @@ void cmd_bookmark_remove_removes_bookmark(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_remove();
|
mock_bookmark_remove();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room@conf.server";
|
char *jid = "room@conf.server";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "remove", jid, NULL };
|
gchar *args[] = { "remove", jid, NULL };
|
||||||
@@ -245,6 +253,7 @@ void cmd_bookmark_remove_shows_message_when_no_bookmark(void **state)
|
|||||||
{
|
{
|
||||||
mock_bookmark_remove();
|
mock_bookmark_remove();
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
mock_current_win_type(WIN_CONSOLE);
|
||||||
char *jid = "room@conf.server";
|
char *jid = "room@conf.server";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "remove", jid, NULL };
|
gchar *args[] = { "remove", jid, NULL };
|
||||||
|
|||||||
Reference in New Issue
Block a user