From 8ef35290bdde58c6a0e7231c1870152f946d78e0 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 9 Jun 2021 15:45:09 +0200 Subject: [PATCH] Add command to show single bookmark details `/bookmark list` lists all bookmarks with its details. `/bookmark list ` shows the details of a single bookmark. Implement https://github.com/profanity-im/profanity/issues/1558 --- src/command/cmd_ac.c | 4 ++++ src/command/cmd_defs.c | 6 ++++-- src/command/cmd_funcs.c | 15 ++++++++++++--- src/ui/console.c | 28 ++++++++++++++++++++++++++++ src/ui/ui.h | 1 + src/xmpp/bookmark.c | 7 +++++++ src/xmpp/xmpp.h | 1 + tests/unittests/ui/stub_ui.c | 5 +++++ tests/unittests/xmpp/stub_xmpp.c | 6 ++++++ 9 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 03c6e404..6b46d079 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2206,6 +2206,10 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo if (found) { return found; } + found = autocomplete_param_with_func(input, "/bookmark list", bookmark_find, previous, NULL); + if (found) { + return found; + } found = autocomplete_param_with_ac(input, "/bookmark", bookmark_ac, TRUE, previous); return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 0ebcf04f..a9621e0e 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -822,7 +822,7 @@ static struct cmd_t command_defs[] = { CMD_TAG_GROUPCHAT) CMD_SYN( "/bookmark", - "/bookmark list", + "/bookmark list []", "/bookmark add [] [nick ] [password ] [name ] [autojoin on|off]", "/bookmark update [nick ] [password ] [name ] [autojoin on|off]", "/bookmark remove []", @@ -836,7 +836,7 @@ static struct cmd_t command_defs[] = { "If you are in a chat room and no arguments are supplied to `/bookmark add`, autojoin is set to \"on\". " "There is also an autojoin ignore list in case you want to autojoin in many clients but not on Profanity. ") CMD_ARGS( - { "list", "List all bookmarks." }, + { "list []", "List all bookmarks. Or the details of one." }, { "add []", "Add a bookmark, passing no room will bookmark the current room, setting autojoin to \"on\"." }, { "remove []", "Remove a bookmark, passing no room will remove the bookmark for the current room, if one exists." }, { "update ", "Update the properties associated with a bookmark." }, @@ -853,6 +853,8 @@ static struct cmd_t command_defs[] = { "/bookmark join room@example.com", "/bookmark update room@example.com nick NEWNICK autojoin on", "/bookmark ignore room@example.com", + "/bookmark list", + "/bookmark list room@example.com", "/bookmark remove room@example.com") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 901c81a3..8282a134 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -4661,9 +4661,18 @@ cmd_bookmark(ProfWin* window, const char* const command, gchar** args) } if (strcmp(cmd, "list") == 0) { - GList* bookmarks = bookmark_get_list(); - cons_show_bookmarks(bookmarks); - g_list_free(bookmarks); + char* bookmark_jid = args[1]; + if (bookmark_jid == NULL) { + // list all bookmarks + GList* bookmarks = bookmark_get_list(); + cons_show_bookmarks(bookmarks); + g_list_free(bookmarks); + } else { + // list one bookmark + Bookmark *bookmark = bookmark_get_by_jid(bookmark_jid); + cons_show_bookmark(bookmark); + } + return TRUE; } diff --git a/src/ui/console.c b/src/ui/console.c index 74a7740f..4494bce0 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -744,6 +744,34 @@ cons_show_bookmarks(const GList* list) cons_alert(NULL); } +void +cons_show_bookmark(Bookmark* item) +{ + cons_show(""); + if (!item) { + cons_show("No such bookmark"); + } else { + cons_show("Bookmark details:"); + cons_show("Room jid : %s", item->barejid); + if (item->name) { + cons_show("name : %s", item->name); + } + if (item->nick) { + cons_show("nick : %s", item->nick); + } + if (item->password) { + cons_show("password : %s", item->password); + } + if (item->autojoin) { + cons_show("autojoin : ON"); + } else { + cons_show("autojoin : OFF"); + } + } + + cons_alert(NULL); +} + void cons_show_disco_info(const char* jid, GSList* identities, GSList* features) { diff --git a/src/ui/ui.h b/src/ui/ui.h index f9ef5cff..0c58b09c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -271,6 +271,7 @@ void cons_show_aliases(GList* aliases); void cons_show_login_success(ProfAccount* account, gboolean secured); void cons_show_account_list(gchar** accounts); void cons_show_room_list(GSList* room, const char* const conference_node); +void cons_show_bookmark(Bookmark* item); void cons_show_bookmarks(const GList* list); void cons_show_bookmarks_ignore(gchar** list, gsize len); void cons_show_disco_items(GSList* items, const char* const jid); diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 65c3bd01..4e40e3ec 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -225,6 +225,13 @@ bookmark_remove(const char* jid) return TRUE; } +Bookmark* +bookmark_get_by_jid(const char* jid) +{ + Bookmark* bookmark = g_hash_table_lookup(bookmarks, jid); + return bookmark; +} + GList* bookmark_get_list(void) { diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 4229ddae..003c3e07 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -274,6 +274,7 @@ gboolean bookmark_update(const char* jid, const char* nick, const char* password gboolean bookmark_remove(const char* jid); gboolean bookmark_join(const char* jid); GList* bookmark_get_list(void); +Bookmark* bookmark_get_by_jid(const char* jid); char* bookmark_find(const char* const search_str, gboolean previous, void* context); void bookmark_autocomplete_reset(void); gboolean bookmark_exists(const char* const room); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 578ebcda..1cae8bde 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -907,6 +907,11 @@ cons_show_bookmarks(const GList* list) check_expected(list); } +void +cons_show_bookmark(Bookmark* item) +{ +} + void cons_show_disco_items(GSList* items, const char* const jid) { diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c index cffaae7f..ba72024c 100644 --- a/tests/unittests/xmpp/stub_xmpp.c +++ b/tests/unittests/xmpp/stub_xmpp.c @@ -487,6 +487,12 @@ bookmark_get_list(void) return mock_ptr_type(GList*); } +Bookmark* +bookmark_get_by_jid(const char* jid) +{ + return NULL; +} + char* bookmark_find(const char* const search_str, gboolean previous, void* context) {