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