Drop the writable-name capability

Make this implict - if the profile has a name, it's writable. Otherwise it's
not and you'll have to rely on the index or make up your own naming.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2019-02-20 14:11:43 +10:00
parent 5328c20a58
commit 32a5ad377e
8 changed files with 20 additions and 28 deletions

View File

@@ -196,7 +196,8 @@ org.freedesktop.ratbag1.Profile
:type: s
:flags: read-write, mutable
The name of this profile.
The name of this profile. If the name is the empty string, the
profile name cannot be changed.
.. attribute:: Enabled

View File

@@ -384,11 +384,14 @@ ratbagd_profile_get_name(sd_bus *bus,
const char *name = ratbag_profile_get_name(profile->lib_profile);
_cleanup_free_ char *asciiname;
/* This should really be a UTF8 check and it should really be in
* libratbag, but for now this will do to at least not kick us off
* the bus. https://github.com/libratbag/libratbag/issues/617
*/
asciiname = strdup_ascii_only(name);
if (!name)
asciiname = strdup("");
else
/* This should really be a UTF8 check and it should really be in
* libratbag, but for now this will do to at least not kick us off
* the bus. https://github.com/libratbag/libratbag/issues/617
*/
asciiname = strdup_ascii_only(name);
CHECK_CALL(sd_bus_message_append(reply, "s", asciiname));
@@ -408,7 +411,6 @@ ratbagd_profile_get_capabilities(sd_bus *bus,
struct ratbag_profile *lib_profile = profile->lib_profile;
enum ratbag_profile_capability cap;
enum ratbag_profile_capability caps[] = {
RATBAG_PROFILE_CAP_WRITABLE_NAME,
RATBAG_PROFILE_CAP_SET_DEFAULT,
RATBAG_PROFILE_CAP_DISABLE,
};

View File

@@ -42,7 +42,7 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
.svg = "fallback.svg",
.profiles = {
{
.name = "test profile 1",
.name = NULL,
.buttons = {
{ .button_type = RATBAG_BUTTON_TYPE_LEFT,
.action_type = RATBAG_BUTTON_ACTION_TYPE_BUTTON,
@@ -115,7 +115,7 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
},
.active = false,
.dflt = true,
.caps = { RATBAG_PROFILE_CAP_WRITABLE_NAME },
.name = "test profile 2",
},
{
.buttons = {

View File

@@ -407,7 +407,6 @@ hidpp10drv_read_profile(struct ratbag_profile *profile)
if (rc)
return;
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_WRITABLE_NAME);
if (hidpp10->profile_type != HIDPP10_PROFILE_UNKNOWN)
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_DISABLE);

View File

@@ -81,15 +81,6 @@ enum ratbag_error_code {
enum ratbag_profile_capability {
RATBAG_PROFILE_CAP_NONE = 0,
/**
* The device has the capability to write a name to a profile
* and store it in its flash.
*
* Any changes uploaded to the device will be cached in libratbag
* and will be committed to it after a commit only.
*/
RATBAG_PROFILE_CAP_WRITABLE_NAME = 100,
/**
* This profile can be assigned as the default profile. A default
* profile is the profile that is selected when the device
@@ -97,7 +88,7 @@ enum ratbag_profile_capability {
* profile, the device either picks last-used profile or a specific
* profile (usually the first).
*/
RATBAG_PROFILE_CAP_SET_DEFAULT,
RATBAG_PROFILE_CAP_SET_DEFAULT = 101,
/**
* The profile can be disabled and enabled. Profiles are not

View File

@@ -671,7 +671,7 @@ ratbag_create_profile(struct ratbag_device *device,
profile->index = index;
profile->num_resolutions = 0;
profile->is_enabled = true;
profile->name = asprintf_safe("Profile %d", index + 1);
profile->name = NULL;
list_insert(&device->profiles, &profile->link);
list_init(&profile->buttons);
@@ -1589,8 +1589,7 @@ ratbag_profile_set_name(struct ratbag_profile *profile,
{
char *name_copy;
if (!ratbag_profile_has_capability(profile,
RATBAG_PROFILE_CAP_WRITABLE_NAME))
if (!profile->name)
return RATBAG_ERROR_CAPABILITY;
name_copy = strdup_safe(name);

View File

@@ -242,7 +242,7 @@ def print_profile(d, p, level):
" (disabled)" if not p.enabled else "",
" (active)" if p.is_active else ""))
if p.enabled:
print(" " * level + "Name : '{}'".format(p.name))
print(" " * level + "Name: {}".format(p.name or 'n/a'))
print(" " * level + "Resolutions:")
for r in p.resolutions:
print_resolution(d, p, r, level + 2)
@@ -512,7 +512,7 @@ def func_profile_name_get(r, args):
def func_profile_name_set(r, args):
p, d = find_profile(r, args)
if RatbagdProfile.CAP_WRITABLE_NAME not in p.capabilities:
if not p.name:
raise RatbagErrorCapability("assigning a profile name is not supported on this profile")
p.name = args.name
commit(d, args)

View File

@@ -139,16 +139,16 @@ class TestRatbagCtlProfile(TestRatbagCtl):
cls.setProfile(0)
def test_profile_name_get(self):
command = "profile 0 name get"
command = "profile 1 name get"
r = self.launch_good_test(command + " test_device")
self.assertEqual(r, 'test profile 1')
self.assertEqual(r, 'test profile 2')
self.launch_fail_test(command)
self.launch_fail_test(command + " X test_device")
self.launch_fail_test("profile name get test_device")
def test_profile_name_set(self):
r = self.launch_good_test("profile 1 name get test_device")
self.assertEqual(r, 'Profile 2')
self.assertEqual(r, 'test profile 2')
self.launch_good_test("profile 1 name set banana test_device")
r = self.launch_good_test("profile 1 name get test_device")
self.assertEqual(r, 'banana')