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 
21 {
22  if (!LoadWindowFromXML("schedule-ui.xml", "schedulediff", this))
23  return false;
24 
25  bool err = false;
26  UIUtilE::Assign(this, m_conflictList, "conflictlist", &err);
27 
28  UIUtilW::Assign(this, m_titleText, "titletext");
29  UIUtilW::Assign(this, m_noChangesText, "nochanges");
30 
31  if (err)
32  {
33  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'schedulediff'");
34  return false;
35  }
36 
41 
42  if (m_titleText)
44 
47 
48  return true;
49 }
50 
52 {
53  fillList();
54 }
55 
57 {
58  updateUIList();
59 }
60 
62 {
63  if (m_inEvent)
64  return true;
65 
66  m_inEvent = true;
67 
68  QStringList actions;
69 
70  bool handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", e, actions);
71 
72  if (!handled && MythScreenType::keyPressEvent(e))
73  handled = true;
74 
75  m_inEvent = false;
76 
77  return handled;
78 }
79 
81 {
83  if (!pi)
84  return;
85 
86  QString timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");
87 
88  QString message = pi->toString(ProgramInfo::kTitleSubtitle, " - ");
89  message += "\n\n";
92  pi->GetRecordingStartTime());
93 
96  {
97  message += " " + QObject::tr("The following programs will be recorded "
98  "instead:") + "\n\n";
99 
100  for (auto *pa : m_recListAfter)
101  {
102  if (pa->GetRecordingStartTime() >= pi->GetRecordingEndTime())
103  break;
104  if (pa->GetRecordingEndTime() > pi->GetRecordingStartTime() &&
105  (pa->GetRecordingStatus() == RecStatus::WillRecord ||
106  pa->GetRecordingStatus() == RecStatus::Pending ||
107  pa->GetRecordingStatus() == RecStatus::Recording ||
108  pa->GetRecordingStatus() == RecStatus::Tuning ||
109  pa->GetRecordingStatus() == RecStatus::Failing))
110  {
111  message += QString("%1 - %2 %3\n")
112  .arg(pa->GetRecordingStartTime()
113  .toLocalTime().toString(timeFormat))
114  .arg(pa->GetRecordingEndTime()
115  .toLocalTime().toString(timeFormat))
116  .arg(pa->toString(ProgramInfo::kTitleSubtitle, " - "));
117  }
118  }
119  }
120 
121  QString title = QObject::tr("Program Status");
122  MythScreenStack *mainStack = GetMythMainWindow()->GetStack("main stack");
123  auto *dlg = new MythDialogBox(title, message, mainStack,
124  "statusdialog", true);
125 
126  if (dlg->Create())
127  {
128  dlg->AddButton(QObject::tr("OK"));
129  mainStack->AddScreen(dlg);
130  }
131  else
132  delete dlg;
133 }
134 
135 static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
136 {
138  {
140  return 1;
141  return -1;
142  }
143  if (a->GetRecordingEndTime() != b->GetRecordingEndTime())
144  {
146  return 1;
147  return -1;
148  }
150  {
152  return 1;
153  return -1;
154  }
155  if (a->GetRecordingPriority() != b->GetRecordingPriority() &&
160  {
162  return 1;
163  return -1;
164  }
165  return 0;
166 }
167 
168 static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
169 {
170  return comp_recstart(a,b) < 0;
171 }
172 
174 {
175  m_inFill = true;
176 
177  bool dummy = false;
178 
181 
182  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
184  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
186 
187  QDateTime now = MythDate::current();
188 
189  auto it = m_recListBefore.begin();
190  while (it != m_recListBefore.end())
191  {
192  if ((*it)->GetRecordingEndTime() >= now ||
193  (*it)->GetScheduledEndTime() >= now)
194  {
195  ++it;
196  }
197  else
198  {
199  it = m_recListBefore.erase(it);
200  }
201  }
202 
203  it = m_recListAfter.begin();
204  while (it != m_recListAfter.end())
205  {
206  if ((*it)->GetRecordingEndTime() >= now ||
207  (*it)->GetScheduledEndTime() >= now)
208  {
209  ++it;
210  }
211  else
212  {
213  it = m_recListAfter.erase(it);
214  }
215  }
216 
217  auto pb = m_recListBefore.begin();
218  auto pa = m_recListAfter.begin();
219  ProgramStruct s;
220 
221  m_recList.clear();
222  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
223  {
224  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
225  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
226 
227  if (pa == m_recListAfter.end())
228  {
229  ++pb;
230  }
231  else if (pb == m_recListBefore.end())
232  {
233  ++pa;
234  }
235  else
236  {
237  switch (comp_recstart(*pb, *pa))
238  {
239  case 0:
240  ++pb;
241  ++pa;
242  break;
243  case -1: // pb BEFORE pa
244  ++pb;
245  s.m_after = nullptr;
246  break;
247  case 1: // pa BEFORE pb
248  s.m_before = nullptr;
249  ++pa;
250  break;
251  }
252  }
253 
254  if (s.m_before && s.m_after &&
255  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
257  {
258  continue;
259  }
260 
261  m_recList.push_back(s);
262  }
263 
264  m_inFill = false;
265 }
266 
268 {
269  for (auto s : m_recList)
270  {
271  class ProgramInfo *pginfo = s.m_after;
272  if (!pginfo)
273  pginfo = s.m_before;
274 
275  auto *item = new MythUIButtonListItem(m_conflictList, "",
276  QVariant::fromValue(pginfo));
277 
278  InfoMap infoMap;
279  pginfo->ToMap(infoMap);
280 
281  QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
282 
283  item->DisplayState(state, "status");
284  item->SetTextFromMap(infoMap, state);
285 
286  if (s.m_before)
287  {
288  item->SetText(RecStatus::toString(s.m_before->GetRecordingStatus(),
289  s.m_before->GetInputID()), "statusbefore",
290  state);
291  }
292  else
293  {
294  item->SetText("-", "statusbefore");
295  }
296 
297  if (s.m_after)
298  {
299  item->SetText(RecStatus::toString(s.m_after->GetRecordingStatus(),
300  s.m_after->GetInputID()), "statusafter",
301  state);
302  }
303  else
304  {
305  item->SetText("-", "statusafter");
306  }
307  }
308 
309  if (m_noChangesText)
310  {
311  if (m_recList.empty())
313  else
315  }
316 }
317 
319 {
320  if (!item)
321  return;
322 
323  auto *pginfo = item->GetData().value<ProgramInfo*> ();
324  if (pginfo)
325  {
326  InfoMap infoMap;
327  pginfo->ToMap(infoMap);
328  SetTextFromMap(infoMap);
329  }
330 }
331 
333 {
334  int pos = m_conflictList->GetCurrentPos();
335  if (pos >= (int)m_recList.size())
336  return nullptr;
337 
338  ProgramStruct s = m_recList[pos];
339 
340  if (s.m_after)
341  return s.m_after;
342  return s.m_before;
343 }
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:56
ViewScheduleDiff::m_recListAfter
ProgramList m_recListAfter
Definition: viewschedulediff.h:55
MythScreenType::LoadInBackground
void LoadInBackground(const QString &message="")
Definition: mythscreentype.cpp:302
RecStatus::LaterShowing
@ LaterShowing
Definition: recStatus.h:40
ViewScheduleDiff::m_inEvent
bool m_inEvent
Definition: viewschedulediff.h:51
e
QDomElement e
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1420
tv.h
ViewScheduleDiff::showStatus
void showStatus(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:80
ViewScheduleDiff::updateUIList
void updateUIList()
Definition: viewschedulediff.cpp:267
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:636
RecStatus::Tuning
@ Tuning
Definition: recStatus.h:22
ViewScheduleDiff::Create
bool Create(void) override
Definition: viewschedulediff.cpp:20
ViewScheduleDiff::m_recList
std::vector< class ProgramStruct > m_recList
Definition: viewschedulediff.h:64
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
ProgramInfo::kTitleSubtitle
@ kTitleSubtitle
Definition: programinfo.h:500
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:15
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:168
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
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
AutoDeleteDeque::begin
iterator begin(void)
Definition: autodeletedeque.h:50
RecStatus::WillRecord
@ WillRecord
Definition: recStatus.h:31
MythUIButtonListItem
Definition: mythuibuttonlist.h:27
viewschedulediff.h
ViewScheduleDiff::CurrentProgram
ProgramInfo * CurrentProgram(void)
Definition: viewschedulediff.cpp:332
RecStatus::toUIState
static QString toUIState(Type recstatus)
Definition: recStatus.cpp:4
ProgramStruct
Definition: viewschedulediff.h:14
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1125
mythlogging.h
ProgramInfo::GetRecordingStatus
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:445
ViewScheduleDiff::updateInfo
void updateInfo(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:318
MythUIButtonList::itemClicked
void itemClicked(MythUIButtonListItem *item)
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1114
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:198
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:166
ViewScheduleDiff::m_title
QString m_title
Definition: viewschedulediff.h:58
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:51
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
RecStatus::Failing
@ Failing
Definition: recStatus.h:18
ViewScheduleDiff::m_recordid
int m_recordid
recordid that differs from master (-1 = assume all)
Definition: viewschedulediff.h:66
ViewScheduleDiff::fillList
void fillList(void)
Definition: viewschedulediff.cpp:173
MythUIComposite::SetTextFromMap
virtual void SetTextFromMap(const InfoMap &infoMap)
Definition: mythuicomposite.cpp:9
RecStatus::Conflict
@ Conflict
Definition: recStatus.h:39
ViewScheduleDiff::m_titleText
MythUIText * m_titleText
Definition: viewschedulediff.h:61
ProgramInfo::toString
QString toString(Verbosity v=kLongDescription, const QString &sep=":", const QString &grp="\"") const
Definition: programinfo.cpp:1832
scheduledrecording.h
ViewScheduleDiff::m_recListBefore
ProgramList m_recListBefore
Definition: viewschedulediff.h:54
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3580
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
AutoDeleteDeque::end
iterator end(void)
Definition: autodeletedeque.h:51
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
MythUIType::Hide
void Hide(void)
Definition: mythuitype.cpp:1120
ProgramStruct::m_before
ProgramInfo * m_before
Definition: viewschedulediff.h:18
RecStatus::Pending
@ Pending
Definition: recStatus.h:17
ViewScheduleDiff::m_inFill
bool m_inFill
Definition: viewschedulediff.h:52
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:135
ProgramInfo::GetRecordingRuleType
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:449
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
RecStatus::Recording
@ Recording
Definition: recStatus.h:30
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
ViewScheduleDiff::m_noChangesText
MythUIText * m_noChangesText
Definition: viewschedulediff.h:62
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:133
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:104
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
ViewScheduleDiff::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: viewschedulediff.cpp:61
ViewScheduleDiff::m_conflictList
MythUIButtonList * m_conflictList
Definition: viewschedulediff.h:60
AutoDeleteDeque::erase
iterator erase(iterator it)
Definition: autodeletedeque.h:34
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:52
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919
ViewScheduleDiff::m_altTable
QString m_altTable
Definition: viewschedulediff.h:57