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