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);
|
|
| 39 |
if (aud_get_bool ("notify", "actions"))
|
|
| 40 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, notif, TRUE);
|
|
| 65 | 41 | |
| 66 | 42 |
return; |
| 67 | 43 |
} |
| ... | ... | |
| 88 | 64 |
str_unref (artist); |
| 89 | 65 |
str_unref (album); |
| 90 | 66 | |
| 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 |
} |
|
| 67 |
gchar *coverfile = NULL; |
|
| 68 |
gchar *filename = aud_playlist_entry_get_filename(list,entry); |
|
| 69 |
const gchar *coverfileuri = aud_art_request_file(filename); |
|
| 98 | 70 | |
| 99 |
str_unref (last_title); |
|
| 100 |
last_title = title; |
|
| 101 |
str_unref (last_message); |
|
| 102 |
last_message = message; |
|
| 71 |
if (coverfileuri /*&& !g_strcmp0(coverfile,"")*/){
|
|
| 72 |
if(g_str_has_prefix (coverfileuri, "file://")) |
|
| 73 |
coverfile = g_uri_unescape_string(coverfileuri + 7,""); |
|
| 74 |
else |
|
| 75 |
coverfile = g_uri_unescape_string(coverfileuri,""); |
|
| 76 |
} |
|
| 77 |
else{
|
|
| 78 |
GtkIconInfo * iconinfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(),"audio-x-generic",512,GTK_ICON_LOOKUP_FORCE_SVG); |
|
| 79 |
coverfile = g_strdup(gtk_icon_info_get_filename(iconinfo)); |
|
| 80 |
gtk_icon_info_free(iconinfo); |
|
| 81 |
} |
|
| 82 | ||
| 83 |
osd_show (title, message, coverfile, notif, FALSE); |
|
| 84 | ||
| 85 |
if (filename) |
|
| 86 |
str_unref (filename); |
|
| 87 |
if (coverfile) |
|
| 88 |
g_free (coverfile); |
|
| 89 | ||
| 90 |
str_unref (message); |
|
| 91 |
str_unref (title); |
|
| 92 |
} |
|
| 103 | 93 | |
| 104 |
reshow (); |
|
| 94 |
static void update_explicit (void * unused, void * notif) |
|
| 95 |
{
|
|
| 96 |
if (! aud_drct_get_playing () || ! aud_drct_get_ready ()) |
|
| 97 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, notif, FALSE);
|
|
| 98 |
else |
|
| 99 |
update(unused, notif); |
|
| 100 |
return; |
|
| 105 | 101 |
} |
| 106 | 102 | |
| 107 |
void event_init (void) |
|
| 103 |
void event_init (void* notif)
|
|
| 108 | 104 |
{
|
| 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);
|
|
| 105 |
hook_associate ("aosd toggle", (HookFunction) update_explicit, notif);
|
|
| 106 |
hook_associate ("playback ready", (HookFunction) update, notif);
|
|
| 107 |
hook_associate ("playlist update", (HookFunction) update, notif);
|
|
| 108 |
hook_associate ("playback pause", (HookFunction) update, notif);
|
|
| 109 |
hook_associate ("playback unpause", (HookFunction) update, notif);
|
|
| 115 | 110 |
} |
| 116 | 111 | |
| 117 | 112 |
void event_uninit (void) |
| 118 | 113 |
{
|
| 119 |
hook_dissociate ("aosd toggle", (HookFunction) update);
|
|
| 114 |
hook_dissociate ("aosd toggle", (HookFunction) update_explicit);
|
|
| 120 | 115 |
hook_dissociate ("playback ready", (HookFunction) update);
|
| 121 | 116 |
hook_dissociate ("playlist update", (HookFunction) update);
|
| 122 |
hook_dissociate ("current art ready", (HookFunction) reshow);
|
|
| 123 |
hook_dissociate ("playback stop", (HookFunction) clear);
|
|
| 124 |
clear (); |
|
| 117 |
hook_dissociate ("playback pause", (HookFunction) update);
|
|
| 118 |
hook_dissociate ("playback unpause", (HookFunction) update);
|
|
| 125 | 119 |
} |
| 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 | |
| ... | ... | |
| 61 | 81 |
gboolean plugin_init (void) |
| 62 | 82 |
{
|
| 63 | 83 |
AUDDBG("started!\n");
|
| 64 |
if(!osd_init()) {
|
|
| 84 |
aud_config_set_defaults ("notify", notify_defaults);
|
|
| 85 |
void* notif = osd_init(); |
|
| 86 |
if(!notif) {
|
|
| 65 | 87 |
AUDDBG("osd_init failed!\n");
|
| 66 | 88 |
return FALSE; |
| 67 | 89 |
} |
| 68 |
event_init(); |
|
| 90 |
event_init(notif);
|
|
| 69 | 91 | |
| 70 | 92 |
plugin_active = 1; |
| 93 |
AUDDBG("Juste après plugin_active\n");
|
|
| 94 |
|
|
| 71 | 95 |
return TRUE; |
| 72 | 96 |
} |
| 73 | 97 | |
| 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); |
|
