notifyactionsupport.patch
src/notify/event.c | ||
---|---|---|
21 | 21 |
#include <audacious/drct.h> |
22 | 22 |
#include <audacious/i18n.h> |
23 | 23 |
#include <audacious/playlist.h> |
24 |
#include <audacious/misc.h> |
|
24 | 25 |
#include <libaudcore/hook.h> |
25 | 26 |
#include <libaudgui/libaudgui-gtk.h> |
26 | 27 | |
28 |
#include "config.h" |
|
27 | 29 |
#include "event.h" |
28 | 30 |
#include "osd.h" |
29 | 31 | |
32 | ||
30 | 33 |
static char * last_title = NULL, * last_message = NULL; /* pooled */ |
31 | 34 | |
32 | 35 |
static void clear (void) |
... | ... | |
37 | 40 |
last_message = NULL; |
38 | 41 |
} |
39 | 42 | |
40 |
static void reshow (void)
|
|
43 |
static void update_button (void * unused, void * useless)
|
|
41 | 44 |
{ |
42 |
if (! last_title || ! last_message) |
|
43 |
return; |
|
44 | ||
45 |
GdkPixbuf * pb = audgui_pixbuf_request_current (); |
|
46 |
if (pb) |
|
47 |
audgui_pixbuf_scale_within (& pb, 96); |
|
48 | ||
49 |
osd_show (last_title, last_message, "audio-x-generic", pb); |
|
50 | ||
51 |
if (pb) |
|
52 |
g_object_unref (pb); |
|
45 |
osd_update_button (); |
|
53 | 46 |
} |
54 | 47 | |
55 |
static void update (void * unused, void * explicit) |
|
48 | ||
49 |
static void update (void * unused, void * useless) |
|
56 | 50 |
{ |
57 | 51 |
if (! aud_drct_get_playing () || ! aud_drct_get_ready ()) |
58 | 52 |
{ |
59 |
if (GPOINTER_TO_INT (explicit)) |
|
60 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, NULL); |
|
61 | ||
62 | 53 |
return; |
63 | 54 |
} |
64 | 55 | |
... | ... | |
85 | 76 |
str_unref (album); |
86 | 77 | |
87 | 78 |
/* pointer comparison works for pooled strings */ |
88 |
if (! GPOINTER_TO_INT (explicit) && title == last_title && message == last_message)
|
|
79 |
if (title == last_title && message == last_message) |
|
89 | 80 |
{ |
90 | 81 |
str_unref (title); |
91 | 82 |
str_unref (message); |
... | ... | |
97 | 88 |
str_unref (last_message); |
98 | 89 |
last_message = message; |
99 | 90 | |
100 |
reshow (); |
|
91 |
GdkPixbuf *pixbuf = audgui_pixbuf_request_current(); |
|
92 | ||
93 |
if (pixbuf) |
|
94 |
audgui_pixbuf_scale_within (& pixbuf, 96); |
|
95 | ||
96 |
osd_show (title, message, pixbuf, FALSE); |
|
97 | ||
98 |
if (pixbuf) |
|
99 |
g_object_unref (pixbuf); |
|
100 |
} |
|
101 | ||
102 |
static void update_explicit (void * unused, void * useless) |
|
103 |
{ |
|
104 |
if (! aud_drct_get_playing () || ! aud_drct_get_ready ()) |
|
105 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, FALSE); |
|
106 |
else |
|
107 |
update(unused, useless); |
|
108 |
return; |
|
101 | 109 |
} |
102 | 110 | |
103 |
void event_init (void)
|
|
111 |
void event_init () |
|
104 | 112 |
{ |
105 |
update (NULL, GINT_TO_POINTER (FALSE)); |
|
106 |
hook_associate ("aosd toggle", (HookFunction) update, GINT_TO_POINTER (TRUE)); |
|
107 |
hook_associate ("playback ready", (HookFunction) update, GINT_TO_POINTER (FALSE)); |
|
108 |
hook_associate ("playlist update", (HookFunction) update, GINT_TO_POINTER (FALSE)); |
|
109 |
hook_associate ("current art ready", (HookFunction) reshow, NULL); |
|
113 |
hook_associate ("aosd toggle", (HookFunction) update_explicit, NULL); |
|
114 |
hook_associate ("playback ready", (HookFunction) update, NULL); |
|
115 |
hook_associate ("playlist update", (HookFunction) update, NULL); |
|
116 |
hook_associate ("current art ready", (HookFunction) update, NULL); |
|
117 |
hook_associate ("playback pause", (HookFunction) update_button, NULL); |
|
118 |
hook_associate ("playback unpause", (HookFunction) update_button, NULL); |
|
119 |
hook_associate ("playback begin", (HookFunction) update_button, NULL); |
|
120 |
hook_associate ("playback stop", (HookFunction) update_button, NULL); |
|
110 | 121 |
hook_associate ("playback begin", (HookFunction) clear, NULL); |
111 | 122 |
hook_associate ("playback stop", (HookFunction) clear, NULL); |
112 | 123 |
} |
113 | 124 | |
114 | 125 |
void event_uninit (void) |
115 | 126 |
{ |
116 |
hook_dissociate ("aosd toggle", (HookFunction) update); |
|
127 |
hook_dissociate ("aosd toggle", (HookFunction) update_explicit);
|
|
117 | 128 |
hook_dissociate ("playback ready", (HookFunction) update); |
118 | 129 |
hook_dissociate ("playlist update", (HookFunction) update); |
119 |
hook_dissociate ("current art ready", (HookFunction) reshow); |
|
130 |
hook_dissociate ("current art ready", (HookFunction) update); |
|
131 |
hook_dissociate ("playback pause", (HookFunction) update_button); |
|
132 |
hook_dissociate ("playback unpause", (HookFunction) update_button); |
|
133 |
hook_dissociate ("playback begin", (HookFunction) update_button); |
|
134 |
hook_dissociate ("playback stop", (HookFunction) update_button); |
|
120 | 135 |
hook_dissociate ("playback begin", (HookFunction) clear); |
121 | 136 |
hook_dissociate ("playback stop", (HookFunction) clear); |
122 | 137 |
clear (); |
src/notify/event.h | ||
---|---|---|
17 | 17 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
*/ |
19 | 19 | |
20 |
void event_init (void);
|
|
20 |
void event_init (); |
|
21 | 21 |
void event_uninit (void); |
src/notify/notify.c | ||
---|---|---|
23 | 23 |
#include <audacious/i18n.h> |
24 | 24 |
#include <audacious/plugin.h> |
25 | 25 |
#include <audacious/debug.h> |
26 |
#include <audacious/preferences.h> |
|
27 |
#include <audacious/misc.h> |
|
26 | 28 | |
29 |
#include "config.h" |
|
27 | 30 |
#include "event.h" |
28 | 31 |
#include "osd.h" |
29 | 32 | |
... | ... | |
46 | 49 |
"You should have received a copy of the GNU General Public License " |
47 | 50 |
"along with this program. If not, see <http://www.gnu.org/licenses/>."); |
48 | 51 | |
52 |
static const char * const notify_defaults[] = { |
|
53 |
"actions", "TRUE", |
|
54 |
NULL}; |
|
55 | ||
56 | ||
57 |
static const PreferencesWidget notify_widgets[] = { |
|
58 |
{WIDGET_CHK_BTN, N_("Activate controls inside of the notification"), |
|
59 |
.cfg_type = VALUE_BOOLEAN, .csect = "notify", .cname = "actions"}, |
|
60 |
}; |
|
61 | ||
62 |
static const PluginPreferences notify_prefs = { |
|
63 |
.widgets = notify_widgets, |
|
64 |
.n_widgets = G_N_ELEMENTS (notify_widgets) |
|
65 |
}; |
|
66 | ||
67 | ||
68 | ||
49 | 69 |
AUD_GENERAL_PLUGIN |
50 | 70 |
( |
51 | 71 |
.name = N_("Desktop Notifications"), |
52 | 72 |
.domain = PACKAGE, |
53 | 73 |
.about_text = plugin_about, |
54 | 74 |
.init = plugin_init, |
75 |
.prefs = & notify_prefs, |
|
55 | 76 |
.cleanup = plugin_cleanup |
56 | 77 |
) |
57 | 78 | |
... | ... | |
59 | 80 | |
60 | 81 |
gboolean plugin_init (void) |
61 | 82 |
{ |
62 |
AUDDBG("started!\n"); |
|
63 |
if(!osd_init()) { |
|
64 |
AUDDBG("osd_init failed!\n"); |
|
65 |
return FALSE; |
|
66 |
} |
|
83 |
aud_config_set_defaults ("notify", notify_defaults); |
|
84 |
osd_init(); |
|
67 | 85 |
event_init(); |
68 | ||
69 | 86 |
plugin_active = 1; |
87 |
AUDDBG("Osd plugin initted\n"); |
|
70 | 88 |
return TRUE; |
71 | 89 |
} |
72 | 90 | |
73 | 91 | |
74 | 92 |
void plugin_cleanup() { |
75 | 93 |
if(plugin_active) { |
76 |
AUDDBG("started!\n"); |
|
77 | 94 |
event_uninit(); |
78 | 95 |
osd_uninit(); |
79 | 96 |
plugin_active = 0; |
80 |
AUDDBG("done!\n");
|
|
97 |
AUDDBG("Osd plugin uninitted\n");
|
|
81 | 98 |
} |
82 | 99 |
} |
src/notify/osd.c | ||
---|---|---|
17 | 17 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
*/ |
19 | 19 | |
20 |
#include <libaudcore/core.h> |
|
21 |
#include <libaudcore/hook.h> |
|
22 |
#include <audacious/debug.h> |
|
23 |
#include <audacious/i18n.h> |
|
24 |
#include <audacious/drct.h> |
|
25 |
#include <audacious/misc.h> |
|
26 |
#include <libnotify/notify.h> |
|
20 | 27 |
#include "osd.h" |
21 | 28 | |
22 |
static NotifyNotification * notification = NULL; |
|
29 |
static NotifyNotification *notification = NULL; |
|
30 |
static gboolean actions_available = FALSE; |
|
23 | 31 | |
24 |
bool_t osd_init() |
|
25 |
{ |
|
26 |
return notify_init ("Audacious"); |
|
32 |
void osd_init() { |
|
33 |
if (notify_is_initted()) |
|
34 |
{ |
|
35 |
AUDDBG("Notify is already initted, that shouldn't happen\n"); |
|
36 |
return; |
|
37 |
} |
|
38 |
if (notify_init("Audacious")) |
|
39 |
{ |
|
40 |
notification = notify_notification_new("Notification", NULL, NULL); |
|
41 | ||
42 |
notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); |
|
43 |
notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("audacious")); |
|
44 | ||
45 |
GList *server_caps; |
|
46 |
server_caps = notify_get_server_caps (); |
|
47 | ||
48 |
if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0)) |
|
49 |
{ |
|
50 |
actions_available = TRUE; |
|
51 |
if (g_list_find_custom (server_caps, "action-icons", (GCompareFunc)g_strcmp0)) |
|
52 |
notify_notification_set_hint (notification, "action-icons", g_variant_new_boolean (TRUE)); |
|
53 |
} |
|
54 |
if (g_list_find_custom (server_caps, "persistence", (GCompareFunc)g_strcmp0)) |
|
55 |
{ |
|
56 |
AUDDBG("Notification server supports persistence\n"); |
|
57 |
if (aud_get_bool ("notify", "actions") && actions_available) |
|
58 |
notify_notification_set_hint (notification, "resident", g_variant_new_boolean (TRUE)); |
|
59 |
else |
|
60 |
notify_notification_set_hint (notification, "resident", g_variant_new_boolean (FALSE)); |
|
61 |
} |
|
62 |
else |
|
63 |
{ |
|
64 |
AUDDBG("Notification server doesn't supports persistence\n"); |
|
65 |
} |
|
66 |
g_list_free_full(server_caps, g_free); |
|
67 |
} |
|
68 |
return; |
|
27 | 69 |
} |
28 | 70 | |
29 | 71 |
void osd_uninit (void) |
30 | 72 |
{ |
31 | 73 |
if (notification) |
32 | 74 |
{ |
75 |
GError *error = NULL; |
|
76 |
if (notify_notification_close (notification, &error) == FALSE) |
|
77 |
AUDDBG("%s!\n", error->message); |
|
33 | 78 |
g_object_unref (notification); |
34 | 79 |
notification = NULL; |
35 | 80 |
} |
36 | 81 | |
37 | 82 |
notify_uninit(); |
83 |
AUDDBG("Notify uninitted\n"); |
|
38 | 84 |
} |
39 | 85 | |
40 |
static void osd_closed_handler (void) |
|
86 | ||
87 |
void goprevious (NotifyNotification *notification, |
|
88 |
const char *action, |
|
89 |
gpointer user_data) |
|
41 | 90 |
{ |
42 |
if (notification) |
|
43 |
{ |
|
44 |
g_object_unref (notification); |
|
45 |
notification = NULL; |
|
91 |
aud_drct_pl_prev(); |
|
92 |
} |
|
93 | ||
94 |
void gonext (NotifyNotification *notification, |
|
95 |
const char *action, |
|
96 |
gpointer user_data) |
|
97 |
{ |
|
98 |
aud_drct_pl_next(); |
|
99 |
} |
|
100 | ||
101 |
void show_audacious (NotifyNotification *notification, |
|
102 |
const char *action, |
|
103 |
gpointer user_data) |
|
104 |
{ |
|
105 |
aud_interface_show(TRUE); |
|
106 |
} |
|
107 | ||
108 |
void playpause (NotifyNotification *notification, |
|
109 |
const char *action, |
|
110 |
gpointer user_data) |
|
111 |
{ |
|
112 |
if(aud_drct_get_playing()) |
|
113 |
{aud_drct_pause();} |
|
114 |
else |
|
115 |
{aud_drct_play();} |
|
116 |
} |
|
117 | ||
118 |
void osd_update_button(void){ |
|
119 |
if(actions_available){ |
|
120 |
GError *error = NULL; |
|
121 |
gboolean paused = TRUE; |
|
122 |
if (aud_drct_get_playing()) {paused = aud_drct_get_paused();} |
|
123 | ||
124 |
notify_notification_clear_actions (notification); |
|
125 | ||
126 |
notify_notification_add_action (notification, |
|
127 |
"media-skip-backward", |
|
128 |
N_("Previous"), |
|
129 |
NOTIFY_ACTION_CALLBACK(goprevious), |
|
130 |
NULL, |
|
131 |
NULL); |
|
132 | ||
133 |
notify_notification_add_action (notification, |
|
134 |
paused ? "media-playback-start" : "media-playback-pause", |
|
135 |
paused ? N_("Play") : N_("Pause"), |
|
136 |
NOTIFY_ACTION_CALLBACK(playpause), |
|
137 |
NULL, |
|
138 |
NULL); |
|
139 | ||
140 |
notify_notification_add_action (notification, |
|
141 |
"media-skip-forward", |
|
142 |
N_("Next"), |
|
143 |
NOTIFY_ACTION_CALLBACK(gonext), |
|
144 |
NULL, |
|
145 |
NULL); |
|
146 | ||
147 |
notify_notification_add_action (notification, |
|
148 |
"default", |
|
149 |
N_("Show Audacious"), |
|
150 |
NOTIFY_ACTION_CALLBACK(show_audacious), |
|
151 |
NULL, |
|
152 |
NULL); |
|
153 |
if(!notify_notification_show(notification, &error)) |
|
154 |
AUDDBG("Error “%s” when trying to send notification\n", error->message); |
|
46 | 155 |
} |
47 | 156 |
} |
48 | 157 | |
49 |
void osd_show (const char * title, const char * _message, const char * icon, |
|
50 |
GdkPixbuf * pixbuf)
|
|
158 | ||
159 |
void osd_show (const gchar * title, const gchar * _message, const GdkPixbuf *cover, gboolean actiononly)
|
|
51 | 160 |
{ |
52 |
char * message = g_markup_escape_text (_message, -1); |
|
161 |
gchar * message = g_markup_escape_text (_message, -1); |
|
162 |
GError *error = NULL; |
|
53 | 163 | |
54 |
if (pixbuf)
|
|
55 |
icon = NULL;
|
|
164 |
if(cover)
|
|
165 |
notify_notification_set_image_from_pixbuf(notification, cover);
|
|
56 | 166 | |
57 |
if (notification) |
|
58 |
notify_notification_update (notification, title, message, icon); |
|
167 |
if (actions_available) |
|
168 |
{ |
|
169 |
osd_update_button(); |
|
170 |
} |
|
59 | 171 |
else |
60 | 172 |
{ |
61 |
notification = notify_notification_new (title, message, icon); |
|
62 |
g_signal_connect (notification, "closed", (GCallback) osd_closed_handler, NULL); |
|
173 |
if (actiononly) |
|
174 |
{ |
|
175 |
g_free (message); |
|
176 |
return; |
|
177 |
} |
|
63 | 178 |
} |
64 | 179 | |
65 |
if (pixbuf)
|
|
66 |
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
|
|
180 |
if(!notify_notification_update(notification, title, message, "audacious"))
|
|
181 |
AUDDBG("Could not update osd!\n");
|
|
67 | 182 | |
68 |
notify_notification_show (notification, NULL); |
|
183 |
if(!notify_notification_show(notification, &error)) |
|
184 |
AUDDBG("Error “%s” when trying to send notification\n", error->message); |
|
69 | 185 | |
70 | 186 |
g_free (message); |
71 | 187 |
} |
src/notify/osd.h | ||
---|---|---|
17 | 17 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
*/ |
19 | 19 | |
20 |
#include <libaudcore/core.h> |
|
21 |
#include <libnotify/notify.h> |
|
22 | ||
23 |
bool_t osd_init (void); |
|
24 |
void osd_uninit (void); |
|
25 |
void osd_show (const char * title, const char * message, const char * icon, GdkPixbuf * pixbuf); |
|
20 |
void osd_init(); |
|
21 |
void osd_uninit(); |
|
22 |
void osd_show(const gchar *title, const gchar *message, const GdkPixbuf *pixbuf, gboolean actiononly); |
|
23 |
void osd_update_button(void); |