1 /**
2 * Copyright (C) 2005 by Koos Vriezen <koos.vriezen@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 **/
18
19 #include "config-kmplayer.h"
20 #include <kdebug.h>
21 #include "kmplayer_rss.h"
22 #include "kmplayer_atom.h"
23
24 using namespace KMPlayer;
25
childFromTag(const QString & tag)26 KDE_NO_EXPORT Node *RSS::Rss::childFromTag (const QString & tag) {
27 if (!strcmp (tag.toLatin1 ().constData (), "channel"))
28 return new RSS::Channel (m_doc);
29 return 0L;
30 }
31
role(RoleType msg,void * content)32 void *RSS::Rss::role (RoleType msg, void *content)
33 {
34 if (RolePlaylist == msg)
35 return NULL;
36 return Element::role (msg, content);
37 }
38
childFromTag(const QString & tag)39 KDE_NO_EXPORT Node *RSS::Channel::childFromTag (const QString & tag) {
40 QByteArray ba = tag.toLatin1 ();
41 const char *ctag = ba.constData ();
42 if (!strcmp (ctag, "item"))
43 return new RSS::Item (m_doc);
44 else if (!strcmp (ctag, "title"))
45 return new DarkNode (m_doc, ctag, id_node_title);
46 else if (!strncmp (ctag, "itunes", 6) ||
47 !strncmp (ctag, "media", 5))
48 return new DarkNode (m_doc, ctag, id_node_ignored);
49 return 0L;
50 }
51
closed()52 KDE_NO_EXPORT void RSS::Channel::closed () {
53 for (Node *c = firstChild (); c; c = c->nextSibling ())
54 if (c->id == id_node_title) {
55 title = c->innerText ().simplified ();
56 break;
57 }
58 Element::closed ();
59 }
60
role(RoleType msg,void * content)61 void *RSS::Channel::role (RoleType msg, void *content)
62 {
63 if (RolePlaylist == msg)
64 return !title.isEmpty () || //return false if no title and only one
65 previousSibling () || nextSibling () ? (PlaylistRole *) this : NULL;
66 return Element::role (msg, content);
67 }
68
childFromTag(const QString & tag)69 KDE_NO_EXPORT Node *RSS::Item::childFromTag (const QString & tag) {
70 QByteArray ba = tag.toLatin1 ();
71 const char *ctag = ba.constData ();
72 if (!strcmp (ctag, "enclosure"))
73 return new RSS::Enclosure (m_doc);
74 else if (!strcmp (ctag, "title"))
75 return new DarkNode (m_doc, ctag, id_node_title);
76 else if (!strcmp (ctag, "description"))
77 return new DarkNode (m_doc, ctag, id_node_description);
78 else if (!strcmp (ctag, "category"))
79 return new DarkNode (m_doc, ctag, id_node_category);
80 else if (!strcmp (ctag, "media:group"))
81 return new ATOM::MediaGroup (m_doc);
82 else if (!strcmp (ctag, "media:thumbnail"))
83 return new DarkNode (m_doc, ctag, id_node_thumbnail);
84 else if (!strncmp (ctag, "itunes", 6) ||
85 !strncmp (ctag, "feedburner", 10) ||
86 !strcmp (ctag, "link") ||
87 !strcmp (ctag, "pubDate") ||
88 !strcmp (ctag, "guid") ||
89 !strncmp (ctag, "media", 5))
90 return new DarkNode (m_doc, ctag, id_node_ignored);
91 return 0L;
92 }
93
closed()94 KDE_NO_EXPORT void RSS::Item::closed () {
95 if (!summary_added) {
96 ATOM::MediaGroup *group = NULL;
97 Enclosure *enclosure = NULL;
98 QString description;
99 QString thumbnail;
100 int width = 0, height = 0;
101 for (Node *c = firstChild (); c; c = c->nextSibling ()) {
102 switch (c->id) {
103 case id_node_title:
104 title = c->innerText ().simplified ();
105 break;
106 case id_node_enclosure:
107 enclosure = static_cast <Enclosure *> (c);
108 break;
109 case id_node_description:
110 description = c->innerText ();
111 break;
112 case ATOM::id_node_media_group:
113 group = static_cast <ATOM::MediaGroup *> (c);
114 break;
115 case id_node_thumbnail:
116 thumbnail = static_cast<Element*>(c)->getAttribute(Ids::attr_url);
117 width = static_cast<Element*>(c)->getAttribute(Ids::attr_width).toInt();
118 height = static_cast<Element*>(c)->getAttribute(Ids::attr_height).toInt();
119 break;
120 }
121 }
122 if (group)
123 group->addSummary (this, NULL, title, description, thumbnail, width, height);
124 if (enclosure) {
125 enclosure->setCaption (title);
126 enclosure->description = description;
127 }
128 summary_added = true;
129 }
130 Element::closed ();
131 }
132
activate()133 KDE_NO_EXPORT void RSS::Enclosure::activate () {
134 document ()->message (MsgInfoString, &description);
135 Mrl::activate ();
136 }
137
deactivate()138 KDE_NO_EXPORT void RSS::Enclosure::deactivate () {
139 document ()->message (MsgInfoString, NULL);
140 Mrl::deactivate ();
141 }
142
closed()143 KDE_NO_EXPORT void RSS::Enclosure::closed () {
144 src = getAttribute (Ids::attr_url);
145 Mrl::closed ();
146 }
147