MythTV  master
viewschedulediff.cpp
Go to the documentation of this file.
1 // MythTV
8 #include "libmythtv/tv.h"
12 #include "libmythui/mythuitext.h"
13 
14 // MythFrontend
15 #include "viewschedulediff.h"
16 
18 {
19  if (!LoadWindowFromXML("schedule-ui.xml", "schedulediff", this))
20  return false;
21 
22  bool err = false;
23  UIUtilE::Assign(this, m_conflictList, "conflictlist", &err);
24 
25  UIUtilW::Assign(this, m_titleText, "titletext");
26  UIUtilW::Assign(this, m_noChangesText, "nochanges");
27 
28  if (err)
29  {
30  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'schedulediff'");
31  return false;
32  }
33 
38 
39  if (m_titleText)
41 
44 
45  return true;
46 }
47 
49 {
50  fillList();
51 }
52 
54 {
55  updateUIList();
56 }
57 
59 {
60  if (m_inEvent)
61  return true;
62 
63  m_inEvent = true;
64 
65  QStringList actions;
66 
67  bool handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", e, actions);
68 
69  if (!handled && MythScreenType::keyPressEvent(e))
70  handled = true;
71 
72  m_inEvent = false;
73 
74  return handled;
75 }
76 
78 {
80  if (!pi)
81  return;
82 
83  QString timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");
84 
85  QString message = QString("%1 - %2 %3\n")
86  .arg(pi->GetRecordingStartTime().toLocalTime().toString(timeFormat),
87  pi->GetRecordingEndTime().toLocalTime().toString(timeFormat),
89 
90  message += "\n";
93  pi->GetRecordingStartTime());
94 
95  QString messageConflict;
98  {
99  uint pi_chanid = pi->GetChanID();
100  uint pi_sourceid = ChannelUtil::GetSourceIDForChannel(pi_chanid);
101 
102  for (auto *pa : m_recListAfter)
103  {
104  if ((pa->GetRecordingStartTime() < pi->GetRecordingEndTime() ) &&
105  (pa->GetRecordingEndTime() > pi->GetRecordingStartTime()) &&
106  (pa->GetSourceID() == pi_sourceid ) &&
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  messageConflict += QString("%1 - %2 %3\n")
114  .arg(pa->GetRecordingStartTime().toLocalTime().toString(timeFormat),
115  pa->GetRecordingEndTime().toLocalTime().toString(timeFormat),
116  pa->toString(ProgramInfo::kTitleSubtitle, " - "));
117  }
118  }
119  }
120 
121  if (!messageConflict.isEmpty())
122  {
123  message += " ";
124  message += tr("The following programs will be recorded instead:");
125  message += "\n";
126  message += messageConflict;
127  message += "\n";
128  }
129 
130  QString title = QObject::tr("Program Status");
131  MythScreenStack *mainStack = GetMythMainWindow()->GetStack("main stack");
132  auto *dlg = new MythDialogBox(title, message, mainStack, "statusdialog", true);
133 
134  if (dlg->Create())
135  {
136  dlg->AddButton(QObject::tr("OK"));
137  mainStack->AddScreen(dlg);
138  }
139  else
140  {
141  delete dlg;
142  }
143 }
144 
145 static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
146 {
148  {
150  return 1;
151  return -1;
152  }
153  if (a->GetRecordingEndTime() != b->GetRecordingEndTime())
154  {
156  return 1;
157  return -1;
158  }
160  {
162  return 1;
163  return -1;
164  }
165  if (a->GetRecordingPriority() != b->GetRecordingPriority() &&
170  {
172  return 1;
173  return -1;
174  }
175  return 0;
176 }
177 
178 static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
179 {
180  return comp_recstart(a,b) < 0;
181 }
182 
184 {
185  m_inFill = true;
186 
187  bool dummy = false;
188 
191 
192  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
194  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
196 
197  QDateTime now = MythDate::current();
198 
199  auto it = m_recListBefore.begin();
200  while (it != m_recListBefore.end())
201  {
202  if ((*it)->GetRecordingEndTime() >= now ||
203  (*it)->GetScheduledEndTime() >= now)
204  {
205  ++it;
206  }
207  else
208  {
209  it = m_recListBefore.erase(it);
210  }
211  }
212 
213  it = m_recListAfter.begin();
214  while (it != m_recListAfter.end())
215  {
216  if ((*it)->GetRecordingEndTime() >= now ||
217  (*it)->GetScheduledEndTime() >= now)
218  {
219  ++it;
220  }
221  else
222  {
223  it = m_recListAfter.erase(it);
224  }
225  }
226 
227  auto pb = m_recListBefore.begin();
228  auto pa = m_recListAfter.begin();
229  ProgramStruct s;
230 
231  m_recList.clear();
232  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
233  {
234  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
235  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
236 
237  if (pa == m_recListAfter.end())
238  {
239  ++pb;
240  }
241  else if (pb == m_recListBefore.end())
242  {
243  ++pa;
244  }
245  else
246  {
247  switch (comp_recstart(*pb, *pa))
248  {
249  case 0:
250  ++pb;
251  ++pa;
252  break;
253  case -1: // pb BEFORE pa
254  ++pb;
255  s.m_after = nullptr;
256  break;
257  case 1: // pa BEFORE pb
258  s.m_before = nullptr;
259  ++pa;
260  break;
261  }
262  }
263 
264  if (s.m_before && s.m_after &&
265  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
267  {
268  continue;
269  }
270 
271  m_recList.push_back(s);
272  }
273 
274  m_inFill = false;
275 }
276 
278 {
279  for (const auto& s : m_recList)
280  {
281  class ProgramInfo *pginfo = s.m_after;
282  if (!pginfo)
283  pginfo = s.m_before;
284 
285  auto *item = new MythUIButtonListItem(m_conflictList, "",
286  QVariant::fromValue(pginfo));
287 
288  InfoMap infoMap;
289  pginfo->ToMap(infoMap);
290 
291  QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
292 
293  item->DisplayState(state, "status");
294  item->SetTextFromMap(infoMap, state);
295 
296  if (s.m_before)
297  {
298  item->SetText(RecStatus::toString(s.m_before->GetRecordingStatus(),
299  s.m_before->GetInputID()), "statusbefore",
300  state);
301  }
302  else
303  {
304  item->SetText("-", "statusbefore");
305  }
306 
307  if (s.m_after)
308  {
309  item->SetText(RecStatus::toString(s.m_after->GetRecordingStatus(),
310  s.m_after->GetInputID()), "statusafter",
311  state);
312  }
313  else
314  {
315  item->SetText("-", "statusafter");
316  }
317  }
318 
319  if (m_noChangesText)
320  {
321  if (m_recList.empty())
323  else
325  }
326 }
327 
329 {
330  if (!item)
331  return;
332 
333  auto *pginfo = item->GetData().value<ProgramInfo*> ();
334  if (pginfo)
335  {
336  InfoMap infoMap;
337  pginfo->ToMap(infoMap);
338  SetTextFromMap(infoMap);
339  }
340 }
341 
343 {
344  int pos = m_conflictList->GetCurrentPos();
345  if (pos >= (int)m_recList.size())
346  return nullptr;
347 
348  ProgramStruct s = m_recList[pos];
349 
350  if (s.m_after)
351  return s.m_after;
352  return s.m_before;
353 }
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:53
ViewScheduleDiff::m_recListAfter
ProgramList m_recListAfter
Definition: viewschedulediff.h:53
MythScreenType::LoadInBackground
void LoadInBackground(const QString &message="")
Definition: mythscreentype.cpp:283
RecStatus::toUIState
static QString toUIState(RecStatus::Type recstatus)
Definition: recordingstatus.cpp:5
RecStatus::LaterShowing
@ LaterShowing
Definition: recordingstatus.h:40
ViewScheduleDiff::m_inEvent
bool m_inEvent
Definition: viewschedulediff.h:49
tv.h
ViewScheduleDiff::showStatus
void showStatus(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:77
ViewScheduleDiff::updateUIList
void updateUIList()
Definition: viewschedulediff.cpp:277
mythuitext.h
LoadFromScheduler
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:916
RecStatus::Tuning
@ Tuning
Definition: recordingstatus.h:22
ViewScheduleDiff::Create
bool Create(void) override
Definition: viewschedulediff.cpp:17
ViewScheduleDiff::m_recList
std::vector< class ProgramStruct > m_recList
Definition: viewschedulediff.h:62
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
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:384
comp_recstart_less_than
static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
Definition: viewschedulediff.cpp:178
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
ProgramInfo::GetRecordingEndTime
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:413
ProgramInfo::GetRecordingPriority
int GetRecordingPriority(void) const
Definition: programinfo.h:444
remoteutil.h
mythuibuttonlist.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
ProgramInfo::GetRecordingStartTime
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:405
ProgramStruct::m_after
ProgramInfo * m_after
Definition: viewschedulediff.h:17
RecStatus::toString
static QString toString(RecStatus::Type recstatus, uint id)
Converts "recstatus" into a short (unreadable) string.
Definition: recordingstatus.cpp:40
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
AutoDeleteDeque::begin
iterator begin(void)
Definition: autodeletedeque.h:50
RecStatus::WillRecord
@ WillRecord
Definition: recordingstatus.h:31
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
viewschedulediff.h
ViewScheduleDiff::CurrentProgram
ProgramInfo * CurrentProgram(void)
Definition: viewschedulediff.cpp:342
ProgramStruct
Definition: viewschedulediff.h:12
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1144
mythlogging.h
ProgramInfo::GetRecordingStatus
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:451
ViewScheduleDiff::updateInfo
void updateInfo(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:328
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:1111
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:240
RecStatus::toDescription
static QString toDescription(Type recstatus, RecordingType rectype, const QDateTime &recstartts)
Converts "recstatus" into a long human readable description.
Definition: recordingstatus.cpp:188
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
ViewScheduleDiff::m_title
QString m_title
Definition: viewschedulediff.h:56
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:48
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:203
RecStatus::Failing
@ Failing
Definition: recordingstatus.h:18
ViewScheduleDiff::m_recordid
int m_recordid
recordid that differs from master (-1 = assume all)
Definition: viewschedulediff.h:64
ViewScheduleDiff::fillList
void fillList(void)
Definition: viewschedulediff.cpp:183
MythUIComposite::SetTextFromMap
virtual void SetTextFromMap(const InfoMap &infoMap)
Definition: mythuicomposite.cpp:9
RecStatus::Conflict
@ Conflict
Definition: recordingstatus.h:39
ViewScheduleDiff::m_titleText
MythUIText * m_titleText
Definition: viewschedulediff.h:59
ProgramInfo::toString
QString toString(Verbosity v=kLongDescription, const QString &sep=":", const QString &grp="\"") const
Definition: programinfo.cpp:1945
ProgramInfo::ToMap
virtual void ToMap(InfoMap &progMap, bool showrerecord=false, uint star_range=10, uint date_format=0) const
Converts ProgramInfo into QString QHash containing each field in ProgramInfo converted into localized...
Definition: programinfo.cpp:1553
scheduledrecording.h
ViewScheduleDiff::m_recListBefore
ProgramList m_recListBefore
Definition: viewschedulediff.h:52
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3715
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
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
channelutil.h
MythUIType::Hide
void Hide(void)
Definition: mythuitype.cpp:1139
ProgramStruct::m_before
ProgramInfo * m_before
Definition: viewschedulediff.h:16
RecStatus::Pending
@ Pending
Definition: recordingstatus.h:17
ViewScheduleDiff::m_inFill
bool m_inFill
Definition: viewschedulediff.h:50
ProgramInfo::GetInputID
uint GetInputID(void) const
Definition: programinfo.h:467
recordinginfo.h
ProgramInfo::GetChanID
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:373
comp_recstart
static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
Definition: viewschedulediff.cpp:145
ProgramInfo::GetRecordingRuleType
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:455
ProgramInfo::kTitleSubtitle
@ kTitleSubtitle
Definition: programinfo.h:513
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:401
RecStatus::Recording
@ Recording
Definition: recordingstatus.h:30
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
ViewScheduleDiff::m_noChangesText
MythUIText * m_noChangesText
Definition: viewschedulediff.h:60
ChannelUtil::GetSourceIDForChannel
static uint GetSourceIDForChannel(uint chanid)
Definition: channelutil.cpp:807
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
ViewScheduleDiff::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: viewschedulediff.cpp:58
ViewScheduleDiff::m_conflictList
MythUIButtonList * m_conflictList
Definition: viewschedulediff.h:58
AutoDeleteDeque::erase
iterator erase(iterator it)
Definition: autodeletedeque.h:34
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
uint
unsigned int uint
Definition: freesurround.h:24
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:902
ViewScheduleDiff::m_altTable
QString m_altTable
Definition: viewschedulediff.h:55