00001 #ifndef CHANNELSETTINGS_H
00002 #define CHANNELSETTINGS_H
00003
00004 #include <qwidget.h>
00005 #include <qsqldatabase.h>
00006
00007 #include <cstdlib>
00008
00009 #include "settings.h"
00010 #include "mythwidgets.h"
00011 #include "mythwizard.h"
00012 #include "mythcontext.h"
00013 #include "mythdbcon.h"
00014
00015 class ChannelID : public IntegerSetting, public TransientStorage
00016 {
00017 public:
00018 ChannelID(QString _field = "chanid", QString _table = "channel") :
00019 IntegerSetting(this), field(_field), table(_table)
00020 {
00021 setVisible(false);
00022 }
00023
00024 QWidget* configWidget(ConfigurationGroup* cg, QWidget* widget,
00025 const char* widgetName = 0) {
00026 (void)cg; (void)widget; (void)widgetName;
00027 return NULL;
00028 };
00029
00030 void load() { };
00031 void save(QString table)
00032 {
00033 if (intValue() == 0) {
00034 setValue(findHighest());
00035
00036 MSqlQuery query(MSqlQuery::InitCon());
00037
00038 QString querystr = QString("SELECT %1 FROM %2 WHERE %3='%4'")
00039 .arg(field).arg(table).arg(field).arg(getValue());
00040 query.prepare(querystr);
00041
00042 if (!query.exec() && !query.isActive())
00043 MythContext::DBError("ChannelID::save", query);
00044
00045 if (query.size())
00046 return;
00047
00048 querystr = QString("INSERT INTO %1 (%2) VALUES ('%3')")
00049 .arg(table).arg(field).arg(getValue());
00050 query.prepare(querystr);
00051
00052 if (!query.exec() || !query.isActive())
00053 MythContext::DBError("ChannelID::save", query);
00054
00055 if (query.numRowsAffected() != 1)
00056 cerr << "ChannelID:Failed to insert into: " << table << endl;
00057 }
00058 }
00059 void save()
00060 {
00061 save(table);
00062 }
00063
00064 int findHighest(int floor = 1000)
00065 {
00066 int tmpfloor = floor;
00067 MSqlQuery query(MSqlQuery::InitCon());
00068
00069 QString querystr = QString("SELECT %1 FROM %2")
00070 .arg(field).arg(table);
00071 query.prepare(querystr);
00072
00073 if (!query.exec() || !query.isActive())
00074 {
00075 MythContext::DBError("finding highest id", query);
00076 return floor;
00077 }
00078
00079 if (query.size() > 0)
00080 while (query.next())
00081 if (tmpfloor <= query.value(0).toInt())
00082 tmpfloor = query.value(0).toInt() + 1;
00083
00084 return floor<tmpfloor?tmpfloor:floor;
00085 };
00086
00087 const QString& getField(void) const {
00088 return field;
00089 };
00090
00091 protected:
00092 QString field,table;
00093 };
00094
00095 class ChannelDBStorage : public SimpleDBStorage
00096 {
00097 protected:
00098 ChannelDBStorage(Setting *_setting, const ChannelID &_id, QString _name) :
00099 SimpleDBStorage(_setting, "channel", _name), id(_id)
00100 {
00101 _setting->setName(_name);
00102 }
00103
00104 virtual QString setClause(MSqlBindings& bindings);
00105 virtual QString whereClause(MSqlBindings& bindings);
00106
00107 const ChannelID& id;
00108 };
00109
00110 class OnAirGuide;
00111 class XmltvID;
00112
00113 class ChannelOptionsCommon: public VerticalConfigurationGroup
00114 {
00115 Q_OBJECT
00116
00117 public:
00118 ChannelOptionsCommon(const ChannelID &id, uint default_sourceid);
00119 void load(void);
00120
00121 public slots:
00122 void onAirGuideChanged(bool);
00123 void sourceChanged(const QString&);
00124
00125 protected:
00126 OnAirGuide *onairguide;
00127 XmltvID *xmltvID;
00128 };
00129
00130 class ChannelOptionsFilters: public VerticalConfigurationGroup {
00131 public:
00132 ChannelOptionsFilters(const ChannelID& id);
00133 };
00134
00135 class ChannelOptionsV4L: public VerticalConfigurationGroup {
00136 public:
00137 ChannelOptionsV4L(const ChannelID& id);
00138 };
00139
00140 class MPUBLIC ChannelTVFormat : public ComboBoxSetting, public ChannelDBStorage
00141 {
00142 public:
00143 ChannelTVFormat(const ChannelID &id);
00144
00145 static QStringList GetFormats(void);
00146 };
00147
00148 #endif //CHANNELEDITOR_H