File indexing completed on 2024-04-21 15:38:22

0001 /* This file is part of the KMPlayer application
0002    Copyright (C) 2003 Koos Vriezen <koos.vriezen@xs4all.nl>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef _KMPLAYER_TV_SOURCE_H_
0021 #define _KMPLAYER_TV_SOURCE_H_
0022 
0023 #include <QPointer>
0024 #include <qstring.h>
0025 #include <qframe.h>
0026 
0027 #include "kmplayer.h"
0028 #include "kmplayerconfig.h"
0029 #include "mediaobject.h"
0030 #include "kmplayer_lists.h"
0031 
0032 const short id_node_tv_document = 40;
0033 const short id_node_tv_device = 41;
0034 const short id_node_tv_input = 42;
0035 const short id_node_tv_channel = 43;
0036 
0037 class KMPlayerPrefSourcePageTV;         // source, TV
0038 class TVDeviceScannerSource;
0039 class KMPlayerTVSource;
0040 class KUrlRequester;
0041 class KMPlayerApp;
0042 class QTabWidget;
0043 class QLineEdit;
0044 class QCheckBox;
0045 class QPushButton;
0046 
0047 
0048 class KMPLAYER_NO_EXPORT TVDevicePage : public QFrame {
0049     Q_OBJECT
0050 public:
0051     TVDevicePage (QWidget *parent, KMPlayer::NodePtr dev);
0052     KDE_NO_CDTOR_EXPORT ~TVDevicePage () {}
0053 
0054     QLineEdit * name;
0055     KUrlRequester * audiodevice;
0056     QLineEdit * sizewidth;
0057     QLineEdit * sizeheight;
0058     QCheckBox * noplayback;
0059     QTabWidget * inputsTab;
0060     KMPlayer::NodePtrW device_doc;
0061 signals:
0062     void deleted (TVDevicePage *);
0063 private slots:
0064     void slotDelete ();
0065 };
0066 
0067 class KMPLAYER_NO_EXPORT KMPlayerPrefSourcePageTV : public QFrame {
0068     Q_OBJECT
0069 public:
0070     KMPlayerPrefSourcePageTV (QWidget *parent, KMPlayerTVSource *);
0071     KDE_NO_CDTOR_EXPORT ~KMPlayerPrefSourcePageTV () {}
0072     QLineEdit * driver;
0073     KUrlRequester * device;
0074     QPushButton * scan;
0075     QTabWidget * notebook;
0076 protected:
0077     void showEvent (QShowEvent *);
0078     KMPlayerTVSource * m_tvsource;
0079 };
0080 
0081 class KMPLAYER_NO_EXPORT TVNode : public KMPlayer::GenericMrl {
0082 public:
0083     TVNode (KMPlayer::NodePtr &d, const QString &s, const char * t, short id, const QString &n=QString ());
0084     virtual void setNodeName (const QString &);
0085 };
0086 
0087 /*
0088  * Element for channels
0089  */
0090 class KMPLAYER_NO_EXPORT TVChannel : public TVNode {
0091 public:
0092     TVChannel (KMPlayer::NodePtr & d, const QString & n, double f);
0093     TVChannel (KMPlayer::NodePtr & d);
0094     KDE_NO_CDTOR_EXPORT ~TVChannel () {}
0095     void closed ();
0096 };
0097 
0098 /*
0099  * Element for inputs
0100  */
0101 class KMPLAYER_NO_EXPORT TVInput : public TVNode {
0102 public:
0103     TVInput (KMPlayer::NodePtr & d, const QString & n, int id);
0104     TVInput (KMPlayer::NodePtr & d);
0105     KDE_NO_CDTOR_EXPORT ~TVInput () {}
0106     KMPlayer::Node *childFromTag (const QString &);
0107     void setNodeName (const QString &);
0108     void closed ();
0109 };
0110 
0111 /*
0112  * Element for TV devices
0113  */
0114 class KMPLAYER_NO_EXPORT TVDevice : public TVNode {
0115 public:
0116     TVDevice (KMPlayer::NodePtr & d, const QString & s);
0117     TVDevice (KMPlayer::NodePtr & d);
0118     ~TVDevice ();
0119     KMPlayer::Node *childFromTag (const QString &);
0120     void closed ();
0121     void message (KMPlayer::MessageType msg, void *content=NULL);
0122     void *role (KMPlayer::RoleType msg, void *content=NULL);
0123     void setNodeName (const QString &);
0124     void updateNodeName ();
0125     void updateDevicePage ();
0126     bool zombie;
0127     QPointer <TVDevicePage> device_page;
0128 };
0129 
0130 class KMPLAYER_NO_EXPORT TVDocument : public FileDocument {
0131     KMPlayerTVSource * m_source;
0132 public:
0133     TVDocument (KMPlayerTVSource *);
0134     KMPlayer::Node *childFromTag (const QString &);
0135     void defer ();
0136     KDE_NO_EXPORT const char * nodeName () const { return "tvdevices"; }
0137     void message (KMPlayer::MessageType msg, void *content=NULL);
0138 };
0139 
0140 
0141 /*
0142  * Source form scanning TV devices
0143  */
0144 class KMPLAYER_NO_EXPORT TVDeviceScannerSource
0145                              : public KMPlayer::Source, KMPlayer::ProcessUser {
0146     Q_OBJECT
0147 public:
0148     TVDeviceScannerSource (KMPlayerTVSource * src);
0149     KDE_NO_CDTOR_EXPORT ~TVDeviceScannerSource () {};
0150     virtual void init ();
0151     virtual bool processOutput (const QString & line);
0152     virtual QString filterOptions ();
0153     virtual bool hasLength ();
0154     virtual bool isSeekable ();
0155     virtual bool scan (const QString & device, const QString & driver);
0156 
0157     virtual void starting (KMPlayer::IProcess *) {}
0158     virtual void stateChange (KMPlayer::IProcess *, KMPlayer::IProcess::State, KMPlayer::IProcess::State);
0159     virtual void processDestroyed (KMPlayer::IProcess *p);
0160     virtual KMPlayer::IViewer *viewer ();
0161     virtual KMPlayer::Mrl *getMrl ();
0162 
0163     virtual void activate ();
0164     virtual void deactivate ();
0165     virtual void play (KMPlayer::Mrl *);
0166 public slots:
0167     void scanningFinished ();
0168 signals:
0169     void scanFinished (TVDevice * tvdevice);
0170 private:
0171     KMPlayerTVSource * m_tvsource;
0172     TVDevice * m_tvdevice;
0173     KMPlayer::IProcess *m_process;
0174     KMPlayer::IViewer *m_viewer;
0175     KMPlayer::Source * m_old_source;
0176     QString m_driver;
0177     QString m_caps;
0178     QRegExp m_nameRegExp;
0179     QRegExp m_sizesRegExp;
0180     QRegExp m_inputRegExp;
0181     QRegExp m_inputRegExpV4l2;
0182 };
0183 
0184 /*
0185  * Source form TV devices, also implementing preference page for it
0186  */
0187 class KMPLAYER_NO_EXPORT KMPlayerTVSource : public KMPlayer::Source, public KMPlayer::PreferencesPage {
0188     Q_OBJECT
0189 public:
0190     KMPlayerTVSource(KMPlayerApp* app);
0191     virtual ~KMPlayerTVSource ();
0192     virtual QString filterOptions ();
0193     virtual bool hasLength ();
0194     virtual bool isSeekable ();
0195     virtual KMPlayer::NodePtr root ();
0196     virtual QString prettyName ();
0197     virtual void write (KSharedConfigPtr);
0198     virtual void read (KSharedConfigPtr);
0199     virtual void sync (bool);
0200     virtual void prefLocation (QString & item, QString & icon, QString & tab);
0201     virtual QFrame * prefPage (QWidget * parent);
0202     void readXML ();
0203     void setCurrent (KMPlayer::Mrl *);
0204     virtual void activate ();
0205     virtual void deactivate ();
0206     virtual void play (KMPlayer::Mrl *);
0207 public slots:
0208     void menuClicked (int id);
0209 private slots:
0210     void slotScan ();
0211     void slotScanFinished (TVDevice * device);
0212     void slotDeviceDeleted (TVDevicePage *);
0213 private:
0214     void addTVDevicePage (TVDevice * dev, bool show=false);
0215     KMPlayer::NodePtrW m_cur_tvdevice;
0216     KMPlayer::NodePtrW m_cur_tvinput;
0217     KMPlayerApp* m_app;
0218     QMenu * m_channelmenu;
0219     QString tvdriver;
0220     KMPlayerPrefSourcePageTV * m_configpage;
0221     TVDeviceScannerSource * scanner;
0222     int tree_id;
0223     bool config_read; // whether tv.xml is read
0224 };
0225 
0226 #endif //_KMPLAYER_TV_SOURCE_H_