notifyactionsupport2.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 | |
| ... | ... | |
| 37 | 39 |
last_message = NULL; |
| 38 | 40 |
} |
| 39 | 41 | |
| 42 |
static void update_button (void * unused, void * useless) |
|
| 43 |
{
|
|
| 44 |
osd_refresh (); |
|
| 45 |
} |
|
| 46 | ||
| 40 | 47 |
static void reshow (void) |
| 41 | 48 |
{
|
| 42 | 49 |
if (! last_title || ! last_message) |
| ... | ... | |
| 46 | 53 |
if (pb) |
| 47 | 54 |
audgui_pixbuf_scale_within (& pb, 96); |
| 48 | 55 | |
| 49 |
osd_show (last_title, last_message, "audio-x-generic", pb);
|
|
| 56 |
osd_show (last_title, last_message, pb); |
|
| 50 | 57 | |
| 51 | 58 |
if (pb) |
| 52 | 59 |
g_object_unref (pb); |
| ... | ... | |
| 57 | 64 |
if (! aud_drct_get_playing () || ! aud_drct_get_ready ()) |
| 58 | 65 |
{
|
| 59 | 66 |
if (GPOINTER_TO_INT (explicit)) |
| 60 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL, NULL);
|
|
| 67 |
osd_show (_("Stopped"), _("Audacious is not playing."), NULL);
|
|
| 61 | 68 | |
| 62 | 69 |
return; |
| 63 | 70 |
} |
| ... | ... | |
| 107 | 114 |
hook_associate ("playback ready", (HookFunction) update, GINT_TO_POINTER (FALSE));
|
| 108 | 115 |
hook_associate ("playlist update", (HookFunction) update, GINT_TO_POINTER (FALSE));
|
| 109 | 116 |
hook_associate ("current art ready", (HookFunction) reshow, 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 |
} |
| ... | ... | |
| 117 | 128 |
hook_dissociate ("playback ready", (HookFunction) update);
|
| 118 | 129 |
hook_dissociate ("playlist update", (HookFunction) update);
|
| 119 | 130 |
hook_dissociate ("current art ready", (HookFunction) reshow);
|
| 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/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 |
.apply = toggleaction |
|
| 66 |
}; |
|
| 67 | ||
| 68 | ||
| 69 | ||
| 49 | 70 |
AUD_GENERAL_PLUGIN |
| 50 | 71 |
( |
| 51 | 72 |
.name = N_("Desktop Notifications"),
|
| 52 | 73 |
.domain = PACKAGE, |
| 53 | 74 |
.about_text = plugin_about, |
| 54 | 75 |
.init = plugin_init, |
| 76 |
.prefs = & notify_prefs, |
|
| 55 | 77 |
.cleanup = plugin_cleanup |
| 56 | 78 |
) |
| 57 | 79 | |
| ... | ... | |
| 60 | 82 |
gboolean plugin_init (void) |
| 61 | 83 |
{
|
| 62 | 84 |
AUDDBG("started!\n");
|
| 85 |
aud_config_set_defaults ("notify", notify_defaults);
|
|
| 63 | 86 |
if(!osd_init()) {
|
| 64 | 87 |
AUDDBG("osd_init failed!\n");
|
| 65 | 88 |
return FALSE; |
| ... | ... | |
| 67 | 90 |
event_init(); |
| 68 | 91 | |
| 69 | 92 |
plugin_active = 1; |
| 93 |
AUDDBG("Osd plugin initted\n");
|
|
| 70 | 94 |
return TRUE; |
| 71 | 95 |
} |
| 72 | 96 | |
| 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 | 29 |
static NotifyNotification * notification = NULL; |
| 30 |
static gboolean actions_available = FALSE; |
|
| 31 |
static gboolean resident_notification = FALSE; |
|
| 32 | ||
| 33 | ||
| 23 | 34 | |
| 24 | 35 |
bool_t osd_init() |
| 25 | 36 |
{
|
| 26 |
return notify_init ("Audacious");
|
|
| 37 |
if (notify_is_initted()) |
|
| 38 |
{
|
|
| 39 |
AUDDBG("Notify is already initted, that shouldn't happen\n");
|
|
| 40 |
return FALSE; |
|
| 41 |
} |
|
| 42 |
if (notify_init("Audacious"))
|
|
| 43 |
{
|
|
| 44 |
notification = notify_notification_new("Notification", NULL, NULL);
|
|
| 45 | ||
| 46 |
notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); |
|
| 47 |
notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("audacious"));
|
|
| 48 |
notify_notification_set_category (notification, "x-gnome.music"); |
|
| 49 | ||
| 50 |
GList *server_caps; |
|
| 51 |
server_caps = notify_get_server_caps (); |
|
| 52 | ||
| 53 |
if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0) && aud_get_bool ("notify", "actions"))
|
|
| 54 |
{
|
|
| 55 |
actions_available = TRUE; |
|
| 56 |
if (g_list_find_custom (server_caps, "action-icons", (GCompareFunc)g_strcmp0)) |
|
| 57 |
notify_notification_set_hint (notification, "action-icons", g_variant_new_boolean (TRUE)); |
|
| 58 |
if (g_list_find_custom (server_caps, "persistence", (GCompareFunc)g_strcmp0) ) |
|
| 59 |
{
|
|
| 60 |
AUDDBG("Notification server supports persistence\n");
|
|
| 61 |
resident_notification = TRUE; |
|
| 62 |
notify_notification_set_hint (notification, "resident", g_variant_new_boolean (TRUE)); |
|
| 63 |
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (FALSE)); |
|
| 64 |
} |
|
| 65 |
} |
|
| 66 |
else |
|
| 67 |
{
|
|
| 68 |
notify_notification_set_hint (notification, "resident", g_variant_new_boolean (FALSE)); |
|
| 69 |
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE)); |
|
| 70 |
} |
|
| 71 |
g_list_free_full(server_caps, g_free); |
|
| 72 |
return TRUE; |
|
| 73 |
} |
|
| 74 |
else |
|
| 75 |
return FALSE; |
|
| 27 | 76 |
} |
| 28 | 77 | |
| 29 | 78 |
void osd_uninit (void) |
| 30 | 79 |
{
|
| 31 | 80 |
if (notification) |
| 32 | 81 |
{
|
| 82 |
GError *error = NULL; |
|
| 83 |
if (notify_notification_close (notification, &error) == FALSE) |
|
| 84 |
AUDDBG("%s!\n", error->message);
|
|
| 85 |
if(error) |
|
| 86 |
g_error_free(error); |
|
| 33 | 87 |
g_object_unref (notification); |
| 34 | 88 |
notification = NULL; |
| 35 | 89 |
} |
| 36 | 90 | |
| 37 | 91 |
notify_uninit(); |
| 92 |
AUDDBG("Notify uninitted\n");
|
|
| 38 | 93 |
} |
| 39 | 94 | |
| 40 |
static void osd_closed_handler (void) |
|
| 95 | ||
| 96 |
void goprevious (NotifyNotification *notification, |
|
| 97 |
const char *action, |
|
| 98 |
gpointer user_data) |
|
| 41 | 99 |
{
|
| 42 |
if (notification) |
|
| 43 |
{
|
|
| 44 |
g_object_unref (notification); |
|
| 45 |
notification = NULL; |
|
| 46 |
} |
|
| 100 |
aud_drct_pl_prev(); |
|
| 47 | 101 |
} |
| 48 | 102 | |
| 49 |
void osd_show (const char * title, const char * _message, const char * icon, |
|
| 50 |
GdkPixbuf * pixbuf) |
|
| 103 |
void gonext (NotifyNotification *notification, |
|
| 104 |
const char *action, |
|
| 105 |
gpointer user_data) |
|
| 51 | 106 |
{
|
| 52 |
char * message = g_markup_escape_text (_message, -1); |
|
| 107 |
aud_drct_pl_next(); |
|
| 108 |
} |
|
| 53 | 109 | |
| 54 |
if (pixbuf) |
|
| 55 |
icon = NULL; |
|
| 110 |
void show_audacious (NotifyNotification *notification, |
|
| 111 |
const char *action, |
|
| 112 |
gpointer user_data) |
|
| 113 |
{
|
|
| 114 |
aud_interface_show(TRUE); |
|
| 115 |
} |
|
| 56 | 116 | |
| 57 |
if (notification) |
|
| 58 |
notify_notification_update (notification, title, message, icon); |
|
| 117 |
void playpause (NotifyNotification *notification, |
|
| 118 |
const char *action, |
|
| 119 |
gpointer user_data) |
|
| 120 |
{
|
|
| 121 |
if(aud_drct_get_playing()) |
|
| 122 |
{aud_drct_pause();}
|
|
| 59 | 123 |
else |
| 124 |
{aud_drct_play();}
|
|
| 125 |
} |
|
| 126 | ||
| 127 |
void osd_update_button(void){
|
|
| 128 |
if(actions_available){
|
|
| 129 |
gboolean paused = TRUE; |
|
| 130 |
if (aud_drct_get_playing()) {paused = aud_drct_get_paused();}
|
|
| 131 | ||
| 132 |
notify_notification_clear_actions (notification); |
|
| 133 | ||
| 134 |
notify_notification_add_action (notification, |
|
| 135 |
"media-skip-backward", |
|
| 136 |
N_("Previous"),
|
|
| 137 |
NOTIFY_ACTION_CALLBACK(goprevious), |
|
| 138 |
NULL, |
|
| 139 |
NULL); |
|
| 140 | ||
| 141 |
notify_notification_add_action (notification, |
|
| 142 |
paused ? "media-playback-start" : "media-playback-pause", |
|
| 143 |
paused ? N_("Play") : N_("Pause"),
|
|
| 144 |
NOTIFY_ACTION_CALLBACK(playpause), |
|
| 145 |
NULL, |
|
| 146 |
NULL); |
|
| 147 | ||
| 148 |
notify_notification_add_action (notification, |
|
| 149 |
"media-skip-forward", |
|
| 150 |
N_("Next"),
|
|
| 151 |
NOTIFY_ACTION_CALLBACK(gonext), |
|
| 152 |
NULL, |
|
| 153 |
NULL); |
|
| 154 | ||
| 155 |
notify_notification_add_action (notification, |
|
| 156 |
"default", |
|
| 157 |
N_("Show Audacious"),
|
|
| 158 |
NOTIFY_ACTION_CALLBACK(show_audacious), |
|
| 159 |
NULL, |
|
| 160 |
NULL); |
|
| 161 |
} |
|
| 162 |
} |
|
| 163 | ||
| 164 |
void osd_refresh(void){
|
|
| 165 |
osd_update_button(); |
|
| 166 |
if(resident_notification) |
|
| 60 | 167 |
{
|
| 61 |
notification = notify_notification_new (title, message, icon); |
|
| 62 |
g_signal_connect (notification, "closed", (GCallback) osd_closed_handler, NULL); |
|
| 168 |
GError *error = NULL; |
|
| 169 |
if(!notify_notification_show(notification, &error)) |
|
| 170 |
AUDDBG("Error “%s” when trying to send notification\n", error->message);
|
|
| 171 |
if(error) |
|
| 172 |
g_error_free(error); |
|
| 63 | 173 |
} |
| 174 |
} |
|
| 175 | ||
| 176 |
void osd_show (const gchar * title, const gchar * _message, GdkPixbuf *cover) |
|
| 177 |
{
|
|
| 178 |
gchar * message = g_markup_escape_text (_message, -1); |
|
| 179 |
GError *error = NULL; |
|
| 64 | 180 | |
| 65 |
if (pixbuf)
|
|
| 66 |
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
|
|
| 181 |
if(cover)
|
|
| 182 |
notify_notification_set_image_from_pixbuf(notification, cover);
|
|
| 67 | 183 | |
| 68 |
notify_notification_show (notification, NULL); |
|
| 184 |
osd_update_button(); |
|
| 185 | ||
| 186 |
if(!notify_notification_update(notification, title, message, "audacious")) |
|
| 187 |
AUDDBG("Could not update osd!\n");
|
|
| 188 | ||
| 189 |
if(!notify_notification_show(notification, &error)) |
|
| 190 |
AUDDBG("Error “%s” when trying to send notification\n", error->message);
|
|
| 191 |
if(error) |
|
| 192 |
g_error_free(error); |
|
| 69 | 193 | |
| 70 | 194 |
g_free (message); |
| 71 | 195 |
} |
| 196 | ||
| 197 |
void toggleaction(){
|
|
| 198 |
GList *server_caps; |
|
| 199 |
server_caps = notify_get_server_caps (); |
|
| 200 | ||
| 201 |
if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0) && aud_get_bool ("notify", "actions"))
|
|
| 202 |
{
|
|
| 203 |
actions_available = TRUE; |
|
| 204 |
if (g_list_find_custom (server_caps, "action-icons", (GCompareFunc)g_strcmp0)) |
|
| 205 |
notify_notification_set_hint (notification, "action-icons", g_variant_new_boolean (TRUE)); |
|
| 206 |
if (g_list_find_custom (server_caps, "persistence", (GCompareFunc)g_strcmp0) ) |
|
| 207 |
{
|
|
| 208 |
AUDDBG("Notification server supports persistence\n");
|
|
| 209 |
resident_notification = TRUE; |
|
| 210 |
notify_notification_set_hint (notification, "resident", g_variant_new_boolean (TRUE)); |
|
| 211 |
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (FALSE)); |
|
| 212 |
osd_update_button(); |
|
| 213 |
notify_notification_show(notification, NULL); |
|
| 214 |
} |
|
| 215 |
} |
|
| 216 |
else |
|
| 217 |
{
|
|
| 218 |
actions_available = FALSE; |
|
| 219 |
resident_notification = FALSE; |
|
| 220 |
notify_notification_clear_actions (notification); |
|
| 221 |
notify_notification_set_hint (notification, "resident", g_variant_new_boolean (FALSE)); |
|
| 222 |
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE)); |
|
| 223 |
notify_notification_close (notification, NULL); |
|
| 224 |
} |
|
| 225 |
} |
|
| 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 | 20 |
bool_t osd_init (void); |
| 24 | 21 |
void osd_uninit (void); |
| 25 |
void osd_show (const char * title, const char * message, const char * icon, GdkPixbuf * pixbuf); |
|
| 22 |
void osd_show (const gchar *title, const gchar *message, GdkPixbuf *pixbuf); |
|
| 23 |
void osd_refresh (void); |
|
| 24 |
void toggleaction (void); |
|
