/
channelsettings.h
191 lines (150 loc) · 4.88 KB
/
channelsettings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#ifndef CHANNELSETTINGS_H
#define CHANNELSETTINGS_H
// C++
#include <cstdlib>
#include <utility>
#include <vector>
// Qt
#include <QString>
// MythTV
#include "libmyth/standardsettings.h"
#include "libmythbase/mythdb.h"
#include "libmythbase/mythlogging.h"
#include "mythtvexp.h"
class QWidget;
class ChannelID : public GroupSetting
{
public:
explicit ChannelID(QString field = "chanid",
QString table = "channel") :
m_field(std::move(field)), m_table(std::move(table))
{
setVisible(false);
}
void Save(void) override // StandardSetting
{
if (getValue().toInt() == 0) {
setValue(findHighest());
MSqlQuery query(MSqlQuery::InitCon());
QString querystr = QString("SELECT %1 FROM %2 WHERE %3='%4'")
.arg(m_field, m_table, m_field, getValue());
query.prepare(querystr);
if (!query.exec() && !query.isActive())
MythDB::DBError("ChannelID::save", query);
if (query.size())
return;
querystr = QString("INSERT INTO %1 (%2) VALUES ('%3')")
.arg(m_table, m_field, getValue());
query.prepare(querystr);
if (!query.exec() || !query.isActive())
MythDB::DBError("ChannelID::save", query);
if (query.numRowsAffected() != 1)
{
LOG(VB_GENERAL, LOG_ERR, QString("ChannelID, Error: ") +
QString("Failed to insert into: %1").arg(m_table));
}
}
}
int findHighest(int floor = 1000)
{
int tmpfloor = floor;
MSqlQuery query(MSqlQuery::InitCon());
QString querystr = QString("SELECT %1 FROM %2")
.arg(m_field, m_table);
query.prepare(querystr);
if (!query.exec() || !query.isActive())
{
MythDB::DBError("finding highest id", query);
return floor;
}
if (query.size() > 0)
{
while (query.next())
if (tmpfloor <= query.value(0).toInt())
tmpfloor = query.value(0).toInt() + 1;
}
return floor<tmpfloor?tmpfloor:floor;
};
const QString& getField(void) const {
return m_field;
};
protected:
QString m_field;
QString m_table;
};
class ChannelDBStorage : public SimpleDBStorage
{
public:
ChannelDBStorage(StorageUser *_user, const ChannelID &_id, const QString& _name) :
SimpleDBStorage(_user, "channel", _name), m_id(_id) { }
QString GetSetClause(MSqlBindings &bindings) const override; // SimpleDBStorage
QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
const ChannelID& m_id;
};
class IPTVChannelDBStorage : public SimpleDBStorage
{
public:
IPTVChannelDBStorage(StorageUser *_user, const ChannelID &_id, const QString& _name) :
SimpleDBStorage(_user, "iptv_channel", _name), m_id(_id) { }
QString GetSetClause(MSqlBindings &bindings) const override; // SimpleDBStorage
QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
const ChannelID& m_id;
};
class OnAirGuide;
class XmltvID;
class Freqid;
class TransportID_CO;
class Frequency_CO;
class MTV_PUBLIC ChannelOptionsCommon: public GroupSetting
{
Q_OBJECT
public:
ChannelOptionsCommon(const ChannelID &id,
uint default_sourceid, bool add_freqid);
public slots:
static void onAirGuideChanged(bool fValue);
void sourceChanged(const QString &sourceid);
protected:
OnAirGuide *m_onAirGuide {nullptr};
XmltvID *m_xmltvID {nullptr};
Freqid *m_freqId {nullptr};
TransportID_CO *m_transportId {nullptr};
Frequency_CO *m_frequency {nullptr};
};
class MTV_PUBLIC ChannelOptionsFilters: public GroupSetting
{
public:
explicit ChannelOptionsFilters(const ChannelID& id);
};
class MTV_PUBLIC ChannelOptionsIPTV: public GroupSetting
{
public:
explicit ChannelOptionsIPTV(const ChannelID& id);
};
class MTV_PUBLIC ChannelOptionsV4L: public GroupSetting
{
public:
explicit ChannelOptionsV4L(const ChannelID& id);
};
class MTV_PUBLIC ChannelOptionsRawTS: public GroupSetting
{
public:
explicit ChannelOptionsRawTS(const ChannelID &id);
void Load(void) override; // StandardSetting
void Save(void) override; // StandardSetting
virtual void Save(const QString& /*destination*/) { Save(); }
private:
const ChannelID &m_cid;
std::vector<TransTextEditSetting*> m_pids;
std::vector<TransMythUIComboBoxSetting*> m_sids;
std::vector<TransMythUICheckBoxSetting*> m_pcrs;
static const uint kMaxPIDs = 10;
};
class MTV_PUBLIC ChannelTVFormat :
public MythUIComboBoxSetting
{
public:
explicit ChannelTVFormat(const ChannelID &id);
static QStringList GetFormats(void);
};
#endif //CHANNELEDITOR_H