MythTV  master
channelsettings.h
Go to the documentation of this file.
1 #ifndef CHANNELSETTINGS_H
2 #define CHANNELSETTINGS_H
3 
4 // C++
5 #include <cstdlib>
6 #include <utility>
7 #include <vector>
8 
9 // Qt
10 #include <QString>
11 
12 // MythTV
13 #include "mythtvexp.h"
14 #include "standardsettings.h"
15 #include "mythdb.h"
16 #include "mythlogging.h"
17 
18 class QWidget;
19 
20 class ChannelID : public GroupSetting
21 {
22  public:
23  explicit ChannelID(QString field = "chanid",
24  QString table = "channel") :
25  m_field(std::move(field)), m_table(std::move(table))
26  {
27  setVisible(false);
28  }
29 
30  void Save(void) override // StandardSetting
31  {
32  if (getValue().toInt() == 0) {
34 
36 
37  QString querystr = QString("SELECT %1 FROM %2 WHERE %3='%4'")
38  .arg(m_field).arg(m_table).arg(m_field).arg(getValue());
39  query.prepare(querystr);
40 
41  if (!query.exec() && !query.isActive())
42  MythDB::DBError("ChannelID::save", query);
43 
44  if (query.size())
45  return;
46 
47  querystr = QString("INSERT INTO %1 (%2) VALUES ('%3')")
48  .arg(m_table).arg(m_field).arg(getValue());
49  query.prepare(querystr);
50 
51  if (!query.exec() || !query.isActive())
52  MythDB::DBError("ChannelID::save", query);
53 
54  if (query.numRowsAffected() != 1)
55  {
56  LOG(VB_GENERAL, LOG_ERR, QString("ChannelID, Error: ") +
57  QString("Failed to insert into: %1").arg(m_table));
58  }
59  }
60  }
61 
62  int findHighest(int floor = 1000)
63  {
64  int tmpfloor = floor;
66 
67  QString querystr = QString("SELECT %1 FROM %2")
68  .arg(m_field).arg(m_table);
69  query.prepare(querystr);
70 
71  if (!query.exec() || !query.isActive())
72  {
73  MythDB::DBError("finding highest id", query);
74  return floor;
75  }
76 
77  if (query.size() > 0)
78  {
79  while (query.next())
80  if (tmpfloor <= query.value(0).toInt())
81  tmpfloor = query.value(0).toInt() + 1;
82  }
83  return floor<tmpfloor?tmpfloor:floor;
84  };
85 
86  const QString& getField(void) const {
87  return m_field;
88  };
89 
90 protected:
91  QString m_field;
92  QString m_table;
93 };
94 
96 {
97  public:
98  ChannelDBStorage(StorageUser *_user, const ChannelID &_id, const QString& _name) :
99  SimpleDBStorage(_user, "channel", _name), m_id(_id) { }
100 
101  QString GetSetClause(MSqlBindings &bindings) const override; // SimpleDBStorage
102  QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
103 
104  const ChannelID& m_id;
105 };
106 
107 class OnAirGuide;
108 class XmltvID;
109 class Freqid;
110 class TransportID_CO;
111 class Frequency_CO;
112 
114 {
115  Q_OBJECT
116 
117  public:
119  uint default_sourceid, bool add_freqid);
120 
121  public slots:
122  static void onAirGuideChanged(bool fValue);
123  void sourceChanged(const QString &sourceid);
124 
125  protected:
126  OnAirGuide *m_onAirGuide {nullptr};
127  XmltvID *m_xmltvID {nullptr};
128  Freqid *m_freqId {nullptr};
129  TransportID_CO *m_transportId {nullptr};
130  Frequency_CO *m_frequency {nullptr};
131 };
132 
134 {
135  public:
136  explicit ChannelOptionsFilters(const ChannelID& id);
137 };
138 
140 {
141  public:
142  explicit ChannelOptionsV4L(const ChannelID& id);
143 };
144 
146 {
147  public:
148  explicit ChannelOptionsRawTS(const ChannelID &id);
149 
150  void Load(void) override; // StandardSetting
151  void Save(void) override; // StandardSetting
152  virtual void Save(const QString& /*destination*/) { Save(); }
153 
154  private:
155  const ChannelID &m_cid;
156 
157  std::vector<TransTextEditSetting*> m_pids;
158  std::vector<TransMythUIComboBoxSetting*> m_sids;
159  std::vector<TransMythUICheckBoxSetting*> m_pcrs;
160 
161  static const uint kMaxPIDs = 10;
162 };
163 
165  public MythUIComboBoxSetting
166 {
167  public:
168  explicit ChannelTVFormat(const ChannelID &id);
169 
170  static QStringList GetFormats(void);
171 };
172 
173 #endif //CHANNELEDITOR_H
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
ChannelID(QString field="chanid", QString table="channel")
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
virtual void Load(void)
unsigned int slots[4]
Definition: element.cpp:38
const QString & getField(void) const
QString m_field
int size(void) const
Definition: mythdbcon.h:203
ChannelDBStorage(StorageUser *_user, const ChannelID &_id, const QString &_name)
QString m_table
const ChannelID & m_cid
std::vector< TransTextEditSetting * > m_pids
virtual QString getValue(void) const
QVariant value(int i) const
Definition: mythdbcon.h:198
std::vector< TransMythUIComboBoxSetting * > m_sids
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:98
MSqlQuery query(MSqlQuery::InitCon())
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QString GetSetClause(MSqlBindings &bindings) const override
bool isActive(void) const
Definition: mythdbcon.h:204
virtual void Save(const QString &)
int findHighest(int floor=1000)
unsigned int uint
Definition: compat.h:140
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
void Save(void) override
QString GetWhereClause(MSqlBindings &bindings) const override
virtual void Save(void)
void setVisible(bool visible)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
const ChannelID & m_id
int numRowsAffected() const
Definition: mythdbcon.h:206
std::vector< TransMythUICheckBoxSetting * > m_pcrs
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
virtual void setValue(const QString &newValue)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23