forked from community-ssu/hildon-plugins-notify-sv
/
nsv-plugin.c
125 lines (99 loc) · 2.5 KB
/
nsv-plugin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <glib-object.h>
#include <stdio.h>
#include "nsv.h"
#include "nsv-plugin.h"
#include "nsv-util.h"
void
nsv_plugin_load()
{
nsv_initialize_with_x11();
}
void
nsv_plugin_unload()
{
nsv_shutdown();
}
gint
nsv_plugin_play_event(GHashTable *hints, gchar *sender)
{
const gchar *s;
const char *category;
gchar *sound_file;
const GValue *val;
gboolean override;
gint id;
gchar *vibra_pattern;
gint volume;
_sp_timestamp("Notification received.");
val = (const GValue *)g_hash_table_lookup(hints, "category");
if (!G_VALUE_HOLDS_STRING(val) || !(s = g_value_get_string(val)))
goto err_cat;
if (g_str_equal(s, "system-sound"))
category = "System";
else if (g_str_equal(s, "incoming-call"))
category = "Ringtone";
else if (g_str_equal(s, "sms-message") ||
g_str_equal(s, "sms-message-class-0") ||
g_str_equal(s, "voice-mail"))
{
category = "SMS";
}
else if (g_str_equal(s, "chat-message") || g_str_equal(s, "auth-request") ||
g_str_equal(s, "chat-invitation"))
{
category = "Chat";
}
else if (g_str_equal(s, "email-message"))
category = "Email";
else if (g_str_equal(s, "alarm-event"))
{
val = g_hash_table_lookup(hints, "alarm-type");
if (G_VALUE_HOLDS_STRING(val) && (s = g_value_get_string(val)) &&
g_str_equal(s, "clock"))
{
category = "Clock";
}
else
category = "Calendar";
}
else if (g_str_equal(s, "system-critical"))
category = "Critical";
else if (g_str_equal(s, "play-sound") || g_str_has_prefix(s, "system.note."))
category = "Sound";
else
goto err_cat;
val = (const GValue *)g_hash_table_lookup(hints, "sound-file");
if (val)
sound_file = g_value_dup_string(val);
else
sound_file = NULL;
val = (const GValue *)g_hash_table_lookup(hints, "volume");
if (val)
volume = g_value_get_int(val);
else
volume = 100;
val = (const GValue *)g_hash_table_lookup(hints, "vibra");
if (val)
vibra_pattern = g_value_dup_string(val);
else
vibra_pattern = NULL;
val = (const GValue *)g_hash_table_lookup(hints, "override");
if (val)
override = g_value_get_boolean(val);
else
override = FALSE;
id = nsv_play(category, sound_file, volume, vibra_pattern, sender, override);
if (sound_file)
g_free(sound_file);
if (vibra_pattern)
g_free(vibra_pattern);
return id;
err_cat:
g_debug("No category for notification, no need to do anything.");
return -1;
}
void
nsv_plugin_stop_event(gint id)
{
nsv_stop(id);
}