00001 #include <qlayout.h>
00002 #include <qpushbutton.h>
00003 #include <qbuttongroup.h>
00004 #include <qlabel.h>
00005 #include <qcursor.h>
00006 #include <qlistview.h>
00007 #include <qdatetime.h>
00008 #include <qprogressbar.h>
00009 #include <qapplication.h>
00010 #include <qtimer.h>
00011 #include <qimage.h>
00012 #include <qpainter.h>
00013 #include <qheader.h>
00014 #include <qfile.h>
00015 #include <qsqldatabase.h>
00016 #include <qregexp.h>
00017 #include <qhbox.h>
00018 #include <qdatetimeedit.h>
00019
00020 #include <unistd.h>
00021
00022 #include <iostream>
00023 using namespace std;
00024
00025 #include "tv.h"
00026 #include "NuppelVideoPlayer.h"
00027 #include "yuv2rgb.h"
00028 #include "manualschedule.h"
00029
00030 #include "libmyth/mythcontext.h"
00031 #include "libmyth/mythdbcon.h"
00032 #include "libmyth/dialogbox.h"
00033 #include "libmythtv/programinfo.h"
00034 #include "libmythtv/scheduledrecording.h"
00035 #include "libmythtv/recordingtypes.h"
00036 #include "libmythtv/remoteutil.h"
00037 #include "libmythtv/channelutil.h"
00038
00039 ManualSchedule::ManualSchedule(MythMainWindow *parent, const char *name)
00040 : MythDialog(parent, name)
00041 {
00042 m_nowDateTime = QDateTime::currentDateTime();
00043 m_startDateTime = m_nowDateTime;
00044 daysahead = 0;
00045
00046 QVBoxLayout *vbox = new QVBoxLayout(this, (int)(20 * wmult));
00047
00048 dateformat = gContext->GetSetting("DateFormat", "ddd MMMM d");
00049 shortdateformat = gContext->GetSetting("ShortDateFormat", "M/d");
00050 timeformat = gContext->GetSetting("TimeFormat", "h:mm AP");
00051
00052
00053
00054 QString message = tr("Manual Recording Scheduler");
00055 QLabel *label = new QLabel(message, this);
00056 label->setBackgroundOrigin(WindowOrigin);
00057 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00058 vbox->addWidget(label);
00059
00060 QVBoxLayout *vkbox = new QVBoxLayout(vbox, (int)(1 * wmult));
00061 QHBoxLayout *hbox = new QHBoxLayout(vkbox, (int)(1 * wmult));
00062
00063
00064 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00065
00066 message = tr("Channel:");
00067 label = new QLabel(message, this);
00068 label->setBackgroundOrigin(WindowOrigin);
00069 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00070 hbox->addWidget(label);
00071
00072 m_channel = new MythComboBox( false, this, "channel");
00073 m_channel->setBackgroundOrigin(WindowOrigin);
00074
00075
00076 QString longChannelFormat = gContext->GetSetting("LongChannelFormat",
00077 "<num> <name>");
00078 QString chanorder = gContext->GetSetting("ChannelOrdering", "channum");
00079 DBChanList channels = ChannelUtil::GetChannels(0, false, "channum,callsign");
00080 ChannelUtil::SortChannels(channels, chanorder);
00081
00082 for (uint i = 0; i < channels.size(); i++)
00083 {
00084 QString chantext = QDeepCopy<QString>(longChannelFormat);
00085 chantext
00086 .replace("<num>", channels[i].channum)
00087 .replace("<sign>", channels[i].callsign)
00088 .replace("<name>", channels[i].name);
00089
00090 m_channel->insertItem(chantext);
00091 m_chanids << QString::number(channels[i].chanid);
00092 }
00093
00094 hbox->addWidget(m_channel);
00095
00096
00097 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00098
00099 message = tr("Date or day of the week") + ": ";
00100 label = new QLabel(message, this);
00101 label->setBackgroundOrigin(WindowOrigin);
00102 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00103 hbox->addWidget(label);
00104
00105 m_startdate = new MythComboBox(false, this, "startdate");
00106
00107 for(int m_index = 0; m_index <= 60; m_index++)
00108 {
00109 QString dinfo = m_nowDateTime.addDays(m_index).toString(dateformat);
00110 if (m_nowDateTime.addDays(m_index).date().dayOfWeek() < 6)
00111 dinfo += QString(" (%1)").arg(tr("5 weekdays if daily"));
00112 else
00113 dinfo += QString(" (%1)").arg(tr("7 days per week if daily"));
00114 m_startdate->insertItem(dinfo);
00115 if (m_nowDateTime.addDays(m_index).toString("MMdd") ==
00116 m_startDateTime.toString("MMdd"))
00117 m_startdate->setCurrentItem(m_startdate->count() - 1);
00118 }
00119 hbox->addWidget(m_startdate);
00120
00121 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00122
00123 QTime thisTime = m_nowDateTime.time();
00124 thisTime = thisTime.addSecs((30 - thisTime.minute() % 30) * 60);
00125
00126 if (thisTime < QTime::QTime(0,30))
00127 m_startdate->setCurrentItem(m_startdate->currentItem() + 1);
00128
00129 message = tr("Time:");
00130 label = new QLabel(message, this);
00131 label->setBackgroundOrigin(WindowOrigin);
00132 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00133 hbox->addWidget(label);
00134
00135 QString hr_format = "h";
00136 if (timeformat.contains("hh"))
00137 hr_format = "hh";
00138 if (timeformat.contains("AP"))
00139 hr_format += " AP";
00140 if (timeformat.contains("ap"))
00141 hr_format += " ap";
00142
00143 m_starthour = new MythComboBox(false, this, "starthour");
00144
00145 for(int m_index = -1; m_index <= 24; m_index++)
00146 {
00147 m_starthour->insertItem(QTime::QTime((m_index + 24) % 24, 0)
00148 .toString(hr_format));
00149 if (thisTime.hour() == m_index)
00150 m_starthour->setCurrentItem(m_starthour->count() - 1);
00151 }
00152 hbox->addWidget(m_starthour);
00153
00154 m_startminute = new MythComboBox(false, this, "startminute");
00155
00156 for(int m_index = -5; m_index <= 60; m_index += 5)
00157 {
00158 m_startminute->insertItem(QTime::QTime(0, (m_index + 60) % 60)
00159 .toString(":mm"));
00160 if (m_index == thisTime.minute())
00161 m_startminute->setCurrentItem(m_startminute->count() - 1);
00162 }
00163 hbox->addWidget(m_startminute);
00164 dateChanged();
00165
00166
00167 message = tr("Duration:");
00168 label = new QLabel(message, this);
00169 label->setBackgroundOrigin(WindowOrigin);
00170 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00171 hbox->addWidget(label);
00172
00173 m_duration = new MythComboBox(false, this, "duration");
00174
00175 m_duration->insertItem(QString(" 1 %2").arg(tr("minute")));
00176 for(int m_index = 5; m_index <= 360; m_index += 5)
00177 {
00178 m_duration->insertItem(QString(" %1 %2").arg(m_index)
00179 .arg(tr("minutes")));
00180 }
00181 m_duration->setCurrentItem(12);
00182 hbox->addWidget(m_duration);
00183
00184
00185 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00186
00187 message = tr("Title (optional):");
00188 label = new QLabel(message, this);
00189 label->setBackgroundOrigin(WindowOrigin);
00190 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00191 hbox->addWidget(label);
00192
00193 m_title = new MythRemoteLineEdit( this, "title" );
00194 m_title->setBackgroundOrigin(WindowOrigin);
00195 hbox->addWidget(m_title);
00196
00197
00198 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00199
00200 m_recordButton = new MythPushButton( this, "Program" );
00201 m_recordButton->setBackgroundOrigin(WindowOrigin);
00202 m_recordButton->setText( tr( "Set Recording Options" ) );
00203 m_recordButton->setEnabled(true);
00204
00205 hbox->addWidget(m_recordButton);
00206
00207
00208 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00209
00210 m_cancelButton = new MythPushButton( this, "Program" );
00211 m_cancelButton->setBackgroundOrigin(WindowOrigin);
00212 m_cancelButton->setText( tr( "Cancel" ) );
00213 m_cancelButton->setEnabled(true);
00214
00215 hbox->addWidget(m_cancelButton);
00216
00217
00218
00219 connect(this, SIGNAL(dismissWindow()), this, SLOT(accept()));
00220
00221
00222 connect(m_startdate, SIGNAL(activated(int)), this, SLOT(dateChanged(void)));
00223 connect(m_startdate, SIGNAL(highlighted(int)), this, SLOT(dateChanged(void)));
00224 connect(m_starthour, SIGNAL(activated(int)), this, SLOT(hourChanged(void)));
00225 connect(m_starthour, SIGNAL(highlighted(int)), this, SLOT(hourChanged(void)));
00226 connect(m_startminute, SIGNAL(activated(int)), this, SLOT(minuteChanged(void)));
00227 connect(m_startminute, SIGNAL(highlighted(int)), this, SLOT(minuteChanged(void)));
00228 connect(m_recordButton, SIGNAL(clicked()), this, SLOT(recordClicked()));
00229 connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
00230
00231 m_channel->setFocus();
00232
00233 gContext->addListener(this);
00234 gContext->addCurrentLocation("ManualSchedule");
00235 }
00236
00237 ManualSchedule::~ManualSchedule(void)
00238 {
00239 gContext->removeListener(this);
00240 gContext->removeCurrentLocation();
00241 }
00242
00243 void ManualSchedule::minuteChanged(void)
00244 {
00245 if (m_startminute->currentItem() == 0 ) {
00246 m_startminute->setCurrentItem(12);
00247 m_starthour->setCurrentItem(m_starthour->currentItem() - 1);
00248 }
00249 if (m_startminute->currentItem() == 13 ) {
00250 m_starthour->setCurrentItem(m_starthour->currentItem() + 1);
00251 m_startminute->setCurrentItem(1);
00252 }
00253 dateChanged();
00254 }
00255
00256 void ManualSchedule::hourChanged(void)
00257 {
00258 if (m_starthour->currentItem() == 0 ) {
00259 m_starthour->setCurrentItem(24);
00260 m_startdate->setCurrentItem(m_startdate->currentItem() - 1);
00261 }
00262 if (m_starthour->currentItem() == 25 ) {
00263 m_startdate->setCurrentItem(m_startdate->currentItem() + 1);
00264 m_starthour->setCurrentItem(1);
00265 }
00266 dateChanged();
00267 }
00268
00269 void ManualSchedule::dateChanged(void)
00270 {
00271 daysahead = m_startdate->currentItem();
00272 m_startDateTime.setDate(m_nowDateTime.addDays(daysahead).date());
00273
00274 int hr = (m_starthour->currentItem() - 1) % 24;
00275 int min = (m_startminute->currentItem() - 1) * 5 % 60;
00276 m_startDateTime.setTime(QTime(hr, min));
00277
00278 VERBOSE(VB_SCHEDULE, QString("Start Date Time: %1")
00279 .arg(m_startDateTime.toString()));
00280
00281 if (m_startDateTime < m_nowDateTime)
00282 {
00283 QTime thisTime = m_nowDateTime.time();
00284 m_starthour->setCurrentItem(thisTime.hour() + 1);
00285 m_startDateTime.setDate(m_nowDateTime.date());
00286 m_startDateTime.setTime(QTime(hr, min));
00287 }
00288 }
00289
00290 void ManualSchedule::recordClicked(void)
00291 {
00292 ProgramInfo p;
00293
00294 QString channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>");
00295 p.chanid = m_chanids[m_channel->currentItem()];
00296
00297 MSqlQuery query(MSqlQuery::InitCon());
00298 query.prepare("SELECT chanid, channum, callsign, name "
00299 "FROM channel WHERE chanid=:CHANID");
00300 query.bindValue(":CHANID", p.chanid);
00301
00302 query.exec();
00303
00304 if (query.isActive() && query.size())
00305 {
00306 query.next();
00307 p.chanstr = query.value(1).toString();
00308 p.chansign = QString::fromUtf8(query.value(2).toString());
00309 p.channame = QString::fromUtf8(query.value(3).toString());
00310 }
00311
00312 int addsec = m_duration->currentItem() * 300;
00313
00314 if (!addsec)
00315 addsec = 60;
00316
00317 p.startts = m_startDateTime;
00318 p.endts = p.startts.addSecs(addsec);
00319
00320 if (m_title->text() > "")
00321 p.title = m_title->text();
00322 else
00323 p.title = p.ChannelText(channelFormat) + " - " +
00324 p.startts.toString(timeformat);
00325
00326 p.title += " (" + tr("Manual Record") + ")";
00327 p.description = QDeepCopy<QString>(p.title);
00328
00329 ScheduledRecording *record = new ScheduledRecording();
00330 record->loadByProgram(&p);
00331 record->setSearchType(kManualSearch);
00332 record->exec();
00333
00334 if (record->getRecordID())
00335 accept();
00336 else
00337 m_recordButton->setFocus();
00338
00339 record->deleteLater();
00340 }
00341
00342 void ManualSchedule::cancelClicked(void)
00343 {
00344 accept();
00345 }