Switch to unified view

a/upadapt/upputils.cpp b/upadapt/upputils.cpp
...
...
13
 *   along with this program; if not, write to the
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
#include <string>
17
#include <string>
18
#include <set>
18
using namespace std;
19
using namespace std;
19
20
20
#include <QString>
21
#include <QString>
21
22
22
#include <libupnpp/upnpavutils.hxx>
23
#include <libupnpp/upnpavutils.hxx>
...
...
86
    mdp->is_disabled = false;
87
    mdp->is_disabled = false;
87
    mdp->didl = u8s2qs(dop->getdidl());
88
    mdp->didl = u8s2qs(dop->getdidl());
88
    mdp->albumArtURI = uf2qs(dop, "upnp:albumArtURI", false);
89
    mdp->albumArtURI = uf2qs(dop, "upnp:albumArtURI", false);
89
    return true;
90
    return true;
90
}
91
}
92
93
static std::set<string> specfields{"upnp:artist", "upnp:album", "upnp:genre",
94
        "upnp:albumArtURI", "upnp:originalTrackNumber"};
95
96
void metaDataToHtml(const MetaData* metap, QString& html)
97
{
98
    // We reparse from didl because we want to catch everything, even
99
    // what does not go into the MetaData fields. Also it may happen
100
    // that we have something in MetaData which does not come from the
101
    // Didl data
102
    
103
    UPnPDirContent dir;
104
    UPnPDirObject dirent;
105
    bool okdidl(true);
106
    // qDebug() << "metaDataToHtml: DIDL: " << metap->didl;
107
    if (metap->didl.isEmpty() || !dir.parse(qs2utf8s(metap->didl)) ||
108
        dir.m_items.empty()) {
109
        okdidl = false;
110
        //qDebug() << "metaDataToHtml: no DIDL data or no items";
111
    } else {
112
        //qDebug() << "metaDataToHtml: DIDL parsed ok";
113
        dirent = dir.m_items[0];
114
    }
115
    html = "";
116
    QString val;
117
118
    // Some fields are treated specially (see specfields list above),
119
    // because we want them in order.
120
    val = okdidl ? u8s2qs(dirent.m_title) : metap->title;
121
    if (!val.isEmpty()) html += "<p>" + val + "</p>";
122
123
    val = okdidl ? u8s2qs(dirent.f2s("upnp:artist", false)) : metap->artist;
124
    if (!val.isEmpty()) html += "<p>" + val + "</p>";
125
    
126
    val = okdidl ? u8s2qs(dirent.f2s("upnp:album", false)) : metap->album;
127
    if (!val.isEmpty()) html += "<p>" + val + "</p>";
128
129
    val = okdidl ? u8s2qs(dirent.f2s("upnp:genre", false)) :
130
        (metap->genres.size() ? metap->genres[0]: QString());
131
    if (!val.isEmpty()) html += "<b>Genre: </b>" + val + "<br/>";
132
    val = okdidl?u8s2qs(dirent.f2s("upnp:originalTrackNumber", false)) : "";
133
    if (!val.isEmpty()) html += "<b>Original track number:</b> " + val + "<br/>";
134
135
    if (okdidl) {
136
        // Dump all the rest
137
        for (auto it : dirent.m_props) {
138
            if (specfields.find(it.first) == specfields.end() &&
139
                !it.second.empty()) {
140
                html += "<b>" + u8s2qs(it.first) + "</b> : " +
141
                    u8s2qs(it.second) + "<br/>";
142
            }
143
        }
144
        val = u8s2qs(dirent.f2s("upnp:albumArtURI", false));
145
        if (!val.isEmpty()) html += "<b>Album Art URI</b>: " + val + "<br/>";
146
147
        for (auto resit : dirent.m_resources) {
148
            html += "<p><b>Resource URI:</b> " + u8s2qs(resit.m_uri) + "<br/>";
149
            html += "<blockquote>";
150
            for (auto it : resit.m_props) {
151
                html += "<b>" + u8s2qs(it.first) + "</b> : " +
152
                    u8s2qs(it.second) + "<br/>";
153
            }
154
            html += "</blockquote></p>";
155
        }
156
    }
157
    // qDebug() << "metaDataToHtml: html now: " << html;
158
}
159