Commit 30493e68 authored by Andrea Schaefer's avatar Andrea Schaefer
Browse files

Add notification sound

parent 29fa32b3
Pipeline #52165 passed with stages
in 12 minutes and 43 seconds
......@@ -13,6 +13,7 @@ Build-Depends:
libsqlite3-dev,
libgee-0.8-dev,
libfolks-dev,
libgsound-dev,
meson,
Standards-Version: 4.2.1
Homepage: https://source.puri.sm/Librem5/chatty
......
......@@ -211,6 +211,16 @@
}
]
},
{
"name" : "gsound",
"sources" : [
{
"type" : "archive",
"url" : "https://download.gnome.org/sources/gsound/1.0/gsound-1.0.2.tar.xz",
"sha256" : "bba8ff30eea815037e53bee727bbd5f0b6a2e74d452a7711b819a7c444e78e53"
}
]
},
{
"name": "purism-chatty",
"buildsystem": "meson",
......
......@@ -8,6 +8,7 @@
#define G_LOG_DOMAIN "chatty-conversation"
#include <glib/gi18n.h>
#include <gsound.h>
#include "chatty-window.h"
#include "chatty-manager.h"
#include "chatty-icons.h"
......@@ -27,6 +28,15 @@
static GHashTable *ht_sms_id = NULL;
static GHashTable *ht_emoticon = NULL;
typedef struct {
GSoundContext *ctx;
gchar *sound_theme;
} ConvSound;
static ConvSound *conv_gs;
const char *avatar_colors[16] = {"E57373", "F06292", "BA68C8", "9575CD",
"7986CB", "64B5F6", "4FC3F7", "4DD0E1",
"4DB6AC", "81C784", "AED581", "DCE775",
......@@ -2116,6 +2126,21 @@ chatty_conv_write_conversation (PurpleConversation *conv,
NULL);
} else if (pcm.flags & PURPLE_MESSAGE_RECV) {
if (buddy && purple_blist_node_get_bool (node, "chatty-notifications")) {
g_autoptr(GError) error = NULL;
gsound_context_play_simple (conv_gs->ctx,
NULL,
&error,
GSOUND_ATTR_MEDIA_ROLE, "event",
GSOUND_ATTR_EVENT_ID, "message-new-instant",
GSOUND_ATTR_EVENT_DESCRIPTION, _("New instant message"),
NULL);
if (error) {
g_warning ("Error: %s: %s", __func__, error->message);
}
buddy_name = purple_buddy_get_alias (buddy);
titel = g_strdup_printf (_("New message from %s"), buddy_name);
......@@ -2800,6 +2825,51 @@ cb_ht_check_items (gpointer key,
}
static void
chatty_conv_init_gsound (void)
{
GtkSettings *settings;
GHashTable *attr;
g_autoptr(GError) error = NULL;
conv_gs = g_new0 (ConvSound, 1);
conv_gs->ctx = gsound_context_new (NULL, &error);
settings = gtk_settings_get_default ();
g_object_get (settings,
"gtk-sound-theme-name", &conv_gs->sound_theme,
NULL);
attr = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (attr, GSOUND_ATTR_APPLICATION_ID, CHATTY_APP_ID);
g_hash_table_insert (attr, GSOUND_ATTR_APPLICATION_NAME, CHATTY_APP_NAME);
g_hash_table_insert (attr, GSOUND_ATTR_APPLICATION_ICON_NAME, CHATTY_APP_ID);
if (conv_gs->sound_theme)
g_hash_table_insert (attr, GSOUND_ATTR_CANBERRA_XDG_THEME_NAME, conv_gs->sound_theme);
gsound_context_set_attributesv (conv_gs->ctx, attr, &error);
g_hash_table_unref (attr);
if (!conv_gs->ctx)
g_warning ("Error: %s: %s", __func__, error->message);
}
static void
chatty_conv_init_destroy (void)
{
g_object_unref (conv_gs->ctx);
g_free (conv_gs->sound_theme);
g_free (conv_gs);
}
/**
* chatty_conv_destroy:
* @conv: a PurpleConversation
......@@ -2986,12 +3056,15 @@ chatty_conversations_init (void)
NULL);
chatty_conv_init_emoticon_translations ();
chatty_conv_init_gsound ();
}
void
chatty_conversations_uninit (void)
{
chatty_conv_init_destroy ();
g_hash_table_destroy (ht_sms_id);
purple_prefs_disconnect_by_handle (chatty_conversations_get_handle());
purple_signals_disconnect_by_handle (chatty_conversations_get_handle());
......
......@@ -55,6 +55,7 @@ chatty_deps = [
dependency('sqlite3', version: '>=3.0.0'),
dependency('gee-0.8'),
dependency('folks'),
dependency('gsound'),
libebook_dep,
libm_dep,
]
......
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