/
guidegrid.cpp
2524 lines (2174 loc) · 71.3 KB
/
guidegrid.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 "guidegrid.h"
// c/c++
#include <math.h>
#include <unistd.h>
#include <iostream>
#include <algorithm>
using namespace std;
//qt
#include <QCoreApplication>
#include <QKeyEvent>
#include <QDateTime>
// myth
#include "mythcorecontext.h"
#include "mythdbcon.h"
#include "mythlogging.h"
#include "channelinfo.h"
#include "programinfo.h"
#include "recordingrule.h"
#include "tv_play.h"
#include "tv_rec.h"
#include "mythdate.h"
#include "remoteutil.h"
#include "channelutil.h"
#include "cardutil.h"
#include "tvremoteutil.h"
#include "mythuibuttonlist.h"
#include "mythuiguidegrid.h"
#include "mythdialogbox.h"
#include "progfind.h"
QWaitCondition epgIsVisibleCond;
#define LOC QString("GuideGrid: ")
#define LOC_ERR QString("GuideGrid, Error: ")
#define LOC_WARN QString("GuideGrid, Warning: ")
const QString kUnknownTitle = "";
//const QString kUnknownCategory = QObject::tr("Unknown");
JumpToChannel::JumpToChannel(
JumpToChannelListener *parent, const QString &start_entry,
int start_chan_idx, int cur_chan_idx, uint rows_disp) :
m_listener(parent),
m_entry(start_entry),
m_previous_start_channel_index(start_chan_idx),
m_previous_current_channel_index(cur_chan_idx),
m_rows_displayed(rows_disp),
m_timer(new QTimer(this))
{
if (parent && m_timer)
{
connect(m_timer, SIGNAL(timeout()), SLOT(deleteLater()));
m_timer->setSingleShot(true);
}
Update();
}
void JumpToChannel::deleteLater(void)
{
if (m_listener)
{
m_listener->SetJumpToChannel(NULL);
m_listener = NULL;
}
if (m_timer)
{
m_timer->stop();
m_timer = NULL;
}
QObject::deleteLater();
}
static bool has_action(QString action, const QStringList &actions)
{
QStringList::const_iterator it;
for (it = actions.begin(); it != actions.end(); ++it)
{
if (action == *it)
return true;
}
return false;
}
bool JumpToChannel::ProcessEntry(const QStringList &actions, const QKeyEvent *e)
{
if (!m_listener)
return false;
if (has_action("ESCAPE", actions))
{
m_listener->GoTo(m_previous_start_channel_index,
m_previous_current_channel_index);
deleteLater();
return true;
}
if (has_action("DELETE", actions))
{
if (!m_entry.isEmpty())
m_entry = m_entry.left(m_entry.length()-1);
Update();
return true;
}
if (has_action(ACTION_SELECT, actions))
{
if (Update())
deleteLater();
return true;
}
QString txt = e->text();
bool isUInt;
txt.toUInt(&isUInt);
if (isUInt)
{
m_entry += txt;
Update();
return true;
}
if (!m_entry.isEmpty() && (txt=="_" || txt=="-" || txt=="#" || txt=="."))
{
m_entry += txt;
Update();
return true;
}
return false;
}
bool JumpToChannel::Update(void)
{
if (!m_timer || !m_listener)
return false;
m_timer->stop();
// find the closest channel ...
int i = m_listener->FindChannel(0, m_entry, false);
if (i >= 0)
{
// setup the timeout timer for jump mode
m_timer->start(kJumpToChannelTimeout);
// rows_displayed to center
int start = i - m_rows_displayed/2;
int cur = m_rows_displayed/2;
m_listener->GoTo(start, cur);
return true;
}
else
{ // prefix must be invalid.. reset entry..
deleteLater();
return false;
}
}
// GuideStatus is used for transferring the relevant read-only data
// from GuideGrid to the GuideUpdateProgramRow constructor.
class GuideStatus
{
public:
GuideStatus(unsigned int firstRow, unsigned int numRows,
const QVector<int> &channums,
int channelInfos_size,
const MythRect &gg_programRect,
int gg_channelCount,
const QDateTime ¤tStartTime,
const QDateTime ¤tEndTime,
uint currentStartChannel,
int currentRow, int currentCol,
int channelCount, int timeCount,
bool verticalLayout,
const QDateTime &firstTime, const QDateTime &lastTime)
: m_firstRow(firstRow), m_numRows(numRows), m_channums(channums),
m_channelInfos_size(channelInfos_size),
m_gg_programRect(gg_programRect), m_gg_channelCount(gg_channelCount),
m_currentStartTime(currentStartTime),
m_currentEndTime(currentEndTime),
m_currentStartChannel(currentStartChannel), m_currentRow(currentRow),
m_currentCol(currentCol), m_channelCount(channelCount),
m_timeCount(timeCount), m_verticalLayout(verticalLayout),
m_firstTime(firstTime), m_lastTime(lastTime) {}
const unsigned int m_firstRow, m_numRows;
const QVector<int> m_channums;
const int m_channelInfos_size;
const MythRect m_gg_programRect;
const int m_gg_channelCount;
const QDateTime m_currentStartTime, m_currentEndTime;
const uint m_currentStartChannel;
const int m_currentRow, m_currentCol;
const int m_channelCount, m_timeCount;
const bool m_verticalLayout;
const QDateTime m_firstTime, m_lastTime;
};
class GuideUpdaterBase
{
public:
GuideUpdaterBase(GuideGrid *guide) : m_guide(guide) {}
virtual ~GuideUpdaterBase() {}
// Execute the initial non-UI part (in a separate thread). Return
// true if ExecuteUI() should be run later, or false if the work
// is no longer relevant (e.g., the UI elements have scrolled
// offscreen by now).
virtual bool ExecuteNonUI(void) = 0;
// Execute the UI part in the UI thread.
virtual void ExecuteUI(void) = 0;
protected:
GuideGrid *m_guide;
};
class GuideUpdateProgramRow : public GuideUpdaterBase
{
public:
GuideUpdateProgramRow(GuideGrid *guide, const GuideStatus &gs,
const QVector<ProgramList*> &proglists)
: GuideUpdaterBase(guide),
m_firstRow(gs.m_firstRow),
m_numRows(gs.m_numRows),
m_channums(gs.m_channums),
m_channelInfos_size(gs.m_channelInfos_size),
m_gg_programRect(gs.m_gg_programRect),
m_gg_channelCount(gs.m_gg_channelCount),
m_currentStartTime(gs.m_currentStartTime),
m_currentEndTime(gs.m_currentEndTime),
m_currentStartChannel(gs.m_currentStartChannel),
m_currentRow(gs.m_currentRow),
m_currentCol(gs.m_currentCol),
m_channelCount(gs.m_channelCount),
m_timeCount(gs.m_timeCount),
m_verticalLayout(gs.m_verticalLayout),
m_firstTime(gs.m_firstTime),
m_lastTime(gs.m_lastTime),
m_proglists(proglists),
m_progPast(0)
{
for (unsigned int i = m_firstRow;
i < m_firstRow + m_numRows; ++i)
for (int j = 0; j < MAX_DISPLAY_TIMES; ++j)
m_programInfos[i][j] = NULL;
}
virtual ~GuideUpdateProgramRow() {}
virtual bool ExecuteNonUI(void)
{
// Don't bother to do any work if the starting coordinates of
// the guide have changed while the thread was waiting to
// start.
if (m_currentStartChannel != m_guide->GetCurrentStartChannel() ||
m_currentStartTime != m_guide->GetCurrentStartTime())
{
return false;
}
for (unsigned int i = 0; i < m_numRows; ++i)
{
unsigned int row = i + m_firstRow;
if (!m_proglists[i])
m_proglists[i] =
m_guide->getProgramListFromProgram(m_channums[i]);
fillProgramRowInfosWith(row, m_channums[i],
m_currentStartTime,
m_proglists[i]);
}
return true;
}
virtual void ExecuteUI(void)
{
m_guide->updateProgramsUI(m_firstRow, m_numRows,
m_progPast, m_proglists,
m_programInfos, m_result);
}
private:
void fillProgramRowInfosWith(int row, int chanNum, QDateTime start,
ProgramList *proglist);
const unsigned int m_firstRow;
const unsigned int m_numRows;
const QVector<int> m_channums;
const int m_channelInfos_size;
const MythRect m_gg_programRect;
const int m_gg_channelCount;
const QDateTime m_currentStartTime;
const QDateTime m_currentEndTime;
const uint m_currentStartChannel;
const int m_currentRow;
const int m_currentCol;
const int m_channelCount;
const int m_timeCount;
const bool m_verticalLayout;
const QDateTime m_firstTime;
const QDateTime m_lastTime;
QVector<ProgramList*> m_proglists;
ProgInfoGuideArray m_programInfos;
int m_progPast;
//QVector<GuideUIElement> m_result;
QLinkedList<GuideUIElement> m_result;
};
class GuideUpdateChannels : public GuideUpdaterBase
{
public:
GuideUpdateChannels(GuideGrid *guide, uint startChan)
: GuideUpdaterBase(guide), m_currentStartChannel(startChan) {}
virtual bool ExecuteNonUI(void)
{
if (m_currentStartChannel != m_guide->GetCurrentStartChannel())
return false;
m_guide->updateChannelsNonUI(m_chinfos, m_unavailables);
return true;
}
virtual void ExecuteUI(void)
{
m_guide->updateChannelsUI(m_chinfos, m_unavailables);
}
uint m_currentStartChannel;
QVector<ChannelInfo *> m_chinfos;
QVector<bool> m_unavailables;
};
class UpdateGuideEvent : public QEvent
{
public:
UpdateGuideEvent(GuideUpdaterBase *updater) :
QEvent(kEventType), m_updater(updater) {}
GuideUpdaterBase *m_updater;
static Type kEventType;
};
QEvent::Type UpdateGuideEvent::kEventType =
(QEvent::Type) QEvent::registerEventType();
class GuideHelper : public QRunnable
{
public:
GuideHelper(GuideGrid *guide, GuideUpdaterBase *updater)
: m_guide(guide), m_updater(updater)
{
QMutexLocker locker(&s_lock);
++s_loading[m_guide];
}
virtual void run(void)
{
QThread::currentThread()->setPriority(QThread::IdlePriority);
if (m_updater)
{
if (m_updater->ExecuteNonUI())
QCoreApplication::postEvent(m_guide,
new UpdateGuideEvent(m_updater));
else
{
delete m_updater;
m_updater = NULL;
}
}
QMutexLocker locker(&s_lock);
--s_loading[m_guide];
if (!s_loading[m_guide])
s_wait.wakeAll();
}
static bool IsLoading(GuideGrid *guide)
{
QMutexLocker locker(&s_lock);
return s_loading[guide];
}
static void Wait(GuideGrid *guide)
{
QMutexLocker locker(&s_lock);
if (!s_loading[guide])
return;
while (s_wait.wait(&s_lock))
{
if (!s_loading[guide])
return;
}
}
private:
GuideGrid *m_guide;
GuideUpdaterBase *m_updater;
static QMutex s_lock;
static QWaitCondition s_wait;
static QMap<GuideGrid*,uint> s_loading;
};
QMutex GuideHelper::s_lock;
QWaitCondition GuideHelper::s_wait;
QMap<GuideGrid*,uint> GuideHelper::s_loading;
void GuideGrid::RunProgramGuide(uint chanid, const QString &channum,
const QDateTime &startTime,
TV *player, bool embedVideo,
bool allowFinder, int changrpid)
{
// which channel group should we default to
if (changrpid == -2)
changrpid = gCoreContext->GetNumSetting("ChannelGroupDefault", -1);
// check there are some channels setup
ChannelInfoList channels = ChannelUtil::GetChannels(
0, true, "", (changrpid<0) ? 0 : changrpid);
if (channels.empty())
{
QString message;
if (changrpid == -1)
{
message = tr("You don't have any channels defined in the database."
"\n\t\t\tThe program guide will have nothing to show you.");
}
else
{
message = tr("Channel group '%1' doesn't have any channels defined."
"\n\t\t\tThe program guide will have nothing to show you.")
.arg(ChannelGroup::GetChannelGroupName(changrpid));
}
LOG(VB_GENERAL, LOG_WARNING, LOC + message);
if (!player)
ShowOkPopup(message);
else
{
if (player && allowFinder)
{
message = QString("EPG_EXITING");
qApp->postEvent(player, new MythEvent(message));
}
}
return;
}
// If chanid/channum are unset, find the channel that would
// naturally be selected when Live TV is started. This depends on
// the available tuners, their capturecard.livetvorder values, and
// their capturecard.startchan values.
QString actualChannum = channum;
if (chanid == 0 && actualChannum.isEmpty())
{
uint defaultChanid = gCoreContext->GetNumSetting("DefaultChanid", 0);
if (defaultChanid && TV::IsTunable(defaultChanid))
chanid = defaultChanid;
}
if (chanid == 0 && actualChannum.isEmpty())
{
vector<uint> excluded_cardids;
vector<uint> inputIDs = RemoteRequestFreeInputList(excluded_cardids);
if (!inputIDs.empty())
actualChannum = CardUtil::GetStartingChannel(inputIDs[0]);
}
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
GuideGrid *gg = new GuideGrid(mainStack,
chanid, actualChannum, startTime,
player, embedVideo, allowFinder,
changrpid);
if (gg->Create())
mainStack->AddScreen(gg, (player == NULL));
else
delete gg;
}
GuideGrid::GuideGrid(MythScreenStack *parent,
uint chanid, const QString &channum, const QDateTime &startTime,
TV *player, bool embedVideo,
bool allowFinder, int changrpid)
: ScheduleCommon(parent, "guidegrid"),
m_selectRecThreshold(gCoreContext->GetNumSetting("SelChangeRecThreshold", 16)),
m_allowFinder(allowFinder),
m_currentStartChannel(0),
m_startChanID(chanid),
m_startChanNum(channum),
m_currentRow(0),
m_currentCol(0),
m_sortReverse(gCoreContext->GetNumSetting("EPGSortReverse", 0)),
m_channelCount(5),
m_timeCount(30),
m_verticalLayout(false),
m_player(player),
m_usingNullVideo(false),
m_embedVideo(embedVideo),
m_previewVideoRefreshTimer(new QTimer(this)),
m_channelOrdering(gCoreContext->GetSetting("ChannelOrdering", "channum")),
m_updateTimer(NULL),
m_threadPool("GuideGridHelperPool"),
m_changrpid(changrpid),
m_changrplist(ChannelGroup::GetChannelGroups(false)),
m_jumpToChannelLock(QMutex::Recursive),
m_jumpToChannel(NULL),
m_timeList(NULL),
m_channelList(NULL),
m_guideGrid(NULL),
m_dateText(NULL),
m_longdateText(NULL),
m_jumpToText(NULL),
m_changroupname(NULL),
m_channelImage(NULL)
{
connect(m_previewVideoRefreshTimer, SIGNAL(timeout()),
this, SLOT(refreshVideo()));
for (uint i = 0; i < MAX_DISPLAY_CHANS; i++)
m_programs.push_back(NULL);
for (int x = 0; x < MAX_DISPLAY_TIMES; ++x)
{
for (int y = 0; y < MAX_DISPLAY_CHANS; ++y)
m_programInfos[y][x] = NULL;
}
m_originalStartTime = MythDate::current();
if (startTime.isValid() &&
startTime > m_originalStartTime.addSecs(-8 * 3600))
m_originalStartTime = startTime;
int secsoffset = -((m_originalStartTime.time().minute() % 30) * 60 +
m_originalStartTime.time().second());
m_currentStartTime = m_originalStartTime.addSecs(secsoffset);
m_threadPool.setMaxThreadCount(1);
}
bool GuideGrid::Create()
{
QString windowName = "programguide";
if (m_embedVideo)
windowName = "programguide-video";
if (!LoadWindowFromXML("schedule-ui.xml", windowName, this))
return false;
bool err = false;
UIUtilE::Assign(this, m_timeList, "timelist", &err);
UIUtilE::Assign(this, m_channelList, "channellist", &err);
UIUtilE::Assign(this, m_guideGrid, "guidegrid", &err);
UIUtilW::Assign(this, m_dateText, "datetext");
UIUtilW::Assign(this, m_longdateText, "longdatetext");
UIUtilW::Assign(this, m_changroupname, "channelgroup");
UIUtilW::Assign(this, m_channelImage, "channelicon");
UIUtilW::Assign(this, m_jumpToText, "jumptotext");
if (err)
{
LOG(VB_GENERAL, LOG_ERR,
QString("Cannot load screen '%1'").arg(windowName));
return false;
}
BuildFocusList();
MythUIImage *videoImage = dynamic_cast<MythUIImage *>(GetChild("video"));
if (videoImage && m_embedVideo)
m_videoRect = videoImage->GetArea();
else
m_videoRect = QRect(0,0,0,0);
m_channelCount = m_guideGrid->getChannelCount();
m_timeCount = m_guideGrid->getTimeCount() * 6;
m_verticalLayout = m_guideGrid->isVerticalLayout();
m_currentEndTime = m_currentStartTime.addSecs(m_timeCount * 60 * 5);
LoadInBackground();
return true;
}
void GuideGrid::Load(void)
{
LoadFromScheduler(m_recList);
fillChannelInfos();
int maxchannel = max((int)GetChannelCount() - 1, 0);
setStartChannel((int)(m_currentStartChannel) - (int)(m_channelCount / 2));
m_channelCount = min(m_channelCount, maxchannel + 1);
for (int y = 0; y < m_channelCount; ++y)
{
int chanNum = y + m_currentStartChannel;
if (chanNum >= (int) m_channelInfos.size())
chanNum -= (int) m_channelInfos.size();
if (chanNum >= (int) m_channelInfos.size())
continue;
if (chanNum < 0)
chanNum = 0;
delete m_programs[y];
m_programs[y] = getProgramListFromProgram(chanNum);
}
}
void GuideGrid::Init(void)
{
m_currentRow = (int)(m_channelCount / 2);
m_currentCol = 0;
fillTimeInfos();
updateChannels();
fillProgramInfos(true);
m_updateTimer = new QTimer(this);
connect(m_updateTimer, SIGNAL(timeout()), SLOT(updateTimeout()) );
m_updateTimer->start(60 * 1000);
updateDateText();
QString changrpname = ChannelGroup::GetChannelGroupName(m_changrpid);
if (m_changroupname)
m_changroupname->SetText(changrpname);
gCoreContext->addListener(this);
}
GuideGrid::~GuideGrid()
{
GuideHelper::Wait(this);
gCoreContext->removeListener(this);
while (!m_programs.empty())
{
if (m_programs.back())
delete m_programs.back();
m_programs.pop_back();
}
m_channelInfos.clear();
if (m_updateTimer)
{
m_updateTimer->disconnect(this);
m_updateTimer = NULL;
}
if (m_previewVideoRefreshTimer)
{
m_previewVideoRefreshTimer->disconnect(this);
m_previewVideoRefreshTimer = NULL;
}
gCoreContext->SaveSetting("EPGSortReverse", m_sortReverse ? "1" : "0");
// if we have a player and we are returning to it we need
// to tell it to stop embedding and return to fullscreen
if (m_player && m_allowFinder)
{
QString message = QString("EPG_EXITING");
qApp->postEvent(m_player, new MythEvent(message));
}
// maybe the user selected a different channel group,
// tell the player to update its channel list just in case
if (m_player)
m_player->UpdateChannelList(m_changrpid);
if (gCoreContext->GetNumSetting("ChannelGroupRememberLast", 0))
gCoreContext->SaveSetting("ChannelGroupDefault", m_changrpid);
}
bool GuideGrid::keyPressEvent(QKeyEvent *event)
{
QStringList actions;
bool handled = false;
handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", event, actions);
if (handled)
return true;
if (actions.size())
{
QMutexLocker locker(&m_jumpToChannelLock);
if (!m_jumpToChannel)
{
QString chanNum = actions[0];
bool isNum;
chanNum.toInt(&isNum);
if (isNum)
{
// see if we can find a matching channel before creating the JumpToChannel otherwise
// JumpToChannel will delete itself in the ctor leading to a segfault
int i = FindChannel(0, chanNum, false);
if (i >= 0)
{
m_jumpToChannel = new JumpToChannel(this, chanNum,
m_currentStartChannel,
m_currentRow, m_channelCount);
updateJumpToChannel();
}
handled = true;
}
}
if (m_jumpToChannel && !handled)
handled = m_jumpToChannel->ProcessEntry(actions, event);
}
for (int i = 0; i < actions.size() && !handled; ++i)
{
QString action = actions[i];
handled = true;
if (action == ACTION_UP)
{
if (m_verticalLayout)
cursorLeft();
else
cursorUp();
}
else if (action == ACTION_DOWN)
{
if (m_verticalLayout)
cursorRight();
else
cursorDown();
}
else if (action == ACTION_LEFT)
{
if (m_verticalLayout)
cursorUp();
else
cursorLeft();
}
else if (action == ACTION_RIGHT)
{
if (m_verticalLayout)
cursorDown();
else
cursorRight();
}
else if (action == "PAGEUP")
{
if (m_verticalLayout)
moveLeftRight(kPageLeft);
else
moveUpDown(kPageUp);
}
else if (action == "PAGEDOWN")
{
if (m_verticalLayout)
moveLeftRight(kPageRight);
else
moveUpDown(kPageDown);
}
else if (action == ACTION_PAGELEFT)
{
if (m_verticalLayout)
moveUpDown(kPageUp);
else
moveLeftRight(kPageLeft);
}
else if (action == ACTION_PAGERIGHT)
{
if (m_verticalLayout)
moveUpDown(kPageDown);
else
moveLeftRight(kPageRight);
}
else if (action == ACTION_DAYLEFT)
moveLeftRight(kDayLeft);
else if (action == ACTION_DAYRIGHT)
moveLeftRight(kDayRight);
else if (action == "NEXTFAV")
toggleGuideListing();
else if (action == ACTION_FINDER)
showProgFinder();
else if (action == ACTION_CHANNELSEARCH)
ShowChannelSearch();
else if (action == "MENU")
ShowMenu();
else if (action == "ESCAPE" || action == ACTION_GUIDE)
Close();
else if (action == ACTION_SELECT)
{
if (m_player && (m_player->GetState(-1) == kState_WatchingLiveTV))
{
// See if this show is far enough into the future that it's
// probable that the user wanted to schedule it to record
// instead of changing the channel.
ProgramInfo *pginfo =
m_programInfos[m_currentRow][m_currentCol];
int secsTillStart =
(pginfo) ? MythDate::current().secsTo(
pginfo->GetScheduledStartTime()) : 0;
if (pginfo && (pginfo->GetTitle() != kUnknownTitle) &&
((secsTillStart / 60) >= m_selectRecThreshold))
{
EditRecording();
}
else
{
enter();
}
}
else
EditRecording();
}
else if (action == "EDIT")
EditScheduled();
else if (action == "CUSTOMEDIT")
EditCustom();
else if (action == "DELETE")
deleteRule();
else if (action == "UPCOMING")
ShowUpcoming();
else if (action == "PREVRECORDED")
ShowPrevious();
else if (action == "DETAILS" || action == "INFO")
ShowDetails();
else if (action == ACTION_TOGGLERECORD)
QuickRecord();
else if (action == ACTION_TOGGLEFAV)
{
if (m_changrpid == -1)
ChannelGroupMenu(0);
else
toggleChannelFavorite();
}
else if (action == "CHANUPDATE")
channelUpdate();
else if (action == ACTION_VOLUMEUP)
volumeUpdate(true);
else if (action == ACTION_VOLUMEDOWN)
volumeUpdate(false);
else if (action == "CYCLEAUDIOCHAN")
toggleMute(true);
else if (action == ACTION_MUTEAUDIO)
toggleMute();
else if (action == ACTION_TOGGLEPGORDER)
{
m_sortReverse = !m_sortReverse;
generateListings();
updateChannels();
}
else
handled = false;
}
if (!handled && MythScreenType::keyPressEvent(event))
handled = true;
return handled;
}
static bool SelectionIsTunable(const ChannelInfoList &selection)
{
for (uint i = 0; i < selection.size(); ++i)
{
if (TV::IsTunable(selection[i].chanid))
return true;
}
return false;
}
void GuideGrid::ShowMenu(void)
{
QString label = tr("Guide Options");
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
MythDialogBox *menuPopup = new MythDialogBox(label, popupStack,
"guideMenuPopup");
if (menuPopup->Create())
{
menuPopup->SetReturnEvent(this, "guidemenu");
if (m_player && (m_player->GetState(-1) == kState_WatchingLiveTV))
menuPopup->AddButton(tr("Change to Channel"));
else if (SelectionIsTunable(GetSelection()))
menuPopup->AddButton(tr("Watch This Channel"));
menuPopup->AddButton(tr("Record This"));
menuPopup->AddButton(tr("Recording Options"), NULL, true);
menuPopup->AddButton(tr("Program Details"));
menuPopup->AddButton(tr("Jump to Time"), NULL, true);
menuPopup->AddButton(tr("Reverse Channel Order"));
menuPopup->AddButton(tr("Channel Search"));
if (!m_changrplist.empty())
{
menuPopup->AddButton(tr("Choose Channel Group"));
if (m_changrpid == -1)
menuPopup->AddButton(tr("Add To Channel Group"), NULL, true);
else
menuPopup->AddButton(tr("Remove from Channel Group"), NULL, true);
}
popupStack->AddScreen(menuPopup);
}
else
{
delete menuPopup;
}
}
void GuideGrid::ShowRecordingMenu(void)
{
QString label = tr("Recording Options");
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
MythDialogBox *menuPopup = new MythDialogBox(label, popupStack,
"recMenuPopup");
if (menuPopup->Create())
{
menuPopup->SetReturnEvent(this, "recmenu");
ProgramInfo *pginfo = m_programInfos[m_currentRow][m_currentCol];
if (pginfo && pginfo->GetRecordingRuleID())
menuPopup->AddButton(tr("Edit Recording Status"));
menuPopup->AddButton(tr("Edit Schedule"));
menuPopup->AddButton(tr("Show Upcoming"));
menuPopup->AddButton(tr("Previously Recorded"));
menuPopup->AddButton(tr("Custom Edit"));
if (pginfo && pginfo->GetRecordingRuleID())
menuPopup->AddButton(tr("Delete Rule"));
popupStack->AddScreen(menuPopup);
}
else
{
delete menuPopup;
}
}
ChannelInfo *GuideGrid::GetChannelInfo(uint chan_idx, int sel)
{
sel = (sel >= 0) ? sel : m_channelInfoIdx[chan_idx];
if (chan_idx >= GetChannelCount())
return NULL;
if (sel >= (int) m_channelInfos[chan_idx].size())
return NULL;
return &(m_channelInfos[chan_idx][sel]);
}
const ChannelInfo *GuideGrid::GetChannelInfo(uint chan_idx, int sel) const
{
return ((GuideGrid*)this)->GetChannelInfo(chan_idx, sel);
}
uint GuideGrid::GetChannelCount(void) const
{
return m_channelInfos.size();
}
int GuideGrid::GetStartChannelOffset(int row) const
{
uint cnt = GetChannelCount();
if (!cnt)
return -1;
row = (row < 0) ? m_currentRow : row;
return (row + m_currentStartChannel) % cnt;
}
ProgramList GuideGrid::GetProgramList(uint chanid) const
{
ProgramList proglist;
MSqlBindings bindings;
QString querystr =
"WHERE program.chanid = :CHANID AND "
" program.endtime >= :STARTTS AND "
" program.starttime <= :ENDTS AND "
" program.starttime >= :STARTLIMITTS AND "
" program.manualid = 0 ";
QDateTime starttime = m_currentStartTime.addSecs(0 - m_currentStartTime.time().second());
bindings[":STARTTS"] = starttime;
bindings[":STARTLIMITTS"] = starttime.addDays(-1);
bindings[":ENDTS"] = m_currentEndTime.addSecs(0 - m_currentEndTime.time().second());
bindings[":CHANID"] = chanid;
ProgramList dummy;
LoadFromProgram(proglist, querystr, bindings, dummy);