/
statusbox.cpp
1724 lines (1482 loc) · 56.3 KB
/
statusbox.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "statusbox.h"
#include <QRegExp>
#include <QHostAddress>
#include <QNetworkInterface>
#include "mythcorecontext.h"
#include "filesysteminfo.h"
#include "mythmiscutil.h"
#include "mythdb.h"
#include "mythlogging.h"
#include "mythversion.h"
#include "mythdate.h"
#include "config.h"
#include "remoteutil.h"
#include "tv.h"
#include "jobqueue.h"
#include "cardutil.h"
#include "recordinginfo.h"
#include "mythmiscutil.h"
#include "mythuihelper.h"
#include "mythuibuttonlist.h"
#include "mythuitext.h"
#include "mythuistatetype.h"
#include "mythdialogbox.h"
#include "mythrender_base.h"
#include "opengl/mythrenderopengl.h"
#include "mythdisplay.h"
#include "decoders/mythcodeccontext.h"
struct LogLine {
QString m_line;
QString m_detail;
QString m_help;
QString m_helpdetail;
QString m_data;
QString m_state;
};
void StatusBoxItem::Start(int Interval)
{
connect(this, &QTimer::timeout, [=]() { emit UpdateRequired(this); });
start(Interval * 1000);
}
/** \class StatusBox
* \brief Reports on various status items.
*
* StatusBox reports on the listing status, that is how far
* into the future program listings exists. It also reports
* on the status of each tuner, the log entries, the status
* of the job queue, and the machine status.
*/
StatusBox::StatusBox(MythScreenStack *parent)
: MythScreenType(parent, "StatusBox")
{
m_minLevel = gCoreContext->GetNumSetting("LogDefaultView",5);
QStringList strlist;
strlist << "QUERY_IS_ACTIVE_BACKEND";
strlist << gCoreContext->GetHostName();
gCoreContext->SendReceiveStringList(strlist);
m_isBackendActive = (strlist[0] == "TRUE");
m_popupStack = GetMythMainWindow()->GetStack("popup stack");
}
StatusBox::~StatusBox(void)
{
if (m_logList)
gCoreContext->SaveSetting("StatusBoxItemCurrent",
m_logList->GetCurrentPos());
}
bool StatusBox::Create()
{
if (!LoadWindowFromXML("status-ui.xml", "status", this))
return false;
m_categoryList = dynamic_cast<MythUIButtonList *>(GetChild("category"));
m_logList = dynamic_cast<MythUIButtonList *>(GetChild("log"));
m_iconState = dynamic_cast<MythUIStateType *>(GetChild("icon"));
m_helpText = dynamic_cast<MythUIText *>(GetChild("helptext"));
m_justHelpText = dynamic_cast<MythUIText *>(GetChild("justhelptext"));
if (!m_categoryList || !m_logList || (!m_helpText && !m_justHelpText))
{
LOG(VB_GENERAL, LOG_ERR, "StatusBox, theme is missing "
"required elements");
return false;
}
connect(m_categoryList, &MythUIButtonList::itemSelected,
this, &StatusBox::updateLogList);
connect(m_logList, &MythUIButtonList::itemSelected,
this, &StatusBox::setHelpText);
connect(m_logList, &MythUIButtonList::itemClicked,
this, &StatusBox::clicked);
BuildFocusList();
return true;
}
void StatusBox::Init()
{
auto *item = new MythUIButtonListItem(m_categoryList, tr("Listings Status"),
&StatusBox::doListingsStatus);
item->DisplayState("listings", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("Schedule Status"),
&StatusBox::doScheduleStatus);
item->DisplayState("schedule", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("Input Status"),
&StatusBox::doTunerStatus);
item->DisplayState("tuner", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("Job Queue"),
&StatusBox::doJobQueueStatus);
item->DisplayState("jobqueue", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("Video decoders"),
&StatusBox::doDecoderStatus);
item->DisplayState("decoders", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("Display"),
&StatusBox::doDisplayStatus);
item->DisplayState("display", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("Machine Status"),
&StatusBox::doMachineStatus);
item->DisplayState("machine", "icon");
item = new MythUIButtonListItem(m_categoryList, tr("AutoExpire List"),
qOverload<>(&StatusBox::doAutoExpireList));
item->DisplayState("autoexpire", "icon");
int itemCurrent = gCoreContext->GetNumSetting("StatusBoxItemCurrent", 0);
m_categoryList->SetItemCurrent(itemCurrent);
}
StatusBoxItem *StatusBox::AddLogLine(const QString & line,
const QString & help,
const QString & detail,
const QString & helpdetail,
const QString & state,
const QString & data)
{
LogLine logline;
logline.m_line = line;
if (detail.isEmpty())
logline.m_detail = line;
else
logline.m_detail = detail;
if (help.isEmpty())
logline.m_help = logline.m_detail;
else
logline.m_help = help;
if (helpdetail.isEmpty())
logline.m_helpdetail = logline.m_detail;
else
logline.m_helpdetail = helpdetail;
logline.m_state = state;
logline.m_data = data;
auto *item = new StatusBoxItem(m_logList, line, QVariant::fromValue(logline));
if (logline.m_state.isEmpty())
logline.m_state = "normal";
item->SetFontState(logline.m_state);
item->DisplayState(logline.m_state, "status");
item->SetText(logline.m_detail, "detail");
return item;
}
bool StatusBox::keyPressEvent(QKeyEvent *event)
{
if (GetFocusWidget()->keyPressEvent(event))
return true;
QStringList actions;
bool handled = GetMythMainWindow()->TranslateKeyPress("Status", event, actions);
for (int i = 0; i < actions.size() && !handled; ++i)
{
QString action = actions[i];
handled = true;
QRegExp logNumberKeys( "^[12345678]$" );
MythUIButtonListItem* currentButton = m_categoryList->GetItemCurrent();
QString currentItem;
if (currentButton)
currentItem = currentButton->GetText();
if (action == "MENU")
{
if (currentItem == tr("Log Entries"))
{
QString message = tr("Acknowledge all log entries at "
"this priority level or lower?");
auto *confirmPopup =
new MythConfirmationDialog(m_popupStack, message);
confirmPopup->SetReturnEvent(this, "LogAckAll");
if (confirmPopup->Create())
m_popupStack->AddScreen(confirmPopup, false);
}
}
else if ((currentItem == tr("Log Entries")) &&
(logNumberKeys.indexIn(action) == 0))
{
m_minLevel = action.toInt();
if (m_helpText)
m_helpText->SetText(tr("Setting priority level to %1")
.arg(m_minLevel));
if (m_justHelpText)
m_justHelpText->SetText(tr("Setting priority level to %1")
.arg(m_minLevel));
doLogEntries();
}
else
handled = false;
}
if (!handled && MythScreenType::keyPressEvent(event))
handled = true;
return handled;
}
void StatusBox::setHelpText(MythUIButtonListItem *item)
{
if (!item || GetFocusWidget() != m_logList)
return;
auto logline = item->GetData().value<LogLine>();
if (m_helpText)
m_helpText->SetText(logline.m_helpdetail);
if (m_justHelpText)
m_justHelpText->SetText(logline.m_help);
}
void StatusBox::updateLogList(MythUIButtonListItem *item)
{
if (!item)
return;
disconnect(this, &StatusBox::updateLog,nullptr,nullptr);
if (item->GetData().value<MythUICallbackMF>())
{
connect(this, &StatusBox::updateLog,
item->GetData().value<MythUICallbackMF>());
emit updateLog();
}
else if (item->GetData().value<MythUICallbackMFc>())
{
connect(this, &StatusBox::updateLog,
item->GetData().value<MythUICallbackMFc>());
emit updateLog();
}
}
void StatusBox::clicked(MythUIButtonListItem *item)
{
if (!item)
return;
auto logline = item->GetData().value<LogLine>();
MythUIButtonListItem *currentButton = m_categoryList->GetItemCurrent();
QString currentItem;
if (currentButton)
currentItem = currentButton->GetText();
// FIXME: Comparisons against strings here is not great, changing names
// breaks everything and it's inefficient
if (currentItem == tr("Log Entries"))
{
QString message = tr("Acknowledge this log entry?");
auto *confirmPopup = new MythConfirmationDialog(m_popupStack, message);
confirmPopup->SetReturnEvent(this, "LogAck");
confirmPopup->SetData(logline.m_data);
if (confirmPopup->Create())
m_popupStack->AddScreen(confirmPopup, false);
}
else if (currentItem == tr("Job Queue"))
{
QStringList msgs;
int jobStatus = JobQueue::GetJobStatus(logline.m_data.toInt());
if (jobStatus == JOB_QUEUED)
{
QString message = tr("Delete Job?");
auto *confirmPopup =
new MythConfirmationDialog(m_popupStack, message);
confirmPopup->SetReturnEvent(this, "JobDelete");
confirmPopup->SetData(logline.m_data);
if (confirmPopup->Create())
m_popupStack->AddScreen(confirmPopup, false);
}
else if ((jobStatus == JOB_PENDING) ||
(jobStatus == JOB_STARTING) ||
(jobStatus == JOB_RUNNING) ||
(jobStatus == JOB_PAUSED))
{
QString label = tr("Job Queue Actions:");
auto *menuPopup = new MythDialogBox(label, m_popupStack,
"statusboxpopup");
if (menuPopup->Create())
m_popupStack->AddScreen(menuPopup, false);
menuPopup->SetReturnEvent(this, "JobModify");
QVariant data = QVariant::fromValue(logline.m_data);
if (jobStatus == JOB_PAUSED)
menuPopup->AddButtonV(tr("Resume"), data);
else
menuPopup->AddButtonV(tr("Pause"), data);
menuPopup->AddButtonV(tr("Stop"), data);
menuPopup->AddButtonV(tr("No Change"), data);
}
else if (jobStatus & JOB_DONE)
{
QString message = tr("Requeue Job?");
auto *confirmPopup =
new MythConfirmationDialog(m_popupStack, message);
confirmPopup->SetReturnEvent(this, "JobRequeue");
confirmPopup->SetData(logline.m_data);
if (confirmPopup->Create())
m_popupStack->AddScreen(confirmPopup, false);
}
}
else if (currentItem == tr("AutoExpire List"))
{
ProgramInfo* rec = m_expList[m_logList->GetCurrentPos()];
if (rec)
{
QString label = tr("AutoExpire Actions:");
auto *menuPopup = new MythDialogBox(label, m_popupStack,
"statusboxpopup");
if (menuPopup->Create())
m_popupStack->AddScreen(menuPopup, false);
menuPopup->SetReturnEvent(this, "AutoExpireManage");
menuPopup->AddButtonV(tr("Delete Now"), QVariant::fromValue(rec));
if ((rec)->GetRecordingGroup() == "LiveTV")
{
menuPopup->AddButtonV(tr("Move to Default group"),
QVariant::fromValue(rec));
}
else if ((rec)->GetRecordingGroup() == "Deleted")
menuPopup->AddButtonV(tr("Undelete"), QVariant::fromValue(rec));
else
menuPopup->AddButtonV(tr("Disable AutoExpire"),
QVariant::fromValue(rec));
menuPopup->AddButtonV(tr("No Change"), QVariant::fromValue(rec));
}
}
}
void StatusBox::customEvent(QEvent *event)
{
if (event->type() == DialogCompletionEvent::kEventType)
{
auto *dce = (DialogCompletionEvent*)(event);
QString resultid = dce->GetId();
int buttonnum = dce->GetResult();
if (resultid == "LogAck")
{
if (buttonnum == 1)
{
QString sql = dce->GetData().toString();
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("UPDATE mythlog SET acknowledged = 1 "
"WHERE logid = :LOGID ;");
query.bindValue(":LOGID", sql);
if (!query.exec())
MythDB::DBError("StatusBox::customEvent -- LogAck", query);
m_logList->RemoveItem(m_logList->GetItemCurrent());
}
}
else if (resultid == "LogAckAll")
{
if (buttonnum == 1)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("UPDATE mythlog SET acknowledged = 1 "
"WHERE priority <= :PRIORITY ;");
query.bindValue(":PRIORITY", m_minLevel);
if (!query.exec())
MythDB::DBError("StatusBox::customEvent -- LogAckAll",
query);
doLogEntries();
}
}
else if (resultid == "JobDelete")
{
if (buttonnum == 1)
{
int jobID = dce->GetData().toInt();
JobQueue::DeleteJob(jobID);
m_logList->RemoveItem(m_logList->GetItemCurrent());
}
}
else if (resultid == "JobRequeue")
{
if (buttonnum == 1)
{
int jobID = dce->GetData().toInt();
JobQueue::ChangeJobStatus(jobID, JOB_QUEUED);
doJobQueueStatus();
}
}
else if (resultid == "JobModify")
{
int jobID = dce->GetData().toInt();
if (buttonnum == 0)
{
if (JobQueue::GetJobStatus(jobID) == JOB_PAUSED)
JobQueue::ResumeJob(jobID);
else
JobQueue::PauseJob(jobID);
}
else if (buttonnum == 1)
{
JobQueue::StopJob(jobID);
}
doJobQueueStatus();
}
else if (resultid == "AutoExpireManage")
{
auto* rec = dce->GetData().value<ProgramInfo*>();
// button 2 is "No Change"
if (!rec || buttonnum == 2)
return;
// button 1 is "Delete Now"
if ((buttonnum == 0) && rec->QueryIsDeleteCandidate())
{
if (!RemoteDeleteRecording(rec->GetRecordingID(),
false, false))
{
LOG(VB_GENERAL, LOG_ERR, QString("Failed to delete recording: %1").arg(rec->GetTitle()));
return;
}
}
// button 1 is "Move To Default Group" or "UnDelete" or "Disable AutoExpire"
else if (buttonnum == 1)
{
if ((rec)->GetRecordingGroup() == "Deleted")
{
RemoteUndeleteRecording(rec->GetRecordingID());
}
else
{
rec->SaveAutoExpire(kDisableAutoExpire);
if ((rec)->GetRecordingGroup() == "LiveTV")
{
RecordingInfo ri(*rec);
ri.ApplyRecordRecGroupChange(RecordingInfo::kDefaultRecGroup);
*rec = ri;
}
}
}
// remove the changed recording from the expire list
delete m_expList[m_logList->GetCurrentPos()];
m_expList.erase(m_expList.begin() + m_logList->GetCurrentPos());
int pos = m_logList->GetCurrentPos();
int topPos = m_logList->GetTopItemPos();
doAutoExpireList(false);
m_logList->SetItemCurrent(pos, topPos);
}
}
}
void StatusBox::doListingsStatus()
{
if (m_iconState)
m_iconState->DisplayState("listings");
m_logList->Reset();
QString helpmsg(tr("Listings Status shows the latest "
"status information from "
"mythfilldatabase"));
if (m_helpText)
m_helpText->SetText(helpmsg);
if (m_justHelpText)
m_justHelpText->SetText(helpmsg);
QDateTime mfdLastRunStart;
QDateTime mfdLastRunEnd;
QDateTime mfdNextRunStart;
QString mfdLastRunStatus;
QDateTime qdtNow;
QDateTime GuideDataThrough;
qdtNow = MythDate::current();
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT max(endtime) FROM program WHERE manualid=0;");
if (query.exec() && query.next())
GuideDataThrough = MythDate::fromString(query.value(0).toString());
QString tmp = gCoreContext->GetSetting("mythfilldatabaseLastRunStart");
mfdLastRunStart = MythDate::fromString(tmp);
tmp = gCoreContext->GetSetting("mythfilldatabaseLastRunEnd");
mfdLastRunEnd = MythDate::fromString(tmp);
tmp = gCoreContext->GetSetting("MythFillSuggestedRunTime");
mfdNextRunStart = MythDate::fromString(tmp);
mfdLastRunStatus = gCoreContext->GetSetting("mythfilldatabaseLastRunStatus");
AddLogLine(tr("Mythfrontend version: %1 (%2)").arg(GetMythSourcePath())
.arg(GetMythSourceVersion()), helpmsg);
AddLogLine(tr("Last mythfilldatabase guide update:"), helpmsg);
tmp = tr("Started: %1").arg(
MythDate::toString(
mfdLastRunStart, MythDate::kDateTimeFull | MythDate::kSimplify));
AddLogLine(tmp, helpmsg);
if (mfdLastRunEnd >= mfdLastRunStart)
{
tmp = tr("Finished: %1")
.arg(MythDate::toString(
mfdLastRunEnd,
MythDate::kDateTimeFull | MythDate::kSimplify));
AddLogLine(tmp, helpmsg);
}
AddLogLine(tr("Result: %1").arg(mfdLastRunStatus), helpmsg);
if (mfdNextRunStart >= mfdLastRunStart)
{
tmp = tr("Suggested Next: %1")
.arg(MythDate::toString(
mfdNextRunStart,
MythDate::kDateTimeFull | MythDate::kSimplify));
AddLogLine(tmp, helpmsg);
}
int DaysOfData = qdtNow.daysTo(GuideDataThrough);
if (GuideDataThrough.isNull())
{
AddLogLine(tr("There's no guide data available!"), helpmsg,
"", "warning");
AddLogLine(tr("Have you run mythfilldatabase?"), helpmsg,
"", "warning");
}
else
{
AddLogLine(
tr("There is guide data until %1")
.arg(MythDate::toString(
GuideDataThrough,
MythDate::kDateTimeFull | MythDate::kSimplify)), helpmsg);
AddLogLine(QString("(%1).").arg(tr("%n day(s)", "", DaysOfData)),
helpmsg);
}
if (DaysOfData <= 3)
AddLogLine(tr("WARNING: is mythfilldatabase running?"), helpmsg,
"", "", "warning");
}
void StatusBox::doScheduleStatus()
{
if (m_iconState)
m_iconState->DisplayState("schedule");
m_logList->Reset();
QString helpmsg(tr("Schedule Status shows current statistics "
"from the scheduler."));
if (m_helpText)
m_helpText->SetText(helpmsg);
if (m_justHelpText)
m_justHelpText->SetText(helpmsg);
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT COUNT(*) FROM record WHERE type = :TEMPLATE");
query.bindValue(":TEMPLATE", kTemplateRecord);
if (query.exec() && query.next())
{
QString rules = tr("%n template rule(s) (is) defined", "",
query.value(0).toInt());
AddLogLine(rules, helpmsg);
}
else
{
MythDB::DBError("StatusBox::doScheduleStatus()", query);
return;
}
query.prepare("SELECT COUNT(*) FROM record "
"WHERE type <> :TEMPLATE AND search = :NOSEARCH");
query.bindValue(":TEMPLATE", kTemplateRecord);
query.bindValue(":NOSEARCH", kNoSearch);
if (query.exec() && query.next())
{
QString rules = tr("%n standard rule(s) (is) defined", "",
query.value(0).toInt());
AddLogLine(rules, helpmsg);
}
else
{
MythDB::DBError("StatusBox::doScheduleStatus()", query);
return;
}
query.prepare("SELECT COUNT(*) FROM record WHERE search > :NOSEARCH");
query.bindValue(":NOSEARCH", kNoSearch);
if (query.exec() && query.next())
{
QString rules = tr("%n search rule(s) are defined", "",
query.value(0).toInt());
AddLogLine(rules, helpmsg);
}
else
{
MythDB::DBError("StatusBox::doScheduleStatus()", query);
return;
}
QMap<RecStatus::Type, int> statusMatch;
QMap<RecStatus::Type, QString> statusText;
QMap<int, int> sourceMatch;
QMap<int, QString> sourceText;
QMap<int, int> cardMatch;
QMap<int, QString> cardText;
QMap<int, int> cardParent;
QMap<int, bool> cardSchedGroup;
QString tmpstr;
int maxSource = 0;
int maxCard = 0;
int lowerpriority = 0;
int hdflag = 0;
query.prepare("SELECT MAX(sourceid) FROM videosource");
if (query.exec())
{
if (query.next())
maxSource = query.value(0).toInt();
}
query.prepare("SELECT sourceid,name FROM videosource");
if (query.exec())
{
while (query.next())
sourceText[query.value(0).toInt()] = query.value(1).toString();
}
query.prepare("SELECT MAX(cardid) FROM capturecard");
if (query.exec())
{
if (query.next())
maxCard = query.value(0).toInt();
}
query.prepare("SELECT cardid, inputname, displayname, parentid, "
" schedgroup "
"FROM capturecard");
if (query.exec())
{
while (query.next())
{
int inputid = query.value(0).toInt();
cardText[inputid] = query.value(2).toString();
if (cardText[inputid].isEmpty())
cardText[inputid] = QString::number(query.value(1).toInt());
cardParent[inputid] = query.value(3).toInt();
cardSchedGroup[inputid] = query.value(4).toBool();
}
}
ProgramList schedList;
LoadFromScheduler(schedList);
tmpstr = tr("%n matching showing(s)", "", schedList.size());
AddLogLine(tmpstr, helpmsg);
for (auto *s : schedList)
{
const RecStatus::Type recstatus = s->GetRecordingStatus();
if (statusMatch[recstatus] < 1)
{
statusText[recstatus] = RecStatus::toString(
recstatus, s->GetRecordingRuleType());
}
++statusMatch[recstatus];
if (recstatus == RecStatus::WillRecord ||
recstatus == RecStatus::Pending ||
recstatus == RecStatus::Recording ||
recstatus == RecStatus::Tuning ||
recstatus == RecStatus::Failing)
{
++sourceMatch[s->GetSourceID()];
int inputid = s->GetInputID();
// When schedgroup is used, always attribute recordings to
// the parent inputs.
if (cardParent[inputid] && cardSchedGroup[cardParent[inputid]])
inputid = cardParent[inputid];
++cardMatch[inputid];
if (s->GetRecordingPriority2() < 0)
++lowerpriority;
if (s->GetVideoProperties() & VID_HDTV)
++hdflag;
}
}
#define ADD_STATUS_LOG_LINE(rtype, fstate) \
do { \
if (statusMatch[rtype] > 0) \
{ \
tmpstr = QString("%1 %2").arg(statusMatch[rtype]) \
.arg(statusText[rtype]); \
AddLogLine(tmpstr, helpmsg, tmpstr, tmpstr, fstate);\
} \
} while (false)
ADD_STATUS_LOG_LINE(RecStatus::Recording, "");
ADD_STATUS_LOG_LINE(RecStatus::Tuning, "");
ADD_STATUS_LOG_LINE(RecStatus::Failing, "error");
ADD_STATUS_LOG_LINE(RecStatus::Pending, "");
ADD_STATUS_LOG_LINE(RecStatus::WillRecord, "");
ADD_STATUS_LOG_LINE(RecStatus::Conflict, "error");
ADD_STATUS_LOG_LINE(RecStatus::TooManyRecordings, "warning");
ADD_STATUS_LOG_LINE(RecStatus::LowDiskSpace, "warning");
ADD_STATUS_LOG_LINE(RecStatus::LaterShowing, "warning");
ADD_STATUS_LOG_LINE(RecStatus::NotListed, "warning");
QString willrec = statusText[RecStatus::WillRecord];
if (lowerpriority > 0)
{
tmpstr = QString("%1 %2 %3").arg(lowerpriority).arg(willrec)
.arg(tr("with lower priority"));
AddLogLine(tmpstr, helpmsg, tmpstr, tmpstr, "warning");
}
if (hdflag > 0)
{
tmpstr = QString("%1 %2 %3").arg(hdflag).arg(willrec)
.arg(tr("marked as HDTV"));
AddLogLine(tmpstr, helpmsg);
}
for (int i = 1; i <= maxSource; ++i)
{
if (sourceMatch[i] > 0)
{
tmpstr = QString("%1 %2 %3 %4 \"%5\"")
.arg(sourceMatch[i]).arg(willrec)
.arg(tr("from source")).arg(i).arg(sourceText[i]);
AddLogLine(tmpstr, helpmsg);
}
}
for (int i = 1; i <= maxCard; ++i)
{
if (cardMatch[i] > 0)
{
tmpstr = QString("%1 %2 %3 %4 \"%5\"")
.arg(cardMatch[i]).arg(willrec)
.arg(tr("on input")).arg(i).arg(cardText[i]);
AddLogLine(tmpstr, helpmsg);
}
}
}
void StatusBox::doTunerStatus()
{
struct info
{
int m_inputid {0};
bool m_schedgroup {false};
QString m_displayname;
int m_errored {0};
int m_unavailable {0};
int m_sleeping {0};
int m_recording {0};
int m_livetv {0};
int m_available {0};
QStringList m_recordings;
};
QMap<int, struct info> info;
QList<int> inputids;
if (m_iconState)
m_iconState->DisplayState("tuner");
m_logList->Reset();
QString helpmsg(tr("Input Status shows the current information "
"about the state of backend inputs"));
if (m_helpText)
m_helpText->SetText(helpmsg);
if (m_justHelpText)
m_justHelpText->SetText(helpmsg);
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT cardid, parentid, schedgroup, displayname "
"FROM capturecard ORDER BY cardid");
if (!query.exec() || !query.isActive())
{
MythDB::DBError("StatusBox::doTunerStatus()", query);
return;
}
while (query.next())
{
int inputid = query.value(0).toInt();
int parentid = query.value(1).toInt();
// If this is a schedgroup child, attribute all status to the
// parent.
int infoid = inputid;
if (parentid && info[parentid].m_schedgroup)
infoid = parentid;
else
{
info[infoid].m_inputid = inputid;
info[infoid].m_schedgroup = query.value(2).toBool();
info[infoid].m_displayname = query.value(3).toString();
inputids.append(inputid);
}
QString cmd = QString("QUERY_REMOTEENCODER %1").arg(inputid);
QStringList strlist( cmd );
strlist << "GET_STATE";
gCoreContext->SendReceiveStringList(strlist);
int state = strlist[0].toInt();
if (state == kState_Error)
{
strlist.clear();
strlist << QString("QUERY_REMOTEENCODER %1").arg(inputid);
strlist << "GET_SLEEPSTATUS";
gCoreContext->SendReceiveStringList(strlist);
int sleepState = strlist[0].toInt();
if (sleepState == -1)
info[infoid].m_errored += 1;
else if (sleepState == sStatus_Undefined)
info[infoid].m_unavailable += 1;
else
info[infoid].m_sleeping += 1;
}
else if (state == kState_RecordingOnly ||
state == kState_WatchingRecording)
info[infoid].m_recording += 1;
else if (state == kState_WatchingLiveTV)
info[infoid].m_livetv += 1;
else
info[infoid].m_available += 1;
if (state == kState_RecordingOnly ||
state == kState_WatchingRecording ||
state == kState_WatchingLiveTV)
{
strlist = QStringList( QString("QUERY_RECORDER %1").arg(inputid));
strlist << "GET_RECORDING";
gCoreContext->SendReceiveStringList(strlist);
ProgramInfo pginfo(strlist);
if (pginfo.GetChanID())
{
QString titlesub = pginfo.GetTitle();
if (!pginfo.GetSubtitle().isEmpty())
titlesub += QString(" - ") + pginfo.GetSubtitle();
info[infoid].m_recordings += titlesub;
}
}
}
for (int inputid : qAsConst(inputids))
{
QStringList statuslist;
if (info[inputid].m_errored)
statuslist << tr("%1 errored").arg(info[inputid].m_errored);
if (info[inputid].m_unavailable)
statuslist << tr("%1 unavailable").arg(info[inputid].m_unavailable);
if (info[inputid].m_sleeping)
statuslist << tr("%1 sleeping").arg(info[inputid].m_sleeping);
if (info[inputid].m_recording)
statuslist << tr("%1 recording").arg(info[inputid].m_recording);
if (info[inputid].m_livetv)
statuslist << tr("%1 live television").arg(info[inputid].m_livetv);
if (info[inputid].m_available)
statuslist << tr("%1 available").arg(info[inputid].m_available);
QString fontstate;
if (info[inputid].m_errored)
fontstate = "error";
else if (info[inputid].m_unavailable || info[inputid].m_sleeping)
fontstate = "warning";
QString shortstatus = tr("Input %1 %2: %3")
.arg(inputid).arg(info[inputid].m_displayname)
.arg(statuslist.join(tr(", ")));
QString longstatus = shortstatus + "\n" +
info[inputid].m_recordings.join("\n");
AddLogLine(shortstatus, helpmsg, longstatus, longstatus, fontstate);
}
}
void StatusBox::doLogEntries(void)
{
if (m_iconState)
m_iconState->DisplayState("log");
m_logList->Reset();
QString helpmsg(tr("Log Entries shows any unread log entries "
"from the system if you have logging enabled"));
if (m_helpText)
m_helpText->SetText(helpmsg);
if (m_justHelpText)
m_justHelpText->SetText(helpmsg);
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT logid, module, priority, logdate, host, "
"message, details "
"FROM mythlog WHERE acknowledged = 0 "
"AND priority <= :PRIORITY ORDER BY logdate DESC;");
query.bindValue(":PRIORITY", m_minLevel);
if (query.exec())
{
QString line;
QString detail;
while (query.next())
{
line = QString("%1").arg(query.value(5).toString());
detail = tr("On %1 from %2.%3\n%4\n")
.arg(MythDate::toString(
MythDate::as_utc(query.value(3).toDateTime()),
MythDate::kDateTimeShort))
.arg(query.value(4).toString())
.arg(query.value(1).toString())
.arg(query.value(5).toString());
QString tmp = query.value(6).toString();
if (!tmp.isEmpty())
detail.append(tmp);
else
detail.append(tr("No further details"));
AddLogLine(line, helpmsg, detail, detail,
"", query.value(0).toString());
}
if (query.size() == 0)
{
AddLogLine(tr("No items found at priority level %1 or lower.")