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