File indexing completed on 2024-03-24 16:22:06

0001 /**
0002   This file belong to the KMPlayer project, a movie player plugin for Konqueror
0003   Copyright (C) 2009  Koos Vriezen <koos.vriezen@gmail.com>
0004 
0005   This library is free software; you can redistribute it and/or
0006   modify it under the terms of the GNU Lesser General Public
0007   License as published by the Free Software Foundation; either
0008   version 2 of the License, or (at your option) any later version.
0009 
0010   This library is distributed in the hope that it will be useful,
0011   but WITHOUT ANY WARRANTY; without even the implied warranty of
0012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013   Lesser General Public License for more details.
0014 
0015   You should have received a copy of the GNU Lesser General Public
0016   License along with this library; if not, write to the Free Software
0017   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018 **/
0019 
0020 #ifndef _KMPLAYER_LISTS_H_
0021 #define _KMPLAYER_LISTS_H_
0022 
0023 #include <config-kmplayer.h>
0024 
0025 #include <qprocess.h>
0026 
0027 #include "kmplayer_def.h"
0028 #include "kmplayerplaylist.h"
0029 #include "kmplayerpartbase.h"
0030 
0031 static const short id_node_recent_document = 31;
0032 static const short id_node_recent_node = 32;
0033 static const short id_node_disk_document = 33;
0034 static const short id_node_disk_node = 34;
0035 static const short id_node_gen_generator = 36;
0036 static const short id_node_gen_input = 37;
0037 static const short id_node_gen_uri = 38;
0038 static const short id_node_gen_literal = 39;
0039 static const short id_node_gen_ask = 40;
0040 static const short id_node_gen_title = 41;
0041 static const short id_node_gen_description = 42;
0042 static const short id_node_gen_process = 43;
0043 static const short id_node_gen_program = 44;
0044 static const short id_node_gen_argument = 45;
0045 static const short id_node_gen_predefined = 46;
0046 static const short id_node_gen_document = 47;
0047 static const short id_node_gen_http_get = 48;
0048 static const short id_node_gen_http_key_value = 49;
0049 static const short id_node_gen_sequence = 50;
0050 
0051 class QTextStream;
0052 class KMPlayerApp;
0053 
0054 class KMPLAYER_NO_EXPORT ListsSource : public KMPlayer::URLSource {
0055 public:
0056     KDE_NO_CDTOR_EXPORT ListsSource (KMPlayer::PartBase * p)
0057         : KMPlayer::URLSource (p, KUrl ("lists://")) {}
0058     void play (KMPlayer::Mrl *);
0059     void activate ();
0060     QString prettyName ();
0061 };
0062 
0063 class KMPLAYER_NO_EXPORT FileDocument : public KMPlayer::SourceDocument {
0064 public:
0065     FileDocument (short id, const QString&, KMPlayer::Source *source = 0L);
0066     KMPlayer::Node *childFromTag (const QString &tag);
0067     void readFromFile (const QString &file);
0068     void writeToFile (const QString &file);
0069     void sync (const QString & file);
0070     unsigned int load_tree_version;
0071 };
0072 
0073 class KMPLAYER_NO_EXPORT Recents : public FileDocument {
0074 public:
0075     Recents (KMPlayerApp *a);
0076     void defer ();
0077     void activate ();
0078     void message (KMPlayer::MessageType msg, void *content=NULL);
0079     KMPlayer::Node *childFromTag (const QString &tag);
0080     KDE_NO_EXPORT const char *nodeName () const { return "playlist"; }
0081     KMPlayerApp *app;
0082 };
0083 
0084 class KMPLAYER_NO_EXPORT Recent : public KMPlayer::Mrl {
0085 public:
0086     Recent (KMPlayer::NodePtr & doc, KMPlayerApp *a, const QString &url = QString());
0087     void activate ();
0088     void closed ();
0089     KDE_NO_EXPORT const char *nodeName () const { return "item"; }
0090     KMPlayerApp *app;
0091 };
0092 
0093 class KMPLAYER_NO_EXPORT Group
0094  : public KMPlayer::Element, public KMPlayer::PlaylistRole
0095 {
0096 public:
0097     Group (KMPlayer::NodePtr &doc, KMPlayerApp *a, const QString &pn=QString());
0098     KMPlayer::Node *childFromTag (const QString &tag);
0099     void defer () {} // TODO lazy loading of largish sub trees
0100     void closed ();
0101     void *role (KMPlayer::RoleType msg, void *content=NULL);
0102     KDE_NO_EXPORT const char *nodeName () const { return "group"; }
0103     KMPlayerApp *app;
0104 };
0105 
0106 class KMPLAYER_NO_EXPORT Playlist : public FileDocument {
0107 public:
0108     Playlist (KMPlayerApp *a, KMPlayer::Source *s, bool plmod = false);
0109     void message (KMPlayer::MessageType msg, void *content=NULL);
0110     void defer ();
0111     void activate ();
0112     KMPlayer::Node *childFromTag (const QString &tag);
0113     KDE_NO_EXPORT const char * nodeName () const { return "playlist"; }
0114     KMPlayerApp *app;
0115     bool playmode;
0116 };
0117 
0118 class KMPLAYER_NO_EXPORT PlaylistItemBase : public KMPlayer::Mrl {
0119 public:
0120     PlaylistItemBase (KMPlayer::NodePtr &d, short id, KMPlayerApp *a, bool pm);
0121     void activate ();
0122     void closed ();
0123     KMPlayerApp *app;
0124     bool playmode;
0125 };
0126 
0127 class KMPLAYER_NO_EXPORT PlaylistItem : public PlaylistItemBase {
0128 public:
0129     PlaylistItem (KMPlayer::NodePtr & doc, KMPlayerApp *a, bool playmode, const QString &url = QString());
0130     void closed ();
0131     void begin ();
0132     void setNodeName (const QString&);
0133     const char *nodeName () const KDE_NO_EXPORT { return "item"; }
0134 };
0135 
0136 class KMPLAYER_NO_EXPORT PlaylistGroup
0137  : public KMPlayer::Element, public KMPlayer::PlaylistRole
0138 {
0139 public:
0140     PlaylistGroup (KMPlayer::NodePtr &doc, KMPlayerApp *a, const QString &pn);
0141     PlaylistGroup (KMPlayer::NodePtr &doc, KMPlayerApp *a, bool plmode=false);
0142     KMPlayer::Node *childFromTag (const QString &tag);
0143     void closed ();
0144     void *role (KMPlayer::RoleType msg, void *content=NULL);
0145     void setNodeName (const QString&);
0146     KDE_NO_EXPORT const char *nodeName () const { return "group"; }
0147     KMPlayerApp *app;
0148     bool playmode;
0149 };
0150 
0151 class KMPLAYER_NO_EXPORT HtmlObject : public PlaylistItemBase {
0152 public:
0153     HtmlObject (KMPlayer::NodePtr &doc, KMPlayerApp *a, bool playmode);
0154     void activate ();
0155     void closed ();
0156     KMPlayer::Node *childFromTag (const QString &tag);
0157     const char *nodeName () const KDE_NO_EXPORT { return "object"; }
0158 };
0159 
0160 class KMPLAYER_NO_EXPORT Generator : public QObject, public FileDocument {
0161     Q_OBJECT
0162 public:
0163     Generator (KMPlayerApp *a);
0164     void activate ();
0165     void begin ();
0166     void deactivate ();
0167     void message (KMPlayer::MessageType msg, void *content=NULL);
0168     KMPlayer::Node *childFromTag (const QString &tag);
0169     KDE_NO_EXPORT const char *nodeName () const { return "generator"; }
0170 
0171 private slots:
0172     void started ();
0173     void error (QProcess::ProcessError err);
0174     void readyRead ();
0175     void finished ();
0176 
0177 private:
0178     QString genReadProcess (KMPlayer::Node *n);
0179     QString genReadInput (KMPlayer::Node *n);
0180     QString genReadString (KMPlayer::Node *n);
0181     QString genReadUriGet (KMPlayer::Node *n);
0182     QString genReadAsk (KMPlayer::Node *n);
0183 
0184     KMPlayerApp *app;
0185     QProcess *qprocess;
0186     QTextStream *data;
0187     QString process;
0188     QString buffer;
0189     bool canceled;
0190     bool quote;
0191 };
0192 
0193 class KMPLAYER_NO_EXPORT GeneratorElement : public KMPlayer::Element {
0194 public:
0195     GeneratorElement (KMPlayer::NodePtr &doc, const QString &t, short id)
0196         : KMPlayer::Element (doc, id), tag (t.toUtf8 ()) {}
0197     KMPlayer::Node *childFromTag (const QString &tag);
0198     KDE_NO_EXPORT const char *nodeName () const { return tag.constData (); }
0199     QByteArray tag;
0200 };
0201 
0202 #endif