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 {
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();
117  connect(m_recordButton, SIGNAL(Clicked()), SLOT(recordClicked()));
118  connect(m_cancelButton, SIGNAL(Clicked()), SLOT(Close()));
119 
121 
122  BuildFocusList();
123 
124  return true;
125 }
126 
128 {
129  connect(m_startdateList, SIGNAL(itemSelected(MythUIButtonListItem*)),
130  SLOT(dateChanged(void)));
131  connect(m_starthourSpin, SIGNAL(itemSelected(MythUIButtonListItem*)),
132  SLOT(dateChanged(void)));
133  connect(m_startminuteSpin, SIGNAL(itemSelected(MythUIButtonListItem*)),
134  SLOT(dateChanged(void)));
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(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 
224  auto *schededit = new ScheduleEditor(mainStack, record);
225  if (schededit->Create())
226  {
227  mainStack->AddScreen(schededit);
228  connect(schededit, SIGNAL(ruleSaved(int)), SLOT(scheduleCreated(int)));
229  }
230  else
231  delete schededit;
232 }
233 
235 {
236  if (ruleid > 0)
237  Close();
238 }
MythUITextEdit * m_titleEdit
QDateTime m_nowDateTime
void recordClicked(void)
MythUIButtonList * m_channelList
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
bool Create(void) override
ManualSchedule(MythScreenStack *parent)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void SetValue(int val) override
Definition: mythuispinbox.h:26
MythScreenStack * GetMainStack()
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:23
QList< uint32_t > m_chanids
static void SortChannels(ChannelInfoList &list, const QString &order, bool eliminate_duplicates=false)
static guint32 * tmp
Definition: goom_core.c:35
void BuildFocusList(void)
void dateChanged(void)
int GetIntValue(void) const override
Definition: mythuispinbox.h:33
void scheduleCreated(int)
virtual void Close()
Holds information on recordings and videos.
Definition: programinfo.h:66
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.
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void SetMaxLength(const int length)
MythUISpinBox * m_starthourSpin
MythUIButtonList * m_startdateList
Construct a recording schedule.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
QString GetSetting(const QString &key, const QString &defaultval="")
QDateTime m_startDateTime
Default local time.
Definition: mythdate.h:16
static ChannelInfoList GetChannels(uint sourceid, bool visible_only, const QString &group_by=QString(), uint channel_groupid=0)
Definition: channelutil.h:237
unsigned int uint
Definition: compat.h:140
Internal representation of a recording rule, mirrors the record table.
Definition: recordingrule.h:32
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:101
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythMainWindow * GetMythMainWindow(void)
void hourRollover(void)
int GetNumSetting(const QString &key, int defaultval=0)
MythUISpinBox * m_durationSpin
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
MythUISpinBox * m_startminuteSpin
void minuteRollover(void)
void SetItemCurrent(MythUIButtonListItem *item)
Default UTC.
Definition: mythdate.h:14
Screen in which all other widgets are contained and rendered.
int GetCurrentPos() const
MythUIButton * m_recordButton
MythUIButton * m_cancelButton
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
vector< ChannelInfo > ChannelInfoList
Definition: channelinfo.h:121
QString GetText(void) const