MythTV  master
viewschedulediff.cpp
Go to the documentation of this file.
1 // myth
2 #include "mythcorecontext.h"
3 #include "mythlogging.h"
4 #include "remoteutil.h"
5 #include "recordinginfo.h"
6 
7 //mythui
8 #include "mythuitext.h"
9 #include "mythuibuttonlist.h"
10 #include "mythmainwindow.h"
11 #include "mythdialogbox.h"
12 
13 //mythtv
14 #include "scheduledrecording.h"
15 #include "tv.h"
16 
17 //mythfrontend
18 #include "viewschedulediff.h"
19 
20 using namespace std;
21 
23 {
24  if (!LoadWindowFromXML("schedule-ui.xml", "schedulediff", this))
25  return false;
26 
27  bool err = false;
28  UIUtilE::Assign(this, m_conflictList, "conflictlist", &err);
29 
30  UIUtilW::Assign(this, m_titleText, "titletext");
31  UIUtilW::Assign(this, m_noChangesText, "nochanges");
32 
33  if (err)
34  {
35  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'schedulediff'");
36  return false;
37  }
38 
39  connect(m_conflictList, SIGNAL(itemSelected(MythUIButtonListItem*)),
40  SLOT(updateInfo(MythUIButtonListItem*)));
41  connect(m_conflictList, SIGNAL(itemClicked(MythUIButtonListItem*)),
43 
44  if (m_titleText)
45  m_titleText->SetText(m_title);
46 
47  BuildFocusList();
48  LoadInBackground();
49 
50  return true;
51 }
52 
54 {
55  fillList();
56 }
57 
59 {
60  updateUIList();
61 }
62 
64 {
65  if (m_inEvent)
66  return true;
67 
68  m_inEvent = true;
69 
70  QStringList actions;
71 
72  bool handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", e, actions);
73 
74  if (!handled && MythScreenType::keyPressEvent(e))
75  handled = true;
76 
77  m_inEvent = false;
78 
79  return handled;
80 }
81 
83 {
84  ProgramInfo *pi = CurrentProgram();
85  if (!pi)
86  return;
87 
88  QString timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");
89 
90  QString message = pi->toString(ProgramInfo::kTitleSubtitle, " - ");
91  message += "\n\n";
94  pi->GetRecordingStartTime());
95 
98  {
99  message += " " + QObject::tr("The following programs will be recorded "
100  "instead:") + "\n\n";
101 
102  for (auto *pa : m_recListAfter)
103  {
104  if (pa->GetRecordingStartTime() >= pi->GetRecordingEndTime())
105  break;
106  if (pa->GetRecordingEndTime() > pi->GetRecordingStartTime() &&
107  (pa->GetRecordingStatus() == RecStatus::WillRecord ||
108  pa->GetRecordingStatus() == RecStatus::Pending ||
109  pa->GetRecordingStatus() == RecStatus::Recording ||
110  pa->GetRecordingStatus() == RecStatus::Tuning ||
111  pa->GetRecordingStatus() == RecStatus::Failing))
112  {
113  message += QString("%1 - %2 %3\n")
114  .arg(pa->GetRecordingStartTime()
115  .toLocalTime().toString(timeFormat))
116  .arg(pa->GetRecordingEndTime()
117  .toLocalTime().toString(timeFormat))
118  .arg(pa->toString(ProgramInfo::kTitleSubtitle, " - "));
119  }
120  }
121  }
122 
123  QString title = QObject::tr("Program Status");
124  MythScreenStack *mainStack = GetMythMainWindow()->GetStack("main stack");
125  auto *dlg = new MythDialogBox(title, message, mainStack,
126  "statusdialog", true);
127 
128  if (dlg->Create())
129  {
130  dlg->AddButton(QObject::tr("OK"));
131  mainStack->AddScreen(dlg);
132  }
133  else
134  delete dlg;
135 }
136 
137 static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
138 {
140  {
142  return 1;
143  return -1;
144  }
145  if (a->GetRecordingEndTime() != b->GetRecordingEndTime())
146  {
148  return 1;
149  return -1;
150  }
152  {
154  return 1;
155  return -1;
156  }
157  if (a->GetRecordingPriority() != b->GetRecordingPriority() &&
162  {
164  return 1;
165  return -1;
166  }
167  return 0;
168 }
169 
170 static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
171 {
172  return comp_recstart(a,b) < 0;
173 }
174 
176 {
177  m_inFill = true;
178 
179  bool dummy = false;
180 
181  LoadFromScheduler(m_recListBefore, dummy);
182  LoadFromScheduler(m_recListAfter, dummy, m_altTable, m_recordid);
183 
184  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
186  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
188 
189  QDateTime now = MythDate::current();
190 
191  auto it = m_recListBefore.begin();
192  while (it != m_recListBefore.end())
193  {
194  if ((*it)->GetRecordingEndTime() >= now ||
195  (*it)->GetScheduledEndTime() >= now)
196  {
197  ++it;
198  }
199  else
200  {
201  it = m_recListBefore.erase(it);
202  }
203  }
204 
205  it = m_recListAfter.begin();
206  while (it != m_recListAfter.end())
207  {
208  if ((*it)->GetRecordingEndTime() >= now ||
209  (*it)->GetScheduledEndTime() >= now)
210  {
211  ++it;
212  }
213  else
214  {
215  it = m_recListAfter.erase(it);
216  }
217  }
218 
219  auto pb = m_recListBefore.begin();
220  auto pa = m_recListAfter.begin();
221  ProgramStruct s;
222 
223  m_recList.clear();
224  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
225  {
226  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
227  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
228 
229  if (pa == m_recListAfter.end())
230  {
231  ++pb;
232  }
233  else if (pb == m_recListBefore.end())
234  {
235  ++pa;
236  }
237  else
238  {
239  switch (comp_recstart(*pb, *pa))
240  {
241  case 0:
242  ++pb;
243  ++pa;
244  break;
245  case -1: // pb BEFORE pa
246  ++pb;
247  s.m_after = nullptr;
248  break;
249  case 1: // pa BEFORE pb
250  s.m_before = nullptr;
251  ++pa;
252  break;
253  }
254  }
255 
256  if (s.m_before && s.m_after &&
257  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
259  {
260  continue;
261  }
262 
263  m_recList.push_back(s);
264  }
265 
266  m_inFill = false;
267 }
268 
270 {
271  for (auto s : m_recList)
272  {
273  class ProgramInfo *pginfo = s.m_after;
274  if (!pginfo)
275  pginfo = s.m_before;
276 
277  auto *item = new MythUIButtonListItem(m_conflictList, "",
278  QVariant::fromValue(pginfo));
279 
280  InfoMap infoMap;
281  pginfo->ToMap(infoMap);
282 
283  QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
284 
285  item->DisplayState(state, "status");
286  item->SetTextFromMap(infoMap, state);
287 
288  if (s.m_before)
289  {
290  item->SetText(RecStatus::toString(s.m_before->GetRecordingStatus(),
291  s.m_before->GetInputID()), "statusbefore",
292  state);
293  }
294  else
295  {
296  item->SetText("-", "statusbefore");
297  }
298 
299  if (s.m_after)
300  {
301  item->SetText(RecStatus::toString(s.m_after->GetRecordingStatus(),
302  s.m_after->GetInputID()), "statusafter",
303  state);
304  }
305  else
306  {
307  item->SetText("-", "statusafter");
308  }
309  }
310 
311  if (m_noChangesText)
312  {
313  if (m_recList.empty())
314  m_noChangesText->Show();
315  else
316  m_noChangesText->Hide();
317  }
318 }
319 
321 {
322  if (!item)
323  return;
324 
325  auto *pginfo = item->GetData().value<ProgramInfo*> ();
326  if (pginfo)
327  {
328  InfoMap infoMap;
329  pginfo->ToMap(infoMap);
330  SetTextFromMap(infoMap);
331  }
332 }
333 
335 {
336  int pos = m_conflictList->GetCurrentPos();
337  if (pos >= (int)m_recList.size())
338  return nullptr;
339 
340  ProgramStruct s = m_recList[pos];
341 
342  if (s.m_after)
343  return s.m_after;
344  return s.m_before;
345 }
ViewScheduleDiff::Init
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
Definition: viewschedulediff.cpp:58
RecStatus::LaterShowing
@ LaterShowing
Definition: recStatus.h:40
e
QDomElement e
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1423
tv.h
ViewScheduleDiff::showStatus
void showStatus(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:82
ViewScheduleDiff::updateUIList
void updateUIList()
Definition: viewschedulediff.cpp:269
mythuitext.h
LoadFromScheduler
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:883
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:639
RecStatus::Tuning
@ Tuning
Definition: recStatus.h:22
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1104
ViewScheduleDiff::Create
bool Create(void) override
Definition: viewschedulediff.cpp:22
ProgramInfo::kTitleSubtitle
@ kTitleSubtitle
Definition: programinfo.h:500
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
ProgramInfo::GetChannelSchedulingID
QString GetChannelSchedulingID(void) const
This is the unique programming identifier of a channel.
Definition: programinfo.h:381
comp_recstart_less_than
static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
Definition: viewschedulediff.cpp:170
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
ProgramInfo::GetRecordingEndTime
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:410
ProgramInfo::GetRecordingPriority
int GetRecordingPriority(void) const
Definition: programinfo.h:438
remoteutil.h
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:309
mythuibuttonlist.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
ProgramInfo::GetRecordingStartTime
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:402
ProgramStruct::m_after
ProgramInfo * m_after
Definition: viewschedulediff.h:19
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
RecStatus::WillRecord
@ WillRecord
Definition: recStatus.h:31
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
viewschedulediff.h
ViewScheduleDiff::CurrentProgram
ProgramInfo * CurrentProgram(void)
Definition: viewschedulediff.cpp:334
RecStatus::toUIState
static QString toUIState(Type recstatus)
Definition: recStatus.cpp:4
ProgramStruct
Definition: viewschedulediff.h:15
mythlogging.h
ProgramInfo::GetRecordingStatus
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:445
ViewScheduleDiff::updateInfo
void updateInfo(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:320
RecStatus::toDescription
static QString toDescription(Type recstatus, RecordingType rectype, const QDateTime &recstartts)
Converts "recstatus" into a long human readable description.
Definition: recStatus.cpp:187
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:138
ViewScheduleDiff::Load
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
Definition: viewschedulediff.cpp:53
RecStatus::Failing
@ Failing
Definition: recStatus.h:18
ViewScheduleDiff::fillList
void fillList(void)
Definition: viewschedulediff.cpp:175
RecStatus::Conflict
@ Conflict
Definition: recStatus.h:39
ProgramInfo::toString
QString toString(Verbosity v=kLongDescription, const QString &sep=":", const QString &grp="\"") const
Definition: programinfo.cpp:1825
scheduledrecording.h
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3580
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
ProgramStruct::m_before
ProgramInfo * m_before
Definition: viewschedulediff.h:18
RecStatus::Pending
@ Pending
Definition: recStatus.h:17
ProgramInfo::GetInputID
uint GetInputID(void) const
Definition: programinfo.h:461
recordinginfo.h
comp_recstart
static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
Definition: viewschedulediff.cpp:137
ProgramInfo::GetRecordingRuleType
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:449
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:68
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
RecStatus::Recording
@ Recording
Definition: recStatus.h:30
mythcorecontext.h
ProgramInfo::ToMap
virtual void ToMap(InfoMap &progMap, bool showrerecord=false, uint star_range=10) const
Converts ProgramInfo into QString QHash containing each field in ProgramInfo converted into localized...
Definition: programinfo.cpp:1464
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
showStatus
static void showStatus(void)
Definition: mythtv/programs/mythfrontend/main.cpp:650
ViewScheduleDiff::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: viewschedulediff.cpp:63
RecStatus::toString
static QString toString(Type recstatus, uint id)
Converts "recstatus" into a short (unreadable) string.
Definition: recStatus.cpp:39
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:916