Project

General

Profile

event.patch

Jean-Alexandre Anglès d'Auriac, November 10, 2012 00:45

View differences:

notify2/event.c 2012-11-10 00:22:15.841171395 +0100
21 21
#include <glib.h>
22 22
#include <string.h>
23 23

  
24
#include <audacious/drct.h>
25 24
#include <audacious/i18n.h>
26
#include <audacious/playlist.h>
27 25
#include <libaudcore/hook.h>
28
#include <libaudgui/libaudgui-gtk.h>
29 26

  
30 27
#include "config.h"
31 28
#include "event.h"
32 29
#include "osd.h"
33 30

  
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 31
static void update (void * unused, void * explicit)
45 32
{
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
    gint list = aud_playlist_get_playing ();
55
    gint entry = aud_playlist_get_position (list);
56

  
57
    gchar * title, * artist, * album;
58
    aud_playlist_entry_describe (list, entry, & title, & artist, & album, FALSE);
59

  
60
    gchar * message;
61
    if (artist)
62
    {
63
        if (album)
64
            message = g_strdup_printf ("%s\n%s", artist, album);
65
        else
66
            message = g_strdup (artist);
67
    }
68
    else if (album)
69
        message = g_strdup (album);
70
    else
71
        message = g_strdup ("");
72

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

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

  
86
    if (pb)
87
        g_object_unref (pb);
88

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

  
93
FREE:
94
    str_unref (title);
95
    str_unref (artist);
96
    str_unref (album);
33
    osd_show ();
97 34
}
98 35

  
99 36
void event_init (void)
......
102 39
    hook_associate ("aosd toggle", (HookFunction) update, GINT_TO_POINTER (TRUE));
103 40
    hook_associate ("playback ready", (HookFunction) update, GINT_TO_POINTER (FALSE));
104 41
    hook_associate ("playlist update", (HookFunction) update, GINT_TO_POINTER (FALSE));
105
    hook_associate ("playback stop", (HookFunction) clear, NULL);
42
    hook_associate ("playback pause", (HookFunction) update, GINT_TO_POINTER (TRUE));
43
    hook_associate ("playback unpause", (HookFunction) update, GINT_TO_POINTER (TRUE));
106 44
}
107 45

  
108 46
void event_uninit (void)
......
110 48
    hook_dissociate ("aosd toggle", (HookFunction) update);
111 49
    hook_dissociate ("playback ready", (HookFunction) update);
112 50
    hook_dissociate ("playlist update", (HookFunction) update);
113
    hook_dissociate ("playback stop", (HookFunction) clear);
114
    clear ();
115
}
51
    hook_dissociate ("playback pause", (HookFunction) update);
52
    hook_dissociate ("playback unpause", (HookFunction) update);
53
 }