MythTV  master
manualschedule.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QDateTime>
3 #include <QTimeZone>
4 
5 // MythTV
7 #include "libmythbase/mythdate.h"
12 #include "libmythtv/channelinfo.h"
13 #include "libmythtv/channelutil.h"
16 #include "libmythui/mythuibutton.h"
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,360,5);
123 
124  connectSignals();
127 
129 
130  BuildFocusList();
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  }
232  connectSignals();
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);
265  connect(schededit, &ScheduleEditor::ruleSaved, this, &ManualSchedule::scheduleCreated);
266  }
267  else
268  {
269  delete schededit;
270  }
271 }
272 
274 {
275  if (ruleid > 0)
276  Close();
277 }
ManualSchedule::m_nowDateTime
QDateTime m_nowDateTime
Definition: manualschedule.h:57
MythUIButton::Clicked
void Clicked()
scheduleeditor.h
ManualSchedule::m_cancelButton
MythUIButton * m_cancelButton
Definition: manualschedule.h:55
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:317
MythUITextEdit::SetMaxLength
void SetMaxLength(int length)
Definition: mythuitextedit.cpp:193
ManualSchedule::m_channelList
MythUIButtonList * m_channelList
Definition: manualschedule.h:47
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
ManualSchedule::minuteRollover
void minuteRollover(void)
Definition: manualschedule.cpp:166
ManualSchedule::m_startdateList
MythUIButtonList * m_startdateList
Definition: manualschedule.h:48
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:384
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
RecordingRule
Internal representation of a recording rule, mirrors the record table.
Definition: recordingrule.h:28
MythUITextEdit
A text entry and edit widget.
Definition: mythuitextedit.h:34
ManualSchedule::m_startminuteSpin
MythUISpinBox * m_startminuteSpin
Definition: manualschedule.h:51
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
ManualSchedule::Create
bool Create(void) override
Definition: manualschedule.cpp:32
ScheduleEditor::ruleSaved
void ruleSaved(int ruleId)
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:50
recordingtypes.h
MythUISpinBox::SetRange
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.
Definition: mythuispinbox.cpp:26
mythuibuttonlist.h
MythUIButtonList::GetCount
int GetCount() const
Definition: mythuibuttonlist.cpp:1679
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
ChannelInfo::kChannelLong
@ kChannelLong
Definition: channelinfo.h:49
ManualSchedule::disconnectSignals
void disconnectSignals()
Definition: manualschedule.cpp:145
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
ChannelUtil::SortChannels
static void SortChannels(ChannelInfoList &list, const QString &order, bool eliminate_duplicates=false)
Definition: channelutil.cpp:2338
kDupCheckNone
@ kDupCheckNone
Definition: recordingtypes.h:64
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythUISpinBox::SetValue
void SetValue(int val) override
Definition: mythuispinbox.h:26
ManualSchedule::m_chanids
QList< uint32_t > m_chanids
Definition: manualschedule.h:43
mythdate.h
programinfo.h
mythlogging.h
ManualSchedule::recordClicked
void recordClicked(void)
Definition: manualschedule.cpp:235
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:240
hardwareprofile.config.p
p
Definition: config.py:33
ManualSchedule::m_starthourSpin
MythUISpinBox * m_starthourSpin
Definition: manualschedule.h:50
MythUISpinBox::GetIntValue
int GetIntValue(void) const override
Definition: mythuispinbox.h:33
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:204
MythUIButton
A single button widget.
Definition: mythuibutton.h:21
kManualSearch
@ kManualSearch
Definition: recordingtypes.h:84
ManualSchedule::ManualSchedule
ManualSchedule(MythScreenStack *parent)
Definition: manualschedule.cpp:25
ChannelUtil::GetChannels
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:251
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:918
channelutil.h
MythDate::kSimplify
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:26
mythuispinbox.h
channelinfo.h
ManualSchedule::dateChanged
void dateChanged(void)
Definition: manualschedule.cpp:180
ManualSchedule::hourRollover
void hourRollover(void)
Definition: manualschedule.cpp:152
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
mythcorecontext.h
mythuitextedit.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
MythDate
Definition: mythdate.cpp:12
ManualSchedule::m_durationSpin
MythUISpinBox * m_durationSpin
Definition: manualschedule.h:52
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
ManualSchedule::m_titleEdit
MythUITextEdit * m_titleEdit
Definition: manualschedule.h:45
ManualSchedule::m_recordButton
MythUIButton * m_recordButton
Definition: manualschedule.h:54
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1581
ManualSchedule::scheduleCreated
void scheduleCreated(int ruleid)
Definition: manualschedule.cpp:273
MythUISpinBox
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:16
mythuibutton.h
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:19
ManualSchedule::connectSignals
void connectSignals()
Definition: manualschedule.cpp:135
manualschedule.h
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:887
ChannelUtil::GetChanNum
static QString GetChanNum(int chan_id)
Returns the channel-number string of the given channel.
Definition: channelutil.cpp:778
recordingrule.h
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:191
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
ManualSchedule::m_daysahead
int m_daysahead
Definition: manualschedule.h:41
ScheduleEditor
Construct a recording schedule.
Definition: scheduleeditor.h:142
ManualSchedule::m_startDateTime
QDateTime m_startDateTime
Definition: manualschedule.h:58
uint
unsigned int uint
Definition: freesurround.h:24
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:904
ChannelInfoList
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:131