[gnome-bluetooth] settings: Replace canberra-gtk by to gsound



commit e7c972c0289f2006cb631339466d52d7a555dcae
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 22 19:24:42 2021 -0300

    settings: Replace canberra-gtk by to gsound
    
    Mainly to reduce the number of GTK3 dependencies before actually start
    porting the library. Fortunately, the usage of libcanberra-gtk by
    gnome-bluetooth is rather trivial, so porting to gsound is just a few
    lines of code away.
    
    Replace canberra-gtk by gsound, adjust the build system to reflect
    that, and update the CI file to install gsound-devel instead of
    libcanberra-devel.

 .gitlab-ci.yml                    |  2 +-
 lib/bluetooth-settings-obexpush.c | 23 ++++++++++++++++-------
 lib/meson.build                   |  2 +-
 meson.build                       |  2 +-
 4 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8ec39f7c..9f7d6813 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,7 +6,7 @@ variables:
     gobject-introspection-devel
     gtk3-devel
     systemd-devel
-    libcanberra-devel
+    gsound-devel
     libnotify-devel
     meson
     redhat-rpm-config
diff --git a/lib/bluetooth-settings-obexpush.c b/lib/bluetooth-settings-obexpush.c
index 9243062c..1b07f3ec 100644
--- a/lib/bluetooth-settings-obexpush.c
+++ b/lib/bluetooth-settings-obexpush.c
@@ -29,10 +29,10 @@
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 #include <gio/gio.h>
+#include <gsound.h>
 #include <gtk/gtk.h>
 #include <bluetooth-client.h>
 #include <libnotify/notify.h>
-#include <canberra-gtk.h>
 
 #include "bluetooth-settings-obexpush.h"
 
@@ -67,6 +67,7 @@ G_DEFINE_TYPE(ObexAgent, obex_agent, G_TYPE_OBJECT)
 static ObexAgent *agent;
 static BluetoothClient *client;
 static GCancellable *cancellable;
+static GSoundContext *gsound_context;
 
 static void
 on_close_notification (NotifyNotification *notification)
@@ -130,7 +131,6 @@ show_notification (const char *filename)
 {
        char *file_uri, *notification_text, *display, *mime_type;
        NotifyNotification *notification;
-       ca_context *ctx;
        GAppInfo *app;
 
        file_uri = g_filename_to_uri (filename, NULL, NULL);
@@ -172,11 +172,12 @@ show_notification (const char *filename)
        g_free (notification_text);
 
        /* Now we do the audio notification */
-       ctx = ca_gtk_context_get ();
-       ca_context_play (ctx, 0,
-                        CA_PROP_EVENT_ID, "complete-download",
-                        CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
-                        NULL);
+       if (gsound_context) {
+               gsound_context_play_simple (gsound_context, cancellable, NULL,
+                                           GSOUND_ATTR_EVENT_ID, "complete-download",
+                                           GSOUND_ATTR_EVENT_DESCRIPTION, _("File reception complete"),
+                                           NULL);
+       }
 }
 
 static void
@@ -852,4 +853,12 @@ obex_agent_up (void)
 
        g_assert (cancellable == NULL);
        cancellable = g_cancellable_new ();
+
+       if (gsound_context == NULL) {
+               g_autoptr(GError) error = NULL;
+
+               gsound_context = gsound_context_new (cancellable, &error);
+               if (!gsound_context)
+                       g_warning ("Failed to open sound context: %s", error->message);
+       }
 }
diff --git a/lib/meson.build b/lib/meson.build
index 5080a952..91e176ff 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -74,7 +74,7 @@ deps = [
 
 private_deps = [
   gio_unix_dep,
-  libcanberra_gtk_dep,
+  gsound_dep,
   libnotify_dep,
   libudev_dep,
 ]
diff --git a/meson.build b/meson.build
index 79bf7a24..badeb896 100644
--- a/meson.build
+++ b/meson.build
@@ -100,7 +100,7 @@ add_project_arguments(common_flags + compiler_flags, language: 'c')
 gio_dep = dependency('gio-2.0', version: '>= 2.44')
 gio_unix_dep = dependency('gio-unix-2.0')
 gtk_dep = dependency('gtk+-3.0', version: '>= 3.12.0')
-libcanberra_gtk_dep = dependency('libcanberra-gtk3')
+gsound_dep = dependency('gsound')
 libnotify_dep = dependency('libnotify', version: '>= 0.7.0')
 libudev_dep = dependency('libudev')
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]