summaryrefslogtreecommitdiffstats
path: root/src/kmplayer_xspf.cpp
blob: c7fbce35b53f45437dce15df944d1ec0472b3e6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
 * Copyright (C) 2006 by Koos Vriezen <[email protected]>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 **/

#include <config.h>
#include <kdebug.h>
#include <kurl.h>

#include "kmplayer_xspf.h"

using namespace KMPlayer;


KDE_NO_EXPORT NodePtr XSPF::Playlist::childFromTag (const QString & tag) {
    const char * name = tag.latin1 ();
    if (!strcasecmp (name, "tracklist"))
        return new Tracklist (m_doc);
    else if (!strcasecmp (name, "creator"))
        return new DarkNode (m_doc, name, id_node_creator);
    else if (!strcasecmp (name, "title"))
        return new DarkNode (m_doc, name, id_node_title);
    else if (!strcasecmp (name, "annotation"))
        return new DarkNode (m_doc, name, id_node_annotation);
    else if (!strcasecmp (name, "info"))
        return new DarkNode (m_doc, name, id_node_info);
    else if (!strcasecmp (name, "location"))
        return new DarkNode (m_doc, name, id_node_location);
    else if (!strcasecmp (name, "identifier"))
        return new DarkNode (m_doc, name, id_node_identifier);
    else if (!strcasecmp (name, "image"))
        return new DarkNode (m_doc, name, id_node_image);
    else if (!strcasecmp (name, "date"))
        return new DarkNode (m_doc, name, id_node_date);
    else if (!strcasecmp (name, "license"))
        return new DarkNode (m_doc, name, id_node_license);
    else if (!strcasecmp (name, "attribution"))
        return new DarkNode (m_doc, name, id_node_attribution);
    else if (!strcasecmp (name, "link"))
        return new DarkNode (m_doc, name, id_node_link);
    else if (!strcasecmp (name, "meta"))
        return new DarkNode (m_doc, name, id_node_meta);
    else if (!strcasecmp (name, "extension"))
        return new DarkNode (m_doc, name, id_node_extension);
    return 0L;
}

KDE_NO_EXPORT void XSPF::Playlist::closed () {
    for (NodePtr e = firstChild (); e; e = e->nextSibling ()) {
        if (e->id == id_node_title)
            pretty_name = e->innerText ().simplifyWhiteSpace ();
        else if (e->id == id_node_location)
            src = e->innerText ().stripWhiteSpace ();
    }
}

//-----------------------------------------------------------------------------

KDE_NO_EXPORT NodePtr XSPF::Tracklist::childFromTag (const QString & tag) {
    const char * name = tag.latin1 ();
    if (!strcasecmp (name, "track"))
        return new XSPF::Track (m_doc);
    return 0L;
}

//-----------------------------------------------------------------------------

KDE_NO_EXPORT NodePtr XSPF::Track::childFromTag (const QString & tag) {
    const char * name = tag.latin1 ();
    if (!strcasecmp (name, "location"))
        return new Location (m_doc);
    else if (!strcasecmp (name, "creator"))
        return new DarkNode (m_doc, name, id_node_creator);
    else if (!strcasecmp (name, "title"))
        return new DarkNode (m_doc, name, id_node_title);
    else if (!strcasecmp (name, "annotation"))
        return new DarkNode (m_doc, name, id_node_annotation);
    else if (!strcasecmp (name, "info"))
        return new DarkNode (m_doc, name, id_node_info);
    else if (!strcasecmp (name, "identifier"))
        return new DarkNode (m_doc, name, id_node_identifier);
    else if (!strcasecmp (name, "album"))
        return new DarkNode (m_doc, name, id_node_album);
    else if (!strcasecmp (name, "image"))
        return new DarkNode (m_doc, name, id_node_image);
    else if (!strcasecmp (name, "trackNum"))
        return new DarkNode (m_doc, name, id_node_tracknum);
    else if (!strcasecmp (name, "duration"))
        return new DarkNode (m_doc, name, id_node_duration);
    else if (!strcasecmp (name, "link"))
        return new DarkNode (m_doc, name, id_node_link);
    else if (!strcasecmp (name, "meta"))
        return new DarkNode (m_doc, name, id_node_meta);
    else if (!strcasecmp (name, "extension"))
        return new DarkNode (m_doc, name, id_node_extension);
    return 0L;
}

KDE_NO_EXPORT void XSPF::Track::closed () {
    for (NodePtr e = firstChild (); e; e = e->nextSibling ()) {
        switch (e->id) {
            case id_node_title:
                pretty_name = e->innerText ();
                break;
            case id_node_location:
                location = e;
                src = e->mrl ()->src;
                break;
        }
    }
}

KDE_NO_EXPORT void XSPF::Track::activate () {
    for (NodePtr e = firstChild (); e; e = e->nextSibling ())
        if (e->id == id_node_annotation) {
            PlayListNotify * n = document ()->notify_listener;
            if (n)
                n->setInfoMessage (e->innerText ().stripWhiteSpace ());
            break;
        }
    Mrl::activate ();
}

KDE_NO_EXPORT Node::PlayType XSPF::Track::playType () {
    if (location)
        return location->playType ();
    return Mrl::playType ();
}

KDE_NO_EXPORT Mrl * XSPF::Track::linkNode () {
    if (location)
        return location->mrl ();
    return Mrl::linkNode ();
}

void XSPF::Location::closed () {
    src = innerText ().stripWhiteSpace ();
}