gdbus-tool: Fix tab-completion for non-message-bus connections

• `gdbus monitor` can’t work at all for non-message-bus connections,
   since it can’t subscribe to signals.
 • Other tab completions for names depend on the connection being a
   message bus connection, but we still need to print `--dest` (etc.)
   when tab completing them, even if we can’t print a list of
   available names.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788594
This commit is contained in:
Philip Withnall 2017-10-09 10:44:47 +01:00
parent 5564ddef12
commit b3acf58779

View File

@ -862,9 +862,6 @@ handle_call (gint *argc,
} }
/* validate and complete destination (bus name) */ /* validate and complete destination (bus name) */
if (g_dbus_connection_get_unique_name (c) != NULL)
{
/* this only makes sense on message bus connections */
if (complete_names) if (complete_names)
{ {
print_names (c, FALSE); print_names (c, FALSE);
@ -883,7 +880,6 @@ handle_call (gint *argc,
print_names (c, g_str_has_prefix (opt_call_dest, ":")); print_names (c, g_str_has_prefix (opt_call_dest, ":"));
goto out; goto out;
} }
}
if (!request_completion && !g_dbus_is_name (opt_call_dest)) if (!request_completion && !g_dbus_is_name (opt_call_dest))
{ {
@ -1619,8 +1615,6 @@ handle_introspect (gint *argc,
goto out; goto out;
} }
if (g_dbus_connection_get_unique_name (c) != NULL)
{
if (complete_names) if (complete_names)
{ {
print_names (c, FALSE); print_names (c, FALSE);
@ -1640,7 +1634,7 @@ handle_introspect (gint *argc,
print_names (c, g_str_has_prefix (opt_introspect_dest, ":")); print_names (c, g_str_has_prefix (opt_introspect_dest, ":"));
goto out; goto out;
} }
}
if (complete_paths) if (complete_paths)
{ {
print_paths (c, opt_introspect_dest, "/"); print_paths (c, opt_introspect_dest, "/");
@ -1854,8 +1848,14 @@ handle_monitor (gint *argc,
goto out; goto out;
} }
if (g_dbus_connection_get_unique_name (c) != NULL) /* Monitoring doesnt make sense on a non-message-bus connection. */
if (g_dbus_connection_get_unique_name (c) == NULL)
{ {
if (!request_completion)
g_printerr (_("Error: cant monitor a non-message-bus connection\n"));
goto out;
}
if (complete_names) if (complete_names)
{ {
print_names (c, FALSE); print_names (c, FALSE);
@ -1875,7 +1875,6 @@ handle_monitor (gint *argc,
print_names (c, g_str_has_prefix (opt_monitor_dest, ":")); print_names (c, g_str_has_prefix (opt_monitor_dest, ":"));
goto out; goto out;
} }
}
if (!request_completion && !g_dbus_is_name (opt_monitor_dest)) if (!request_completion && !g_dbus_is_name (opt_monitor_dest))
{ {