diff --git a/tests/backend/notification.c b/tests/backend/notification.c index 1a2fed247..a62aec913 100644 --- a/tests/backend/notification.c +++ b/tests/backend/notification.c @@ -8,6 +8,8 @@ #include "notification.h" +static GFileMonitor *config_monitor; + typedef struct { XdpDbusImplNotification *impl; char *app_id; @@ -124,10 +126,45 @@ handle_remove_notification (XdpDbusImplNotification *object, return TRUE; } +static void +update_supported_options (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + XdpDbusImplNotification *object) +{ + g_autofree char *path = NULL; + g_autoptr(GKeyFile) keyfile = NULL; + g_autofree char *options_s = NULL; + g_autoptr(GVariant) options = NULL; + g_autoptr(GError) error = NULL; + + if (!g_file_query_exists (file, NULL)) + return; + + path = g_file_get_path (file); + + keyfile = g_key_file_new (); + g_key_file_load_from_file (keyfile, path, 0, &error); + g_assert_no_error (error); + + options_s = g_key_file_get_string (keyfile, "notification", "supported-options", NULL); + + if (!options_s) + return; + + options = g_variant_parse (G_VARIANT_TYPE_VARDICT, options_s, NULL, NULL, &error); + g_assert_no_error (error); + + xdp_dbus_impl_notification_set_supported_options (object, options); +} + void notification_init (GDBusConnection *bus, const char *object_path) { + const char *dir; + g_autoptr(GFile) config_file = NULL; g_autoptr(GError) error = NULL; GDBusInterfaceSkeleton *helper; @@ -136,6 +173,15 @@ notification_init (GDBusConnection *bus, g_signal_connect (helper, "handle-add-notification", G_CALLBACK (handle_add_notification), NULL); g_signal_connect (helper, "handle-remove-notification", G_CALLBACK (handle_remove_notification), NULL); + dir = g_getenv ("XDG_DATA_HOME"); + config_file = g_file_new_build_filename (dir, "notification", NULL); + config_monitor = g_file_monitor_file (config_file, G_FILE_MONITOR_NONE, NULL, NULL); + + g_signal_connect (config_monitor, + "changed", + G_CALLBACK (update_supported_options), + helper); + if (!g_dbus_interface_skeleton_export (helper, bus, object_path, &error)) { g_error ("Failed to export %s skeleton: %s\n", diff --git a/tests/notification.c b/tests/notification.c index 8f7575192..65859b148 100644 --- a/tests/notification.c +++ b/tests/notification.c @@ -551,3 +551,24 @@ test_notification_category (void) run_notification_test ("test5", notification_s, NULL, TRUE); } + +void +test_notification_supported_properties (void) +{ + g_autoptr(XdpPortal) portal = NULL; + g_autoptr(GKeyFile) keyfile = NULL; + g_autoptr(GError) error = NULL; + g_autofree char *path = NULL; + + keyfile = g_key_file_new (); + + g_key_file_set_string (keyfile, "notification", "supported-options", "{ 'something': <'sdfs'> }"); + + path = g_build_filename (outdir, "notification", NULL); + g_key_file_save_to_file (keyfile, path, &error); + g_assert_no_error (error); + + portal = xdp_portal_new (); + + xdp_portal_get_supported_options (portal); +} diff --git a/tests/notification.h b/tests/notification.h index e3c51d338..40e78f0eb 100644 --- a/tests/notification.h +++ b/tests/notification.h @@ -12,3 +12,4 @@ void test_notification_sound (void); void test_notification_desktop_file_id (void); void test_notification_display_hint (void); void test_notification_category (void); +void test_notification_supported_properties (void); diff --git a/tests/test-portals.c b/tests/test-portals.c index 15a598970..daea8f48a 100644 --- a/tests/test-portals.c +++ b/tests/test-portals.c @@ -611,6 +611,7 @@ main (int argc, char **argv) g_test_add_func ("/portal/notification/desktop-file-id", test_notification_desktop_file_id); g_test_add_func ("/portal/notification/display-hint", test_notification_display_hint); g_test_add_func ("/portal/notification/category", test_notification_category); + g_test_add_func ("/portal/notification/supported-properties", test_notification_supported_properties); #endif global_setup ();