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
|
/**
* Copyright (C) 2005 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 "kmplayer_rss.h"
using namespace KMPlayer;
KDE_NO_EXPORT NodePtr RSS::Rss::childFromTag (const QString & tag) {
if (!strcmp (tag.latin1 (), "channel"))
return new RSS::Channel (m_doc);
return 0L;
}
KDE_NO_EXPORT NodePtr RSS::Channel::childFromTag (const QString & tag) {
const char *ctag = tag.ascii ();
if (!strcmp (ctag, "item"))
return new RSS::Item (m_doc);
else if (!strcmp (ctag, "title"))
return new DarkNode (m_doc, tag, id_node_title);
return 0L;
}
KDE_NO_EXPORT void RSS::Channel::closed () {
for (NodePtr c = firstChild (); c; c = c->nextSibling ())
if (c->id == id_node_title) {
pretty_name = c->innerText ().simplifyWhiteSpace ();
break;
}
}
KDE_NO_EXPORT bool RSS::Channel::expose () const {
return !pretty_name.isEmpty () || //return false if no title and only one
previousSibling () || nextSibling ();
}
KDE_NO_EXPORT NodePtr RSS::Item::childFromTag (const QString & tag) {
const char *ctag = tag.ascii ();
if (!strcmp (ctag, "enclosure"))
return new RSS::Enclosure (m_doc);
else if (!strcmp (ctag, "title"))
return new DarkNode (m_doc, tag, id_node_title);
else if (!strcmp (ctag, "description"))
return new DarkNode (m_doc, tag, id_node_description);
return 0L;
}
KDE_NO_EXPORT void RSS::Item::closed () {
cached_play_type = play_type_none;
for (NodePtr c = firstChild (); c; c = c->nextSibling ()) {
switch (c->id) {
case id_node_title:
pretty_name = c->innerText ().simplifyWhiteSpace ();
break;
case id_node_enclosure:
enclosure = c;
src = c->mrl ()->src;
break;
case id_node_description:
cached_play_type = play_type_info;
break;
}
}
if (enclosure && !enclosure->mrl ()->src.isEmpty ())
cached_play_type = play_type_audio;
}
KDE_NO_EXPORT Mrl * RSS::Item::linkNode () {
if (enclosure)
return enclosure->mrl ();
return Mrl::linkNode ();
}
KDE_NO_EXPORT void RSS::Item::activate () {
PlayListNotify * n = document()->notify_listener;
if (n) {
for (NodePtr c = firstChild (); c; c = c->nextSibling ())
if (c->id == id_node_description) {
QString s = c->innerText ();
n->setInfoMessage (s);
if (!enclosure && !s.isEmpty ()) {
setState (state_activated);
begin ();
timer = document ()->setTimeout (this, 5000+s.length()*200);
return;
}
break;
}
}
Mrl::activate ();
}
KDE_NO_EXPORT void RSS::Item::deactivate () {
if (timer) {
document ()->cancelTimer (timer);
timer = 0L;
}
PlayListNotify * n = document()->notify_listener;
if (n)
n->setInfoMessage (QString ());
Mrl::deactivate ();
}
KDE_NO_EXPORT bool RSS::Item::handleEvent (EventPtr event) {
if (event->id () == event_timer) {
timer = 0L;
finish ();
}
return true;
}
KDE_NO_EXPORT void RSS::Enclosure::closed () {
src = getAttribute (StringPool::attr_url);
}
|