libfeedback: Allow to set sound-file hint
Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
+77
-7
@@ -1,5 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Purism SPC
|
* Copyright (C) 2020 Purism SPC
|
||||||
|
* 2024-2025 The Phosh Developers
|
||||||
|
*
|
||||||
* SPDX-License-Identifier: LGPL-2.1+
|
* SPDX-License-Identifier: LGPL-2.1+
|
||||||
* Author: Guido Günther <agx@sigxcpu.org>
|
* Author: Guido Günther <agx@sigxcpu.org>
|
||||||
*/
|
*/
|
||||||
@@ -81,6 +83,7 @@ enum {
|
|||||||
PROP_FEEDBACK_PROFILE,
|
PROP_FEEDBACK_PROFILE,
|
||||||
PROP_IMPORTANT,
|
PROP_IMPORTANT,
|
||||||
PROP_APP_ID,
|
PROP_APP_ID,
|
||||||
|
PROP_SOUND_FILE,
|
||||||
PROP_LAST_PROP,
|
PROP_LAST_PROP,
|
||||||
};
|
};
|
||||||
static GParamSpec *props[PROP_LAST_PROP];
|
static GParamSpec *props[PROP_LAST_PROP];
|
||||||
@@ -99,6 +102,7 @@ typedef struct _LfbEvent {
|
|||||||
gchar *profile;
|
gchar *profile;
|
||||||
gboolean important;
|
gboolean important;
|
||||||
char *app_id;
|
char *app_id;
|
||||||
|
char *sound_file;
|
||||||
|
|
||||||
guint id;
|
guint id;
|
||||||
LfbEventState state;
|
LfbEventState state;
|
||||||
@@ -139,10 +143,18 @@ build_hints (LfbEvent *self)
|
|||||||
GVariantBuilder hints_builder;
|
GVariantBuilder hints_builder;
|
||||||
|
|
||||||
g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}"));
|
g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}"));
|
||||||
if (self->profile)
|
if (self->profile) {
|
||||||
g_variant_builder_add (&hints_builder, "{sv}", "profile", g_variant_new_string (self->profile));
|
g_variant_builder_add (&hints_builder, "{sv}", "profile",
|
||||||
if (self->important)
|
g_variant_new_string (self->profile));
|
||||||
g_variant_builder_add (&hints_builder, "{sv}", "important", g_variant_new_boolean (self->important));
|
}
|
||||||
|
if (self->important) {
|
||||||
|
g_variant_builder_add (&hints_builder, "{sv}", "important",
|
||||||
|
g_variant_new_boolean (self->important));
|
||||||
|
}
|
||||||
|
if (self->sound_file) {
|
||||||
|
g_variant_builder_add (&hints_builder, "{sv}", "sound-file",
|
||||||
|
g_variant_new_string (self->sound_file));
|
||||||
|
}
|
||||||
return g_variant_builder_end (&hints_builder);
|
return g_variant_builder_end (&hints_builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +245,9 @@ lfb_event_set_property (GObject *object,
|
|||||||
case PROP_APP_ID:
|
case PROP_APP_ID:
|
||||||
lfb_event_set_app_id (self, g_value_get_string (value));
|
lfb_event_set_app_id (self, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
|
case PROP_SOUND_FILE:
|
||||||
|
lfb_event_set_sound_file (self, g_value_get_string (value));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -264,6 +279,9 @@ lfb_event_get_property (GObject *object,
|
|||||||
case PROP_APP_ID:
|
case PROP_APP_ID:
|
||||||
g_value_set_string (value, lfb_event_get_app_id (self));
|
g_value_set_string (value, lfb_event_get_app_id (self));
|
||||||
break;
|
break;
|
||||||
|
case PROP_SOUND_FILE:
|
||||||
|
g_value_set_string (value, lfb_event_get_sound_file (self));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -278,6 +296,7 @@ lfb_event_finalize (GObject *object)
|
|||||||
/* Signal handler is disconnected automatically due to g_signal_connect_object */
|
/* Signal handler is disconnected automatically due to g_signal_connect_object */
|
||||||
self->handler_id = 0;
|
self->handler_id = 0;
|
||||||
|
|
||||||
|
g_clear_pointer (&self->sound_file, g_free);
|
||||||
g_clear_pointer (&self->event, g_free);
|
g_clear_pointer (&self->event, g_free);
|
||||||
g_clear_pointer (&self->profile, g_free);
|
g_clear_pointer (&self->profile, g_free);
|
||||||
g_clear_pointer (&self->app_id, g_free);
|
g_clear_pointer (&self->app_id, g_free);
|
||||||
@@ -340,7 +359,6 @@ lfb_event_class_init (LfbEventClass *klass)
|
|||||||
LFB_TYPE_EVENT_END_REASON,
|
LFB_TYPE_EVENT_END_REASON,
|
||||||
LFB_EVENT_END_REASON_NATURAL,
|
LFB_EVENT_END_REASON_NATURAL,
|
||||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LfbEvent:feedback-profile:
|
* LfbEvent:feedback-profile:
|
||||||
*
|
*
|
||||||
@@ -354,7 +372,6 @@ lfb_event_class_init (LfbEventClass *klass)
|
|||||||
"Feedback profile to use for this event",
|
"Feedback profile to use for this event",
|
||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LfbEvent:important:
|
* LfbEvent:important:
|
||||||
*
|
*
|
||||||
@@ -368,7 +385,6 @@ lfb_event_class_init (LfbEventClass *klass)
|
|||||||
"Whether to flags this event as important",
|
"Whether to flags this event as important",
|
||||||
FALSE,
|
FALSE,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LfbEvent:app-id:
|
* LfbEvent:app-id:
|
||||||
*
|
*
|
||||||
@@ -382,6 +398,19 @@ lfb_event_class_init (LfbEventClass *klass)
|
|||||||
"The Application id to use for this event",
|
"The Application id to use for this event",
|
||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
/**
|
||||||
|
* LfbEvent:sound-file:
|
||||||
|
*
|
||||||
|
* A custom sound-file to play. See [method@LfbEvent.set_sound_file]
|
||||||
|
* for details.
|
||||||
|
*/
|
||||||
|
props[PROP_SOUND_FILE] =
|
||||||
|
g_param_spec_string (
|
||||||
|
"sound-file",
|
||||||
|
"Sound file",
|
||||||
|
"Custom sound file to play",
|
||||||
|
NULL,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
||||||
|
|
||||||
@@ -863,3 +892,44 @@ lfb_event_get_app_id (LfbEvent *self)
|
|||||||
|
|
||||||
return self->app_id;
|
return self->app_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lfb_event_set_sound_file:
|
||||||
|
* @self: The event
|
||||||
|
* @sound_file: The sound file
|
||||||
|
*
|
||||||
|
* Tells the feedback server to use the given sound file if a sound is
|
||||||
|
* to be played. It will only be used if sound is suitable for the
|
||||||
|
* events feedback level.
|
||||||
|
*
|
||||||
|
* A value of %NULL (the default) lets the server pick the sound
|
||||||
|
* based on the event.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
lfb_event_set_sound_file (LfbEvent *self, const gchar *sound_file)
|
||||||
|
{
|
||||||
|
g_return_if_fail (LFB_IS_EVENT (self));
|
||||||
|
|
||||||
|
if (!g_strcmp0 (self->sound_file, sound_file))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_free (self->sound_file);
|
||||||
|
self->sound_file = g_strdup (sound_file);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SOUND_FILE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lfb_event_get_sound_file:
|
||||||
|
* @self: The event
|
||||||
|
*
|
||||||
|
* Returns the sound file for this event if set.
|
||||||
|
*
|
||||||
|
* Returns:(transfer none): The set sound file for this event or %NULL.
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
lfb_event_get_sound_file (LfbEvent *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (LFB_IS_EVENT (self), NULL);
|
||||||
|
|
||||||
|
return self->sound_file;
|
||||||
|
}
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ gboolean lfb_event_get_important (LfbEvent *self);
|
|||||||
void lfb_event_set_app_id (LfbEvent *self, const char *app_id);
|
void lfb_event_set_app_id (LfbEvent *self, const char *app_id);
|
||||||
const char *lfb_event_get_app_id (LfbEvent *self);
|
const char *lfb_event_get_app_id (LfbEvent *self);
|
||||||
const char *lfb_event_get_event (LfbEvent *self);
|
const char *lfb_event_get_event (LfbEvent *self);
|
||||||
|
void lfb_event_set_sound_file (LfbEvent *self, const char *sound_file);
|
||||||
|
const char *lfb_event_get_sound_file (LfbEvent *self);
|
||||||
|
|
||||||
LfbEventState lfb_event_get_state (LfbEvent *self);
|
LfbEventState lfb_event_get_state (LfbEvent *self);
|
||||||
LfbEventEndReason lfb_event_get_end_reason (LfbEvent *self);
|
LfbEventEndReason lfb_event_get_end_reason (LfbEvent *self);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ test_lfb_event_props (void)
|
|||||||
g_autofree gchar *evname = NULL;
|
g_autofree gchar *evname = NULL;
|
||||||
g_autofree gchar *profile = NULL;
|
g_autofree gchar *profile = NULL;
|
||||||
g_autofree gchar *app_id = NULL;
|
g_autofree gchar *app_id = NULL;
|
||||||
|
g_autofree gchar *sound_file = NULL;
|
||||||
gboolean important;
|
gboolean important;
|
||||||
gint timeout;
|
gint timeout;
|
||||||
|
|
||||||
@@ -29,12 +30,14 @@ test_lfb_event_props (void)
|
|||||||
"feedback-profile", &profile,
|
"feedback-profile", &profile,
|
||||||
"app-id", &app_id,
|
"app-id", &app_id,
|
||||||
"important", &important,
|
"important", &important,
|
||||||
|
"sound-file", &sound_file,
|
||||||
NULL);
|
NULL);
|
||||||
g_assert_cmpstr (evname, ==, "window-close");
|
g_assert_cmpstr (evname, ==, "window-close");
|
||||||
g_assert_cmpint (timeout, ==, -1);
|
g_assert_cmpint (timeout, ==, -1);
|
||||||
g_assert_null (profile);
|
g_assert_null (profile);
|
||||||
g_assert_false (important);
|
g_assert_false (important);
|
||||||
g_assert_null (app_id);
|
g_assert_null (app_id);
|
||||||
|
g_assert_null (sound_file);
|
||||||
|
|
||||||
g_assert_cmpint (lfb_event_get_end_reason (event), ==, LFB_EVENT_END_REASON_NATURAL);
|
g_assert_cmpint (lfb_event_get_end_reason (event), ==, LFB_EVENT_END_REASON_NATURAL);
|
||||||
g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_NONE);
|
g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_NONE);
|
||||||
@@ -49,6 +52,11 @@ test_lfb_event_props (void)
|
|||||||
g_assert_cmpstr (app_id, ==, "com.example.foo");
|
g_assert_cmpstr (app_id, ==, "com.example.foo");
|
||||||
g_assert_cmpstr (lfb_event_get_app_id (event), ==, "com.example.foo");
|
g_assert_cmpstr (lfb_event_get_app_id (event), ==, "com.example.foo");
|
||||||
|
|
||||||
|
g_object_set (event, "sound-file", "/does/not/exist", NULL);
|
||||||
|
g_object_get (event, "sound-file", &sound_file, NULL);
|
||||||
|
g_assert_cmpstr (sound_file, ==, "/does/not/exist");
|
||||||
|
g_assert_cmpstr (lfb_event_get_sound_file (event), ==, "/does/not/exist");
|
||||||
|
|
||||||
lfb_uninit ();
|
lfb_uninit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user