1 /**
2   This file belong to the KMPlayer project, a movie player plugin for Konqueror
3   Copyright (C) 2009  Koos Vriezen <koos.vriezen@gmail.com>
4 
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2 of the License, or (at your option) any later version.
9 
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14 
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 **/
19 
20 #ifndef _KMPLAYER_LISTS_H_
21 #define _KMPLAYER_LISTS_H_
22 
23 #include <config-kmplayer.h>
24 
25 #include <qprocess.h>
26 
27 #include "kmplayer_def.h"
28 #include "kmplayerplaylist.h"
29 #include "kmplayerpartbase.h"
30 
31 static const short id_node_recent_document = 31;
32 static const short id_node_recent_node = 32;
33 static const short id_node_disk_document = 33;
34 static const short id_node_disk_node = 34;
35 static const short id_node_gen_generator = 36;
36 static const short id_node_gen_input = 37;
37 static const short id_node_gen_uri = 38;
38 static const short id_node_gen_literal = 39;
39 static const short id_node_gen_ask = 40;
40 static const short id_node_gen_title = 41;
41 static const short id_node_gen_description = 42;
42 static const short id_node_gen_process = 43;
43 static const short id_node_gen_program = 44;
44 static const short id_node_gen_argument = 45;
45 static const short id_node_gen_predefined = 46;
46 static const short id_node_gen_document = 47;
47 static const short id_node_gen_http_get = 48;
48 static const short id_node_gen_http_key_value = 49;
49 static const short id_node_gen_sequence = 50;
50 
51 class QTextStream;
52 class KMPlayerApp;
53 
54 class KMPLAYER_NO_EXPORT ListsSource : public KMPlayer::URLSource {
55 public:
ListsSource(KMPlayer::PartBase * p)56     KDE_NO_CDTOR_EXPORT ListsSource (KMPlayer::PartBase * p)
57         : KMPlayer::URLSource (p, KUrl ("lists://")) {}
58     void play (KMPlayer::Mrl *);
59     void activate ();
60     QString prettyName ();
61 };
62 
63 class KMPLAYER_NO_EXPORT FileDocument : public KMPlayer::SourceDocument {
64 public:
65     FileDocument (short id, const QString&, KMPlayer::Source *source = 0L);
66     KMPlayer::Node *childFromTag (const QString &tag);
67     void readFromFile (const QString &file);
68     void writeToFile (const QString &file);
69     void sync (const QString & file);
70     unsigned int load_tree_version;
71 };
72 
73 class KMPLAYER_NO_EXPORT Recents : public FileDocument {
74 public:
75     Recents (KMPlayerApp *a);
76     void defer ();
77     void activate ();
78     void message (KMPlayer::MessageType msg, void *content=NULL);
79     KMPlayer::Node *childFromTag (const QString &tag);
nodeName()80     KDE_NO_EXPORT const char *nodeName () const { return "playlist"; }
81     KMPlayerApp *app;
82 };
83 
84 class KMPLAYER_NO_EXPORT Recent : public KMPlayer::Mrl {
85 public:
86     Recent (KMPlayer::NodePtr & doc, KMPlayerApp *a, const QString &url = QString());
87     void activate ();
88     void closed ();
nodeName()89     KDE_NO_EXPORT const char *nodeName () const { return "item"; }
90     KMPlayerApp *app;
91 };
92 
93 class KMPLAYER_NO_EXPORT Group
94  : public KMPlayer::Element, public KMPlayer::PlaylistRole
95 {
96 public:
97     Group (KMPlayer::NodePtr &doc, KMPlayerApp *a, const QString &pn=QString());
98     KMPlayer::Node *childFromTag (const QString &tag);
defer()99     void defer () {} // TODO lazy loading of largish sub trees
100     void closed ();
101     void *role (KMPlayer::RoleType msg, void *content=NULL);
nodeName()102     KDE_NO_EXPORT const char *nodeName () const { return "group"; }
103     KMPlayerApp *app;
104 };
105 
106 class KMPLAYER_NO_EXPORT Playlist : public FileDocument {
107 public:
108     Playlist (KMPlayerApp *a, KMPlayer::Source *s, bool plmod = false);
109     void message (KMPlayer::MessageType msg, void *content=NULL);
110     void defer ();
111     void activate ();
112     KMPlayer::Node *childFromTag (const QString &tag);
nodeName()113     KDE_NO_EXPORT const char * nodeName () const { return "playlist"; }
114     KMPlayerApp *app;
115     bool playmode;
116 };
117 
118 class KMPLAYER_NO_EXPORT PlaylistItemBase : public KMPlayer::Mrl {
119 public:
120     PlaylistItemBase (KMPlayer::NodePtr &d, short id, KMPlayerApp *a, bool pm);
121     void activate ();
122     void closed ();
123     KMPlayerApp *app;
124     bool playmode;
125 };
126 
127 class KMPLAYER_NO_EXPORT PlaylistItem : public PlaylistItemBase {
128 public:
129     PlaylistItem (KMPlayer::NodePtr & doc, KMPlayerApp *a, bool playmode, const QString &url = QString());
130     void closed ();
131     void begin ();
132     void setNodeName (const QString&);
nodeName()133     const char *nodeName () const KDE_NO_EXPORT { return "item"; }
134 };
135 
136 class KMPLAYER_NO_EXPORT PlaylistGroup
137  : public KMPlayer::Element, public KMPlayer::PlaylistRole
138 {
139 public:
140     PlaylistGroup (KMPlayer::NodePtr &doc, KMPlayerApp *a, const QString &pn);
141     PlaylistGroup (KMPlayer::NodePtr &doc, KMPlayerApp *a, bool plmode=false);
142     KMPlayer::Node *childFromTag (const QString &tag);
143     void closed ();
144     void *role (KMPlayer::RoleType msg, void *content=NULL);
145     void setNodeName (const QString&);
nodeName()146     KDE_NO_EXPORT const char *nodeName () const { return "group"; }
147     KMPlayerApp *app;
148     bool playmode;
149 };
150 
151 class KMPLAYER_NO_EXPORT HtmlObject : public PlaylistItemBase {
152 public:
153     HtmlObject (KMPlayer::NodePtr &doc, KMPlayerApp *a, bool playmode);
154     void activate ();
155     void closed ();
156     KMPlayer::Node *childFromTag (const QString &tag);
nodeName()157     const char *nodeName () const KDE_NO_EXPORT { return "object"; }
158 };
159 
160 class KMPLAYER_NO_EXPORT Generator : public QObject, public FileDocument {
161     Q_OBJECT
162 public:
163     Generator (KMPlayerApp *a);
164     void activate ();
165     void begin ();
166     void deactivate ();
167     void message (KMPlayer::MessageType msg, void *content=NULL);
168     KMPlayer::Node *childFromTag (const QString &tag);
nodeName()169     KDE_NO_EXPORT const char *nodeName () const { return "generator"; }
170 
171 private slots:
172     void started ();
173     void error (QProcess::ProcessError err);
174     void readyRead ();
175     void finished ();
176 
177 private:
178     QString genReadProcess (KMPlayer::Node *n);
179     QString genReadInput (KMPlayer::Node *n);
180     QString genReadString (KMPlayer::Node *n);
181     QString genReadUriGet (KMPlayer::Node *n);
182     QString genReadAsk (KMPlayer::Node *n);
183 
184     KMPlayerApp *app;
185     QProcess *qprocess;
186     QTextStream *data;
187     QString process;
188     QString buffer;
189     bool canceled;
190     bool quote;
191 };
192 
193 class KMPLAYER_NO_EXPORT GeneratorElement : public KMPlayer::Element {
194 public:
GeneratorElement(KMPlayer::NodePtr & doc,const QString & t,short id)195     GeneratorElement (KMPlayer::NodePtr &doc, const QString &t, short id)
196         : KMPlayer::Element (doc, id), tag (t.toUtf8 ()) {}
197     KMPlayer::Node *childFromTag (const QString &tag);
nodeName()198     KDE_NO_EXPORT const char *nodeName () const { return tag.constData (); }
199     QByteArray tag;
200 };
201 
202 #endif
203