MythTV master
manualschedule.cpp
Go to the documentation of this file.
1// Qt
2#include <QChar> // Fix Qt6 GCC SFINAE warning
3#include <QDateTime>
4#include <QTimeZone>
5
6// MythTV
21
22// MythFrontend
23#include "manualschedule.h"
24#include "scheduleeditor.h"
25
27 : MythScreenType(parent, "ManualSchedule"),
28 m_nowDateTime(MythDate::current()),
29 m_startDateTime(m_nowDateTime)
30{
31}
32
34{
35 if (!LoadWindowFromXML("schedule-ui.xml", "manualschedule", this))
36 return false;
37
38 m_channelList = dynamic_cast<MythUIButtonList *>(GetChild("channel"));
39 m_startdateList = dynamic_cast<MythUIButtonList *>(GetChild("startdate"));
40
41 m_starthourSpin = dynamic_cast<MythUISpinBox *>(GetChild("starthour"));
42 m_startminuteSpin = dynamic_cast<MythUISpinBox *>(GetChild("startminute"));
43 m_durationSpin = dynamic_cast<MythUISpinBox *>(GetChild("duration"));
44
45 m_titleEdit = dynamic_cast<MythUITextEdit *>(GetChild("title"));
46
47 m_recordButton = dynamic_cast<MythUIButton *>(GetChild("next"));
48 m_cancelButton = dynamic_cast<MythUIButton *>(GetChild("cancel"));
49
53 {
54 LOG(VB_GENERAL, LOG_ERR,
55 "ManualSchedule, theme is missing required elements");
56 return false;
57 }
58
59 QString startchan = gCoreContext->GetSetting("DefaultTVChannel", "");
60 QString chanorder = gCoreContext->GetSetting("ChannelOrdering", "channum");
61 QString lastManualRecordChan = gCoreContext->GetSetting("LastManualRecordChan", startchan);
62 int manStartChanType = gCoreContext->GetNumSetting("ManualRecordStartChanType", 1);
63 ChannelInfoList channels = ChannelUtil::GetChannels(0, true, "channum,callsign");
64 ChannelUtil::SortChannels(channels, chanorder);
65
66 for (size_t i = 0; i < channels.size(); i++)
67 {
68 QString chantext = channels[i].GetFormatted(ChannelInfo::kChannelLong);
69
70 auto *item = new MythUIButtonListItem(m_channelList, chantext);
71 InfoMap infomap;
72 channels[i].ToMap(infomap);
73 item->SetTextFromMap(infomap);
74 if (manStartChanType == 1)
75 {
76 // Use DefaultTVChannel as starting channel
77 if (channels[i].m_chanNum == startchan)
78 {
80 startchan = "";
81 }
82 }
83 else
84 {
85 // Use LastManualRecordChan as starting channel
86 if (channels[i].m_chanNum == lastManualRecordChan)
87 {
89 lastManualRecordChan = "";
90 }
91 }
92 m_chanids.push_back(channels[i].m_chanId);
93 }
94
95 for (uint index = 0; index <= 60; index++)
96 {
97 QString dinfo = MythDate::toString(
98 m_nowDateTime.addDays(index),
100 if (m_nowDateTime.addDays(index).toLocalTime().date().dayOfWeek() < 6)
101 dinfo += QString(" (%1)").arg(tr("5 weekdays if daily"));
102 else
103 dinfo += QString(" (%1)").arg(tr("7 days per week if daily"));
105 if (m_nowDateTime.addDays(index).toLocalTime().toString("MMdd") ==
106 m_startDateTime.toLocalTime().toString("MMdd"))
108 }
109
110 QTime thisTime = m_nowDateTime.toLocalTime().time();
111 thisTime = thisTime.addSecs((30 - (thisTime.minute() % 30)) * 60);
112
113 if (thisTime < QTime(0,30))
115
116 m_starthourSpin->SetRange(0,23,1);
117 m_starthourSpin->SetValue(thisTime.hour());
118 int minute_increment =
119 gCoreContext->GetNumSetting("ManualScheduleMinuteIncrement", 5);
120 m_startminuteSpin->SetRange(0, 60-minute_increment, minute_increment);
121 m_startminuteSpin->SetValue((thisTime.minute()/5)*5);
122 m_durationSpin->SetRange(5,1440,5);
124
128
130
132
133 return true;
134}
135
137{
144}
145
147{
148 disconnect(m_startdateList, nullptr, this, nullptr);
149 disconnect(m_starthourSpin, nullptr, this, nullptr);
150 disconnect(m_startminuteSpin, nullptr, this, nullptr);
151}
152
154{
155 if (m_startminuteSpin->GetIntValue() == 0 )
156 {
159 }
160 if (m_startminuteSpin->GetIntValue() == 13 )
161 {
164 }
165}
166
168{
169 if (m_starthourSpin->GetIntValue() == 0 )
170 {
173 }
174 if (m_starthourSpin->GetIntValue() == 25 )
175 {
178 }
179}
180
182{
185 int hr = m_starthourSpin->GetIntValue();
186 int min = m_startminuteSpin->GetIntValue();
187
188#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
189 m_startDateTime = QDateTime(
190 m_nowDateTime.toLocalTime().addDays(m_daysahead).date(),
191 QTime(hr, min), Qt::LocalTime).toUTC();
192#else
194 QDateTime(m_nowDateTime.toLocalTime().addDays(m_daysahead).date(),
195 QTime(hr, min),
196 QTimeZone(QTimeZone::LocalTime))
197 .toUTC();
198#endif
199
200 LOG(VB_SCHEDULE, LOG_INFO, QString("Start Date Time: %1")
201 .arg(m_startDateTime.toString(Qt::ISODate)));
202
203 // Note we allow start times up to one hour in the past so
204 // if it is 20:25 the user can start a recording at 20:30
205 // by first setting the hour and then the minute.
206#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
207 QDateTime tmp = QDateTime(
208 m_startDateTime.toLocalTime().date(),
209 QTime(m_startDateTime.toLocalTime().time().hour(),59,59),
210 Qt::LocalTime).toUTC();
211#else
212 QDateTime tmp =
213 QDateTime(m_startDateTime.toLocalTime().date(),
214 QTime(m_startDateTime.toLocalTime().time().hour(),59,59),
215 QTimeZone(QTimeZone::LocalTime))
216 .toUTC();
217#endif
218 if (tmp < m_nowDateTime)
219 {
220 hr = m_nowDateTime.toLocalTime().time().hour();
222#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
224 QDateTime(m_nowDateTime.toLocalTime().date(),
225 QTime(hr, min), Qt::LocalTime).toUTC();
226#else
227 m_startDateTime = QDateTime(m_nowDateTime.toLocalTime().date(),
228 QTime(hr, min),
229 QTimeZone(QTimeZone::LocalTime))
230 .toUTC();
231#endif
232 }
234}
235
237{
238 QDateTime endts = m_startDateTime
239 .addSecs(std::max(m_durationSpin->GetIntValue() * 60, 60));
240
241 if (m_channelList->GetCurrentPos() >= m_chanids.size())
242 {
243 LOG(VB_GENERAL, LOG_ERR, "Channel out of range.");
244 return; // this can happen if there are no channels..
245 }
246
247 ProgramInfo p(m_titleEdit->GetText().trimmed(),
249 m_startDateTime, endts);
250
251 // Save the channel because we might want to use it as the
252 // starting channel for the next Manual Record rule.
253 gCoreContext->SaveSetting("LastManualRecordChan",
255
256 auto *record = new RecordingRule();
257 record->LoadByProgram(&p);
258 record->m_searchType = kManualSearch;
259 record->m_dupMethod = kDupCheckNone;
260
262 auto *schededit = new ScheduleEditor(mainStack, record);
263 if (schededit->Create())
264 {
265 mainStack->AddScreen(schededit);
267 }
268 else
269 {
270 delete schededit;
271 }
272}
273
275{
276 if (ruleid > 0)
277 Close();
278}
279
280#include "moc_manualschedule.cpp"
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:130
static void SortChannels(ChannelInfoList &list, const QString &order, bool eliminate_duplicates=false)
static QString GetChanNum(int chan_id)
Returns the channel-number string of the given channel.
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:252
MythUISpinBox * m_starthourSpin
MythUITextEdit * m_titleEdit
bool Create(void) override
MythUIButtonList * m_startdateList
ManualSchedule(MythScreenStack *parent)
MythUISpinBox * m_durationSpin
void scheduleCreated(int ruleid)
MythUIButtonList * m_channelList
QDateTime m_startDateTime
void minuteRollover(void)
void dateChanged(void)
MythUISpinBox * m_startminuteSpin
void recordClicked(void)
QList< uint32_t > m_chanids
MythUIButton * m_recordButton
MythUIButton * m_cancelButton
void hourRollover(void)
QDateTime m_nowDateTime
void SaveSetting(const QString &key, int newValue)
QString GetSetting(const QString &key, const QString &defaultval="")
int GetNumSetting(const QString &key, int defaultval=0)
MythScreenStack * GetMainStack()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
virtual void Close()
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
void SetItemCurrent(MythUIButtonListItem *item)
int GetCurrentPos() const
void itemSelected(MythUIButtonListItem *item)
A single button widget.
Definition: mythuibutton.h:22
void Clicked()
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:19
void SetRange(int low, int high, int step, uint pageMultiple=5)
Set the lower and upper bounds of the spinbox, the interval and page amount.
void SetValue(int val) override
Definition: mythuispinbox.h:28
int GetIntValue(void) const override
Definition: mythuispinbox.h:35
A text entry and edit widget.
QString GetText(void) const
void SetMaxLength(int length)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
Holds information on recordings and videos.
Definition: programinfo.h:75
Internal representation of a recording rule, mirrors the record table.
Definition: recordingrule.h:31
Construct a recording schedule.
void ruleSaved(int ruleId)
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
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:27
@ kDateFull
Default local time.
Definition: mythdate.h:20
@ ISODate
Default UTC.
Definition: mythdate.h:18
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
@ kManualSearch
@ kDupCheckNone