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