MythTV  master
manualschedule.cpp
Go to the documentation of this file.
1 
2 #include "manualschedule.h"
3 
4 // qt
5 #include <QDateTime>
6 
7 // libmythbase
8 #include "mythdbcon.h"
9 #include "mythlogging.h"
10 #include "mythdate.h"
11 
12 // libmyth
13 #include "mythcorecontext.h"
14 #include "programinfo.h"
15 
16 // libmythtv
17 #include "recordingrule.h"
18 #include "recordingtypes.h"
19 #include "channelinfo.h"
20 #include "channelutil.h"
21 
22 // libmythui
23 #include "mythuitextedit.h"
24 #include "mythuibutton.h"
25 #include "mythuibuttonlist.h"
26 #include "mythuispinbox.h"
27 #include "mythmainwindow.h"
28 
29 // mythfrontend
30 #include "scheduleeditor.h"
31 
33  : MythScreenType(parent, "ManualSchedule"),
34  m_nowDateTime(MythDate::current()),
35  m_startDateTime(m_nowDateTime)
36 {
37 }
38 
40 {
41  if (!LoadWindowFromXML("schedule-ui.xml", "manualschedule", this))
42  return false;
43 
44  m_channelList = dynamic_cast<MythUIButtonList *>(GetChild("channel"));
45  m_startdateList = dynamic_cast<MythUIButtonList *>(GetChild("startdate"));
46 
47  m_starthourSpin = dynamic_cast<MythUISpinBox *>(GetChild("starthour"));
48  m_startminuteSpin = dynamic_cast<MythUISpinBox *>(GetChild("startminute"));
49  m_durationSpin = dynamic_cast<MythUISpinBox *>(GetChild("duration"));
50 
51  m_titleEdit = dynamic_cast<MythUITextEdit *>(GetChild("title"));
52 
53  m_recordButton = dynamic_cast<MythUIButton *>(GetChild("next"));
54  m_cancelButton = dynamic_cast<MythUIButton *>(GetChild("cancel"));
55 
59  {
60  LOG(VB_GENERAL, LOG_ERR,
61  "ManualSchedule, theme is missing required elements");
62  return false;
63  }
64 
65  QString startchan = gCoreContext->GetSetting("DefaultTVChannel", "");
66  QString chanorder = gCoreContext->GetSetting("ChannelOrdering", "channum");
67  ChannelInfoList channels = ChannelUtil::GetChannels(0, true, "channum,callsign");
68  ChannelUtil::SortChannels(channels, chanorder);
69 
70  for (size_t i = 0; i < channels.size(); i++)
71  {
72  QString chantext = channels[i].GetFormatted(ChannelInfo::kChannelLong);
73 
74  auto *item = new MythUIButtonListItem(m_channelList, chantext);
75  InfoMap infomap;
76  channels[i].ToMap(infomap);
77  item->SetTextFromMap(infomap);
78  if (channels[i].m_chanNum == startchan)
79  {
81  startchan = "";
82  }
83  m_chanids.push_back(channels[i].m_chanId);
84  }
85 
86  for (uint index = 0; index <= 60; index++)
87  {
88  QString dinfo = MythDate::toString(
89  m_nowDateTime.addDays(index),
91  if (m_nowDateTime.addDays(index).toLocalTime().date().dayOfWeek() < 6)
92  dinfo += QString(" (%1)").arg(tr("5 weekdays if daily"));
93  else
94  dinfo += QString(" (%1)").arg(tr("7 days per week if daily"));
96  if (m_nowDateTime.addDays(index).toLocalTime().toString("MMdd") ==
97  m_startDateTime.toLocalTime().toString("MMdd"))
99  }
100 
101  QTime thisTime = m_nowDateTime.toLocalTime().time();
102  thisTime = thisTime.addSecs((30 - (thisTime.minute() % 30)) * 60);
103 
104  if (thisTime < QTime(0,30))
106 
107  m_starthourSpin->SetRange(0,23,1);
108  m_starthourSpin->SetValue(thisTime.hour());
109  int minute_increment =
110  gCoreContext->GetNumSetting("ManualScheduleMinuteIncrement", 5);
111  m_startminuteSpin->SetRange(0, 60-minute_increment, minute_increment);
112  m_startminuteSpin->SetValue((thisTime.minute()/5)*5);
113  m_durationSpin->SetRange(5,360,5);
115 
116  connectSignals();
119 
121 
122  BuildFocusList();
123 
124  return true;
125 }
126 
128 {
135 }
136 
138 {
139  disconnect(m_startdateList, nullptr, this, nullptr);
140  disconnect(m_starthourSpin, nullptr, this, nullptr);
141  disconnect(m_startminuteSpin, nullptr, this, nullptr);
142 }
143 
145 {
146  if (m_startminuteSpin->GetIntValue() == 0 )
147  {
150  }
151  if (m_startminuteSpin->GetIntValue() == 13 )
152  {
155  }
156 }
157 
159 {
160  if (m_starthourSpin->GetIntValue() == 0 )
161  {
164  }
165  if (m_starthourSpin->GetIntValue() == 25 )
166  {
169  }
170 }
171 
173 {
176  int hr = m_starthourSpin->GetIntValue();
177  int min = m_startminuteSpin->GetIntValue();
178 
179  m_startDateTime = QDateTime(
180  m_nowDateTime.toLocalTime().addDays(m_daysahead).date(),
181  QTime(hr, min), Qt::LocalTime).toUTC();
182 
183  LOG(VB_SCHEDULE, LOG_INFO, QString("Start Date Time: %1")
184  .arg(m_startDateTime.toString(Qt::ISODate)));
185 
186  // Note we allow start times up to one hour in the past so
187  // if it is 20:25 the user can start a recording at 20:30
188  // by first setting the hour and then the minute.
189  QDateTime tmp = QDateTime(
190  m_startDateTime.toLocalTime().date(),
191  QTime(m_startDateTime.toLocalTime().time().hour(),59,59),
192  Qt::LocalTime).toUTC();
193  if (tmp < m_nowDateTime)
194  {
195  hr = m_nowDateTime.toLocalTime().time().hour();
198  QDateTime(m_nowDateTime.toLocalTime().date(),
199  QTime(hr, min), Qt::LocalTime).toUTC();
200  }
201  connectSignals();
202 }
203 
205 {
206  QDateTime endts = m_startDateTime
207  .addSecs(std::max(m_durationSpin->GetIntValue() * 60, 60));
208 
209  if (m_channelList->GetCurrentPos() >= m_chanids.size())
210  {
211  LOG(VB_GENERAL, LOG_ERR, "Channel out of range.");
212  return; // this can happen if there are no channels..
213  }
214 
215  ProgramInfo p(m_titleEdit->GetText().trimmed(),
217  m_startDateTime, endts);
218 
219  auto *record = new RecordingRule();
220  record->LoadByProgram(&p);
221  record->m_searchType = kManualSearch;
222  record->m_dupMethod = kDupCheckNone;
223 
225  auto *schededit = new ScheduleEditor(mainStack, record);
226  if (schededit->Create())
227  {
228  mainStack->AddScreen(schededit);
229  connect(schededit, &ScheduleEditor::ruleSaved, this, &ManualSchedule::scheduleCreated);
230  }
231  else
232  delete schededit;
233 }
234 
236 {
237  if (ruleid > 0)
238  Close();
239 }
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:324
MythUITextEdit::SetMaxLength
void SetMaxLength(int length)
Definition: mythuitextedit.cpp:211
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:80
ManualSchedule::minuteRollover
void minuteRollover(void)
Definition: manualschedule.cpp:158
ManualSchedule::m_startdateList
MythUIButtonList * m_startdateList
Definition: manualschedule.h:48
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:131
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
MythScreenStack
Definition: mythscreenstack.h:16
arg
arg(title).arg(filename).arg(doDelete))
mythdbcon.h
RecordingRule
Internal representation of a recording rule, mirrors the record table.
Definition: recordingrule.h:33
MythUITextEdit
A text entry and edit widget.
Definition: mythuitextedit.h:33
ManualSchedule::m_startminuteSpin
MythUISpinBox * m_startminuteSpin
Definition: manualschedule.h:51
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
ManualSchedule::Create
bool Create(void) override
Definition: manualschedule.cpp:39
ScheduleEditor::ruleSaved
void ruleSaved(int ruleId)
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:47
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:25
mythuibuttonlist.h
MythUIButtonList::GetCount
int GetCount() const
Definition: mythuibuttonlist.cpp:1655
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
ManualSchedule::disconnectSignals
void disconnectSignals()
Definition: manualschedule.cpp:137
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
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:2280
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
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:204
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:198
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:222
MythUIButton
A single button widget.
Definition: mythuibutton.h:22
ManualSchedule::ManualSchedule
ManualSchedule(MythScreenStack *parent)
Definition: manualschedule.cpp:32
ChannelUtil::GetChannels
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:240
kManualSearch
@ kManualSearch
Definition: recordingtypes.h:78
uint
unsigned int uint
Definition: compat.h:141
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:933
channelutil.h
MythDate::kSimplify
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:23
mythuispinbox.h
channelinfo.h
ManualSchedule::dateChanged
void dateChanged(void)
Definition: manualschedule.cpp:172
ManualSchedule::hourRollover
void hourRollover(void)
Definition: manualschedule.cpp:144
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:68
mythcorecontext.h
mythuitextedit.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
MythDate
Definition: mythdate.cpp:8
ManualSchedule::m_durationSpin
MythUISpinBox * m_durationSpin
Definition: manualschedule.h:52
kDupCheckNone
@ kDupCheckNone
Definition: recordingtypes.h:60
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:14
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:108
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1557
ManualSchedule::scheduleCreated
void scheduleCreated(int ruleid)
Definition: manualschedule.cpp:235
MythUISpinBox
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:17
mythuibutton.h
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:16
ManualSchedule::connectSignals
void connectSignals()
Definition: manualschedule.cpp:127
manualschedule.h
recordingrule.h
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:152
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:150
ManualSchedule::m_startDateTime
QDateTime m_startDateTime
Definition: manualschedule.h:58
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919
ChannelInfoList
std::vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:131