MythTV  master
manualschedule.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QDateTime>
3 
4 // MythTV
6 #include "libmythbase/mythdate.h"
11 #include "libmythtv/channelinfo.h"
12 #include "libmythtv/channelutil.h"
15 #include "libmythui/mythuibutton.h"
19 
20 // MythFrontend
21 #include "manualschedule.h"
22 #include "scheduleeditor.h"
23 
25  : MythScreenType(parent, "ManualSchedule"),
26  m_nowDateTime(MythDate::current()),
27  m_startDateTime(m_nowDateTime)
28 {
29 }
30 
32 {
33  if (!LoadWindowFromXML("schedule-ui.xml", "manualschedule", this))
34  return false;
35 
36  m_channelList = dynamic_cast<MythUIButtonList *>(GetChild("channel"));
37  m_startdateList = dynamic_cast<MythUIButtonList *>(GetChild("startdate"));
38 
39  m_starthourSpin = dynamic_cast<MythUISpinBox *>(GetChild("starthour"));
40  m_startminuteSpin = dynamic_cast<MythUISpinBox *>(GetChild("startminute"));
41  m_durationSpin = dynamic_cast<MythUISpinBox *>(GetChild("duration"));
42 
43  m_titleEdit = dynamic_cast<MythUITextEdit *>(GetChild("title"));
44 
45  m_recordButton = dynamic_cast<MythUIButton *>(GetChild("next"));
46  m_cancelButton = dynamic_cast<MythUIButton *>(GetChild("cancel"));
47 
51  {
52  LOG(VB_GENERAL, LOG_ERR,
53  "ManualSchedule, theme is missing required elements");
54  return false;
55  }
56 
57  QString startchan = gCoreContext->GetSetting("DefaultTVChannel", "");
58  QString chanorder = gCoreContext->GetSetting("ChannelOrdering", "channum");
59  QString lastManualRecordChan = gCoreContext->GetSetting("LastManualRecordChan", startchan);
60  int manStartChanType = gCoreContext->GetNumSetting("ManualRecordStartChanType", 1);
61  ChannelInfoList channels = ChannelUtil::GetChannels(0, true, "channum,callsign");
62  ChannelUtil::SortChannels(channels, chanorder);
63 
64  for (size_t i = 0; i < channels.size(); i++)
65  {
66  QString chantext = channels[i].GetFormatted(ChannelInfo::kChannelLong);
67 
68  auto *item = new MythUIButtonListItem(m_channelList, chantext);
69  InfoMap infomap;
70  channels[i].ToMap(infomap);
71  item->SetTextFromMap(infomap);
72  if (manStartChanType == 1)
73  {
74  // Use DefaultTVChannel as starting channel
75  if (channels[i].m_chanNum == startchan)
76  {
78  startchan = "";
79  }
80  }
81  else
82  {
83  // Use LastManualRecordChan as starting channel
84  if (channels[i].m_chanNum == lastManualRecordChan)
85  {
87  lastManualRecordChan = "";
88  }
89  }
90  m_chanids.push_back(channels[i].m_chanId);
91  }
92 
93  for (uint index = 0; index <= 60; index++)
94  {
95  QString dinfo = MythDate::toString(
96  m_nowDateTime.addDays(index),
98  if (m_nowDateTime.addDays(index).toLocalTime().date().dayOfWeek() < 6)
99  dinfo += QString(" (%1)").arg(tr("5 weekdays if daily"));
100  else
101  dinfo += QString(" (%1)").arg(tr("7 days per week if daily"));
103  if (m_nowDateTime.addDays(index).toLocalTime().toString("MMdd") ==
104  m_startDateTime.toLocalTime().toString("MMdd"))
106  }
107 
108  QTime thisTime = m_nowDateTime.toLocalTime().time();
109  thisTime = thisTime.addSecs((30 - (thisTime.minute() % 30)) * 60);
110 
111  if (thisTime < QTime(0,30))
113 
114  m_starthourSpin->SetRange(0,23,1);
115  m_starthourSpin->SetValue(thisTime.hour());
116  int minute_increment =
117  gCoreContext->GetNumSetting("ManualScheduleMinuteIncrement", 5);
118  m_startminuteSpin->SetRange(0, 60-minute_increment, minute_increment);
119  m_startminuteSpin->SetValue((thisTime.minute()/5)*5);
120  m_durationSpin->SetRange(5,360,5);
122 
123  connectSignals();
126 
128 
129  BuildFocusList();
130 
131  return true;
132 }
133 
135 {
142 }
143 
145 {
146  disconnect(m_startdateList, nullptr, this, nullptr);
147  disconnect(m_starthourSpin, nullptr, this, nullptr);
148  disconnect(m_startminuteSpin, nullptr, this, nullptr);
149 }
150 
152 {
153  if (m_startminuteSpin->GetIntValue() == 0 )
154  {
157  }
158  if (m_startminuteSpin->GetIntValue() == 13 )
159  {
162  }
163 }
164 
166 {
167  if (m_starthourSpin->GetIntValue() == 0 )
168  {
171  }
172  if (m_starthourSpin->GetIntValue() == 25 )
173  {
176  }
177 }
178 
180 {
183  int hr = m_starthourSpin->GetIntValue();
184  int min = m_startminuteSpin->GetIntValue();
185 
186  m_startDateTime = QDateTime(
187  m_nowDateTime.toLocalTime().addDays(m_daysahead).date(),
188  QTime(hr, min), Qt::LocalTime).toUTC();
189 
190  LOG(VB_SCHEDULE, LOG_INFO, QString("Start Date Time: %1")
191  .arg(m_startDateTime.toString(Qt::ISODate)));
192 
193  // Note we allow start times up to one hour in the past so
194  // if it is 20:25 the user can start a recording at 20:30
195  // by first setting the hour and then the minute.
196  QDateTime tmp = QDateTime(
197  m_startDateTime.toLocalTime().date(),
198  QTime(m_startDateTime.toLocalTime().time().hour(),59,59),
199  Qt::LocalTime).toUTC();
200  if (tmp < m_nowDateTime)
201  {
202  hr = m_nowDateTime.toLocalTime().time().hour();
205  QDateTime(m_nowDateTime.toLocalTime().date(),
206  QTime(hr, min), Qt::LocalTime).toUTC();
207  }
208  connectSignals();
209 }
210 
212 {
213  QDateTime endts = m_startDateTime
214  .addSecs(std::max(m_durationSpin->GetIntValue() * 60, 60));
215 
216  if (m_channelList->GetCurrentPos() >= m_chanids.size())
217  {
218  LOG(VB_GENERAL, LOG_ERR, "Channel out of range.");
219  return; // this can happen if there are no channels..
220  }
221 
222  ProgramInfo p(m_titleEdit->GetText().trimmed(),
224  m_startDateTime, endts);
225 
226  // Save the channel because we might want to use it as the
227  // starting channel for the next Manual Record rule.
228  gCoreContext->SaveSetting("LastManualRecordChan",
230 
231  auto *record = new RecordingRule();
232  record->LoadByProgram(&p);
233  record->m_searchType = kManualSearch;
234  record->m_dupMethod = kDupCheckNone;
235 
237  auto *schededit = new ScheduleEditor(mainStack, record);
238  if (schededit->Create())
239  {
240  mainStack->AddScreen(schededit);
241  connect(schededit, &ScheduleEditor::ruleSaved, this, &ManualSchedule::scheduleCreated);
242  }
243  else
244  delete schededit;
245 }
246 
248 {
249  if (ruleid > 0)
250  Close();
251 }
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:315
MythUITextEdit::SetMaxLength
void SetMaxLength(int length)
Definition: mythuitextedit.cpp:192
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:84
ManualSchedule::minuteRollover
void minuteRollover(void)
Definition: manualschedule.cpp:165
ManualSchedule::m_startdateList
MythUIButtonList * m_startdateList
Definition: manualschedule.h:48
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:386
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:133
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:31
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:1652
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
ManualSchedule::disconnectSignals
void disconnectSignals()
Definition: manualschedule.cpp:144
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:2320
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
ChannelInfo::kChannelLong
@ kChannelLong
Definition: channelinfo.h:49
ManualSchedule::recordClicked
void recordClicked(void)
Definition: manualschedule.cpp:211
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:238
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:206
MythUIButton
A single button widget.
Definition: mythuibutton.h:21
ManualSchedule::ManualSchedule
ManualSchedule(MythScreenStack *parent)
Definition: manualschedule.cpp:24
ChannelUtil::GetChannels
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:251
kManualSearch
@ kManualSearch
Definition: recordingtypes.h:85
uint
unsigned int uint
Definition: compat.h:81
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:54
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:910
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:179
ManualSchedule::hourRollover
void hourRollover(void)
Definition: manualschedule.cpp:151
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:695
MythDate
Definition: mythdate.cpp:11
ManualSchedule::m_durationSpin
MythUISpinBox * m_durationSpin
Definition: manualschedule.h:52
kDupCheckNone
@ kDupCheckNone
Definition: recordingtypes.h:65
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:102
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1554
ManualSchedule::scheduleCreated
void scheduleCreated(int ruleid)
Definition: manualschedule.cpp:247
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:134
manualschedule.h
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:879
ChannelUtil::GetChanNum
static QString GetChanNum(int chan_id)
Returns the channel-number string of the given channel.
Definition: channelutil.cpp:775
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:143
ManualSchedule::m_startDateTime
QDateTime m_startDateTime
Definition: manualschedule.h:58
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:896
ChannelInfoList
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:131