MythTV  0.26-pre
channelsettings.h
Go to the documentation of this file.
00001 #ifndef CHANNELSETTINGS_H
00002 #define CHANNELSETTINGS_H
00003 
00004 // ANSI C
00005 #include <cstdlib>
00006 
00007 // Qt
00008 #include <QString>
00009 
00010 // MythTV
00011 #include "mythtvexp.h"
00012 #include "settings.h"
00013 #include "mythwidgets.h"
00014 #include "mythwizard.h"
00015 #include "mythdb.h"
00016 #include "mythlogging.h"
00017 
00018 class QWidget;
00019 
00020 class ChannelID : public IntegerSetting, public TransientStorage
00021 {
00022   public:
00023     ChannelID(QString _field = "chanid", QString _table = "channel") :
00024         IntegerSetting(this), field(_field), table(_table)
00025     {
00026         setVisible(false);
00027     }
00028 
00029     QWidget* configWidget(ConfigurationGroup* cg, QWidget* widget,
00030                           const char* widgetName = 0) {
00031         (void)cg; (void)widget; (void)widgetName;
00032         return NULL;
00033     };
00034 
00035     void Load() { };
00036     void Save(QString table)
00037     {
00038         if (intValue() == 0) {
00039             setValue(findHighest());
00040 
00041             MSqlQuery query(MSqlQuery::InitCon());
00042 
00043             QString querystr = QString("SELECT %1 FROM %2 WHERE %3='%4'")
00044                              .arg(field).arg(table).arg(field).arg(getValue());
00045             query.prepare(querystr);
00046 
00047             if (!query.exec() && !query.isActive())
00048                 MythDB::DBError("ChannelID::save", query);
00049 
00050             if (query.size())
00051                 return;
00052 
00053             querystr = QString("INSERT INTO %1 (%2) VALUES ('%3')")
00054                              .arg(table).arg(field).arg(getValue());
00055             query.prepare(querystr);
00056 
00057             if (!query.exec() || !query.isActive())
00058                 MythDB::DBError("ChannelID::save", query);
00059 
00060             if (query.numRowsAffected() != 1)
00061             {
00062                 LOG(VB_GENERAL, LOG_ERR, QString("ChannelID, Error: ") +
00063                         QString("Failed to insert into: %1").arg(table));
00064             }
00065         }
00066     }
00067     void Save(void)
00068     {
00069         Save(table);
00070     }
00071 
00072     int findHighest(int floor = 1000)
00073     {
00074         int tmpfloor = floor;
00075         MSqlQuery query(MSqlQuery::InitCon());
00076 
00077         QString querystr = QString("SELECT %1 FROM %2")
00078                                 .arg(field).arg(table);
00079         query.prepare(querystr);
00080 
00081         if (!query.exec() || !query.isActive())
00082         {
00083             MythDB::DBError("finding highest id", query);
00084             return floor;
00085         }
00086 
00087         if (query.size() > 0)
00088             while (query.next())
00089                 if (tmpfloor <= query.value(0).toInt())
00090                     tmpfloor = query.value(0).toInt() + 1;
00091 
00092         return floor<tmpfloor?tmpfloor:floor;
00093     };
00094 
00095     const QString& getField(void) const {
00096         return field;
00097     };
00098 
00099 protected:
00100     QString field,table;
00101 };
00102 
00103 class ChannelDBStorage : public SimpleDBStorage
00104 {
00105   protected:
00106     ChannelDBStorage(StorageUser *_user, const ChannelID &_id, QString _name) :
00107         SimpleDBStorage(_user, "channel", _name), id(_id) { }
00108 
00109     virtual QString GetSetClause(MSqlBindings &bindings) const;
00110     virtual QString GetWhereClause(MSqlBindings &bindings) const;
00111 
00112     const ChannelID& id;
00113 };
00114 
00115 class OnAirGuide;
00116 class XmltvID;
00117 
00118 class MTV_PUBLIC ChannelOptionsCommon: public VerticalConfigurationGroup
00119 {
00120     Q_OBJECT
00121 
00122   public:
00123     ChannelOptionsCommon(const ChannelID &id, uint default_sourceid);
00124     void Load(void);
00125 
00126   public slots:
00127     void onAirGuideChanged(bool);
00128     void sourceChanged(const QString&);
00129 
00130   protected:
00131     OnAirGuide *onairguide;
00132     XmltvID    *xmltvID;
00133 };
00134 
00135 class MTV_PUBLIC ChannelOptionsFilters: public VerticalConfigurationGroup
00136 {
00137   public:
00138     ChannelOptionsFilters(const ChannelID& id);
00139 };
00140 
00141 class MTV_PUBLIC ChannelOptionsV4L: public VerticalConfigurationGroup
00142 {
00143   public:
00144     ChannelOptionsV4L(const ChannelID& id);
00145 };
00146 
00147 class MTV_PUBLIC ChannelOptionsRawTS: public VerticalConfigurationGroup
00148 {
00149   public:
00150     ChannelOptionsRawTS(const ChannelID &id);
00151 
00152     virtual void Load(void);
00153     virtual void Save(void);
00154 
00155   private:
00156     const ChannelID &cid;
00157 
00158     vector<TransLineEditSetting*> pids;
00159     vector<TransComboBoxSetting*> sids;
00160     vector<TransCheckBoxSetting*> pcrs;
00161 
00162     static const uint kMaxPIDs = 10;
00163 };
00164 
00165 class MTV_PUBLIC ChannelTVFormat :
00166     public ComboBoxSetting, public ChannelDBStorage
00167 {
00168   public:
00169     ChannelTVFormat(const ChannelID &id);
00170 
00171     static QStringList GetFormats(void);
00172 };
00173 
00174 #endif //CHANNELEDITOR_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends