MythTV  0.26-pre
dbchannelinfo.cpp
Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 
00003 // Qt headers
00004 #include <QFile>
00005 #include <QDir>
00006 #include <QFileInfo>
00007 #include <QImage>
00008 #include <QUrl>
00009 
00010 // MythTV headers
00011 #include "dbchannelinfo.h"
00012 #include "mythcorecontext.h"
00013 #include "mythdb.h"
00014 #include "mythdirs.h"
00015 #include "mpegstreamdata.h" // for CryptStatus
00016 #include "remotefile.h"
00017 #include "channelgroup.h"
00018 #include "sourceutil.h"
00019 
00020 DBChannel::DBChannel(const DBChannel &other) :
00021     channum(other.channum),       callsign(other.callsign),
00022     name(other.name),             icon(other.icon),
00023     chanid(other.chanid),
00024     major_chan(other.major_chan), minor_chan(other.minor_chan),
00025     mplexid((other.mplexid == 32767) ? 0 : other.mplexid),
00026     sourceid(other.sourceid),     cardid (other.cardid),
00027     grpid(other.grpid),           visible(other.visible)
00028 {
00029 }
00030 
00031 DBChannel::DBChannel(
00032     const QString &_channum, const QString &_callsign,
00033     uint _chanid, uint _major_chan, uint _minor_chan,
00034     uint _mplexid, bool _visible,
00035     const QString &_name, const QString &_icon,
00036     uint _sourceid, uint _cardid, uint _grpid) :
00037     channum(_channum),
00038     callsign(_callsign),
00039     name(_name), icon((_icon == "none") ? QString() : _icon),
00040     chanid(_chanid),
00041     major_chan(_major_chan), minor_chan(_minor_chan),
00042     mplexid((_mplexid == 32767) ? 0 : _mplexid),
00043     sourceid(_sourceid), cardid(_cardid), grpid(_grpid),
00044     visible(_visible)
00045 {
00046 }
00047 
00048 DBChannel &DBChannel::operator=(const DBChannel &other)
00049 {
00050     channum    = other.channum;
00051     callsign   = other.callsign;
00052     name       = other.name;
00053     icon       = other.icon;
00054     chanid     = other.chanid;
00055     major_chan = other.major_chan;
00056     minor_chan = other.minor_chan;
00057     mplexid    = (other.mplexid == 32767) ? 0 : other.mplexid;
00058     sourceid   = other.sourceid;
00059     cardid     = other.cardid;
00060     grpid      = other.grpid;
00061     visible    = other.visible;
00062 
00063     return *this;
00064 }
00065 
00066 void DBChannel::ToMap(InfoMap& infoMap) const
00067 {
00068     infoMap["channelnumber"] = channum;
00069     infoMap["callsign"] = callsign;
00070     infoMap["channelname"] = name;
00071     infoMap["channeliconpath"] = icon;
00072     infoMap["channelid"] = QString().setNum(chanid);
00073     infoMap["majorchan"] = QString().setNum(major_chan);
00074     infoMap["minorchan"] = QString().setNum(minor_chan);
00075     infoMap["mplexid"] = QString().setNum(mplexid);
00076     infoMap["channelvisible"] = visible ? QObject::tr("Yes") : QObject::tr("No");
00077 
00078     infoMap["channelgroupname"] = ChannelGroup::GetChannelGroupName(grpid);
00079     infoMap["channelsourcename"] = SourceUtil::GetSourceName(sourceid);
00080 }
00081 
00082 QString DBChannel::GetFormatted(const ChannelFormat &format) const
00083 {
00084     QString tmp;
00085 
00086     if (format & kChannelLong)
00087         tmp = gCoreContext->GetSetting("LongChannelFormat", "<num> <name>");
00088     else // kChannelShort
00089         tmp = gCoreContext->GetSetting("ChannelFormat", "<num> <sign>");
00090 
00091 
00092     if (tmp.isEmpty())
00093         return QString();
00094 
00095     tmp.replace("<num>",  channum);
00096     tmp.replace("<sign>", callsign);
00097     tmp.replace("<name>", name);
00098 
00099     return tmp;
00100 }
00101 
00104 
00105 QString ChannelInfo::GetFormatted(const ChannelFormat &format) const
00106 {
00107     QString tmp;
00108 
00109     if (format & kChannelLong)
00110         tmp = gCoreContext->GetSetting("LongChannelFormat", "<num> <name>");
00111     else // kChannelShort
00112         tmp = gCoreContext->GetSetting("ChannelFormat", "<num> <sign>");
00113 
00114 
00115     if (tmp.isEmpty())
00116         return QString();
00117 
00118     tmp.replace("<num>",  chanstr);
00119     tmp.replace("<sign>", callsign);
00120     tmp.replace("<name>", channame);
00121 
00122     return tmp;
00123 }
00124 
00125 void ChannelInfo::ToMap(InfoMap& infoMap) const
00126 {
00127     infoMap["callsign"] = callsign;
00128     infoMap["channeliconpath"] = iconpath;
00129     infoMap["chanstr"] = chanstr;
00130     infoMap["channelname"] = channame;
00131     infoMap["channelid"] = QString().setNum(chanid);
00132     infoMap["channelsourcename"] = sourcename;
00133     infoMap["channelrecpriority"] = recpriority;
00134 }
00135 
00138 
00139 bool ChannelInsertInfo::SaveScan(uint scanid, uint transportid) const
00140 {
00141     MSqlQuery query(MSqlQuery::InitCon());
00142     query.prepare(
00143         "INSERT INTO channelscan_channel "
00144         " (  scanid,             transportid,                            "
00145         "    mplex_id,           source_id,          channel_id,         "
00146         "    callsign,           service_name,       chan_num,           "
00147         "    service_id,         atsc_major_channel, atsc_minor_channel, "
00148         "    use_on_air_guide,   hidden,             hidden_in_guide,    "
00149         "    freqid,             icon,               tvformat,           "
00150         "    xmltvid,            pat_tsid,           vct_tsid,           "
00151         "    vct_chan_tsid,      sdt_tsid,           orig_netid,         "
00152         "    netid,              si_standard,        in_channels_conf,   "
00153         "    in_pat,             in_pmt,             in_vct,             "
00154         "    in_nit,             in_sdt,             is_encrypted,       "
00155         "    is_data_service,    is_audio_service,   is_opencable,       "
00156         "    could_be_opencable, decryption_status,  default_authority   "
00157         " )  "
00158         "VALUES "
00159         " ( :SCANID,            :TRANSPORTID,                            "
00160         "   :MPLEX_ID,          :SOURCE_ID,         :CHANNEL_ID,         "
00161         "   :CALLSIGN,          :SERVICE_NAME,      :CHAN_NUM,           "
00162         "   :SERVICE_ID,        :ATSC_MAJOR_CHANNEL,:ATSC_MINOR_CHANNEL, "
00163         "   :USE_ON_AIR_GUIDE,  :HIDDEN,            :HIDDEN_IN_GUIDE,    "
00164         "   :FREQID,            :ICON,              :TVFORMAT,           "
00165         "   :XMLTVID,           :PAT_TSID,          :VCT_TSID,           "
00166         "   :VCT_CHAN_TSID,     :SDT_TSID,          :ORIG_NETID,         "
00167         "   :NETID,             :SI_STANDARD,       :IN_CHANNELS_CONF,   "
00168         "   :IN_PAT,            :IN_PMT,            :IN_VCT,             "
00169         "   :IN_NIT,            :IN_SDT,            :IS_ENCRYPTED,       "
00170         "   :IS_DATA_SERVICE,   :IS_AUDIO_SERVICE,  :IS_OPEBCABLE,       "
00171         "   :COULD_BE_OPENCABLE,:DECRYPTION_STATUS, :DEFAULT_AUTHORITY   "
00172         " );");
00173 
00174     query.bindValue(":SCANID", scanid);
00175     query.bindValue(":TRANSPORTID", transportid);
00176     query.bindValue(":MPLEX_ID", db_mplexid);
00177     query.bindValue(":SOURCE_ID", source_id);
00178     query.bindValue(":CHANNEL_ID", channel_id);
00179     query.bindValue(":CALLSIGN", callsign);
00180     query.bindValue(":SERVICE_NAME", service_name);
00181     query.bindValue(":CHAN_NUM", chan_num);
00182     query.bindValue(":SERVICE_ID", service_id);
00183     query.bindValue(":ATSC_MAJOR_CHANNEL", atsc_major_channel);
00184     query.bindValue(":ATSC_MINOR_CHANNEL", atsc_minor_channel);
00185     query.bindValue(":USE_ON_AIR_GUIDE", use_on_air_guide);
00186     query.bindValue(":HIDDEN", hidden);
00187     query.bindValue(":HIDDEN_IN_GUIDE", hidden_in_guide);
00188     query.bindValue(":FREQID", freqid);
00189     query.bindValue(":ICON", icon);
00190     query.bindValue(":TVFORMAT", format);
00191     query.bindValue(":XMLTVID", xmltvid);
00192     query.bindValue(":PAT_TSID", pat_tsid);
00193     query.bindValue(":VCT_TSID", vct_tsid);
00194     query.bindValue(":VCT_CHAN_TSID", vct_chan_tsid);
00195     query.bindValue(":SDT_TSID", sdt_tsid);
00196     query.bindValue(":ORIG_NETID",  orig_netid);
00197     query.bindValue(":NETID", netid);
00198     query.bindValue(":SI_STANDARD", si_standard);
00199     query.bindValue(":IN_CHANNELS_CONF", in_channels_conf);
00200     query.bindValue(":IN_PAT", in_pat);
00201     query.bindValue(":IN_PMT", in_pmt);
00202     query.bindValue(":IN_VCT", in_vct);
00203     query.bindValue(":IN_NIT", in_nit);
00204     query.bindValue(":IN_SDT", in_sdt);
00205     query.bindValue(":IS_ENCRYPTED", is_encrypted);
00206     query.bindValue(":IS_DATA_SERVICE", is_data_service);
00207     query.bindValue(":IS_AUDIO_SERVICE", is_audio_service);
00208     query.bindValue(":IS_OPEBCABLE", is_opencable);
00209     query.bindValue(":COULD_BE_OPENCABLE", could_be_opencable);
00210     query.bindValue(":DECRYPTION_STATUS", decryption_status);
00211     query.bindValue(":DEFAULT_AUTHORITY", default_authority);
00212 
00213     if (!query.exec())
00214     {
00215         MythDB::DBError("ChannelInsertInfo SaveScan 1", query);
00216         return false;
00217     }
00218 
00219     return true;
00220 }
00221 
00222 ChannelInsertInfo::ChannelInsertInfo(
00223     uint    _db_mplexid,         uint    _source_id,
00224     uint    _channel_id,         QString _callsign,
00225     QString _service_name,       QString _chan_num,
00226     uint    _service_id,
00227     uint    _atsc_major_channel, uint    _atsc_minor_channel,
00228     bool    _use_on_air_guide,   bool    _hidden,
00229     bool    _hidden_in_guide,
00230     QString _freqid,             QString _icon,
00231     QString _format,             QString _xmltvid,
00232     uint    _pat_tsid,           uint    _vct_tsid,
00233     uint    _vct_chan_tsid,      uint    _sdt_tsid,
00234     uint    _orig_netid,         uint    _netid,
00235     QString _si_standard,
00236     bool    _in_channels_conf,   bool    _in_pat,
00237     bool    _in_pmt,             bool    _in_vct,
00238     bool    _in_nit,             bool    _in_sdt,
00239     bool    _is_encrypted,       bool    _is_data_service,
00240     bool    _is_audio_service,   bool    _is_opencable,
00241     bool    _could_be_opencable, int     _decryption_status,
00242     QString _default_authority) :
00243     db_mplexid(_db_mplexid),
00244     source_id(_source_id),
00245     channel_id(_channel_id),
00246     callsign(_callsign),
00247     service_name(_service_name),
00248     chan_num(_chan_num),
00249     service_id(_service_id),
00250     atsc_major_channel(_atsc_major_channel),
00251     atsc_minor_channel(_atsc_minor_channel),
00252     use_on_air_guide(_use_on_air_guide),
00253     hidden(_hidden),
00254     hidden_in_guide(_hidden_in_guide),
00255     freqid(_freqid),
00256     icon(_icon),
00257     format(_format),
00258     xmltvid(_xmltvid),
00259     default_authority(_default_authority),
00260     pat_tsid(_pat_tsid),
00261     vct_tsid(_vct_tsid),
00262     vct_chan_tsid(_vct_chan_tsid),
00263     sdt_tsid(_sdt_tsid),
00264     orig_netid(_orig_netid),
00265     netid(_netid),
00266     si_standard(_si_standard),
00267     in_channels_conf(_in_channels_conf),
00268     in_pat(_in_pat),
00269     in_pmt(_in_pmt),
00270     in_vct(_in_vct),
00271     in_nit(_in_nit),
00272     in_sdt(_in_sdt),
00273     is_encrypted(_is_encrypted),
00274     is_data_service(_is_data_service),
00275     is_audio_service(_is_audio_service),
00276     is_opencable(_is_opencable),
00277     could_be_opencable(_could_be_opencable),
00278     decryption_status(_decryption_status)
00279 {
00280     callsign.detach();
00281     service_name.detach();
00282     chan_num.detach();
00283     freqid.detach();
00284     icon.detach();
00285     format.detach();
00286     xmltvid.detach();
00287     default_authority.detach();
00288     si_standard.detach();
00289 }
00290 
00291 ChannelInsertInfo &ChannelInsertInfo::operator=(
00292     const ChannelInsertInfo &other)
00293 {
00294     db_mplexid         = other.db_mplexid;
00295     source_id          = other.source_id;
00296     channel_id         = other.channel_id;
00297     callsign           = other.callsign;     callsign.detach();
00298     service_name       = other.service_name; service_name.detach();
00299     chan_num           = other.chan_num;     chan_num.detach();
00300     service_id         = other.service_id;
00301     atsc_major_channel = other.atsc_major_channel;
00302     atsc_minor_channel = other.atsc_minor_channel;
00303     use_on_air_guide   = other.use_on_air_guide;
00304     hidden             = other.hidden;
00305     hidden_in_guide    = other.hidden_in_guide;
00306     freqid             = other.freqid;      freqid.detach();
00307     icon               = other.icon;        icon.detach();
00308     format             = other.format;      format.detach();
00309     xmltvid            = other.xmltvid;     xmltvid.detach();
00310     default_authority  = other.default_authority; default_authority.detach();
00311 
00312     // non-DB info
00313     pat_tsid           = other.pat_tsid;
00314     vct_tsid           = other.vct_tsid;
00315     vct_chan_tsid      = other.vct_chan_tsid;
00316     sdt_tsid           = other.sdt_tsid;
00317     orig_netid         = other.orig_netid;
00318     netid              = other.netid;
00319     si_standard        = other.si_standard; si_standard.detach();
00320     in_channels_conf   = other.in_channels_conf;
00321     in_pat             = other.in_pat;
00322     in_pmt             = other.in_pmt;
00323     in_vct             = other.in_vct;
00324     in_nit             = other.in_nit;
00325     in_sdt             = other.in_sdt;
00326     is_encrypted       = other.is_encrypted;
00327     is_data_service    = other.is_data_service;
00328     is_audio_service   = other.is_audio_service;
00329     is_opencable       = other.is_opencable;
00330     could_be_opencable = other.could_be_opencable;
00331     decryption_status  = other.decryption_status;
00332 
00333     return *this;
00334 }
00335 
00336 void ChannelInsertInfo::ImportExtraInfo(const ChannelInsertInfo &other)
00337 {
00338     if (other.db_mplexid && !db_mplexid)
00339         db_mplexid         = other.db_mplexid;
00340     if (other.source_id && !source_id)
00341         source_id          = other.source_id;
00342     if (other.channel_id && !channel_id)
00343         channel_id         = other.channel_id;
00344     if (!other.callsign.isEmpty() && callsign.isEmpty())
00345     {
00346         callsign           = other.callsign;     callsign.detach();
00347     }
00348     if (!other.service_name.isEmpty() && service_name.isEmpty())
00349     {
00350         service_name       = other.service_name; service_name.detach();
00351     }
00352     if (!other.chan_num.isEmpty() &&
00353         ((chan_num.isEmpty() || chan_num == "0")))
00354     {
00355         chan_num           = other.chan_num;     chan_num.detach();
00356     }
00357     if (other.service_id && !service_id)
00358         service_id         = other.service_id;
00359     if (other.atsc_major_channel && !atsc_major_channel)
00360         atsc_major_channel = other.atsc_major_channel;
00361     if (other.atsc_minor_channel && !atsc_minor_channel)
00362         atsc_minor_channel = other.atsc_minor_channel;
00363     //use_on_air_guide   = other.use_on_air_guide;
00364     //hidden             = other.hidden;
00365     //hidden_in_guide    = other.hidden_in_guide;
00366     if (!other.freqid.isEmpty() && freqid.isEmpty())
00367     {
00368         freqid             = other.freqid;      freqid.detach();
00369     }
00370     if (!other.icon.isEmpty() && icon.isEmpty())
00371     {
00372         icon               = other.icon;        icon.detach();
00373     }
00374     if (!other.format.isEmpty() && format.isEmpty())
00375     {
00376         format             = other.format;      format.detach();
00377     }
00378     if (!other.xmltvid.isEmpty() && xmltvid.isEmpty())
00379     {
00380         xmltvid            = other.xmltvid;     xmltvid.detach();
00381     }
00382     if (!other.default_authority.isEmpty() && default_authority.isEmpty())
00383     {
00384         default_authority  = other.default_authority; default_authority.detach();
00385     }
00386     // non-DB info
00387     if (other.pat_tsid && !pat_tsid)
00388         pat_tsid           = other.pat_tsid;
00389     if (other.vct_tsid && !vct_tsid)
00390         vct_tsid           = other.vct_tsid;
00391     if (other.vct_chan_tsid && !vct_chan_tsid)
00392         vct_chan_tsid      = other.vct_chan_tsid;
00393     if (other.sdt_tsid && !sdt_tsid)
00394         sdt_tsid           = other.sdt_tsid;
00395     if (other.orig_netid && !orig_netid)
00396         orig_netid         = other.orig_netid;
00397     if (other.netid && !netid)
00398         netid              = other.netid;
00399     if (!other.si_standard.isEmpty() && si_standard.isEmpty())
00400     {
00401         si_standard        = other.si_standard; si_standard.detach();
00402     }
00403     if (other.in_channels_conf && !in_channels_conf)
00404         in_channels_conf   = other.in_channels_conf;
00405     if (other.in_pat && !in_pat)
00406         in_pat             = other.in_pat;
00407     if (other.in_pmt && !in_pmt)
00408         in_pmt             = other.in_pmt;
00409     if (other.in_vct && !in_vct)
00410         in_vct             = other.in_vct;
00411     if (other.in_nit && !in_nit)
00412         in_nit             = other.in_nit;
00413     if (other.in_sdt && !in_sdt)
00414         in_sdt             = other.in_sdt;
00415     if (other.in_pat && !in_pat)
00416         is_encrypted       = other.is_encrypted;
00417     if (other.is_data_service && !is_data_service)
00418         is_data_service    = other.is_data_service;
00419     if (other.is_audio_service && !is_audio_service)
00420         is_audio_service   = other.is_audio_service;
00421     if (other.is_opencable && !is_opencable)
00422         is_opencable       = other.is_opencable;
00423     if (other.could_be_opencable && !could_be_opencable)
00424         could_be_opencable = other.could_be_opencable;
00425     if (kEncUnknown == decryption_status)
00426         decryption_status  = other.decryption_status;
00427 }
00428 
00429 bool ChannelInsertInfo::IsSameChannel(const ChannelInsertInfo &other) const
00430 {
00431     if (atsc_major_channel &&
00432         (atsc_major_channel == other.atsc_major_channel) &&
00433         (atsc_minor_channel == other.atsc_minor_channel))
00434     {
00435         return true;
00436     }
00437 
00438     if ((orig_netid == other.orig_netid) &&
00439         (sdt_tsid == other.sdt_tsid)     &&
00440         (service_id == other.service_id))
00441         return true;
00442 
00443     if (!orig_netid && !other.orig_netid &&
00444         (pat_tsid == other.pat_tsid) && (service_id == other.service_id))
00445         return true;
00446 
00447     return false;
00448 }
00449 
00450 /* vim: set expandtab tabstop=4 shiftwidth=4: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends