File indexing completed on 2024-05-12 04:52:15

0001 /*
0002  * dvbmanager.h
0003  *
0004  * Copyright (C) 2008-2011 Christoph Pfister <christophpfister@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License along
0017  * with this program; if not, write to the Free Software Foundation, Inc.,
0018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019  */
0020 
0021 #ifndef DVBMANAGER_H
0022 #define DVBMANAGER_H
0023 
0024 #include <QObject>
0025 #include <QDate>
0026 #include <QMap>
0027 #include <QPair>
0028 #include <QStringList>
0029 #include "dvbtransponder.h"
0030 
0031 class QTreeView;
0032 class DvbBackendDevice;
0033 class DvbChannelModel;
0034 class DvbConfig;
0035 class DvbDevice;
0036 class DvbDeviceConfig;
0037 class DvbDeviceConfigUpdate;
0038 class DvbEpgModel;
0039 class DvbLiveView;
0040 class DvbRecordingModel;
0041 class DvbScanData;
0042 class MediaWidget;
0043 class XmlTv;
0044 
0045 class DvbManager : public QObject
0046 {
0047     Q_OBJECT
0048 public:
0049     enum RequestType {
0050         Shared,
0051         Exclusive, // you can freely tune() and stop(), because the device isn't shared
0052         Prioritized // takes precedence over 'Shared' and 'Exclusive'
0053     };
0054 
0055     enum TransmissionType {
0056         DvbC,
0057         DvbS,
0058         DvbS2, // includes DvbS
0059         DvbT,
0060         DvbT2, // includes DvbT
0061         Atsc,
0062         IsdbT
0063     };
0064 
0065     DvbManager(MediaWidget *mediaWidget_, QWidget *parent_);
0066     ~DvbManager();
0067 
0068     QWidget *getParentWidget() const
0069     {
0070         return parent;
0071     }
0072 
0073     MediaWidget *getMediaWidget() const
0074     {
0075         return mediaWidget;
0076     }
0077 
0078     QStringList getSources() const
0079     {
0080         return sources;
0081     }
0082 
0083     DvbChannelModel *getChannelModel() const
0084     {
0085         return channelModel;
0086     }
0087 
0088     QTreeView *getChannelView() const
0089     {
0090         return channelView;
0091     }
0092 
0093     DvbEpgModel *getEpgModel() const
0094     {
0095         return epgModel;
0096     }
0097 
0098     DvbLiveView *getLiveView() const
0099     {
0100         return liveView;
0101     }
0102 
0103     DvbRecordingModel *getRecordingModel() const
0104     {
0105         return recordingModel;
0106     }
0107 
0108     void setChannelView(QTreeView *channelView_)
0109     {
0110         channelView = channelView_;
0111     }
0112 
0113     DvbDevice *requestDevice(const QString &source, const DvbTransponder &transponder,
0114         RequestType requestType);
0115     DvbDevice *requestExclusiveDevice(const QString &source);
0116     void releaseDevice(DvbDevice *device, RequestType requestType);
0117 
0118     QList<DvbDeviceConfig> getDeviceConfigs() const;
0119     void updateDeviceConfigs(const QList<DvbDeviceConfigUpdate> &configUpdates);
0120 
0121     QDate getScanDataDate();
0122     QStringList getScanSources(TransmissionType type);
0123     QString getAutoScanSource(const QString &source) const;
0124     QList<DvbTransponder> getTransponders(DvbDevice *device, const QString &source);
0125     QHash<QString, bool> languageCodes;
0126     QString currentEpgLanguage;
0127     bool updateScanData(const QByteArray &data);
0128 
0129     QString getRecordingFolder() const;
0130     QString getTimeShiftFolder() const;
0131     QString getXmltvFileName() const;
0132     QString getNamingFormat() const;
0133     QString getRecordingRegex() const;
0134     QStringList getRecordingRegexList() const;
0135     QList<int> getRecordingRegexPriorityList() const;
0136     QString getActionAfterRecording() const;
0137     int getBeginMargin() const; // seconds
0138     int getEndMargin() const; // seconds
0139     bool override6937Charset() const;
0140     bool createInfoFile() const;
0141     bool disableEpg() const;
0142     bool isScanWhenIdle() const;
0143     void setRecordingFolder(const QString &path);
0144     void setTimeShiftFolder(const QString &path);
0145     void setXmltvFileName(const QString &path);
0146     void setNamingFormat(const QString namingFormat);
0147     void setRecordingRegex(const QString regex);
0148     void setRecordingRegexList(const QStringList regexList);
0149     void setRecordingRegexPriorityList(const QList<int> regexList);
0150     bool removeRecordingRegex(QString regex);
0151     bool addRecordingRegex(QString regex);
0152     bool removeRecordingRegexPriority(int priority);
0153     bool addRecordingRegexPriority(int index);
0154     void setActionAfterRecording(const QString actionAfterRecording);
0155     void setBeginMargin(int beginMargin); // seconds
0156     void setEndMargin(int endMargin); // seconds
0157     void setOverride6937Charset(bool override);
0158     void setCreateInfoFile(bool createInfoFile);
0159     void setDisableEpg(bool disableEpg);
0160     void setScanWhenIdle(bool scanWhenIdle);
0161     void writeDeviceConfigs();
0162 
0163     void enableDvbDump();
0164     bool hasReacquired() { return reacquireDevice; };
0165 
0166 private slots:
0167     void requestBuiltinDeviceManager(QObject *&builtinDeviceManager);
0168     void deviceAdded(DvbBackendDevice *backendDevice);
0169     void deviceRemoved(DvbBackendDevice *backendDevice);
0170 
0171 private:
0172     void loadDeviceManager();
0173 
0174     void readDeviceConfigs();
0175     void updateSourceMapping();
0176 
0177     void readScanData();
0178     bool readScanSources(DvbScanData &data, const char *tag, TransmissionType type);
0179 
0180     QWidget *parent;
0181     MediaWidget *mediaWidget;
0182     DvbChannelModel *channelModel;
0183     QTreeView *channelView;
0184     DvbEpgModel *epgModel;
0185     XmlTv *xmlTv;
0186     DvbLiveView *liveView;
0187     DvbRecordingModel *recordingModel;
0188     bool reacquireDevice;
0189 
0190     QList<DvbDeviceConfig> deviceConfigs;
0191     bool dvbDumpEnabled;
0192     QMap<QString, QPair<TransmissionType, QString> > sourceMapping;
0193     QStringList sources;
0194 
0195     QDate scanDataDate;
0196     QMap<TransmissionType, QStringList> scanSources;
0197     QMap<QPair<TransmissionType, QString>, QList<DvbTransponder> > scanData;
0198 };
0199 
0200 class DvbDeviceConfig
0201 {
0202 public:
0203     DvbDeviceConfig(const QString &deviceId_, const QString &frontendName_,
0204         DvbDevice *device_);
0205     ~DvbDeviceConfig();
0206 
0207     QString deviceId;
0208     QString frontendName;
0209     DvbDevice *device;
0210     QList<DvbConfig> configs;
0211     int useCount; // -1 means exclusive use
0212     int prioritizedUseCount;
0213     int numberOfTuners;
0214     QString source;
0215     DvbTransponder transponder;
0216 };
0217 
0218 class DvbDeviceConfigUpdate
0219 {
0220 public:
0221     explicit DvbDeviceConfigUpdate(const DvbDeviceConfig *deviceConfig_);
0222     ~DvbDeviceConfigUpdate();
0223 
0224     const DvbDeviceConfig *deviceConfig;
0225     QList<DvbConfig> configs;
0226 };
0227 
0228 #endif /* DVBMANAGER_H */