MythTV master
viewschedulediff.cpp
Go to the documentation of this file.
1// Standard UNIX C headers
2#include <algorithm>
3
4// MythTV
10#include "libmythtv/tv.h"
15
16// MythFrontend
17#include "viewschedulediff.h"
18
20{
21 if (!LoadWindowFromXML("schedule-ui.xml", "schedulediff", this))
22 return false;
23
24 bool err = false;
25 UIUtilE::Assign(this, m_conflictList, "conflictlist", &err);
26
27 UIUtilW::Assign(this, m_titleText, "titletext");
28 UIUtilW::Assign(this, m_noChangesText, "nochanges");
29
30 if (err)
31 {
32 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'schedulediff'");
33 return false;
34 }
35
40
41 if (m_titleText)
43
46
47 return true;
48}
49
51{
52 fillList();
53}
54
56{
58}
59
61{
62 if (m_inEvent)
63 return true;
64
65 m_inEvent = true;
66
67 QStringList actions;
68
69 bool handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", e, actions);
70
71 if (!handled && MythScreenType::keyPressEvent(e))
72 handled = true;
73
74 m_inEvent = false;
75
76 return handled;
77}
78
80{
82 if (!pi)
83 return;
84
85 QString timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");
86
87 QString message = QString("%1 - %2 %3\n")
88 .arg(pi->GetRecordingStartTime().toLocalTime().toString(timeFormat),
89 pi->GetRecordingEndTime().toLocalTime().toString(timeFormat),
91
92 message += "\n";
96
97 QString messageConflict;
100 {
101 uint pi_chanid = pi->GetChanID();
102 uint pi_sourceid = ChannelUtil::GetSourceIDForChannel(pi_chanid);
103
104 for (auto *pa : m_recListAfter)
105 {
106 if ((pa->GetRecordingStartTime() < pi->GetRecordingEndTime() ) &&
107 (pa->GetRecordingEndTime() > pi->GetRecordingStartTime()) &&
108 (pa->GetSourceID() == pi_sourceid ) &&
109 (pa->GetRecordingStatus() == RecStatus::WillRecord ||
110 pa->GetRecordingStatus() == RecStatus::Pending ||
111 pa->GetRecordingStatus() == RecStatus::Recording ||
112 pa->GetRecordingStatus() == RecStatus::Tuning ||
113 pa->GetRecordingStatus() == RecStatus::Failing))
114 {
115 messageConflict += QString("%1 - %2 %3\n")
116 .arg(pa->GetRecordingStartTime().toLocalTime().toString(timeFormat),
117 pa->GetRecordingEndTime().toLocalTime().toString(timeFormat),
118 pa->toString(ProgramInfo::kTitleSubtitle, " - "));
119 }
120 }
121 }
122
123 if (!messageConflict.isEmpty())
124 {
125 message += " ";
126 message += tr("The following programs will be recorded instead:");
127 message += "\n";
128 message += messageConflict;
129 message += "\n";
130 }
131
132 QString title = QObject::tr("Program Status");
133 MythScreenStack *mainStack = GetMythMainWindow()->GetStack("main stack");
134 auto *dlg = new MythDialogBox(title, message, mainStack, "statusdialog", true);
135
136 if (dlg->Create())
137 {
138 dlg->AddButton(QObject::tr("OK"));
139 mainStack->AddScreen(dlg);
140 }
141 else
142 {
143 delete dlg;
144 }
145}
146
147static int comp_recstart(const ProgramInfo *a, const ProgramInfo *b)
148{
150 {
152 return 1;
153 return -1;
154 }
156 {
158 return 1;
159 return -1;
160 }
162 {
164 return 1;
165 return -1;
166 }
172 {
174 return 1;
175 return -1;
176 }
177 return 0;
178}
179
180static bool comp_recstart_less_than(const ProgramInfo *a, const ProgramInfo *b)
181{
182 return comp_recstart(a,b) < 0;
183}
184
186{
187 m_inFill = true;
188
189 bool dummy = false;
190
193
194 std::ranges::stable_sort(m_recListBefore,
196 std::ranges::stable_sort(m_recListAfter,
198
199 QDateTime now = MythDate::current();
200
201 auto it = m_recListBefore.begin();
202 while (it != m_recListBefore.end())
203 {
204 if ((*it)->GetRecordingEndTime() >= now ||
205 (*it)->GetScheduledEndTime() >= now)
206 {
207 ++it;
208 }
209 else
210 {
211 it = m_recListBefore.erase(it);
212 }
213 }
214
215 it = m_recListAfter.begin();
216 while (it != m_recListAfter.end())
217 {
218 if ((*it)->GetRecordingEndTime() >= now ||
219 (*it)->GetScheduledEndTime() >= now)
220 {
221 ++it;
222 }
223 else
224 {
225 it = m_recListAfter.erase(it);
226 }
227 }
228
229 auto pb = m_recListBefore.begin();
230 auto pa = m_recListAfter.begin();
232
233 m_recList.clear();
234 while (pa != m_recListAfter.end() || pb != m_recListBefore.end())
235 {
236 s.m_before = (pb != m_recListBefore.end()) ? *pb : nullptr;
237 s.m_after = (pa != m_recListAfter.end()) ? *pa : nullptr;
238
239 if (pa == m_recListAfter.end())
240 {
241 ++pb;
242 }
243 else if (pb == m_recListBefore.end())
244 {
245 ++pa;
246 }
247 else
248 {
249 switch (comp_recstart(*pb, *pa))
250 {
251 case 0:
252 ++pb;
253 ++pa;
254 break;
255 case -1: // pb BEFORE pa
256 ++pb;
257 s.m_after = nullptr;
258 break;
259 case 1: // pa BEFORE pb
260 s.m_before = nullptr;
261 ++pa;
262 break;
263 }
264 }
265
266 if (s.m_before && s.m_after &&
267 (s.m_before->GetInputID() == s.m_after->GetInputID()) &&
269 {
270 continue;
271 }
272
273 m_recList.push_back(s);
274 }
275
276 m_inFill = false;
277}
278
280{
281 for (const auto& s : m_recList)
282 {
283 class ProgramInfo *pginfo = s.m_after;
284 if (!pginfo)
285 pginfo = s.m_before;
286
287 auto *item = new MythUIButtonListItem(m_conflictList, "",
288 QVariant::fromValue(pginfo));
289
290 InfoMap infoMap;
291 pginfo->ToMap(infoMap);
292
293 QString state = RecStatus::toUIState(pginfo->GetRecordingStatus());
294
295 item->DisplayState(state, "status");
296 item->SetTextFromMap(infoMap, state);
297
298 if (s.m_before)
299 {
300 item->SetText(RecStatus::toString(s.m_before->GetRecordingStatus(),
301 s.m_before->GetInputID()), "statusbefore",
302 state);
303 }
304 else
305 {
306 item->SetText("-", "statusbefore");
307 }
308
309 if (s.m_after)
310 {
311 item->SetText(RecStatus::toString(s.m_after->GetRecordingStatus(),
312 s.m_after->GetInputID()), "statusafter",
313 state);
314 }
315 else
316 {
317 item->SetText("-", "statusafter");
318 }
319 }
320
321 if (m_noChangesText)
322 {
323 if (m_recList.empty())
325 else
327 }
328}
329
331{
332 if (!item)
333 return;
334
335 auto *pginfo = item->GetData().value<ProgramInfo*> ();
336 if (pginfo)
337 {
338 InfoMap infoMap;
339 pginfo->ToMap(infoMap);
340 SetTextFromMap(infoMap);
341 }
342}
343
345{
346 int pos = m_conflictList->GetCurrentPos();
347 if (pos >= (int)m_recList.size())
348 return nullptr;
349
350 ProgramStruct s = m_recList[pos];
351
352 if (s.m_after)
353 return s.m_after;
354 return s.m_before;
355}
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:74
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:380
QString toString(Verbosity v=kLongDescription, const QString &sep=":", const QString &grp="\"") const
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:412
int GetRecordingPriority(void) const
Definition: programinfo.h:451
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:474
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:458
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:420
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:462
QString GetChannelSchedulingID(void) const
This is the unique programming identifier of a channel.
Definition: programinfo.h:391
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: compat.h:60
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:945
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)