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  QString callsign;
180  QDateTime startts;
181  QDateTime recstartts;
182  bool dummy = false;
183 
184  LoadFromScheduler(m_recListBefore, dummy);
185  LoadFromScheduler(m_recListAfter, dummy, m_altTable, m_recordid);
186 
187  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
189  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
191 
192  QDateTime now = MythDate::current();
193 
194  auto it = m_recListBefore.begin();
195  while (it != m_recListBefore.end())
196  {
197  if ((*it)->GetRecordingEndTime() >= now ||
198  (*it)->GetScheduledEndTime() >= now)
199  {
200  ++it;
201  }
202  else
203  {
204  it = m_recListBefore.erase(it);
205  }
206  }
207 
208  it = m_recListAfter.begin();
209  while (it != m_recListAfter.end())
210  {
211  if ((*it)->GetRecordingEndTime() >= now ||
212  (*it)->GetScheduledEndTime() >= now)
213  {
214  ++it;
215  }
216  else
217  {
218  it = m_recListAfter.erase(it);
219  }
220  }
221 
222  auto pb = m_recListBefore.begin();
223  auto pa = m_recListAfter.begin();
224  ProgramStruct s;
225 
226  m_recList.clear();
227  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
228  {
229  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
230  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
231 
232  if (pa == m_recListAfter.end())
233  {
234  ++pb;
235  }
236  else if (pb == m_recListBefore.end())
237  {
238  ++pa;
239  }
240  else
241  {
242  switch (comp_recstart(*pb, *pa))
243  {
244  case 0:
245  ++pb;
246  ++pa;
247  break;
248  case -1: // pb BEFORE pa
249  ++pb;
250  s.m_after = nullptr;
251  break;
252  case 1: // pa BEFORE pb
253  s.m_before = nullptr;
254  ++pa;
255  break;
256  }
257  }
258 
259  if (s.m_before && s.m_after &&
260  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
262  {
263  continue;
264  }
265 
266  m_recList.push_back(s);
267  }
268 
269  m_inFill = false;
270 }
271 
273 {
274  for (auto s : m_recList)
275  {
276  class ProgramInfo *pginfo = s.m_after;
277  if (!pginfo)
278  pginfo = s.m_before;
279 
280  auto *item = new MythUIButtonListItem(m_conflictList, "",
281  QVariant::fromValue(pginfo));
282 
283  InfoMap infoMap;
284  pginfo->ToMap(infoMap);
285 
286  QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
287 
288  item->DisplayState(state, "status");
289  item->SetTextFromMap(infoMap, state);
290 
291  if (s.m_before)
292  {
293  item->SetText(RecStatus::toString(s.m_before->GetRecordingStatus(),
294  s.m_before->GetInputID()), "statusbefore",
295  state);
296  }
297  else
298  {
299  item->SetText("-", "statusbefore");
300  }
301 
302  if (s.m_after)
303  {
304  item->SetText(RecStatus::toString(s.m_after->GetRecordingStatus(),
305  s.m_after->GetInputID()), "statusafter",
306  state);
307  }
308  else
309  {
310  item->SetText("-", "statusafter");
311  }
312  }
313 
314  if (m_noChangesText)
315  {
316  if (m_recList.empty())
317  m_noChangesText->Show();
318  else
319  m_noChangesText->Hide();
320  }
321 }
322 
324 {
325  if (!item)
326  return;
327 
328  auto *pginfo = item->GetData().value<ProgramInfo*> ();
329  if (pginfo)
330  {
331  InfoMap infoMap;
332  pginfo->ToMap(infoMap);
333  SetTextFromMap(infoMap);
334  }
335 }
336 
338 {
339  int pos = m_conflictList->GetCurrentPos();
340  if (pos >= (int)m_recList.size())
341  return nullptr;
342 
343  ProgramStruct s = m_recList[pos];
344 
345  if (s.m_after)
346  return s.m_after;
347  return s.m_before;
348 }
uint GetInputID(void) const
Definition: programinfo.h:457
void updateInfo(MythUIButtonListItem *item)
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...
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
Basic menu dialog, message and a list of options.
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
QString toString(Verbosity v=kLongDescription, const QString &sep=":", const QString &grp="\"") const
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int GetRecordingPriority(void) const
Definition: programinfo.h:434
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
ProgramInfo * m_after
Holds information on recordings and videos.
Definition: programinfo.h:67
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString GetChannelSchedulingID(void) const
This is the unique programming identifier of a channel.
Definition: programinfo.h:377
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
QString GetSetting(const QString &key, const QString &defaultval="")
static QString toDescription(Type recstatus, RecordingType rectype, const QDateTime &recstartts)
Converts "recstatus" into a long human readable description.
Definition: recStatus.cpp:187
void showStatus(MythUIButtonListItem *item)
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
bool Create(void) override
MythMainWindow * GetMythMainWindow(void)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:441
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:445
static QString toUIState(Type recstatus)
Definition: recStatus.cpp:4
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:398
static void showStatus(void)
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:406
ProgramInfo * CurrentProgram(void)
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:877
ProgramInfo * m_before
static QString toString(Type recstatus, uint id)
Converts "recstatus" into a short (unreadable) string.
Definition: recStatus.cpp:39
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23