2017-12-11 07:13:57

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 1/4] shared/shell: Fix hidden default menu if no submenu

Also fixes the output of the default menu in the help command of obexctl.
---
src/shared/shell.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index a4be844b7..f9dbdb194 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -198,8 +198,9 @@ static void shell_print_menu(void)
/* Skip menu command if not on main menu or if there are no
* submenus.
*/
- if ((data.menu != data.main && !strcmp(entry->cmd, "menu")) ||
- queue_isempty(data.submenus))
+ if (!strcmp(entry->cmd, "menu") &&
+ (data.menu != data.main ||
+ queue_isempty(data.submenus)))
continue;

/* Skip back command if on main menu */
--
2.14.1



2017-12-11 13:04:22

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/4] shared/shell: Fix hidden default menu if no submenu

Hi Eramoto,

On Mon, Dec 11, 2017 at 5:13 AM, ERAMOTO Masaya
<[email protected]> wrote:
> Also fixes the output of the default menu in the help command of obexctl.
> ---
> src/shared/shell.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index a4be844b7..f9dbdb194 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -198,8 +198,9 @@ static void shell_print_menu(void)
> /* Skip menu command if not on main menu or if there are no
> * submenus.
> */
> - if ((data.menu != data.main && !strcmp(entry->cmd, "menu")) ||
> - queue_isempty(data.submenus))
> + if (!strcmp(entry->cmd, "menu") &&
> + (data.menu != data.main ||
> + queue_isempty(data.submenus)))
> continue;
>
> /* Skip back command if on main menu */
> --
> 2.14.1

Applied, thanks.

--
Luiz Augusto von Dentz

2017-12-11 07:18:10

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 4/4] shared/shell: Fix auto-completion of invalid commands

bt_shell always complements the invalid commands, which are the menu/back
command.
---
src/shared/shell.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 26194f758..f20c74901 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -498,7 +498,7 @@ static char *find_cmd(const char *text,
while ((cmd = entry[*index].cmd)) {
(*index)++;

- if (!strncmp(cmd, text, len))
+ if (!strncmp(cmd, text, len) && !command_isskipped(cmd))
return strdup(cmd);
}

--
2.14.1


2017-12-11 07:17:12

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 3/4] shared/shell: Create command_isskipped()

---
src/shared/shell.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index f9dbdb194..26194f758 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -169,6 +169,22 @@ static const struct bt_shell_menu_entry default_menu[] = {
{ }
};

+static bool command_isskipped(const char *cmd)
+{
+ /* Skip menu command if not on main menu or if there are no
+ * submenus.
+ */
+ if (!strcmp(cmd, "menu") &&
+ (data.menu != data.main || queue_isempty(data.submenus)))
+ return true;
+
+ /* Skip back command if on main menu */
+ if (data.menu == data.main && !strcmp(cmd, "back"))
+ return true;
+
+ return false;
+}
+
static void shell_print_menu(void)
{
const struct bt_shell_menu_entry *entry;
@@ -195,16 +211,7 @@ static void shell_print_menu(void)
}

for (entry = default_menu; entry->cmd; entry++) {
- /* Skip menu command if not on main menu or if there are no
- * submenus.
- */
- if (!strcmp(entry->cmd, "menu") &&
- (data.menu != data.main ||
- queue_isempty(data.submenus)))
- continue;
-
- /* Skip back command if on main menu */
- if (data.menu == data.main && !strcmp(entry->cmd, "back"))
+ if (command_isskipped(entry->cmd))
continue;

print_menu(entry->cmd, entry->arg ? : "", entry->desc ? : "");
--
2.14.1


2017-12-11 07:16:34

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 2/4] toosl/bluetooth-player: Remove extra commands

Removes the output of redundant commands in bluetooth-player since the
previous patch ("shared/shell: Fix hidden default menu if no submenu")
made bluetooth-player output the default menu.
---
tools/bluetooth-player.c | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index f819488f3..b22de2775 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -49,7 +49,6 @@
#define BLUEZ_MEDIA_FOLDER_INTERFACE "org.bluez.MediaFolder1"
#define BLUEZ_MEDIA_ITEM_INTERFACE "org.bluez.MediaItem1"

-static GMainLoop *main_loop;
static DBusConnection *dbus_conn;
static GDBusProxy *default_player;
static GSList *players = NULL;
@@ -66,11 +65,6 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
bt_shell_set_prompt(PROMPT_OFF);
}

-static void cmd_quit(int argc, char *argv[])
-{
- g_main_loop_quit(main_loop);
-}
-
static bool check_default_player(void)
{
if (!default_player) {
@@ -971,9 +965,6 @@ static const struct bt_shell_menu main_menu = {
"Search items containing string" },
{ "queue", "<item>", cmd_queue, "Add item to playlist queue" },
{ "show-item", "<item>", cmd_show_item, "Show item information" },
- { "quit", NULL, cmd_quit, "Quit program" },
- { "exit", NULL, cmd_quit },
- { "help" },
{} },
};

--
2.14.1