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  delete dlg;
141 }
142 
143 static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
144 {
146  {
148  return 1;
149  return -1;
150  }
151  if (a->GetRecordingEndTime() != b->GetRecordingEndTime())
152  {
154  return 1;
155  return -1;
156  }
158  {
160  return 1;
161  return -1;
162  }
163  if (a->GetRecordingPriority() != b->GetRecordingPriority() &&
168  {
170  return 1;
171  return -1;
172  }
173  return 0;
174 }
175 
176 static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
177 {
178  return comp_recstart(a,b) < 0;
179 }
180 
182 {
183  m_inFill = true;
184 
185  bool dummy = false;
186 
189 
190  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
192  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
194 
195  QDateTime now = MythDate::current();
196 
197  auto it = m_recListBefore.begin();
198  while (it != m_recListBefore.end())
199  {
200  if ((*it)->GetRecordingEndTime() >= now ||
201  (*it)->GetScheduledEndTime() >= now)
202  {
203  ++it;
204  }
205  else
206  {
207  it = m_recListBefore.erase(it);
208  }
209  }
210 
211  it = m_recListAfter.begin();
212  while (it != m_recListAfter.end())
213  {
214  if ((*it)->GetRecordingEndTime() >= now ||
215  (*it)->GetScheduledEndTime() >= now)
216  {
217  ++it;
218  }
219  else
220  {
221  it = m_recListAfter.erase(it);
222  }
223  }
224 
225  auto pb = m_recListBefore.begin();
226  auto pa = m_recListAfter.begin();
227  ProgramStruct s;
228 
229  m_recList.clear();
230  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
231  {
232  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
233  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
234 
235  if (pa == m_recListAfter.end())
236  {
237  ++pb;
238  }
239  else if (pb == m_recListBefore.end())
240  {
241  ++pa;
242  }
243  else
244  {
245  switch (comp_recstart(*pb, *pa))
246  {
247  case 0:
248  ++pb;
249  ++pa;
250  break;
251  case -1: // pb BEFORE pa
252  ++pb;
253  s.m_after = nullptr;
254  break;
255  case 1: // pa BEFORE pb
256  s.m_before = nullptr;
257  ++pa;
258  break;
259  }
260  }
261 
262  if (s.m_before && s.m_after &&
263  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
265  {
266  continue;
267  }
268 
269  m_recList.push_back(s);
270  }
271 
272  m_inFill = false;
273 }
274 
276 {
277  for (const auto& s : m_recList)
278  {
279  class ProgramInfo *pginfo = s.m_after;
280  if (!pginfo)
281  pginfo = s.m_before;
282 
283  auto *item = new MythUIButtonListItem(m_conflictList, "",
284  QVariant::fromValue(pginfo));
285 
286  InfoMap infoMap;
287  pginfo->ToMap(infoMap);
288 
289  QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
290 
291  item->DisplayState(state, "status");
292  item->SetTextFromMap(infoMap, state);
293 
294  if (s.m_before)
295  {
296  item->SetText(RecStatus::toString(s.m_before->GetRecordingStatus(),
297  s.m_before->GetInputID()), "statusbefore",
298  state);
299  }
300  else
301  {
302  item->SetText("-", "statusbefore");
303  }
304 
305  if (s.m_after)
306  {
307  item->SetText(RecStatus::toString(s.m_after->GetRecordingStatus(),
308  s.m_after->GetInputID()), "statusafter",
309  state);
310  }
311  else
312  {
313  item->SetText("-", "statusafter");
314  }
315  }
316 
317  if (m_noChangesText)
318  {
319  if (m_recList.empty())
321  else
323  }
324 }
325 
327 {
328  if (!item)
329  return;
330 
331  auto *pginfo = item->GetData().value<ProgramInfo*> ();
332  if (pginfo)
333  {
334  InfoMap infoMap;
335  pginfo->ToMap(infoMap);
336  SetTextFromMap(infoMap);
337  }
338 }
339 
341 {
342  int pos = m_conflictList->GetCurrentPos();
343  if (pos >= (int)m_recList.size())
344  return nullptr;
345 
346  ProgramStruct s = m_recList[pos];
347 
348  if (s.m_after)
349  return s.m_after;
350  return s.m_before;
351 }
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:286
RecStatus::toUIState
static QString toUIState(RecStatus::Type recstatus)
Definition: recordingstatus.cpp:5
RecStatus::LaterShowing
@ LaterShowing
Definition: recordingstatus.h:39
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:275
mythuitext.h
LoadFromScheduler
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:912
RecStatus::Tuning
@ Tuning
Definition: recordingstatus.h:21
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)
ProgramInfo::kTitleSubtitle
@ kTitleSubtitle
Definition: programinfo.h:509
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:383
comp_recstart_less_than
static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
Definition: viewschedulediff.cpp:176
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:412
ProgramInfo::GetRecordingPriority
int GetRecordingPriority(void) const
Definition: programinfo.h:440
remoteutil.h
mythuibuttonlist.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
ProgramInfo::GetRecordingStartTime
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:404
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:30
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
viewschedulediff.h
ViewScheduleDiff::CurrentProgram
ProgramInfo * CurrentProgram(void)
Definition: viewschedulediff.cpp:340
ProgramStruct
Definition: viewschedulediff.h:12
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1149
mythlogging.h
ProgramInfo::GetRecordingStatus
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:447
ViewScheduleDiff::updateInfo
void updateInfo(MythUIButtonListItem *item)
Definition: viewschedulediff.cpp:326
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:1112
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:238
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:206
RecStatus::Failing
@ Failing
Definition: recordingstatus.h:17
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:181
MythUIComposite::SetTextFromMap
virtual void SetTextFromMap(const InfoMap &infoMap)
Definition: mythuicomposite.cpp:9
RecStatus::Conflict
@ Conflict
Definition: recordingstatus.h:38
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:1934
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:1542
scheduledrecording.h
ViewScheduleDiff::m_recListBefore
ProgramList m_recListBefore
Definition: viewschedulediff.h:52
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3660
uint
unsigned int uint
Definition: compat.h:81
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:1144
ProgramStruct::m_before
ProgramInfo * m_before
Definition: viewschedulediff.h:16
RecStatus::Pending
@ Pending
Definition: recordingstatus.h:16
ViewScheduleDiff::m_inFill
bool m_inFill
Definition: viewschedulediff.h:50
ProgramInfo::GetInputID
uint GetInputID(void) const
Definition: programinfo.h:463
recordinginfo.h
ProgramInfo::GetChanID
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:372
comp_recstart
static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
Definition: viewschedulediff.cpp:143
ProgramInfo::GetRecordingRuleType
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:451
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:404
RecStatus::Recording
@ Recording
Definition: recordingstatus.h:29
mythcorecontext.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:687
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:132
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:323
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
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898
ViewScheduleDiff::m_altTable
QString m_altTable
Definition: viewschedulediff.h:55