Project

General

Profile

event.c.patch

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

View differences:

event.c 2012-11-18 01:28:56.592294021 +0100
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)
34
static void update (void * unused, void * notif)
37 35
{
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)
45
{
46
    if (! aud_drct_get_playing () || ! aud_drct_get_ready ())
47
    {
48
        if (GPOINTER_TO_INT (explicit))
49
            osd_show (_("Stopped"), _("Audacious is not playing."), NULL, NULL);
50

  
51
        return;
52
    }
53

  
54 36
    gint list = aud_playlist_get_playing ();
55 37
    gint entry = aud_playlist_get_position (list);
56 38

  
......
70 52
    else
71 53
        message = g_strdup ("");
72 54

  
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 55
    GdkPixbuf * pb = audgui_pixbuf_for_current ();
81 56
    if (pb)
82 57
        audgui_pixbuf_scale_within (& pb, 96);
83 58

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

  
86 61
    if (pb)
87 62
        g_object_unref (pb);
88 63

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

  
93
FREE:
64
    if(message)
65
        g_free(message);
94 66
    str_unref (title);
95 67
    str_unref (artist);
96 68
    str_unref (album);
97 69
}
98 70

  
99
void event_init (void)
71
static void update_explicit (void * unused, void * notif)
72
{
73
    if (! aud_drct_get_playing () || ! aud_drct_get_ready ())
74
        osd_show (_("Stopped"), _("Audacious is not playing."), "audio-x-generic", NULL, notif);
75
    else
76
        update(unused, notif);
77
    return;
78
}
79

  
80
void event_init (void* notif)
100 81
{
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);
82
    hook_associate ("aosd toggle", (HookFunction) update_explicit, notif);
83
    hook_associate ("playback ready", (HookFunction) update, notif);
84
    hook_associate ("playlist update", (HookFunction) update, notif);
85
    hook_associate ("playback pause", (HookFunction) update, notif);
86
    hook_associate ("playback unpause", (HookFunction) update, notif);
106 87
}
107 88

  
108 89
void event_uninit (void)
109 90
{
110
    hook_dissociate ("aosd toggle", (HookFunction) update);
91
    hook_dissociate ("aosd toggle", (HookFunction) update_explicit);
111 92
    hook_dissociate ("playback ready", (HookFunction) update);
112 93
    hook_dissociate ("playlist update", (HookFunction) update);
113
    hook_dissociate ("playback stop", (HookFunction) clear);
114
    clear ();
94
    hook_dissociate ("playback pause", (HookFunction) update);
95
    hook_dissociate ("playback unpause", (HookFunction) update);
115 96
}