mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 13:02:44 +01:00
client: autocompletion for the network names
This commit is contained in:
parent
61ac55872e
commit
b0a681d5b3
@ -739,6 +739,16 @@ static char *get_networks_cmd_arg_completion(const char *text, int state)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *connect_cmd_arg_completion(const char *text, int state)
|
||||
{
|
||||
const struct proxy_interface *device = device_get_default();
|
||||
|
||||
if (!device)
|
||||
return NULL;
|
||||
|
||||
return network_name_completion(device, text, state);
|
||||
}
|
||||
|
||||
static const struct command device_commands[] = {
|
||||
{ NULL, "list", NULL, cmd_list, "List devices", true },
|
||||
{ "<wlan>", "show", NULL, cmd_show, "Show device info", true },
|
||||
@ -755,7 +765,8 @@ static const struct command device_commands[] = {
|
||||
{ "<wlan>", "connect",
|
||||
"<\"network name\"> [security]",
|
||||
cmd_connect,
|
||||
"Connect to network", false },
|
||||
"Connect to network", false,
|
||||
connect_cmd_arg_completion },
|
||||
{ "<wlan>", "disconnect",
|
||||
NULL, cmd_disconnect, "Disconnect" },
|
||||
{ }
|
||||
|
@ -148,6 +148,13 @@ void network_args_destroy(struct network_args *network_args)
|
||||
l_free(network_args);
|
||||
}
|
||||
|
||||
static const char *get_name(const void *data)
|
||||
{
|
||||
const struct network *network = data;
|
||||
|
||||
return network->name;
|
||||
}
|
||||
|
||||
static void set_name(void *data, struct l_dbus_message_iter *variant)
|
||||
{
|
||||
struct network *network = data;
|
||||
@ -209,7 +216,7 @@ static void set_type(void *data, struct l_dbus_message_iter *variant)
|
||||
}
|
||||
|
||||
static const struct proxy_interface_property network_properties[] = {
|
||||
{ "Name", "s", set_name},
|
||||
{ "Name", "s", set_name, get_name },
|
||||
{ "Connected", "b", set_connected},
|
||||
{ "Device", "o", set_device},
|
||||
{ "Type", "s", set_type},
|
||||
@ -267,6 +274,44 @@ static struct proxy_interface_type network_interface_type = {
|
||||
.ops = &ops,
|
||||
};
|
||||
|
||||
struct completion_search_parameters {
|
||||
const char *text;
|
||||
const struct proxy_interface *device;
|
||||
};
|
||||
|
||||
static bool match_by_partial_name(const void *a, const void *b)
|
||||
{
|
||||
const struct network *network = a;
|
||||
const struct completion_search_parameters *params = b;
|
||||
const char *name;
|
||||
const char *text;
|
||||
|
||||
if (!proxy_interface_is_same(network->device, params->device))
|
||||
return false;
|
||||
|
||||
for (text = params->text, name = network->name; *text && *name;
|
||||
name++, text++) {
|
||||
if (*name == *text)
|
||||
continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
char *network_name_completion(const struct proxy_interface *device,
|
||||
const char *text, int state)
|
||||
{
|
||||
const struct completion_search_parameters params = {
|
||||
.text = text, .device = device,
|
||||
};
|
||||
|
||||
return proxy_property_str_completion(&network_interface_type,
|
||||
match_by_partial_name, "Name",
|
||||
¶ms, state);
|
||||
}
|
||||
|
||||
static int network_interface_init(void)
|
||||
{
|
||||
proxy_interface_type_register(&network_interface_type);
|
||||
|
@ -30,3 +30,6 @@ void network_connect(const char *path);
|
||||
|
||||
struct network_args *network_parse_args(const char *args);
|
||||
void network_args_destroy(struct network_args *network_args);
|
||||
|
||||
char *network_name_completion(const struct proxy_interface *device,
|
||||
const char *text, int state);
|
||||
|
Loading…
Reference in New Issue
Block a user