|
MythTV
0.26-pre
|
00001 00002 #include "manualschedule.h" 00003 00004 // qt 00005 #include <QDateTime> 00006 00007 // libmythbase 00008 #include "mythdbcon.h" 00009 #include "mythlogging.h" 00010 #include "mythmiscutil.h" 00011 00012 // libmyth 00013 #include "mythcorecontext.h" 00014 #include "programinfo.h" 00015 00016 // libmythtv 00017 #include "recordingrule.h" 00018 #include "recordingtypes.h" 00019 #include "channelutil.h" 00020 00021 // libmythui 00022 #include "mythuitextedit.h" 00023 #include "mythuibutton.h" 00024 #include "mythuibuttonlist.h" 00025 #include "mythuispinbox.h" 00026 #include "mythmainwindow.h" 00027 00028 // mythfrontend 00029 #include "scheduleeditor.h" 00030 00031 ManualSchedule::ManualSchedule(MythScreenStack *parent) 00032 : MythScreenType(parent, "ManualSchedule") 00033 { 00034 m_nowDateTime = QDateTime::currentDateTime(); 00035 m_startDateTime = m_nowDateTime; 00036 00037 m_daysahead = 0; 00038 m_titleEdit = NULL; 00039 m_channelList = m_startdateList = NULL; 00040 m_recordButton = m_cancelButton = NULL; 00041 m_durationSpin = m_starthourSpin = m_startminuteSpin = NULL; 00042 } 00043 00044 bool ManualSchedule::Create(void) 00045 { 00046 if (!LoadWindowFromXML("schedule-ui.xml", "manualschedule", this)) 00047 return false; 00048 00049 m_channelList = dynamic_cast<MythUIButtonList *>(GetChild("channel")); 00050 m_startdateList = dynamic_cast<MythUIButtonList *>(GetChild("startdate")); 00051 00052 m_starthourSpin = dynamic_cast<MythUISpinBox *>(GetChild("starthour")); 00053 m_startminuteSpin = dynamic_cast<MythUISpinBox *>(GetChild("startminute")); 00054 m_durationSpin = dynamic_cast<MythUISpinBox *>(GetChild("duration")); 00055 00056 m_titleEdit = dynamic_cast<MythUITextEdit *>(GetChild("title")); 00057 00058 m_recordButton = dynamic_cast<MythUIButton *>(GetChild("next")); 00059 m_cancelButton = dynamic_cast<MythUIButton *>(GetChild("cancel")); 00060 00061 if (!m_channelList || !m_startdateList || !m_starthourSpin || 00062 !m_startminuteSpin || !m_durationSpin || !m_titleEdit || 00063 !m_recordButton || !m_cancelButton) 00064 { 00065 LOG(VB_GENERAL, LOG_ERR, 00066 "ManualSchedule, theme is missing required elements"); 00067 return false; 00068 } 00069 00070 QString chanorder = gCoreContext->GetSetting("ChannelOrdering", "channum"); 00071 DBChanList channels = ChannelUtil::GetChannels(0, false, "channum,callsign"); 00072 ChannelUtil::SortChannels(channels, chanorder); 00073 00074 for (uint i = 0; i < channels.size(); i++) 00075 { 00076 QString chantext = channels[i].GetFormatted(DBChannel::kChannelLong); 00077 00078 MythUIButtonListItem *item = 00079 new MythUIButtonListItem(m_channelList, chantext); 00080 InfoMap infomap; 00081 channels[i].ToMap(infomap); 00082 item->SetTextFromMap(infomap); 00083 m_chanids.push_back(channels[i].chanid); 00084 } 00085 00086 for (uint index = 0; index <= 60; index++) 00087 { 00088 QString dinfo = MythDateTimeToString(m_nowDateTime.addDays(index), kDateFull | kSimplify); 00089 if (m_nowDateTime.addDays(index).date().dayOfWeek() < 6) 00090 dinfo += QString(" (%1)").arg(tr("5 weekdays if daily")); 00091 else 00092 dinfo += QString(" (%1)").arg(tr("7 days per week if daily")); 00093 new MythUIButtonListItem(m_startdateList, dinfo); 00094 if (m_nowDateTime.addDays(index).toString("MMdd") == 00095 m_startDateTime.toString("MMdd")) 00096 m_startdateList->SetItemCurrent(m_startdateList->GetCount() - 1); 00097 } 00098 00099 QTime thisTime = m_nowDateTime.time(); 00100 thisTime = thisTime.addSecs((30 - (thisTime.minute() % 30)) * 60); 00101 00102 if (thisTime < QTime(0,30)) 00103 m_startdateList->SetItemCurrent(m_startdateList->GetCurrentPos() + 1); 00104 00105 m_starthourSpin->SetRange(0,23,1); 00106 m_starthourSpin->SetValue(thisTime.hour()); 00107 int minute_increment = 00108 gCoreContext->GetNumSetting("ManualScheduleMinuteIncrement", 5); 00109 m_startminuteSpin->SetRange(0, 60-minute_increment, minute_increment); 00110 m_startminuteSpin->SetValue((thisTime.minute()/5)*5); 00111 m_durationSpin->SetRange(5,360,5); 00112 m_durationSpin->SetValue(60); 00113 00114 connectSignals(); 00115 connect(m_recordButton, SIGNAL(Clicked()), SLOT(recordClicked())); 00116 connect(m_cancelButton, SIGNAL(Clicked()), SLOT(Close())); 00117 00118 m_titleEdit->SetMaxLength(128); 00119 00120 BuildFocusList(); 00121 00122 return true; 00123 } 00124 00125 void ManualSchedule::connectSignals() 00126 { 00127 connect(m_startdateList, SIGNAL(itemSelected(MythUIButtonListItem*)), 00128 SLOT(dateChanged(void))); 00129 connect(m_starthourSpin, SIGNAL(itemSelected(MythUIButtonListItem*)), 00130 SLOT(dateChanged(void))); 00131 connect(m_startminuteSpin, SIGNAL(itemSelected(MythUIButtonListItem*)), 00132 SLOT(dateChanged(void))); 00133 } 00134 00135 void ManualSchedule::disconnectSignals() 00136 { 00137 disconnect(m_startdateList, 0, this, 0); 00138 disconnect(m_starthourSpin, 0, this, 0); 00139 disconnect(m_startminuteSpin, 0, this, 0); 00140 } 00141 00142 void ManualSchedule::hourRollover(void) 00143 { 00144 if (m_startminuteSpin->GetIntValue() == 0 ) 00145 { 00146 m_startminuteSpin->SetValue(12); 00147 m_starthourSpin->SetValue(m_starthourSpin->GetIntValue() - 1); 00148 } 00149 if (m_startminuteSpin->GetIntValue() == 13 ) 00150 { 00151 m_starthourSpin->SetValue(m_starthourSpin->GetIntValue() + 1); 00152 m_startminuteSpin->SetValue(1); 00153 } 00154 } 00155 00156 void ManualSchedule::minuteRollover(void) 00157 { 00158 if (m_starthourSpin->GetIntValue() == 0 ) 00159 { 00160 m_starthourSpin->SetValue(24); 00161 m_startdateList->SetItemCurrent(m_startdateList->GetCurrentPos() - 1); 00162 } 00163 if (m_starthourSpin->GetIntValue() == 25 ) 00164 { 00165 m_startdateList->SetItemCurrent(m_startdateList->GetCurrentPos() + 1); 00166 m_starthourSpin->SetValue(1); 00167 } 00168 } 00169 00170 void ManualSchedule::dateChanged(void) 00171 { 00172 disconnectSignals(); 00173 m_daysahead = m_startdateList->GetCurrentPos(); 00174 m_startDateTime.setDate(m_nowDateTime.addDays(m_daysahead).date()); 00175 00176 int hr = m_starthourSpin->GetIntValue(); 00177 int min = m_startminuteSpin->GetIntValue(); 00178 m_startDateTime.setTime(QTime(hr, min)); 00179 00180 LOG(VB_SCHEDULE, LOG_INFO, QString("Start Date Time: %1") 00181 .arg(m_startDateTime.toString())); 00182 00183 // Note we allow start times up to one hour in the past so 00184 // if it is 20:25 the user can start a recording at 20:30 00185 // by first setting the hour and then the minute. 00186 QDateTime tmp = QDateTime(m_startDateTime.date(), 00187 QTime(m_startDateTime.time().hour(),59,59)); 00188 if (tmp < m_nowDateTime) 00189 { 00190 hr = m_nowDateTime.time().hour(); 00191 m_starthourSpin->SetValue(hr); 00192 m_startDateTime.setDate(m_nowDateTime.date()); 00193 m_startDateTime.setTime(QTime(hr, min)); 00194 } 00195 connectSignals(); 00196 } 00197 00198 void ManualSchedule::recordClicked(void) 00199 { 00200 QDateTime endts = m_startDateTime 00201 .addSecs(max(m_durationSpin->GetIntValue() * 60, 60)); 00202 00203 if (m_channelList->GetCurrentPos() >= m_chanids.size()) 00204 { 00205 LOG(VB_GENERAL, LOG_ERR, "Channel out of range."); 00206 return; // this can happen if there are no channels.. 00207 } 00208 00209 ProgramInfo p(m_titleEdit->GetText().trimmed(), 00210 m_chanids[m_channelList->GetCurrentPos()], 00211 m_startDateTime, endts); 00212 00213 RecordingRule *record = new RecordingRule(); 00214 record->LoadByProgram(&p); 00215 record->m_searchType = kManualSearch; 00216 00217 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); 00218 ScheduleEditor *schededit = new ScheduleEditor(mainStack, record); 00219 if (schededit->Create()) 00220 { 00221 mainStack->AddScreen(schededit); 00222 connect(schededit, SIGNAL(ruleSaved(int)), SLOT(scheduleCreated(int))); 00223 } 00224 else 00225 delete schededit; 00226 } 00227 00228 void ManualSchedule::scheduleCreated(int ruleid) 00229 { 00230 if (ruleid > 0) 00231 Close(); 00232 }
1.7.6.1