Switch to unified view

a/src/mpdcli.cxx b/src/mpdcli.cxx
...
...
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
    : m_conn(0), m_ok(false), m_premutevolume(0), m_cachedvolume(50),
35
    : m_conn(0), m_ok(false), m_premutevolume(0), m_cachedvolume(50),
36
      m_host(host), m_port(port), m_password(pass)
36
      m_host(host), m_port(port), m_password(pass), m_lastinsertid(-1),
37
      m_lastinsertpos(-1), m_lastinsertqvers(-1)
37
{
38
{
38
    regcomp(&m_tpuexpr, "^[[:alpha:]]+://.+", REG_EXTENDED|REG_NOSUB);
39
    regcomp(&m_tpuexpr, "^[[:alpha:]]+://.+", REG_EXTENDED|REG_NOSUB);
39
    if (!openconn()) {
40
    if (!openconn()) {
40
        return;
41
        return;
41
    }
42
    }
...
...
500
{
501
{
501
    LOGDEB("MPDCli::insert at :" << pos << " uri " << uri << endl);
502
    LOGDEB("MPDCli::insert at :" << pos << " uri " << uri << endl);
502
    if (!ok())
503
    if (!ok())
503
        return -1;
504
        return -1;
504
505
505
    if (!updStatus())
506
    RETRY_CMD((m_lastinsertid = 
506
        return -1;
507
508
    int id;
509
    RETRY_CMD((id=mpd_run_add_id_to(M_CONN, uri.c_str(), (unsigned)pos))!=-1);
507
               mpd_run_add_id_to(M_CONN, uri.c_str(), (unsigned)pos)) != -1);
510
    
508
    
511
    if (m_have_addtagid)
509
    if (m_have_addtagid)
512
        send_tag_data(id, meta);
510
        send_tag_data(m_lastinsertid, meta);
513
511
514
    return id;
512
    m_lastinsertpos = pos;
513
    updStatus();
514
    m_lastinsertqvers = m_stat.qvers;
515
    return m_lastinsertid;
515
}
516
}
516
517
517
int MPDCli::insertAfterId(const string& uri, int id, const UpSong& meta)
518
int MPDCli::insertAfterId(const string& uri, int id, const UpSong& meta)
518
{
519
{
519
    LOGDEB("MPDCli::insertAfterId: id " << id << " uri " << uri << endl);
520
    LOGDEB("MPDCli::insertAfterId: id " << id << " uri " << uri << endl);
520
    if (!ok())
521
    if (!ok())
521
        return -1;
522
523
    if (!updStatus())
524
        return -1;
522
        return -1;
525
523
526
    // id == 0 means insert at start
524
    // id == 0 means insert at start
527
    if (id == 0) {
525
    if (id == 0) {
528
        return insert(uri, 0, meta);
526
        return insert(uri, 0, meta);
529
    }
527
    }
528
    updStatus();
530
529
530
    int newpos = 0;
531
    if (m_lastinsertid == id && m_lastinsertpos >= 0 &&
532
        m_lastinsertqvers == m_stat.qvers) {
533
        newpos = m_lastinsertpos + 1;
534
    } else {
535
        // Translate input id to insert position
531
    vector<mpd_song*> songs;
536
        vector<mpd_song*> songs;
532
    if (!getQueueSongs(songs)) {
537
        if (!getQueueSongs(songs)) {
533
        return false;
538
            return false;
534
    }
535
    int newid = -1;
536
    for (unsigned int pos = 0; pos < songs.size(); pos++) {
537
        unsigned int qid = mpd_song_get_id(songs[pos]);
538
        if (qid == (unsigned int)id || pos == songs.size() -1) {
539
            newid = insert(uri, pos+1, meta);
540
            break;
541
        }
539
        }
540
        for (unsigned int pos = 0; pos < songs.size(); pos++) {
541
            unsigned int qid = mpd_song_get_id(songs[pos]);
542
            if (qid == (unsigned int)id || pos == songs.size() -1) {
543
                newpos = pos + 1;
544
                break;
545
            }
542
    }
546
        }
543
    freeSongs(songs);
547
        freeSongs(songs);
544
    return newid;
548
    }
549
    return insert(uri, newpos, meta);
545
}
550
}
546
551
547
bool MPDCli::clearQueue()
552
bool MPDCli::clearQueue()
548
{
553
{
549
    LOGDEB("MPDCli::clearQueue " << endl);
554
    LOGDEB("MPDCli::clearQueue " << endl);
...
...
601
606
602
    struct mpd_song *song;
607
    struct mpd_song *song;
603
    while ((song = mpd_recv_song(M_CONN)) != NULL) {
608
    while ((song = mpd_recv_song(M_CONN)) != NULL) {
604
        songs.push_back(song);
609
        songs.push_back(song);
605
    }
610
    }
606
611
    
607
    if (!mpd_response_finish(M_CONN)) {
612
    if (!mpd_response_finish(M_CONN)) {
608
        LOGERR("MPDCli::getQueueSongs: mpd_list_queue_meta failed"<< endl);
613
        LOGERR("MPDCli::getQueueSongs: mpd_list_queue_meta failed"<< endl);
609
        return false;
614
        return false;
610
    }
615
    }
616
    LOGDEB("MPDCli::getQueueSongs: " << songs.size() << " songs " << endl);
611
    return true;
617
    return true;
612
}
618
}
613
619
614
void MPDCli::freeSongs(vector<mpd_song*>& songs)
620
void MPDCli::freeSongs(vector<mpd_song*>& songs)
615
{
621
{