1 /**
2  * Copyright (C) 2006 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 <kurl.h>
22 
23 #include "kmplayer_opml.h"
24 #include "expression.h"
25 
26 using namespace KMPlayer;
27 
28 
childFromTag(const QString & tag)29 KDE_NO_EXPORT Node *OPML::Opml::childFromTag (const QString & tag)
30 {
31     QByteArray ba = tag.toLatin1 ();
32     const char *name = ba.constData ();
33     if (!strcasecmp (name, "head"))
34         return new Head (m_doc);
35     else if (!strcasecmp (name, "body"))
36         return new Body (m_doc);
37     return 0L;
38 }
39 
closed()40 void OPML::Opml::closed ()
41 {
42     Expression *expr = evaluateExpr ("/head/title");
43     if (expr) {
44         expr->setRoot (this);
45         title = expr->toString ();
46         delete expr;
47     }
48     Element::closed ();
49 }
50 
role(RoleType msg,void * content)51 void *OPML::Opml::role (RoleType msg, void *content)
52 {
53     if (RolePlaylist == msg)
54         return !title.isEmpty () ? (PlaylistRole *) this : NULL;
55     return Element::role (msg, content);
56 }
57 
58 //--------------------------%<-------------------------------------------------
59 
childFromTag(const QString & tag)60 Node *OPML::Head::childFromTag (const QString & tag)
61 {
62     QByteArray ba = tag.toLatin1 ();
63     const char *name = ba.constData ();
64     if (!strcasecmp (name, "title"))
65         return new DarkNode (m_doc, name, id_node_title);
66     else if (!strcasecmp (name, "dateCreated"))
67         return new DarkNode (m_doc, name, id_node_ignore);
68     return 0L;
69 }
70 
71 //--------------------------%<-------------------------------------------------
72 
childFromTag(const QString & tag)73 Node *OPML::Body::childFromTag (const QString & tag)
74 {
75     QByteArray ba = tag.toLatin1 ();
76     const char *name = ba.constData ();
77     if (!strcasecmp (name, "outline"))
78         return new Outline (m_doc);
79     return 0L;
80 }
81 
82 //--------------------------%<-------------------------------------------------
83 
closed()84 void OPML::Outline::closed ()
85 {
86     src = getAttribute ("xmlUrl").trimmed ();
87     title = getAttribute ("title").trimmed ();
88     Mrl::closed ();
89 }
90