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  ProgramList::const_iterator it = m_recListAfter.begin();
103  for (; it != m_recListAfter.end(); ++it)
104  {
105  const ProgramInfo *pa = *it;
106  if (pa->GetRecordingStartTime() >= pi->GetRecordingEndTime())
107  break;
108  if (pa->GetRecordingEndTime() > pi->GetRecordingStartTime() &&
114  {
115  message += QString("%1 - %2 %3\n")
116  .arg(pa->GetRecordingStartTime()
117  .toLocalTime().toString(timeFormat))
118  .arg(pa->GetRecordingEndTime()
119  .toLocalTime().toString(timeFormat))
120  .arg(pa->toString(ProgramInfo::kTitleSubtitle, " - "));
121  }
122  }
123  }
124 
125  QString title = QObject::tr("Program Status");
126  MythScreenStack *mainStack = GetMythMainWindow()->GetStack("main stack");
127  MythDialogBox *dlg = new MythDialogBox(title, message, mainStack,
128  "statusdialog", true);
129 
130  if (dlg->Create())
131  {
132  dlg->AddButton(QObject::tr("OK"));
133  mainStack->AddScreen(dlg);
134  }
135  else
136  delete dlg;
137 }
138 
139 static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
140 {
141  if (a->GetRecordingStartTime() != b->GetRecordingStartTime())
142  {
143  if (a->GetRecordingStartTime() > b->GetRecordingStartTime())
144  return 1;
145  return -1;
146  }
147  if (a->GetRecordingEndTime() != b->GetRecordingEndTime())
148  {
149  if (a->GetRecordingEndTime() > b->GetRecordingEndTime())
150  return 1;
151  return -1;
152  }
153  if (a->GetChannelSchedulingID() != b->GetChannelSchedulingID())
154  {
155  if (a->GetChannelSchedulingID() < b->GetChannelSchedulingID())
156  return 1;
157  return -1;
158  }
159  if (a->GetRecordingPriority() != b->GetRecordingPriority() &&
162  b->GetRecordingStatus() == RecStatus::WillRecord ||
163  b->GetRecordingStatus() == RecStatus::Pending))
164  {
165  if (a->GetRecordingPriority() < b->GetRecordingPriority())
166  return 1;
167  return -1;
168  }
169  return 0;
170 }
171 
172 static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
173 {
174  return comp_recstart(a,b) < 0;
175 }
176 
178 {
179  m_inFill = true;
180 
181  QString callsign;
182  QDateTime startts, recstartts;
183  bool dummy;
184 
185  LoadFromScheduler(m_recListBefore, dummy);
186  LoadFromScheduler(m_recListAfter, dummy, m_altTable, m_recordid);
187 
188  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
190  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
192 
193  QDateTime now = MythDate::current();
194 
195  ProgramList::iterator it = m_recListBefore.begin();
196  while (it != m_recListBefore.end())
197  {
198  if ((*it)->GetRecordingEndTime() >= now ||
199  (*it)->GetScheduledEndTime() >= now)
200  {
201  ++it;
202  }
203  else
204  {
205  it = m_recListBefore.erase(it);
206  }
207  }
208 
209  it = m_recListAfter.begin();
210  while (it != m_recListAfter.end())
211  {
212  if ((*it)->GetRecordingEndTime() >= now ||
213  (*it)->GetScheduledEndTime() >= now)
214  {
215  ++it;
216  }
217  else
218  {
219  it = m_recListAfter.erase(it);
220  }
221  }
222 
223  ProgramList::iterator pb = m_recListBefore.begin();
224  ProgramList::iterator pa = m_recListAfter.begin();
225  ProgramStruct s;
226 
227  m_recList.clear();
228  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
229  {
230  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
231  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
232 
233  if (pa == m_recListAfter.end())
234  {
235  ++pb;
236  }
237  else if (pb == m_recListBefore.end())
238  {
239  ++pa;
240  }
241  else
242  {
243  switch (comp_recstart(*pb, *pa))
244  {
245  case 0:
246  ++pb;
247  ++pa;
248  break;
249  case -1: // pb BEFORE pa
250  ++pb;
251  s.m_after = nullptr;
252  break;
253  case 1: // pa BEFORE pb
254  s.m_before = nullptr;
255  ++pa;
256  break;
257  }
258  }
259 
260  if (s.m_before && s.m_after &&
261  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
263  {
264  continue;
265  }
266 
267  m_recList.push_back(s);
268  }
269 
270  m_inFill = false;
271 }
272 
274 {
275  for (size_t i = 0; i < m_recList.size(); i++)
276  {
277  class ProgramStruct s = m_recList[i];
278  class ProgramInfo *pginfo = s.m_after;
279  if (!pginfo)
280  pginfo = s.m_before;
281 
283  m_conflictList, "", qVariantFromValue(pginfo));
284 
285  InfoMap infoMap;
286  pginfo->ToMap(infoMap);
287 
288  QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
289 
290  item->DisplayState(state, "status");
291  item->SetTextFromMap(infoMap, state);
292 
293  if (s.m_before)
295  s.m_before->GetInputID()), "statusbefore",
296  state);
297  else
298  item->SetText("-", "statusbefore");
299 
300  if (s.m_after)
302  s.m_after->GetInputID()), "statusafter",
303  state);
304  else
305  item->SetText("-", "statusafter");
306  }
307 
308  if (m_noChangesText)
309  {
310  if (m_recList.empty())
311  m_noChangesText->Show();
312  else
313  m_noChangesText->Hide();
314  }
315 }
316 
318 {
319  if (!item)
320  return;
321 
322  ProgramInfo *pginfo = item->GetData().value<ProgramInfo*> ();
323  if (pginfo)
324  {
325  InfoMap infoMap;
326  pginfo->ToMap(infoMap);
327  SetTextFromMap(infoMap);
328  }
329 }
330 
332 {
333  int pos = m_conflictList->GetCurrentPos();
334  if (pos >= (int)m_recList.size())
335  return nullptr;
336 
337  ProgramStruct s = m_recList[pos];
338 
339  if (s.m_after)
340  return s.m_after;
341  return s.m_before;
342 }
bool keyPressEvent(QKeyEvent *) override
Key event handler.
uint GetInputID(void) const
Definition: programinfo.h:455
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.
Basic menu dialog, message and a list of options.
static QString toDescription(Type, RecordingType, const QDateTime &recstartts)
Converts "recstatus" into a long human readable description.
Definition: recStatus.cpp:195
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:432
static QString toUIState(Type)
Definition: recStatus.cpp:4
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
unsigned char b
Definition: ParseText.cpp:329
ProgramInfo * m_after
void AddButton(const QString &title, QVariant data=0, bool newMenu=false, bool setCurrent=false)
Holds information on recordings and videos.
Definition: programinfo.h:66
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString GetChannelSchedulingID(void) const
This is the unique programming identifier of a channel.
Definition: programinfo.h:375
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
QString GetSetting(const QString &key, const QString &defaultval="")
void showStatus(MythUIButtonListItem *item)
static QString toString(Type, uint id)
Converts "recstatus" into a short (unreadable) string.
Definition: recStatus.cpp:39
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
void SetText(const QString &text, const QString &name="", const QString &state="")
bool Create(void) override
MythMainWindow * GetMythMainWindow(void)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:439
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:443
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, QString altTable="", int recordid=-1)
Definition: programinfo.h:876
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:396
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:404
ProgramInfo * CurrentProgram(void)
ProgramInfo * m_before
List::const_iterator const_iterator
void DisplayState(const QString &state, const QString &name)
void SetTextFromMap(const InfoMap &infoMap, const QString &state="")
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)
bool Create(void) override