gitdiff.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 | 29 |
#include "event.h" |
29 | 30 |
#include "osd.h" |
30 | 31 | |
32 | ||
31 | 33 |
static char * last_title = NULL, * last_message = NULL; /* pooled */ |
32 | 34 | |
33 | 35 |
static void clear (void) |
... | ... | |
38 | 40 |
last_message = NULL; |
39 | 41 |
} |
40 | 42 | |
41 |
static void reshow (void)
|
|
43 |
static void update_button (void * unused, void * useless)
|
|
42 | 44 |
{ |
43 |
if (! last_title || ! last_message) |
|
44 |
return; |
|
45 | ||
46 |
GdkPixbuf * pb = audgui_pixbuf_request_current (); |
|
47 |
if (pb) |
|
48 |
audgui_pixbuf_scale_within (& pb, 96); |
|
49 | ||
50 |
osd_show (last_title, last_message, "audio-x-generic", pb); |
|
51 | ||
52 |
if (pb) |
|
53 |
g_object_unref (pb); |
|
45 |
osd_update_button (); |
|
54 | 46 |
} |
55 | 47 | |
56 |
static void update (void * unused, void * explicit) |
|
48 | ||
49 |
static void update (void * unused, void * useless) |
|
57 | 50 |
{ |
58 | 51 |
if (! aud_drct_get_playing () || ! aud_drct_get_ready ()) |
59 | 52 |
{ |
60 |
if (GPOINTER_TO_INT (explicit)) |
|
61 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, NULL); |
|
62 | ||
63 | 53 |
return; |
64 | 54 |
} |
65 | 55 | |
... | ... | |
86 | 76 |
str_unref (album); |
87 | 77 | |
88 | 78 |
/* pointer comparison works for pooled strings */ |
89 |
if (! GPOINTER_TO_INT (explicit) && title == last_title && message == last_message)
|
|
79 |
if (title == last_title && message == last_message) |
|
90 | 80 |
{ |
91 | 81 |
str_unref (title); |
92 | 82 |
str_unref (message); |
... | ... | |
98 | 88 |
str_unref (last_message); |
99 | 89 |
last_message = message; |
100 | 90 | |
101 |
reshow (); |
|
91 |
char *coverfile = NULL; |
|
92 |
char *filename = aud_playlist_entry_get_filename(list,entry); |
|
93 |
const char *coverfileuri = aud_art_request_file(filename); |
|
94 | ||
95 |
if (coverfileuri){ |
|
96 |
if(g_str_has_prefix (coverfileuri, "file://")) |
|
97 |
coverfile = str_get (g_uri_unescape_string(coverfileuri + 7,"")); |
|
98 |
else |
|
99 |
coverfile = str_get (g_uri_unescape_string(coverfileuri,"")); |
|
100 |
} |
|
101 |
else{ |
|
102 |
GtkIconInfo * iconinfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(),"audio-x-generic",512,GTK_ICON_LOOKUP_FORCE_SVG); |
|
103 |
coverfile = str_get (gtk_icon_info_get_filename(iconinfo)); |
|
104 |
gtk_icon_info_free(iconinfo); |
|
105 |
} |
|
106 | ||
107 |
osd_show (title, message, coverfile, FALSE); |
|
108 | ||
109 |
if (filename) |
|
110 |
str_unref (filename); |
|
111 |
if (coverfile) |
|
112 |
str_unref (coverfile); |
|
113 |
} |
|
114 | ||
115 |
static void update_explicit (void * unused, void * useless) |
|
116 |
{ |
|
117 |
if (! aud_drct_get_playing () || ! aud_drct_get_ready ()) |
|
118 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, FALSE); |
|
119 |
else |
|
120 |
update(unused, useless); |
|
121 |
return; |
|
102 | 122 |
} |
103 | 123 | |
104 | 124 |
void event_init (void) |
105 | 125 |
{ |
106 |
update (NULL, GINT_TO_POINTER (FALSE)); |
|
107 |
hook_associate ("aosd toggle", (HookFunction) update, GINT_TO_POINTER (TRUE)); |
|
108 |
hook_associate ("playback ready", (HookFunction) update, GINT_TO_POINTER (FALSE)); |
|
109 |
hook_associate ("playlist update", (HookFunction) update, GINT_TO_POINTER (FALSE)); |
|
110 |
hook_associate ("current art ready", (HookFunction) reshow, NULL); |
|
126 |
hook_associate ("aosd toggle", (HookFunction) update_explicit, NULL); |
|
127 |
hook_associate ("playback ready", (HookFunction) update, NULL); |
|
128 |
hook_associate ("playlist update", (HookFunction) update, NULL); |
|
129 |
hook_associate ("current art ready", (HookFunction) update, NULL); |
|
130 |
hook_associate ("playback pause", (HookFunction) update_button, NULL); |
|
131 |
hook_associate ("playback unpause", (HookFunction) update_button, NULL); |
|
132 |
hook_associate ("playback begin", (HookFunction) update_button, NULL); |
|
133 |
hook_associate ("playback stop", (HookFunction) update_button, NULL); |
|
111 | 134 |
hook_associate ("playback begin", (HookFunction) clear, NULL); |
112 | 135 |
hook_associate ("playback stop", (HookFunction) clear, NULL); |
113 | 136 |
} |
114 | 137 | |
115 | 138 |
void event_uninit (void) |
116 | 139 |
{ |
117 |
hook_dissociate ("aosd toggle", (HookFunction) update); |
|
140 |
hook_dissociate ("aosd toggle", (HookFunction) update_explicit);
|
|
118 | 141 |
hook_dissociate ("playback ready", (HookFunction) update); |
119 | 142 |
hook_dissociate ("playlist update", (HookFunction) update); |
120 |
hook_dissociate ("current art ready", (HookFunction) reshow); |
|
143 |
hook_dissociate ("current art ready", (HookFunction) update); |
|
144 |
hook_dissociate ("playback pause", (HookFunction) update_button); |
|
145 |
hook_dissociate ("playback unpause", (HookFunction) update_button); |
|
146 |
hook_dissociate ("playback begin", (HookFunction) update_button); |
|
147 |
hook_dissociate ("playback stop", (HookFunction) update_button); |
|
121 | 148 |
hook_dissociate ("playback begin", (HookFunction) clear); |
122 | 149 |
hook_dissociate ("playback stop", (HookFunction) clear); |
123 | 150 |
clear (); |
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()) { |
|
65 |
AUDDBG("osd_init failed!\n"); |
|
66 |
return FALSE; |
|
67 |
} |
|
83 |
aud_config_set_defaults ("notify", notify_defaults); |
|
84 |
osd_init(); |
|
68 | 85 |
event_init(); |
69 | ||
70 | 86 |
plugin_active = 1; |
87 |
AUDDBG("Osd plugin initted\n"); |
|
71 | 88 |
return TRUE; |
72 | 89 |
} |
73 | 90 | |
74 | 91 | |
75 | 92 |
void plugin_cleanup() { |
76 | 93 |
if(plugin_active) { |
77 |
AUDDBG("started!\n"); |
|
78 | 94 |
event_uninit(); |
79 | 95 |
osd_uninit(); |
80 | 96 |
plugin_active = 0; |
81 |
AUDDBG("done!\n");
|
|
97 |
AUDDBG("Osd plugin uninitted\n");
|
|
82 | 98 |
} |
83 | 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 |
} |
|
27 | 68 |
} |
28 | 69 | |
29 | 70 |
void osd_uninit (void) |
30 | 71 |
{ |
31 | 72 |
if (notification) |
32 | 73 |
{ |
74 |
GError *error = NULL; |
|
75 |
if (notify_notification_close (notification, &error) == FALSE) |
|
76 |
AUDDBG("%s!\n", error->message); |
|
33 | 77 |
g_object_unref (notification); |
34 | 78 |
notification = NULL; |
35 | 79 |
} |
36 | 80 | |
37 | 81 |
notify_uninit(); |
82 |
AUDDBG("Notify uninitted\n"); |
|
38 | 83 |
} |
39 | 84 | |
40 |
static void osd_closed_handler (void) |
|
85 | ||
86 |
void goprevious (NotifyNotification *notification, |
|
87 |
const char *action, |
|
88 |
gpointer user_data) |
|
41 | 89 |
{ |
42 |
if (notification) |
|
43 |
{ |
|
44 |
g_object_unref (notification); |
|
45 |
notification = NULL; |
|
90 |
aud_drct_pl_prev(); |
|
91 |
} |
|
92 | ||
93 |
void gonext (NotifyNotification *notification, |
|
94 |
const char *action, |
|
95 |
gpointer user_data) |
|
96 |
{ |
|
97 |
aud_drct_pl_next(); |
|
98 |
} |
|
99 | ||
100 |
void show_audacious (NotifyNotification *notification, |
|
101 |
const char *action, |
|
102 |
gpointer user_data) |
|
103 |
{ |
|
104 |
aud_interface_show(TRUE); |
|
105 |
} |
|
106 | ||
107 |
void playpause (NotifyNotification *notification, |
|
108 |
const char *action, |
|
109 |
gpointer user_data) |
|
110 |
{ |
|
111 |
if(aud_drct_get_playing()) |
|
112 |
{aud_drct_pause();} |
|
113 |
else |
|
114 |
{aud_drct_play();} |
|
115 |
} |
|
116 | ||
117 |
void osd_update_button(void){ |
|
118 |
if(actions_available){ |
|
119 |
GError *error = NULL; |
|
120 |
gboolean paused = TRUE; |
|
121 |
if (aud_drct_get_playing()) {paused = aud_drct_get_paused();} |
|
122 | ||
123 |
notify_notification_clear_actions (notification); |
|
124 | ||
125 |
notify_notification_add_action (notification, |
|
126 |
"media-skip-backward", |
|
127 |
N_("Previous"), |
|
128 |
NOTIFY_ACTION_CALLBACK(goprevious), |
|
129 |
NULL, |
|
130 |
NULL); |
|
131 | ||
132 |
notify_notification_add_action (notification, |
|
133 |
paused ? "media-playback-start" : "media-playback-pause", |
|
134 |
paused ? N_("Play") : N_("Pause"), |
|
135 |
NOTIFY_ACTION_CALLBACK(playpause), |
|
136 |
NULL, |
|
137 |
NULL); |
|
138 | ||
139 |
notify_notification_add_action (notification, |
|
140 |
"media-skip-forward", |
|
141 |
N_("Next"), |
|
142 |
NOTIFY_ACTION_CALLBACK(gonext), |
|
143 |
NULL, |
|
144 |
NULL); |
|
145 | ||
146 |
notify_notification_add_action (notification, |
|
147 |
"default", |
|
148 |
N_("Show Audacious"), |
|
149 |
NOTIFY_ACTION_CALLBACK(show_audacious), |
|
150 |
NULL, |
|
151 |
NULL); |
|
152 |
if(!notify_notification_show(notification, &error)) |
|
153 |
AUDDBG("Error “%s” when trying to send notification\n", error->message); |
|
46 | 154 |
} |
47 | 155 |
} |
48 | 156 | |
49 |
void osd_show (const char * title, const char * _message, const char * icon, |
|
50 |
GdkPixbuf * pixbuf)
|
|
157 | ||
158 |
void osd_show (const gchar * title, const gchar * _message, const gchar * coverfile, gboolean actiononly)
|
|
51 | 159 |
{ |
52 |
char * message = g_markup_escape_text (_message, -1); |
|
160 |
gchar * message = g_markup_escape_text (_message, -1); |
|
161 |
GError *error = NULL; |
|
53 | 162 | |
54 |
if (pixbuf) |
|
55 |
icon = NULL; |
|
163 |
notify_notification_set_hint_string (notification, "image_path", coverfile); |
|
56 | 164 | |
57 |
if (notification) |
|
58 |
notify_notification_update (notification, title, message, icon); |
|
165 |
if (actions_available) |
|
166 |
{ |
|
167 |
osd_update_button(); |
|
168 |
} |
|
59 | 169 |
else |
60 | 170 |
{ |
61 |
notification = notify_notification_new (title, message, icon); |
|
62 |
g_signal_connect (notification, "closed", (GCallback) osd_closed_handler, NULL); |
|
171 |
if (actiononly) |
|
172 |
{ |
|
173 |
g_free (message); |
|
174 |
return; |
|
175 |
} |
|
63 | 176 |
} |
64 | 177 | |
65 |
if (pixbuf)
|
|
66 |
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
|
|
178 |
if(!notify_notification_update(notification, title, message, "audacious"))
|
|
179 |
AUDDBG("Could not update osd!\n");
|
|
67 | 180 | |
68 |
notify_notification_show (notification, NULL); |
|
181 |
if(!notify_notification_show(notification, &error)) |
|
182 |
AUDDBG("Error “%s” when trying to send notification\n", error->message); |
|
69 | 183 | |
70 | 184 |
g_free (message); |
71 | 185 |
} |
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 gchar *coverfile, gboolean actiononly); |
|
23 |
void osd_update_button(void); |