Project

General

Profile

osd.c.patch

Jean-Alexandre Angl├Ęs d'Auriac, November 22, 2012 12:26

View differences:

osd.c 2012-11-22 12:21:27.045430740 +0100
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;
50 67
}
51 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();}
109
}
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);