Switch to unified view

a/src/mpdcli.cxx b/src/mpdcli.cxx
...
...
29
using namespace std;
29
using namespace std;
30
using namespace UPnPP;
30
using namespace UPnPP;
31
31
32
#define M_CONN ((struct mpd_connection *)m_conn)
32
#define M_CONN ((struct mpd_connection *)m_conn)
33
33
34
MPDCli::MPDCli(const string& host, int port, const string& pass)
34
MPDCli::MPDCli(const string& host, int port, const string& pass,
35
               const string& onstart, const string& onstop)
35
    : m_conn(0), m_ok(false), m_premutevolume(0), m_cachedvolume(50),
36
    : m_conn(0), m_ok(false), m_premutevolume(0), m_cachedvolume(50),
36
      m_host(host), m_port(port), m_password(pass), m_lastinsertid(-1),
37
      m_host(host), m_port(port), m_password(pass), m_onstart(onstart),
37
      m_lastinsertpos(-1), m_lastinsertqvers(-1)
38
      m_onstop(onstop), m_lastinsertid(-1), m_lastinsertpos(-1),
39
      m_lastinsertqvers(-1)
38
{
40
{
39
    regcomp(&m_tpuexpr, "^[[:alpha:]]+://.+", REG_EXTENDED|REG_NOSUB);
41
    regcomp(&m_tpuexpr, "^[[:alpha:]]+://.+", REG_EXTENDED|REG_NOSUB);
40
    if (!openconn()) {
42
    if (!openconn()) {
41
        return;
43
        return;
42
    }
44
    }
...
...
160
    m_stat.consume = mpd_status_get_consume(mpds);
162
    m_stat.consume = mpd_status_get_consume(mpds);
161
    m_stat.qlen = mpd_status_get_queue_length(mpds);
163
    m_stat.qlen = mpd_status_get_queue_length(mpds);
162
    m_stat.qvers = mpd_status_get_queue_version(mpds);
164
    m_stat.qvers = mpd_status_get_queue_version(mpds);
163
165
164
    switch (mpd_status_get_state(mpds)) {
166
    switch (mpd_status_get_state(mpds)) {
165
    case MPD_STATE_STOP: m_stat.state = MpdStatus::MPDS_STOP;break;
167
    case MPD_STATE_STOP:
168
        // Only execute onstop command if mpd was playing or paused
169
        if (m_stat.state != MpdStatus::MPDS_STOP && !m_onstop.empty()) {
170
            system(m_onstop.c_str());
171
        }
172
        m_stat.state = MpdStatus::MPDS_STOP;
173
        break;
166
    case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
174
    case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
167
    case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
175
    case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
168
    case MPD_STATE_UNKNOWN: 
176
    case MPD_STATE_UNKNOWN: 
169
    default:
177
    default:
170
        m_stat.state = MpdStatus::MPDS_UNK;
178
        m_stat.state = MpdStatus::MPDS_UNK;
...
...
382
bool MPDCli::play(int pos)
390
bool MPDCli::play(int pos)
383
{
391
{
384
    LOGDEB("MPDCli::play(pos=" << pos << ")" << endl);
392
    LOGDEB("MPDCli::play(pos=" << pos << ")" << endl);
385
    if (!ok())
393
    if (!ok())
386
        return false;
394
        return false;
395
    if (!m_onstart.empty()) {
396
        system(m_onstart.c_str());
397
    }
387
    if (pos >= 0) {
398
    if (pos >= 0) {
388
        RETRY_CMD(mpd_run_play_pos(M_CONN, (unsigned int)pos));
399
        RETRY_CMD(mpd_run_play_pos(M_CONN, (unsigned int)pos));
389
    } else {
400
    } else {
390
        RETRY_CMD(mpd_run_play(M_CONN));
401
        RETRY_CMD(mpd_run_play(M_CONN));
391
    }
402
    }
...
...
395
bool MPDCli::playId(int id)
406
bool MPDCli::playId(int id)
396
{
407
{
397
    LOGDEB("MPDCli::playId(id=" << id << ")" << endl);
408
    LOGDEB("MPDCli::playId(id=" << id << ")" << endl);
398
    if (!ok())
409
    if (!ok())
399
        return false;
410
        return false;
411
    if (!m_onstart.empty()) {
412
        system(m_onstart.c_str());
413
    }
400
    RETRY_CMD(mpd_run_play_id(M_CONN, (unsigned int)id));
414
    RETRY_CMD(mpd_run_play_id(M_CONN, (unsigned int)id));
401
    return updStatus();
415
    return updStatus();
402
}
416
}
403
bool MPDCli::stop()
417
bool MPDCli::stop()
404
{
418
{