Project

General

Profile

gitdiff.patch

Jean-Alexandre Anglès d'Auriac, November 24, 2012 18:01

View differences:

src/notify/event.c
31 31
#include "event.h"
32 32
#include "osd.h"
33 33

  
34
static gchar * last_title = NULL, * last_message = NULL;
35

  
36
static void clear (void)
37
{
38
    g_free (last_title);
39
    last_title = NULL;
40
    g_free (last_message);
41
    last_message = NULL;
42
}
43

  
44
static void update (void * unused, void * explicit)
34
static void update (void * unused, void * notif)
45 35
{
46 36
    if (! aud_drct_get_playing () || ! aud_drct_get_ready ())
47 37
    {
48
        if (GPOINTER_TO_INT (explicit))
38
        if (aud_get_bool ("notify", "actions"))
49 39
            osd_show (_("Stopped"), _("Audacious is not playing."), NULL, NULL);
50 40

  
51 41
        return;
......
70 60
    else
71 61
        message = g_strdup ("");
72 62

  
73
    if (! GPOINTER_TO_INT (explicit) && last_title && last_message && ! strcmp
74
     (title, last_title) && ! strcmp (message, last_message))
75
    {
76
        g_free (message);
77
        goto FREE;
78
    }
79

  
80 63
    GdkPixbuf * pb = audgui_pixbuf_for_current ();
81 64
    if (pb)
82 65
        audgui_pixbuf_scale_within (& pb, 96);
83 66

  
84
    osd_show (title, message, "audio-x-generic", pb);
67
    osd_show (title, message, "audio-x-generic", pb, notif);
85 68

  
86 69
    if (pb)
87 70
        g_object_unref (pb);
88 71

  
89
    clear ();
90
    last_title = g_strdup (title);
91
    last_message = message;
92

  
93
FREE:
72
    if(message)
73
        g_free(message);
94 74
    str_unref (title);
95 75
    str_unref (artist);
96 76
    str_unref (album);
97 77
}
98 78

  
99
void event_init (void)
79
static void update_explicit (void * unused, void * notif)
80
{
81
    if (! aud_drct_get_playing () || ! aud_drct_get_ready ())
82
        osd_show (_("Stopped"), _("Audacious is not playing."), "audio-x-generic", NULL, notif);
83
    else
84
        update(unused, notif);
85
    return;
86
}
87

  
88
void event_init (void* notif)
100 89
{
101
    update (NULL, GINT_TO_POINTER (FALSE));
102
    hook_associate ("aosd toggle", (HookFunction) update, GINT_TO_POINTER (TRUE));
103
    hook_associate ("playback ready", (HookFunction) update, GINT_TO_POINTER (FALSE));
104
    hook_associate ("playlist update", (HookFunction) update, GINT_TO_POINTER (FALSE));
105
    hook_associate ("playback stop", (HookFunction) clear, NULL);
90
    hook_associate ("aosd toggle", (HookFunction) update_explicit, notif);
91
    hook_associate ("playback ready", (HookFunction) update, notif);
92
    hook_associate ("playlist update", (HookFunction) update, notif);
93
    hook_associate ("playback pause", (HookFunction) update, notif);
94
    hook_associate ("playback unpause", (HookFunction) update, notif);
106 95
}
107 96

  
108 97
void event_uninit (void)
109 98
{
110
    hook_dissociate ("aosd toggle", (HookFunction) update);
99
    hook_dissociate ("aosd toggle", (HookFunction) update_explicit);
111 100
    hook_dissociate ("playback ready", (HookFunction) update);
112 101
    hook_dissociate ("playlist update", (HookFunction) update);
113
    hook_dissociate ("playback stop", (HookFunction) clear);
114
    clear ();
102
    hook_dissociate ("playback pause", (HookFunction) update);
103
    hook_dissociate ("playback unpause", (HookFunction) update);
115 104
}
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
 "silent", "FALSE",
55
 NULL};
56

  
57

  
58
static const PreferencesWidget notify_widgets[] = {
59
 {WIDGET_CHK_BTN, N_("Activate controls inside of the notification"),
60
 .cfg_type = VALUE_BOOLEAN, .csect = "notify", .cname = "actions"},
61
 {WIDGET_CHK_BTN, N_("Silent mode (don't show the notification if activated"),
62
 .cfg_type = VALUE_BOOLEAN, .csect = "notify", .cname = "silent"},
63
};
64

  
65
static const PluginPreferences notify_prefs = {
66
 .widgets = notify_widgets,
67
 .n_widgets = G_N_ELEMENTS (notify_widgets)};
68

  
69

  
70

  
50 71
AUD_GENERAL_PLUGIN
51 72
(
52 73
    .name = N_("Desktop Notifications"),
53 74
    .domain = PACKAGE,
54 75
    .about_text = plugin_about,
55 76
    .init = plugin_init,
77
    .prefs = & notify_prefs,
56 78
    .cleanup = plugin_cleanup
57 79
)
58 80

  
......
61 83
gboolean plugin_init (void)
62 84
{
63 85
    AUDDBG("started!\n");
64
    if(!osd_init()) {
86
    aud_config_set_defaults ("notify", notify_defaults);
87
    void* notif = osd_init();
88
    if(!notif) {
65 89
        AUDDBG("osd_init failed!\n");
66 90
        return FALSE;
67 91
    }
68
    event_init();
92
    event_init(notif);
69 93

  
70 94
    plugin_active = 1;
71 95
    return TRUE;
src/notify/osd.c
18 18
 */
19 19

  
20 20
#include <glib.h>
21
#include <libaudcore/hook.h>
21 22
#include <audacious/debug.h>
23
#include <audacious/i18n.h>
24
#include <audacious/drct.h>
25
#include <audacious/misc.h>
22 26
#include <libnotify/notify.h>
23

  
24 27
#include "osd.h"
25 28

  
26
NotifyNotification *notification = NULL;
27

  
28
gboolean osd_init() {
29
    notification = NULL;
30
    return notify_init ("Audacious");
31
}
32

  
33
void osd_uninit (void)
29
static void clean (void * unused, void * notif)
34 30
{
31
    NotifyNotification *notification = (NotifyNotification *) notif;
35 32
    if (notification)
36 33
    {
34
        GError *error = NULL;
35
        if (notify_notification_close (notification, &error) == FALSE)
36
            AUDDBG("%s!\n", error->message);
37 37
        g_object_unref (notification);
38
        notification = NULL;
39 38
    }
40 39

  
41 40
    notify_uninit();
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
        return NULL;
46
    if (notify_init("Audacious"))
47
    {
48
        NotifyNotification *notif = notify_notification_new("Notification", NULL, NULL);
49

  
50
        hook_associate ("notify shutdown", (HookFunction) clean, notif);
51

  
52
        notify_notification_set_urgency (notif, NOTIFY_URGENCY_LOW);
53
        notify_notification_set_hint (notif, "desktop-entry", g_variant_new_string ("audacious"));
54

  
55
        GList *server_caps;
56
        server_caps = notify_get_server_caps ();
57
        if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0))
58
        {
59
            if (g_list_find_custom (server_caps, "action-icons", (GCompareFunc)g_strcmp0))
60
                notify_notification_set_hint (notif, "action-icons", g_variant_new_boolean (TRUE));
61
        }
62
        g_list_free_full(server_caps, g_free);
63
        return notif;
49 64
    }
65
    
66
    return NULL;
67
}
68

  
69
void osd_uninit (void)
70
{
71
    hook_call("notify shutdown", NULL);
72
    hook_dissociate ("notify shutdown", (HookFunction) clean);
73
}
74

  
75

  
76
static void
77
goprevious (NotifyNotification *notification,
78
            const char *action,
79
            gpointer user_data)
80
{
81
    aud_drct_pl_prev();
82
}
83

  
84
static void
85
gonext (NotifyNotification *notification,
86
        const char *action,
87
        gpointer user_data)
88
{
89
    aud_drct_pl_next();
90
}
91

  
92
static void
93
show_audacious (NotifyNotification *notification,
94
        const char *action,
95
        gpointer user_data)
96
{
97
    aud_interface_show(TRUE);
98
}
99

  
100
static void
101
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

  
111

  
52 112
void osd_show (const gchar * title, const gchar * _message, const gchar * icon,
53
 GdkPixbuf * pb)
113
 GdkPixbuf * pb, void *notif)
54 114
{
115
    NotifyNotification *notification = (NotifyNotification *) notif;
55 116
    gchar * message = g_markup_escape_text (_message, -1);
56 117
    GError *error = NULL;
57 118

  
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);
119
    if(notify_notification_update(notification, title2, message, pb == NULL ? icon : NULL)) {
120
        AUDDBG("Osd updated!\n");
121
     } else {
122
         AUDDBG("Could not update osd!\n");
123
    }
124

  
125

  
126
    GList *server_caps;
127
    server_caps = notify_get_server_caps ();
128
    if (g_list_find_custom (server_caps, "actions", (GCompareFunc)g_strcmp0))
129
    {
130
        gboolean playing = FALSE;
131
        if (aud_drct_get_playing()) {playing = !aud_drct_get_paused();}
132

  
133
        notify_notification_clear_actions (notification);
134

  
135
        if(aud_get_bool ("notify", "actions")){
136
            notify_notification_add_action (notification,
137
                        "media-skip-backward",
138
                        N_("Previous"),
139
                        (NotifyActionCallback) goprevious,
140
                        NULL,
141
                        NULL);
142

  
143
            notify_notification_add_action (notification,
144
                            playing ? "media-playback-pause" : "media-playback-start",
145
                            playing ? N_("Pause") : N_("Play"),
146
                            (NotifyActionCallback) playpause,
147
                            NULL,
148
                            NULL);
149

  
150
            notify_notification_add_action (notification,
151
                        "media-skip-forward",
152
                        N_("Next"),
153
                        (NotifyActionCallback) gonext,
154
                        NULL,
155
                        NULL);
156

  
157
            notify_notification_add_action (notification,
158
                        "default",
159
                        N_("Afficher Audacious"),
160
                        (NotifyActionCallback) show_audacious,
161
                        NULL,
162
                        NULL);
163
            notify_notification_set_timeout(notification, 1);
67 164
        }
68 165
    }
69 166

  
70
    if(pb != NULL)
71
        notify_notification_set_icon_from_pixbuf(notification, pb);
167
    if(aud_get_bool ("notify", "silent"))
168
        notify_notification_set_hint (notif, "transient", g_variant_new_boolean (TRUE));
169
    else
170
        notify_notification_set_hint (notif, "transient", g_variant_new_boolean (FALSE));
171

  
172
    if (g_list_find_custom (server_caps, "persistence", (GCompareFunc)g_strcmp0))
173
        {
174
            AUDDBG("Notification server supports persistence\n");
175
            if (aud_get_bool ("notify", "actions"))
176
                notify_notification_set_hint (notif, "resident", g_variant_new_boolean (TRUE));
177
            else
178
                notify_notification_set_hint (notif, "resident", g_variant_new_boolean (FALSE));
179
        }
180

  
181
    g_list_free_full(server_caps, g_free);
182

  
183

  
184
/*    if(pb != NULL)*/
185
/*    {*/
186
/*        notify_notification_set_icon_from_pixbuf(notification, pb);*/
187
/*        notify_notification_set_image_from_pixbuf(notification, pb);*/
188
/*    }*/
189

  
190
/*    notify_notification_set_hint (notification,*/
191
/*                      "image_path",*/
192
/*                      g_variant_new_string ("/home/oxayotl/.cache/rhythmbox/album-art/00000065"));*/
193

  
72 194

  
73 195
    if(!notify_notification_show(notification, &error))
74 196
        AUDDBG("%s!\n", error->message);
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 *icon, GdkPixbuf *pb, void *notification);