/
channelsettings.cpp
690 lines (580 loc) · 20.7 KB
/
channelsettings.cpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
// C/C++ headers
#include <utility>
// Qt headers
#include <QCoreApplication>
#include <QFile>
#include <QWidget>
// MythTV headers
#include "channelsettings.h"
#include "channelutil.h"
#include "programinfo.h" // for COMM_DETECT*, GetPreferredSkipTypeCombinations()
#include "mpegtables.h"
#include "mythdirs.h"
#include "cardutil.h"
QString ChannelDBStorage::GetWhereClause(MSqlBindings &bindings) const
{
QString fieldTag = (":WHERE" + m_id.getField().toUpper());
QString query(m_id.getField() + " = " + fieldTag);
bindings.insert(fieldTag, m_id.getValue());
return query;
}
QString ChannelDBStorage::GetSetClause(MSqlBindings &bindings) const
{
QString fieldTag = (":SET" + m_id.getField().toUpper());
QString nameTag = (":SET" + GetColumnName().toUpper());
QString query(m_id.getField() + " = " + fieldTag + ", " +
GetColumnName() + " = " + nameTag);
bindings.insert(fieldTag, m_id.getValue());
bindings.insert(nameTag, m_user->GetDBValue());
return query;
}
/*****************************************************************************
Channel Options - Common
*****************************************************************************/
class Name : public MythUITextEditSetting
{
public:
explicit Name(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "name"))
{
setLabel(QCoreApplication::translate("(Common)", "Channel Name"));
}
};
class Channum : public MythUITextEditSetting
{
public:
explicit Channum(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "channum"))
{
setLabel(QCoreApplication::translate("(Common)", "Channel Number"));
setHelpText(QCoreApplication::translate("(Common)",
"This is the number by which the channel is known to MythTV."));
}
};
class Source : public MythUIComboBoxSetting
{
public:
Source(const ChannelID &id, uint _default_sourceid) :
MythUIComboBoxSetting(new ChannelDBStorage(this, id, "sourceid")),
default_sourceid(_default_sourceid)
{
setLabel(QCoreApplication::translate("(Common)", "Video Source"));
}
void Load(void) override // StandardSetting
{
fillSelections();
StandardSetting::Load();
if (default_sourceid && (getValue().toUInt() == 0U))
{
uint which = sourceid_to_index[default_sourceid];
if (which)
setValue(which);
}
}
void fillSelections(void)
{
addSelection(QCoreApplication::translate("(ChannelSettings)",
"[Not Selected]"), "0");
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT name, sourceid "
"FROM videosource "
"ORDER BY sourceid");
if (!query.exec() || !query.isActive())
{
MythDB::DBError("Source::fillSelections", query);
}
else
{
for (uint i = 1; query.next(); i++)
{
sourceid_to_index[query.value(1).toUInt()] = i;
addSelection(query.value(0).toString(),
query.value(1).toString());
}
}
sourceid_to_index[0] = 0; // Not selected entry.
}
private:
uint default_sourceid;
QMap<uint,uint> sourceid_to_index;
};
class Callsign : public MythUITextEditSetting
{
public:
explicit Callsign(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "callsign"))
{
setLabel(QCoreApplication::translate("(Common)", "Callsign"));
}
};
ChannelTVFormat::ChannelTVFormat(const ChannelID &id) :
MythUIComboBoxSetting(new ChannelDBStorage(this, id, "tvformat"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)", "TV Format"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"If this channel uses a format other than TV Format in the General "
"Backend Setup screen, set it here."));
addSelection(QCoreApplication::translate("(Common)", "Default"), "Default");
QStringList list = GetFormats();
for (int i = 0; i < list.size(); i++)
addSelection(list[i]);
}
QStringList ChannelTVFormat::GetFormats(void)
{
QStringList list;
list.push_back("NTSC");
list.push_back("NTSC-JP");
list.push_back("PAL");
list.push_back("PAL-60");
list.push_back("PAL-BG");
list.push_back("PAL-DK");
list.push_back("PAL-D");
list.push_back("PAL-I");
list.push_back("PAL-M");
list.push_back("PAL-N");
list.push_back("PAL-NC");
list.push_back("SECAM");
list.push_back("SECAM-D");
list.push_back("SECAM-DK");
return list;
}
class TimeOffset : public MythUISpinBoxSetting
{
public:
explicit TimeOffset(const ChannelID &id) :
MythUISpinBoxSetting(new ChannelDBStorage(this, id, "tmoffset"),
-1440, 1440, 1)
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"DataDirect Time Offset"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Offset (in minutes) to apply to the program guide data during "
"import. This can be used when the listings for a particular "
"channel are in a different time zone."));
}
};
class Priority : public MythUISpinBoxSetting
{
public:
explicit Priority(const ChannelID &id) :
MythUISpinBoxSetting(new ChannelDBStorage(this, id, "recpriority"),
-99, 99, 1)
{
setLabel(QCoreApplication::translate("(ChannelSettings)", "Priority"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Number of priority points to be added to any recording on this "
"channel during scheduling. Use a positive number as the priority "
"if you want this to be a preferred channel, a negative one to "
"depreciate this channel."));
}
};
class Icon : public MythUITextEditSetting
{
public:
explicit Icon(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "icon"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)", "Icon"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Image file to use as the icon for this channel on various MythTV "
"displays."));
}
};
class VideoFilters : public MythUITextEditSetting
{
public:
explicit VideoFilters(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "videofilters"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Video filters"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Filters to be used when recording from this channel. Not used "
"with hardware encoding cards."));
}
};
class OutputFilters : public MythUITextEditSetting
{
public:
explicit OutputFilters(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "outputfilters"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Playback filters"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Filters to be used when recordings from this channel are viewed. "
"Start with a plus to append to the global playback filters."));
}
};
class XmltvID : public MythUIComboBoxSetting
{
public:
XmltvID(const ChannelID &id, QString _sourceName) :
MythUIComboBoxSetting(new ChannelDBStorage(this, id, "xmltvid"), true),
sourceName(std::move(_sourceName))
{
setLabel(QCoreApplication::translate("(Common)", "XMLTV ID"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"ID used by listing services to get an exact correspondence "
"between a channel in your line-up and a channel in their "
"database. Normally this is set automatically when "
"'mythfilldatabase' is run."));
}
void Load(void) override // StandardSetting
{
fillSelections();
StandardSetting::Load();
}
void fillSelections(void)
{
clearSelections();
QString xmltvFile = GetConfDir() + '/' + sourceName + ".xmltv";
if (QFile::exists(xmltvFile))
{
QFile file(xmltvFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QStringList idList;
while (!file.atEnd())
{
QByteArray line = file.readLine();
if (line.startsWith("channel="))
{
QString id = line.mid(8, -1).trimmed();
idList.append(id);
}
}
idList.sort();
for (int x = 0; x < idList.size(); x++)
addSelection(idList.at(x), idList.at(x));
}
}
private:
QString sourceName;
};
class ServiceID : public MythUISpinBoxSetting
{
public:
explicit ServiceID(const ChannelID &id)
: MythUISpinBoxSetting(new ChannelDBStorage(this, id, "serviceid"),
-1, UINT16_MAX, 1, 1, "NULL")
{
setLabel(QCoreApplication::translate("(ChannelSettings)", "ServiceID"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Service ID (Program Number) of desired channel within the transport stream. "
"If there is only one channel, then setting this to anything will still find it."));
}
void Load(void) override // StandardSetting
{
StandardSetting::Load();
if (getValue().isNull())
setValue("-1");
}
QString getValue(void) const override // StandardSetting
{
if (StandardSetting::getValue().toInt() == -1)
return QString();
return StandardSetting::getValue();
}
};
class CommMethod : public MythUIComboBoxSetting
{
public:
explicit CommMethod(const ChannelID &id) :
MythUIComboBoxSetting(new ChannelDBStorage(this, id, "commmethod"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Commercial Detection Method"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Changes the method of commercial detection used for recordings on "
"this channel or skips detection by marking the channel as "
"Commercial Free."));
deque<int> tmp = GetPreferredSkipTypeCombinations();
tmp.push_front(COMM_DETECT_UNINIT);
tmp.push_back(COMM_DETECT_COMMFREE);
for (size_t i = 0; i < tmp.size(); i++)
addSelection(SkipTypeToString(tmp[i]), QString::number(tmp[i]));
}
};
class Visible : public MythUICheckBoxSetting
{
public:
explicit Visible(const ChannelID &id) :
MythUICheckBoxSetting(new ChannelDBStorage(this, id, "visible"))
{
setValue(true);
setLabel(QCoreApplication::translate("(ChannelSettings)", "Visible"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"If enabled, the channel will be visible in the EPG."));
}
};
class OnAirGuide : public MythUICheckBoxSetting
{
public:
explicit OnAirGuide(const ChannelID &id) :
MythUICheckBoxSetting(new ChannelDBStorage(this, id, "useonairguide"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Use on air guide"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"If enabled, guide information for this channel will be updated "
"using 'Over-the-Air' program listings."));
}
};
/*****************************************************************************
Channel Options - Video 4 Linux
*****************************************************************************/
class Freqid : public MythUITextEditSetting
{
public:
explicit Freqid(const ChannelID &id) :
MythUITextEditSetting(new ChannelDBStorage(this, id, "freqid"))
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Freq/Channel"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Depending on the tuner type, specify either the exact "
"frequency (in kHz) or a valid channel "
"number that will be understood by your tuners."));
}
};
class Finetune : public MythUISpinBoxSetting
{
public:
explicit Finetune(const ChannelID& id)
: MythUISpinBoxSetting(new ChannelDBStorage(this, id, "finetune"),
-300, 300, 1)
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Finetune (kHz)"));
setHelpText(QCoreApplication::translate("(ChannelSettings)",
"Value to be added to your desired frequency (in kHz) for "
"'fine tuning'."));
setValue("0");
}
};
class Contrast : public MythUISpinBoxSetting
{
public:
explicit Contrast(const ChannelID &id) :
MythUISpinBoxSetting(new ChannelDBStorage(this, id, "contrast"),
0, 65535, 655)
{
setLabel(QCoreApplication::translate("(Common)", "Contrast"));
}
};
class Brightness : public MythUISpinBoxSetting
{
public:
explicit Brightness(const ChannelID &id) :
MythUISpinBoxSetting(new ChannelDBStorage(this, id, "brightness"),
0, 65535, 655)
{
setLabel(QCoreApplication::translate("(Common)", "Brightness"));
}
};
class Colour : public MythUISpinBoxSetting
{
public:
explicit Colour(const ChannelID &id) :
MythUISpinBoxSetting(new ChannelDBStorage(this, id, "colour"),
0, 65535, 655)
{
setLabel(QCoreApplication::translate("(Common)", "Color"));
}
};
class Hue : public MythUISpinBoxSetting
{
public:
explicit Hue(const ChannelID &id) :
MythUISpinBoxSetting(new ChannelDBStorage(this, id, "hue"),
0, 65535, 655)
{
setLabel(QCoreApplication::translate("(Common)", "Hue"));
}
};
ChannelOptionsCommon::ChannelOptionsCommon(const ChannelID &id,
uint default_sourceid, bool add_freqid)
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Channel Options - Common"));
addChild(new Name(id));
Source *source = new Source(id, default_sourceid);
Channum *channum = new Channum(id);
addChild(channum);
if (add_freqid)
{
m_freqid = new Freqid(id);
addChild(m_freqid);
}
else
m_freqid = nullptr;
addChild(new Callsign(id));
addChild(new Visible(id));
addChild(new ServiceID(id));
addChild(source);
addChild(new ChannelTVFormat(id));
addChild(new Priority(id));
addChild(m_onairguide = new OnAirGuide(id));
addChild(m_xmltvID = new XmltvID(id, source->getValueLabel()));
addChild(new TimeOffset(id));
addChild(new CommMethod(id));
addChild(new Icon(id));
connect(m_onairguide, SIGNAL(valueChanged( bool)),
this, SLOT( onAirGuideChanged(bool)));
connect(source, SIGNAL(valueChanged( const QString&)),
this, SLOT( sourceChanged(const QString&)));
};
void ChannelOptionsCommon::onAirGuideChanged(bool fValue)
{
(void)fValue;
}
void ChannelOptionsCommon::sourceChanged(const QString& sourceid)
{
bool supports_eit = true;
bool uses_eit_only = false;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT cardtype "
"FROM capturecard, videosource "
"WHERE capturecard.sourceid = videosource.sourceid AND "
" videosource.sourceid = :SOURCEID");
query.bindValue(":SOURCEID", sourceid);
if (!query.exec() || !query.isActive())
MythDB::DBError("sourceChanged -- supports eit", query);
else
{
supports_eit = (query.size() == 0);
while (query.next())
{
supports_eit |= CardUtil::IsEITCapable(
query.value(0).toString().toUpper());
}
query.prepare("SELECT xmltvgrabber "
"FROM videosource "
"WHERE sourceid = :SOURCEID");
query.bindValue(":SOURCEID", sourceid);
if (!query.exec() || !query.isActive())
MythDB::DBError("sourceChanged -- eit only", query);
else
{
uses_eit_only = (query.size() != 0);
while (query.next())
{
uses_eit_only &= (query.value(0).toString() == "eitonly");
}
}
}
m_onairguide->setEnabled(supports_eit);
m_xmltvID->setEnabled(!uses_eit_only);
m_xmltvID->Load();
}
ChannelOptionsFilters::ChannelOptionsFilters(const ChannelID& id)
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Channel Options - Filters"));
addChild(new VideoFilters(id));
addChild(new OutputFilters(id));
}
ChannelOptionsV4L::ChannelOptionsV4L(const ChannelID& id)
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Channel Options - Video4Linux"));
addChild(new Freqid(id));
addChild(new Finetune(id));
addChild(new Contrast(id));
addChild(new Brightness(id));
addChild(new Colour(id));
addChild(new Hue(id));
};
/*****************************************************************************
Channel Options - Video 4 Linux
*****************************************************************************/
ChannelOptionsRawTS::ChannelOptionsRawTS(const ChannelID &id) :
m_cid(id)
{
setLabel(QCoreApplication::translate("(ChannelSettings)",
"Channel Options - Raw Transport Stream"));
const uint mx = kMaxPIDs;
m_pids.resize(mx);
m_sids.resize(mx);
m_pcrs.resize(mx);
for (uint i = 0; i < mx; i++)
{
addChild((m_pids[i] = new TransTextEditSetting()));
m_pids[i]->setLabel("PID");
addChild((m_sids[i] = new TransMythUIComboBoxSetting()));
m_sids[i]->setLabel(" StreamID");
for (uint j = 0x101; j <= 0x1ff; j++)
{
QString desc = StreamID::GetDescription(j&0xff);
if (!desc.isEmpty())
m_sids[i]->addSelection(
QString("%1 (0x%2)")
.arg(desc).arg(j&0xff,2,16,QLatin1Char('0')),
QString::number(j), false);
}
for (uint j = 0x101; j <= 0x1ff; j++)
{
QString desc = StreamID::GetDescription(j&0xff);
if (desc.isEmpty())
m_sids[i]->addSelection(
QString("0x%1").arg(j&0xff,2,16,QLatin1Char('0')),
QString::number(j), false);
}
/* we don't allow tables right now, PAT & PMT generated on the fly
for (uint j = 0; j <= 0xff; j++)
{
QString desc = TableID::GetDescription(j);
if (!desc.isEmpty())
{
m_sids[i]->addSelection(
QString("%1 (0x%2)").arg(j,0,16,QLatin1Char('0')),
QString::number(j),
false);
}
}
*/
addChild((m_pcrs[i] = new TransMythUICheckBoxSetting()));
m_pcrs[i]->setLabel(" Is PCR");
}
};
void ChannelOptionsRawTS::Load(void)
{
uint chanid = m_cid.getValue().toUInt();
pid_cache_t pid_cache;
if (!ChannelUtil::GetCachedPids(chanid, pid_cache))
return;
pid_cache_t::const_iterator it = pid_cache.begin();
for (uint i = 0; i < kMaxPIDs && it != pid_cache.end(); )
{
if (!(it->IsPermanent()))
{
++it;
continue;
}
m_pids[i]->setValue(QString("0x%1")
.arg(it->GetPID(),2,16,QLatin1Char('0')));
m_sids[i]->setValue(QString::number(it->GetComposite()&0x1ff));
m_pcrs[i]->setValue(it->IsPCRPID());
++it;
++i;
}
}
void ChannelOptionsRawTS::Save(void)
{
uint chanid = m_cid.getValue().toUInt();
pid_cache_t pid_cache;
for (uint i = 0; i < kMaxPIDs; i++)
{
bool ok;
uint pid = m_pids[i]->getValue().toUInt(&ok, 0);
if (!ok || (m_sids[i]->getValue().toUInt() == 0U))
continue;
pid_cache.push_back(
pid_cache_item_t(
pid, m_sids[i]->getValue().toUInt() | 0x10000 |
(m_pcrs[i]->getValue().toUInt() ? 0x200 : 0x0)));
}
ChannelUtil::SaveCachedPids(chanid, pid_cache, true /* delete_all */);
}
/* vim: set expandtab tabstop=4 shiftwidth=4: */