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  auto *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 {
142  {
144  return 1;
145  return -1;
146  }
147  if (a->GetRecordingEndTime() != b->GetRecordingEndTime())
148  {
150  return 1;
151  return -1;
152  }
154  {
156  return 1;
157  return -1;
158  }
159  if (a->GetRecordingPriority() != b->GetRecordingPriority() &&
164  {
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;
183  QDateTime recstartts;
184  bool dummy = false;
185 
186  LoadFromScheduler(m_recListBefore, dummy);
187  LoadFromScheduler(m_recListAfter, dummy, m_altTable, m_recordid);
188 
189  std::stable_sort(m_recListBefore.begin(), m_recListBefore.end(),
191  std::stable_sort(m_recListAfter.begin(), m_recListAfter.end(),
193 
194  QDateTime now = MythDate::current();
195 
196  auto it = m_recListBefore.begin();
197  while (it != m_recListBefore.end())
198  {
199  if ((*it)->GetRecordingEndTime() >= now ||
200  (*it)->GetScheduledEndTime() >= now)
201  {
202  ++it;
203  }
204  else
205  {
206  it = m_recListBefore.erase(it);
207  }
208  }
209 
210  it = m_recListAfter.begin();
211  while (it != m_recListAfter.end())
212  {
213  if ((*it)->GetRecordingEndTime() >= now ||
214  (*it)->GetScheduledEndTime() >= now)
215  {
216  ++it;
217  }
218  else
219  {
220  it = m_recListAfter.erase(it);
221  }
222  }
223 
224  auto pb = m_recListBefore.begin();
225  auto pa = m_recListAfter.begin();
226  ProgramStruct s;
227 
228  m_recList.clear();
229  while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
230  {
231  s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
232  s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
233 
234  if (pa == m_recListAfter.end())
235  {
236  ++pb;
237  }
238  else if (pb == m_recListBefore.end())
239  {
240  ++pa;
241  }
242  else
243  {
244  switch (comp_recstart(*pb, *pa))
245  {
246  case 0:
247  ++pb;
248  ++pa;
249  break;
250  case -1: // pb BEFORE pa
251  ++pb;
252  s.m_after = nullptr;
253  break;
254  case 1: // pa BEFORE pb
255  s.m_before = nullptr;
256  ++pa;
257  break;
258  }
259  }
260 
261  if (s.m_before && s.m_after &&
262  (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
264  {
265  continue;
266  }
267 
268  m_recList.push_back(s);
269  }
270 
271  m_inFill = false;
272 }
273 
275 {
276  for (size_t i = 0; i < m_recList.size(); i++)
277  {
278  class ProgramStruct s = m_recList[i];
279  class ProgramInfo *pginfo = s.m_after;
280  if (!pginfo)
281  pginfo = s.m_before;
282 
283  auto *item = new MythUIButtonListItem(m_conflictList, "",
284  qVariantFromValue(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)
296  s.m_before->GetInputID()), "statusbefore",
297  state);
298  else
299  item->SetText("-", "statusbefore");
300 
301  if (s.m_after)
303  s.m_after->GetInputID()), "statusafter",
304  state);
305  else
306  item->SetText("-", "statusafter");
307  }
308 
309  if (m_noChangesText)
310  {
311  if (m_recList.empty())
312  m_noChangesText->Show();
313  else
314  m_noChangesText->Hide();
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 }
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.
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
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:187
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
typename List::const_iterator const_iterator
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: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
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
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
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)