Commit 655b8db9 authored by Nicolas Jager's avatar Nicolas Jager Committed by Adrien Béraud

play sound when notification pops

- play a sound if notifications are enabled
- we are using libcanbera-gtk3 to play the notification. This depency
  is optional.

Change-Id: Ibffc61bac8d2bb2b4f9840f2e087d57260a03c1f
Signed-off-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 3e4055b2
......@@ -90,6 +90,7 @@ PKG_CHECK_MODULES(CLUTTER REQUIRED clutter-1.0)
PKG_CHECK_MODULES(CLUTTERGTK REQUIRED clutter-gtk-1.0)
PKG_CHECK_MODULES(EBOOK REQUIRED libebook-1.2>=3.10)
PKG_CHECK_MODULES(LIBNOTIFY libnotify>=0.7.6) #optional
pkg_check_modules(CANBERRA libcanberra-gtk3>=0.25) #optional
FIND_PACKAGE(Gettext) #optional for translations
PKG_CHECK_MODULES(LIBQRENCODE libqrencode>=3.4)
PKG_CHECK_MODULES(LIBNM libnm>=1.0) #optional to detect changes in the network
......@@ -111,6 +112,7 @@ INCLUDE_DIRECTORIES(${LIBNOTIFY_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${APPINDICATOR_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${LIBNM_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${WEBKIT_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CANBERRA_INCLUDE_DIRS})
# link libs
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
......@@ -123,6 +125,7 @@ LINK_DIRECTORIES(${LIBNOTIFY_LIBRARY_DIRS})
LINK_DIRECTORIES(${APPINDICATOR_LIBRARY_DIRS})
LINK_DIRECTORIES(${LIBNM_LIBRARY_DIRS})
LINK_DIRECTORIES(${WEBKIT_LIBRARY_DIRS})
LINK_DIRECTORIES(${CANBERRA_LIBRARY_DIRS})
# lib compiler flags
ADD_DEFINITIONS(${GTK3_CFLAGS})
......@@ -136,6 +139,7 @@ ADD_DEFINITIONS(${LIBNOTIFY_CFLAGS})
ADD_DEFINITIONS(${APPINDICATOR_CFLAGS})
ADD_DEFINITIONS(${LIBNM_CFLAGS})
ADD_DEFINITIONS(${WEBKIT_CFLAGS})
ADD_DEFINITIONS(${CANBERRA_CFLAGS})
IF(NOT ${ENABLE_STATIC} MATCHES false)
SET(QT5_MODULE_PATH ${QT5_PATH}/lib/cmake)
......@@ -328,6 +332,7 @@ GLIB_COMPILE_RESOURCES( GLIB_RESOURCES_RING
pixmaps/pixmaps.gresource.xml
ui/ui.gresource.xml
web/web.gresource.xml
sounds/sounds.gresource.xml
)
# IF(${ENABLE_TEST} MATCHES true)
......@@ -379,6 +384,7 @@ TARGET_LINK_LIBRARIES(gnome-ring
${LIBNM_LIBRARIES}
${WEBKIT_LIBRARIES}
${LIBQRENCODE_LIBRARIES}
${CANBERRA_LIBRARIES}
-lpthread
-lrt
)
......@@ -395,12 +401,14 @@ TARGET_LINK_LIBRARIES(gnome-ring
${LIBNM_LIBRARIES}
${WEBKIT_LIBRARIES}
${LIBQRENCODE_LIBRARIES}
${CANBERRA_LIBRARIES}
)
ENDIF()
# configure libnotify variable for config.h file
IF( LIBNOTIFY_FOUND )
SET(USE_LIBNOTIFY 1)
SET(USE_CANBERRA 1)
ELSE()
SET(USE_LIBNOTIFY 0)
ENDIF()
......@@ -419,6 +427,13 @@ ELSE()
SET(HAVE_APPINDICATOR 0)
ENDIF()
# configure libcanberra variable for config.h file
IF( CANBERRA_FOUND )
SET(USE_CANBERRA 1)
ELSE()
SET(USE_CANBERRA 0)
ENDIF()
# create config header file to pass cmake settings to source code
CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/src/config.h.in"
......@@ -434,6 +449,11 @@ INSTALL(FILES ${PROJECT_SOURCE_DIR}/gnome-ring.desktop
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
)
# install audio files
INSTALL(FILES ${PROJECT_SOURCE_DIR}/sounds/ringtone_notify.wav
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/sounds/gnome-ring
)
# install .desktop in the gnome-ring data dir, so that it can be copied to the
# autostart dir by the client
INSTALL(FILES ${PROJECT_SOURCE_DIR}/gnome-ring.desktop.autostart
......
ringtone_notify.wav:
https://creativecommons.org/licenses/by-sa/4.0/
made by Andreas Traczyk andreas.traczyk@savoifairelinux.com
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/cx/ring/RingGnome">
<file>ringtone_notify.wav</file>
</gresource>
</gresources>
......@@ -7,6 +7,7 @@
#define USE_LIBNOTIFY @USE_LIBNOTIFY@
#define HAVE_APPINDICATOR @HAVE_APPINDICATOR@
#define USE_LIBNM @USE_LIBNM@
#define USE_CANBERRA @USE_CANBERRA@
#define RING_CLIENT_APP_ID "cx.ring.RingGnome"
......@@ -15,3 +16,4 @@
#define PACKAGE_NAME "@PROJECT_NAME@"
#define LOCALEDIR "@RING_INSTALL_PREFIX@/share/locale"
#define SOUNDSDIR "@RING_INSTALL_PREFIX@/share/sounds/gnome-ring"
......@@ -583,6 +583,10 @@ ring_client_startup(GApplication *app)
g_object_set(G_OBJECT(gtk_settings), "gtk-button-images",
TRUE, NULL);
/* enable sound (for notification) */
g_object_set(G_OBJECT(gtk_settings), "gtk-enable-event-sounds",
TRUE, NULL);
/* add GActions */
g_action_map_add_action_entries(
G_ACTION_MAP(app), ring_actions, G_N_ELEMENTS(ring_actions), app);
......
......@@ -21,6 +21,10 @@
#include "config.h"
#include "ring_client.h"
#if USE_CANBERRA
#include <canberra-gtk.h>
#endif // USE_CANBERRA
#if USE_LIBNOTIFY
#include <glib/gi18n.h>
#include <libnotify/notify.h>
......@@ -40,6 +44,8 @@
static constexpr int MAX_NOTIFICATIONS = 10; // max unread chat msgs to display from the same contact
static constexpr const char* SERVER_NOTIFY_OSD = "notify-osd";
static constexpr const char* NOTIFICATION_FILE = SOUNDSDIR "/ringtone_notify.wav";
/* struct to store the parsed list of the notify server capabilities */
struct RingNotifyServerInfo
......@@ -351,6 +357,17 @@ ring_notify_show_text_message(ContactMethod *cm, const QModelIndex& idx)
GError *error = nullptr;
success = notify_notification_show(notification_new, &error);
#if USE_CANBERRA
auto status = ca_context_play(ca_gtk_context_get(),
0,
CA_PROP_MEDIA_FILENAME,
NOTIFICATION_FILE,
NULL);
if (status != 0)
g_warning("ca_context_play: %s", ca_strerror(status));
#endif // USE_CANBERRA
if (!success) {
g_warning("failed to show notification: %s", error->message);
g_clear_error(&error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment