File indexing completed on 2024-04-21 15:38:10
0001 /** 0002 * Copyright (C) 2005 by Koos Vriezen <koos.vriezen@gmail.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License version 2 as published by the Free Software Foundation. 0007 * 0008 * This library is distributed in the hope that it will be useful, 0009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 * Library General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU Library General Public License 0014 * along with this library; see the file COPYING.LIB. If not, write to 0015 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, 0016 * Boston, MA 02110-1301, USA. 0017 **/ 0018 0019 #include "config-kmplayer.h" 0020 #include <kdebug.h> 0021 #include "kmplayer_rss.h" 0022 #include "kmplayer_atom.h" 0023 0024 using namespace KMPlayer; 0025 0026 KDE_NO_EXPORT Node *RSS::Rss::childFromTag (const QString & tag) { 0027 if (!strcmp (tag.toLatin1 ().constData (), "channel")) 0028 return new RSS::Channel (m_doc); 0029 return 0L; 0030 } 0031 0032 void *RSS::Rss::role (RoleType msg, void *content) 0033 { 0034 if (RolePlaylist == msg) 0035 return NULL; 0036 return Element::role (msg, content); 0037 } 0038 0039 KDE_NO_EXPORT Node *RSS::Channel::childFromTag (const QString & tag) { 0040 QByteArray ba = tag.toLatin1 (); 0041 const char *ctag = ba.constData (); 0042 if (!strcmp (ctag, "item")) 0043 return new RSS::Item (m_doc); 0044 else if (!strcmp (ctag, "title")) 0045 return new DarkNode (m_doc, ctag, id_node_title); 0046 else if (!strncmp (ctag, "itunes", 6) || 0047 !strncmp (ctag, "media", 5)) 0048 return new DarkNode (m_doc, ctag, id_node_ignored); 0049 return 0L; 0050 } 0051 0052 KDE_NO_EXPORT void RSS::Channel::closed () { 0053 for (Node *c = firstChild (); c; c = c->nextSibling ()) 0054 if (c->id == id_node_title) { 0055 title = c->innerText ().simplified (); 0056 break; 0057 } 0058 Element::closed (); 0059 } 0060 0061 void *RSS::Channel::role (RoleType msg, void *content) 0062 { 0063 if (RolePlaylist == msg) 0064 return !title.isEmpty () || //return false if no title and only one 0065 previousSibling () || nextSibling () ? (PlaylistRole *) this : NULL; 0066 return Element::role (msg, content); 0067 } 0068 0069 KDE_NO_EXPORT Node *RSS::Item::childFromTag (const QString & tag) { 0070 QByteArray ba = tag.toLatin1 (); 0071 const char *ctag = ba.constData (); 0072 if (!strcmp (ctag, "enclosure")) 0073 return new RSS::Enclosure (m_doc); 0074 else if (!strcmp (ctag, "title")) 0075 return new DarkNode (m_doc, ctag, id_node_title); 0076 else if (!strcmp (ctag, "description")) 0077 return new DarkNode (m_doc, ctag, id_node_description); 0078 else if (!strcmp (ctag, "category")) 0079 return new DarkNode (m_doc, ctag, id_node_category); 0080 else if (!strcmp (ctag, "media:group")) 0081 return new ATOM::MediaGroup (m_doc); 0082 else if (!strcmp (ctag, "media:thumbnail")) 0083 return new DarkNode (m_doc, ctag, id_node_thumbnail); 0084 else if (!strncmp (ctag, "itunes", 6) || 0085 !strncmp (ctag, "feedburner", 10) || 0086 !strcmp (ctag, "link") || 0087 !strcmp (ctag, "pubDate") || 0088 !strcmp (ctag, "guid") || 0089 !strncmp (ctag, "media", 5)) 0090 return new DarkNode (m_doc, ctag, id_node_ignored); 0091 return 0L; 0092 } 0093 0094 KDE_NO_EXPORT void RSS::Item::closed () { 0095 if (!summary_added) { 0096 ATOM::MediaGroup *group = NULL; 0097 Enclosure *enclosure = NULL; 0098 QString description; 0099 QString thumbnail; 0100 int width = 0, height = 0; 0101 for (Node *c = firstChild (); c; c = c->nextSibling ()) { 0102 switch (c->id) { 0103 case id_node_title: 0104 title = c->innerText ().simplified (); 0105 break; 0106 case id_node_enclosure: 0107 enclosure = static_cast <Enclosure *> (c); 0108 break; 0109 case id_node_description: 0110 description = c->innerText (); 0111 break; 0112 case ATOM::id_node_media_group: 0113 group = static_cast <ATOM::MediaGroup *> (c); 0114 break; 0115 case id_node_thumbnail: 0116 thumbnail = static_cast<Element*>(c)->getAttribute(Ids::attr_url); 0117 width = static_cast<Element*>(c)->getAttribute(Ids::attr_width).toInt(); 0118 height = static_cast<Element*>(c)->getAttribute(Ids::attr_height).toInt(); 0119 break; 0120 } 0121 } 0122 if (group) 0123 group->addSummary (this, NULL, title, description, thumbnail, width, height); 0124 if (enclosure) { 0125 enclosure->setCaption (title); 0126 enclosure->description = description; 0127 } 0128 summary_added = true; 0129 } 0130 Element::closed (); 0131 } 0132 0133 KDE_NO_EXPORT void RSS::Enclosure::activate () { 0134 document ()->message (MsgInfoString, &description); 0135 Mrl::activate (); 0136 } 0137 0138 KDE_NO_EXPORT void RSS::Enclosure::deactivate () { 0139 document ()->message (MsgInfoString, NULL); 0140 Mrl::deactivate (); 0141 } 0142 0143 KDE_NO_EXPORT void RSS::Enclosure::closed () { 0144 src = getAttribute (Ids::attr_url); 0145 Mrl::closed (); 0146 }