File indexing completed on 2024-05-12 04:52:09
0001 /* 0002 * dvbchannel.h 0003 * 0004 * Copyright (C) 2007-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 DVBCHANNEL_H 0022 #define DVBCHANNEL_H 0023 0024 #include <QObject> 0025 #include <QMultiHash> 0026 #include "../shareddata.h" 0027 #include "../sqlinterface.h" 0028 #include "dvbtransponder.h" 0029 0030 class DvbChannel : public SharedData, public SqlKey 0031 { 0032 public: 0033 DvbChannel() : number(-1), networkId(-1), transportStreamId(-1), pmtPid(-1), serviceId(-1), 0034 audioPid(-1), hasVideo(false), isScrambled(false) { } 0035 ~DvbChannel() { } 0036 0037 // checks that all variables are ok 0038 // updates 'pmtSectionData' if 'serviceId' is valid 0039 // (else updates 'serviceId' if 'pmtSectionData' is valid) 0040 // 'sqlKey' is ignored 0041 bool validate(); 0042 0043 QString name; 0044 int number; 0045 0046 QString source; 0047 DvbTransponder transponder; 0048 int networkId; // may be -1 (not present), atsc meaning: source id 0049 int transportStreamId; 0050 int pmtPid; 0051 0052 QByteArray pmtSectionData; 0053 int serviceId; 0054 int audioPid; // may be -1 (not present), doesn't have to be present in the pmt section 0055 bool hasVideo; 0056 bool isScrambled; 0057 }; 0058 0059 typedef ExplicitlySharedDataPointer<const DvbChannel> DvbSharedChannel; 0060 Q_DECLARE_TYPEINFO(DvbSharedChannel, Q_MOVABLE_TYPE); 0061 0062 class DvbChannelId 0063 { 0064 public: 0065 explicit DvbChannelId(const DvbChannel *channel_) : channel(channel_) { } 0066 explicit DvbChannelId(const DvbSharedChannel &channel_) : channel(channel_.constData()) { } 0067 ~DvbChannelId() { } 0068 0069 // compares channels by transmission type and 0070 // ( dvb) 'source', 'networkId', 'transportStreamId', 'serviceId' 0071 // (atsc) 'source', 'transponder', 'networkId' 0072 0073 bool operator==(const DvbChannelId &other) const; 0074 0075 bool operator!=(const DvbChannelId &other) const 0076 { 0077 return !(*this == other); 0078 } 0079 0080 friend uint qHash(const DvbChannelId &channel); 0081 0082 private: 0083 const DvbChannel *channel; 0084 }; 0085 0086 class DvbChannelModel : public QObject, private SqlInterface 0087 { 0088 Q_OBJECT 0089 public: 0090 explicit DvbChannelModel(QObject *parent); 0091 ~DvbChannelModel(); 0092 0093 static DvbChannelModel *createSqlModel(QObject *parent); 0094 0095 // channel names and numbers are guaranteed to be unique within this model 0096 0097 QMap<int, DvbSharedChannel> getChannels() const; 0098 DvbSharedChannel findChannelByName(const QString &channelName) const; 0099 bool hasChannelByName(const QString &channelName); 0100 DvbSharedChannel findChannelByNumber(int channelNumber) const; 0101 DvbSharedChannel findChannelById(const DvbChannel &channel) const; 0102 0103 void cloneFrom(DvbChannelModel *other); 0104 void addChannel(DvbChannel &channel); 0105 void updateChannel(DvbSharedChannel channel, DvbChannel &modifiedChannel); 0106 void removeChannel(DvbSharedChannel channel); 0107 bool areInTheSameBunch(DvbSharedChannel channel1, DvbSharedChannel channel2); 0108 void dndMoveChannels(const QList<DvbSharedChannel> &selectedChannels, 0109 int insertBeforeNumber); 0110 void channelFlush(); 0111 0112 signals: 0113 void channelAdded(const DvbSharedChannel &channel); 0114 // if this is the main model, updating doesn't change the channel pointer 0115 // (modifies existing content); otherwise the channel pointer may be updated 0116 void channelAboutToBeUpdated(const DvbSharedChannel &channel); 0117 void channelUpdated(const DvbSharedChannel &channel); 0118 void channelRemoved(const DvbSharedChannel &channel); 0119 0120 private: 0121 void bindToSqlQuery(SqlKey sqlKey, QSqlQuery &query, int index) const override; 0122 bool insertFromSqlQuery(SqlKey sqlKey, const QSqlQuery &query, int index) override; 0123 0124 QString extractBaseName(const QString &name) const; 0125 QString findNextFreeChannelName(const QString &name) const; 0126 int findNextFreeChannelNumber(int number) const; 0127 0128 QMap<QString, DvbSharedChannel> channelNames; 0129 QMap<int, DvbSharedChannel> channelNumbers; 0130 QMultiHash<DvbChannelId, DvbSharedChannel> channelIds; 0131 QMap<SqlKey, DvbSharedChannel> channels; // only used for the sql model 0132 bool hasPendingOperation; 0133 bool isSqlModel; 0134 }; 0135 0136 #endif /* DVBCHANNEL_H */