Switch to unified view

a b/upadapt/ohrdadapt.h
1
/* Copyright (C) 2015 J.F.Dockes
2
 *   This program is free software; you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation; either version 2 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
17
18
#ifndef _OHRDADAPT_H_INCLUDED_
19
#define _OHRDADAPT_H_INCLUDED_
20
21
// Adapter for the ohradio service interface object, OHRadioQO. This
22
// interfaces to the libupnpp thready interface, and translates to Qt
23
// signals, using still UPNPish data. We translate the data to upplay
24
// formats.
25
#include <string>
26
#include <iostream>
27
using namespace std;
28
29
#include <QDebug>
30
#include <QApplication>
31
32
#include "HelperStructs/MetaData.h"
33
#include "HelperStructs/globals.h"
34
35
#include "upqo/ohradio_qo.h"
36
#include "upadapt/upputils.h"
37
38
using namespace UPnPP;
39
40
class OHRadio : public OHRadioQO {
41
Q_OBJECT
42
43
public:
44
    OHRadio(UPnPClient::OHRDH ohpl, QObject *parent = 0)
45
        : OHRadioQO(ohpl, parent) {
46
        connect(this, SIGNAL(trackArrayChanged()),
47
                this, SLOT(translateMetaData()));
48
        connect(this, SIGNAL(tpStateChanged(int)), 
49
                this, SLOT(playerState(int)));
50
    }
51
52
private slots:
53
54
    void playerState(int ps) {
55
        std::string s;
56
        AudioState as = AUDIO_UNKNOWN;
57
        switch (ps) {
58
        case UPnPClient::OHPlaylist::TPS_Unknown:
59
        case UPnPClient::OHPlaylist::TPS_Buffering:
60
        default:
61
            s = "Unknown";
62
            break;
63
        case UPnPClient::OHPlaylist::TPS_Paused:
64
            as = AUDIO_PAUSED;
65
            s = "Paused";
66
            break;
67
        case UPnPClient::OHPlaylist::TPS_Playing:
68
            as = AUDIO_PLAYING;
69
            s = "Playing";
70
            break;
71
        case UPnPClient::OHPlaylist::TPS_Stopped:
72
            as = AUDIO_STOPPED;
73
            s = "Stopped";
74
            break;
75
        }
76
        if (as != AUDIO_UNKNOWN) {
77
            emit audioStateChanged(as, s.c_str());
78
        }
79
    }
80
81
    void translateMetaData() {
82
        //qDebug() << "OHPlayer::translateMetaData()";
83
        MetaDataList mdv;
84
        for (std::vector<int>::iterator idit = m_idsv.begin(); 
85
             idit != m_idsv.end(); idit++) {
86
            STD_UNORDERED_MAP<int, UPnPClient::UPnPDirObject>::iterator poolit 
87
                = m_metapool.find(*idit);
88
            if (poolit == m_metapool.end()) {
89
                qDebug() << "OHPlayer::translateMetaData: "
90
                    "no data found for " << *idit << "!!!";
91
                continue;
92
            }
93
            UPnPClient::UPnPDirObject& ude = poolit->second;
94
            if (ude.m_resources.empty()) {
95
                LOGDEB("translateMetadata: no resources for:"  <<
96
                       ude.dump() << endl);
97
                //continue; does not seem to be an issue in fact. Only used
98
                // for avt. Funny, this is the exact same problem which bubble
99
                // had initially with ohpl tracks added through mpd (no uri)...
100
            }
101
            MetaData md;
102
            udirentToMetadata(&ude, &md);
103
            md.id = *idit;
104
            md.pl_playing = md.id == m_curid;
105
            
106
            mdv.push_back(md);
107
        }
108
        emit metadataArrayChanged(mdv);
109
    }
110
111
112
signals:
113
    void audioStateChanged(int as, const char *);
114
    void metadataArrayChanged(const MetaDataList& mdv);
115
};
116
117
118
#endif /* _OHRDADAPT_H_INCLUDED_ */