~ubuntu-branches/ubuntu/raring/mpdscribble/raring

« back to all changes in this revision

Viewing changes to src/lmc.c

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2011-08-05 14:14:04 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110805141404-g5ltaxabw4o1anq9
Tags: upstream-0.22
Import upstream version 0.22

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "file.h"
23
23
#include "compat.h"
24
24
 
 
25
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
 
26
#include <mpd/message.h>
 
27
#endif
 
28
 
25
29
#include <glib.h>
26
30
 
27
31
#include <assert.h>
37
41
static struct mpd_song *current_song;
38
42
static bool was_paused;
39
43
 
 
44
/**
 
45
 * Is the current song being "loved"?  That variable gets set when the
 
46
 * client-to-client command "love" is received.
 
47
 */
 
48
static bool love;
 
49
 
 
50
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
 
51
static bool subscribed;
 
52
#endif
 
53
 
40
54
static char *g_host;
41
55
static int g_port;
42
56
 
119
133
                  name);
120
134
        g_free(name);
121
135
 
 
136
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
 
137
        subscribed = mpd_run_subscribe(g_mpd, "mpdscribble");
 
138
        if (!subscribed && !mpd_connection_clear_error(g_mpd)) {
 
139
                lmc_failure();
 
140
                return true;
 
141
        }
 
142
#endif
 
143
 
122
144
        lmc_schedule_update();
123
145
 
124
146
        reconnect_source_id = 0;
276
298
        /* submit the previous song */
277
299
        if (prev != NULL &&
278
300
            (current_song == NULL ||
279
 
             mpd_song_get_id(prev) != mpd_song_get_id(current_song)))
280
 
                song_ended(prev);
 
301
             mpd_song_get_id(prev) != mpd_song_get_id(current_song))) {
 
302
                song_ended(prev, love);
 
303
                love = false;
 
304
        }
281
305
 
282
306
        if (current_song != NULL) {
283
307
                if (mpd_song_get_id(current_song) != last_id) {
319
343
                                                 lmc_update, NULL);
320
344
}
321
345
 
 
346
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
 
347
 
 
348
static bool
 
349
lmc_read_messages(void)
 
350
{
 
351
        assert(subscribed);
 
352
 
 
353
        if (!mpd_send_read_messages(g_mpd))
 
354
                return mpd_connection_clear_error(g_mpd);
 
355
 
 
356
        struct mpd_message *msg;
 
357
        while ((msg = mpd_recv_message(g_mpd)) != NULL) {
 
358
                const char *text = mpd_message_get_text(msg);
 
359
                if (strcmp(text, "love") == 0)
 
360
                        love = true;
 
361
                else
 
362
                        g_message("Unrecognized client-to-client message: '%s'",
 
363
                                  text);
 
364
 
 
365
                mpd_message_free(msg);
 
366
        }
 
367
 
 
368
        return mpd_response_finish(g_mpd);
 
369
}
 
370
 
 
371
#endif
 
372
 
322
373
static gboolean
323
374
lmc_idle(G_GNUC_UNUSED GIOChannel *source,
324
375
         G_GNUC_UNUSED GIOCondition condition,
356
407
                return false;
357
408
        }
358
409
 
 
410
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
 
411
        if (subscribed && (idle & MPD_IDLE_MESSAGE) != 0 &&
 
412
            !lmc_read_messages()) {
 
413
                lmc_failure();
 
414
                lmc_schedule_reconnect();
 
415
                return false;
 
416
        }
 
417
#endif
 
418
 
359
419
        if (idle & MPD_IDLE_PLAYER)
360
420
                /* there was a change: query MPD */
361
421
                lmc_schedule_update();
376
436
 
377
437
        idle_notified = false;
378
438
 
379
 
        if (!mpd_send_idle_mask(g_mpd, MPD_IDLE_PLAYER)) {
 
439
        enum mpd_idle mask = MPD_IDLE_PLAYER;
 
440
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
 
441
        if (subscribed)
 
442
                mask |= MPD_IDLE_MESSAGE;
 
443
#endif
 
444
 
 
445
        if (!mpd_send_idle_mask(g_mpd, mask)) {
380
446
                lmc_failure();
381
447
                lmc_schedule_reconnect();
382
448
                return;