File indexing completed on 2024-04-21 15:38:07
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 0022 #include "kmplayer_asx.h" 0023 0024 #include <QUrl> 0025 0026 using namespace KMPlayer; 0027 0028 static QString getAsxAttribute (Element * e, const QString & attr) { 0029 for (Attribute *a = e->attributes ().first (); a; a = a->nextSibling ()) 0030 if (attr == a->name ().toString ().toLower ()) 0031 return a->value (); 0032 return QString (); 0033 } 0034 0035 KDE_NO_EXPORT Node *ASX::Asx::childFromTag (const QString & tag) { 0036 QByteArray ba = tag.toLatin1 (); 0037 const char *name = ba.constData (); 0038 if (!strcasecmp (name, "entry")) 0039 return new ASX::Entry (m_doc); 0040 else if (!strcasecmp (name, "entryref")) 0041 return new ASX::EntryRef (m_doc); 0042 else if (!strcasecmp (name, "title")) 0043 return new DarkNode (m_doc, name, id_node_title); 0044 else if (!strcasecmp (name, "base")) 0045 return new DarkNode (m_doc, name, id_node_base); 0046 else if (!strcasecmp (name, "param")) 0047 return new DarkNode (m_doc, name, id_node_param); 0048 return 0L; 0049 } 0050 0051 void *ASX::Asx::role (RoleType msg, void *content) 0052 { 0053 if (RolePlaylist == msg) 0054 return !title.isEmpty () ? (PlaylistRole *) this : NULL; 0055 return Mrl::role (msg, content); 0056 } 0057 0058 KDE_NO_EXPORT void ASX::Asx::closed () { 0059 for (Node *e = firstChild (); e; e = e->nextSibling ()) { 0060 if (e->id == id_node_title) 0061 title = e->innerText ().simplified (); 0062 else if (e->id == id_node_base) 0063 src = getAsxAttribute (static_cast <Element *> (e), "href"); 0064 } 0065 } 0066 0067 //----------------------------------------------------------------------------- 0068 0069 KDE_NO_EXPORT Node *ASX::Entry::childFromTag (const QString & tag) { 0070 QByteArray ba = tag.toLatin1 (); 0071 const char *name = ba.constData (); 0072 if (!strcasecmp (name, "ref")) 0073 return new ASX::Ref (m_doc); 0074 else if (!strcasecmp (name, "title")) 0075 return new DarkNode (m_doc, name, id_node_title); 0076 else if (!strcasecmp (name, "base")) 0077 return new DarkNode (m_doc, name, id_node_base); 0078 else if (!strcasecmp (name, "param")) 0079 return new DarkNode (m_doc, name, id_node_param); 0080 else if (!strcasecmp (name, "starttime")) 0081 return new DarkNode (m_doc, name, id_node_starttime); 0082 else if (!strcasecmp (name, "duration")) 0083 return new DarkNode (m_doc, name, id_node_duration); 0084 return 0L; 0085 } 0086 0087 KDE_NO_EXPORT Node::PlayType ASX::Entry::playType () { 0088 return play_type_none; 0089 } 0090 0091 KDE_NO_EXPORT void ASX::Entry::closed () { 0092 ref_child_count = 0; 0093 Node *ref = NULL; 0094 for (Node *e = firstChild (); e; e = e->nextSibling ()) { 0095 switch (e->id) { 0096 case id_node_title: 0097 title = e->innerText (); // already normalized (hopefully) 0098 break; 0099 case id_node_base: 0100 src = getAsxAttribute (static_cast <Element *> (e), "href"); 0101 break; 0102 case id_node_ref: 0103 ref = e; 0104 ref_child_count++; 0105 } 0106 } 0107 if (ref_child_count == 1 && !title.isEmpty ()) 0108 static_cast <ASX::Ref *> (ref)->title = title; 0109 } 0110 0111 KDE_NO_EXPORT void ASX::Entry::activate () { 0112 resolved = true; 0113 for (Node *e = firstChild (); e; e = e->nextSibling ()) 0114 if (e->id == id_node_param) { 0115 Element * elm = static_cast <Element *> (e); 0116 if (getAsxAttribute(elm,"name").toLower() == QString("clipsummary")) { 0117 QString inf = QUrl::fromPercentEncoding ( 0118 getAsxAttribute (elm, "value").toUtf8 ()); 0119 document ()->message (MsgInfoString, &inf); 0120 } 0121 } else if (e->id == id_node_duration) { 0122 QString s = static_cast <Element *> (e)->getAttribute ( 0123 Ids::attr_value); 0124 int pos = parseTimeString( s ); 0125 if (pos > 0) 0126 duration_timer = document()->post ( 0127 this, new TimerPosting (pos * 10)); 0128 } 0129 Mrl::activate (); 0130 } 0131 0132 KDE_NO_EXPORT void ASX::Entry::message (MessageType msg, void *content) { 0133 if (msg == MsgEventTimer) { 0134 duration_timer = NULL; 0135 deactivate (); 0136 return; 0137 } 0138 Mrl::message (msg, content); 0139 } 0140 0141 KDE_NO_EXPORT void ASX::Entry::deactivate () { 0142 document ()->message (MsgInfoString, NULL); 0143 if (duration_timer) { 0144 document()->cancelPosting (duration_timer); 0145 duration_timer = NULL; 0146 } 0147 Mrl::deactivate (); 0148 } 0149 0150 void *ASX::Entry::role (RoleType msg, void *content) 0151 { 0152 if (RolePlaylist == msg) 0153 return ref_child_count > 1 && !title.isEmpty () 0154 ? (PlaylistRole *) this : NULL; 0155 return Mrl::role (msg, content); 0156 } 0157 0158 //----------------------------------------------------------------------------- 0159 0160 KDE_NO_EXPORT void ASX::Ref::opened () { 0161 src = getAsxAttribute (this, "href"); 0162 Mrl::opened (); 0163 } 0164 0165 //----------------------------------------------------------------------------- 0166 0167 KDE_NO_EXPORT void ASX::EntryRef::opened () { 0168 src = getAsxAttribute (this, "href"); 0169 Mrl::opened (); 0170 } 0171