MythTV master
manualschedule.cpp
Go to the documentation of this file.
1// Qt
2#include <QDateTime>
3#include <QTimeZone>
4
5// MythTV
20
21// MythFrontend
22#include "manualschedule.h"
23#include "scheduleeditor.h"
24
26 : MythScreenType(parent, "ManualSchedule"),
27 m_nowDateTime(MythDate::current()),
28 m_startDateTime(m_nowDateTime)
29{
30}
31
33{
34 if (!LoadWindowFromXML("schedule-ui.xml", "manualschedule", this))
35 return false;
36
37 m_channelList = dynamic_cast<MythUIButtonList *>(GetChild("channel"));
38 m_startdateList = dynamic_cast<MythUIButtonList *>(GetChild("startdate"));
39
40 m_starthourSpin = dynamic_cast<MythUISpinBox *>(GetChild("starthour"));
41 m_startminuteSpin = dynamic_cast<MythUISpinBox *>(GetChild("startminute"));
42 m_durationSpin = dynamic_cast<MythUISpinBox *>(GetChild("duration"));
43
44 m_titleEdit = dynamic_cast<MythUITextEdit *>(GetChild("title"));
45
46 m_recordButton = dynamic_cast<MythUIButton *>(GetChild("next"));
47 m_cancelButton = dynamic_cast<MythUIButton *>(GetChild("cancel"));
48
52 {
53 LOG(VB_GENERAL, LOG_ERR,
54 "ManualSchedule, theme is missing required elements");
55 return false;
56 }
57
58 QString startchan = gCoreContext->GetSetting("DefaultTVChannel", "");
59 QString chanorder = gCoreContext->GetSetting("ChannelOrdering", "channum");
60 QString lastManualRecordChan = gCoreContext->GetSetting("LastManualRecordChan", startchan);
61 int manStartChanType = gCoreContext->GetNumSetting("ManualRecordStartChanType", 1);
62 ChannelInfoList channels = ChannelUtil::GetChannels(0, true, "channum,callsign");
63 ChannelUtil::SortChannels(channels, chanorder);
64
65 for (size_t i = 0; i < channels.size(); i++)
66 {
67 QString chantext = channels[i].GetFormatted(ChannelInfo::kChannelLong);
68
69 auto *item = new MythUIButtonListItem(m_channelList, chantext);
70 InfoMap infomap;
71 channels[i].ToMap(infomap);
72 item->SetTextFromMap(infomap);
73 if (manStartChanType == 1)
74 {
75 // Use DefaultTVChannel as starting channel
76 if (channels[i].m_chanNum == startchan)
77 {
79 startchan = "";
80 }
81 }
82 else
83 {
84 // Use LastManualRecordChan as starting channel
85 if (channels[i].m_chanNum == lastManualRecordChan)
86 {
88 lastManualRecordChan = "";
89 }
90 }
91 m_chanids.push_back(channels[i].m_chanId);
92 }
93
94 for (uint index = 0; index <= 60; index++)
95 {
96 QString dinfo = MythDate::toString(
97 m_nowDateTime.addDays(index),
99 if (m_nowDateTime.addDays(index).toLocalTime().date().dayOfWeek() < 6)
100 dinfo += QString(" (%1)").arg(tr("5 weekdays if daily"));
101 else
102 dinfo += QString(" (%1)").arg(tr("7 days per week if daily"));
104 if (m_nowDateTime.addDays(index).toLocalTime().toString("MMdd") ==
105 m_startDateTime.toLocalTime().toString("MMdd"))
107 }
108
109 QTime thisTime = m_nowDateTime.toLocalTime().time();
110 thisTime = thisTime.addSecs((30 - (thisTime.minute() % 30)) * 60);
111
112 if (thisTime < QTime(0,30))
114
115 m_starthourSpin->SetRange(0,23,1);
116 m_starthourSpin->SetValue(thisTime.hour());
117 int minute_increment =
118 gCoreContext->GetNumSetting("ManualScheduleMinuteIncrement", 5);
119 m_startminuteSpin->SetRange(0, 60-minute_increment, minute_increment);
120 m_startminuteSpin->SetValue((thisTime.minute()/5)*5);
121 m_durationSpin->SetRange(5,1440,5);
123
127
129
131
132 return true;
133}
134
136{
143}
144
146{
147 disconnect(m_startdateList, nullptr, this, nullptr);
148 disconnect(m_starthourSpin, nullptr, this, nullptr);
149 disconnect(m_startminuteSpin, nullptr, this, nullptr);
150}
151
153{
154 if (m_startminuteSpin->GetIntValue() == 0 )
155 {
158 }
159 if (m_startminuteSpin->GetIntValue() == 13 )
160 {
163 }
164}
165
167{
168 if (m_starthourSpin->GetIntValue() == 0 )
169 {
172 }
173 if (m_starthourSpin->GetIntValue() == 25 )
174 {
177 }
178}
179
181{
184 int hr = m_starthourSpin->GetIntValue();
185 int min = m_startminuteSpin->GetIntValue();
186
187#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
188 m_startDateTime = QDateTime(
189 m_nowDateTime.toLocalTime().addDays(m_daysahead).date(),
190 QTime(hr, min), Qt::LocalTime).toUTC();
191#else
193 QDateTime(m_nowDateTime.toLocalTime().addDays(m_daysahead).date(),
194 QTime(hr, min),
195 QTimeZone(QTimeZone::LocalTime))
196 .toUTC();
197#endif
198
199 LOG(VB_SCHEDULE, LOG_INFO, QString("Start Date Time: %1")
200 .arg(m_startDateTime.toString(Qt::ISODate)));
201
202 // Note we allow start times up to one hour in the past so
203 // if it is 20:25 the user can start a recording at 20:30
204 // by first setting the hour and then the minute.
205#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
206 QDateTime tmp = QDateTime(
207 m_startDateTime.toLocalTime().date(),
208 QTime(m_startDateTime.toLocalTime().time().hour(),59,59),
209 Qt::LocalTime).toUTC();
210#else
211 QDateTime tmp =
212 QDateTime(m_startDateTime.toLocalTime().date(),
213 QTime(m_startDateTime.toLocalTime().time().hour(),59,59),
214 QTimeZone(QTimeZone::LocalTime))
215 .toUTC();
216#endif
217 if (tmp < m_nowDateTime)
218 {
219 hr = m_nowDateTime.toLocalTime().time().hour();
221#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
223 QDateTime(m_nowDateTime.toLocalTime().date(),
224 QTime(hr, min), Qt::LocalTime).toUTC();
225#else
226 m_startDateTime = QDateTime(m_nowDateTime.toLocalTime().date(),
227 QTime(hr, min),
228 QTimeZone(QTimeZone::LocalTime))
229 .toUTC();
230#endif
231 }
233}
234
236{
237 QDateTime endts = m_startDateTime
238 .addSecs(std::max(m_durationSpin->GetIntValue() * 60, 60));
239
240 if (m_channelList->GetCurrentPos() >= m_chanids.size())
241 {
242 LOG(VB_GENERAL, LOG_ERR, "Channel out of range.");
243 return; // this can happen if there are no channels..
244 }
245
246 ProgramInfo p(m_titleEdit->GetText().trimmed(),
248 m_startDateTime, endts);
249
250 // Save the channel because we might want to use it as the
251 // starting channel for the next Manual Record rule.
252 gCoreContext->SaveSetting("LastManualRecordChan",
254
255 auto *record = new RecordingRule();
256 record->LoadByProgram(&p);
257 record->m_searchType = kManualSearch;
258 record->m_dupMethod = kDupCheckNone;
259
261 auto *schededit = new ScheduleEditor(mainStack, record);
262 if (schededit->Create())
263 {
264 mainStack->AddScreen(schededit);
266 }
267 else
268 {
269 delete schededit;
270 }
271}
272
274{
275 if (ruleid > 0)
276 Close();
277}
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:131
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:251
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:23
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:32
int GetIntValue(void) const override
Definition: mythuispinbox.h:39
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:138
Holds information on recordings and videos.
Definition: programinfo.h:68
Internal representation of a recording rule, mirrors the record table.
Definition: recordingrule.h:30
Construct a recording schedule.
void ruleSaved(int ruleId)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
unsigned int uint
Definition: freesurround.h:24
static guint32 * tmp
Definition: goom_core.cpp:26
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:26
@ kDateFull
Default local time.
Definition: mythdate.h:19
@ ISODate
Default UTC.
Definition: mythdate.h:17
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
@ kManualSearch
@ kDupCheckNone