MythTV master
viewschedulediff.cpp
Go to the documentation of this file.
1// MythTV
8#include "libmythtv/tv.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{
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";
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
145static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
146{
148 {
150 return 1;
151 return -1;
152 }
154 {
156 return 1;
157 return -1;
158 }
160 {
162 return 1;
163 return -1;
164 }
170 {
172 return 1;
173 return -1;
174 }
175 return 0;
176}
177
178static 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();
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}
iterator erase(iterator it)
iterator begin(void)
iterator end(void)
static uint GetSourceIDForChannel(uint chanid)
QString GetSetting(const QString &key, const QString &defaultval="")
Basic menu dialog, message and a list of options.
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void LoadInBackground(const QString &message="")
void BuildFocusList(void)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
int GetCurrentPos() const
void itemClicked(MythUIButtonListItem *item)
void itemSelected(MythUIButtonListItem *item)
virtual void SetTextFromMap(const InfoMap &infoMap)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
void Hide(void)
void Show(void)
Holds information on recordings and videos.
Definition: programinfo.h:68
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:373
QString toString(Verbosity v=kLongDescription, const QString &sep=":", const QString &grp="\"") const
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:405
int GetRecordingPriority(void) const
Definition: programinfo.h:444
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...
uint GetInputID(void) const
Definition: programinfo.h:467
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:451
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:413
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:455
QString GetChannelSchedulingID(void) const
This is the unique programming identifier of a channel.
Definition: programinfo.h:384
ProgramInfo * m_after
ProgramInfo * m_before
static QString toDescription(Type recstatus, RecordingType rectype, const QDateTime &recstartts)
Converts "recstatus" into a long human readable description.
static QString toString(RecStatus::Type recstatus, uint id)
Converts "recstatus" into a short (unreadable) string.
static QString toUIState(RecStatus::Type recstatus)
void updateInfo(MythUIButtonListItem *item)
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
MythUIText * m_titleText
ProgramList m_recListAfter
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
bool Create(void) override
std::vector< class ProgramStruct > m_recList
int m_recordid
recordid that differs from master (-1 = assume all)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIButtonList * m_conflictList
void showStatus(MythUIButtonListItem *item)
MythUIText * m_noChangesText
ProgramInfo * CurrentProgram(void)
ProgramList m_recListBefore
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
unsigned int uint
Definition: freesurround.h:24
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
bool LoadFromScheduler(AutoDeleteDeque< TYPE * > &destination, bool &hasConflicts, const QString &altTable="", int recordid=-1)
Definition: programinfo.h:937
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)