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
00019 #include <unistd.h>
00020
00021 #include <iostream>
00022 using namespace std;
00023
00024 #include "manualbox.h"
00025 #include "tv.h"
00026 #include "NuppelVideoPlayer.h"
00027 #include "yuv2rgb.h"
00028
00029 #include "mythcontext.h"
00030 #include "dialogbox.h"
00031 #include "programinfo.h"
00032 #include "remoteutil.h"
00033
00034 ManualBox::ManualBox(MythMainWindow *parent, const char *name)
00035 : MythDialog(parent, name)
00036 {
00037 m_tv = NULL;
00038 tvstarting = false;
00039
00040 QVBoxLayout *vbox = new QVBoxLayout(this, (int)(15 * wmult));
00041
00042
00043 QString message = tr("Manual Recording");
00044 QLabel *label = new QLabel(message, this);
00045 label->setBackgroundOrigin(WindowOrigin);
00046 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00047 vbox->addWidget(label);
00048
00049
00050 m_boxframe = new QHBox(this);
00051 m_boxframe->setFrameStyle(QFrame::Panel | QFrame::Sunken);
00052 m_boxframe->setLineWidth(2);
00053 m_boxframe->setBackgroundOrigin(WindowOrigin);
00054 m_boxframe->setFocusPolicy(QWidget::StrongFocus);
00055 m_boxframe->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00056 m_boxframe->setMargin((int)(5 * wmult));
00057 m_boxframe->installEventFilter(this);
00058
00059 QPixmap temp((int)(320 * wmult), (int)(240 * hmult));
00060 temp.fill(black);
00061
00062 m_pixlabel = new QLabel(m_boxframe);
00063 m_pixlabel->setBackgroundOrigin(WindowOrigin);
00064 m_pixlabel->setPixmap(temp);
00065 m_pixlabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00066
00067 QHBoxLayout *hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00068 hbox->addWidget(m_boxframe);
00069
00070
00071
00072
00073 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00074
00075 message = tr("Title:");
00076 label = new QLabel(message, this);
00077 label->setBackgroundOrigin(WindowOrigin);
00078 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00079 hbox->addWidget(label);
00080
00081 m_title = new MythLineEdit( this, "title" );
00082 m_title->setBackgroundOrigin(WindowOrigin);
00083 hbox->addWidget(m_title);
00084
00085 m_title->setFocus();
00086
00087
00088 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00089
00090 message = tr("Subtitle:");
00091 label = new QLabel(message, this);
00092 label->setBackgroundOrigin(WindowOrigin);
00093 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00094 hbox->addWidget(label);
00095
00096 m_subtitle = new MythLineEdit( this, "subtitle" );
00097 m_subtitle->setBackgroundOrigin(WindowOrigin);
00098 hbox->addWidget(m_subtitle);
00099
00100
00101
00102 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00103
00104 message = tr("Duration:");
00105 label = new QLabel(message, this);
00106 label->setBackgroundOrigin(WindowOrigin);
00107 label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00108 hbox->addWidget(label);
00109
00110 m_duration = new MythSpinBox( this, "duration" );
00111 m_duration->setMinValue(1);
00112 m_duration->setMaxValue(300);
00113 m_duration->setValue(60);
00114 m_duration->setBackgroundOrigin(WindowOrigin);
00115 hbox->addWidget(m_duration);
00116
00117 message = tr("minutes");
00118 label = new QLabel(message, this);
00119 label->setBackgroundOrigin(WindowOrigin);
00120 hbox->addWidget(label);
00121
00122
00123
00124 hbox = new QHBoxLayout(vbox, (int)(10 * wmult));
00125
00126 m_startButton = new MythPushButton( this, "start" );
00127 m_startButton->setBackgroundOrigin(WindowOrigin);
00128 m_startButton->setText( tr( "Start" ) );
00129 m_startButton->setEnabled(false);
00130
00131 m_stopButton = new MythPushButton( this, "stop" );
00132 m_stopButton->setBackgroundOrigin(WindowOrigin);
00133 m_stopButton->setText( tr( "Stop" ) );
00134
00135 hbox->addWidget(m_startButton);
00136 hbox->addWidget(m_stopButton);
00137
00138
00139 m_timer = new QTimer(this);
00140 m_refreshTimer = new QTimer(this);
00141
00142 connect(this, SIGNAL(dismissWindow()), this, SLOT(accept()));
00143
00144 connect(m_title, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
00145 connect(m_startButton, SIGNAL(clicked()), this, SLOT(startClicked()));
00146 connect(m_stopButton, SIGNAL(clicked()), this, SLOT(stopClicked()));
00147 connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
00148 connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refreshTimeout()));
00149 m_timer->start(300);
00150
00151 gContext->addListener(this);
00152 gContext->addCurrentLocation("ManualBox");
00153 }
00154
00155 ManualBox::~ManualBox(void)
00156 {
00157 gContext->removeListener(this);
00158 gContext->removeCurrentLocation();
00159 killPlayer();
00160 }
00161
00162 bool ManualBox::eventFilter(QObject *, QEvent *e)
00163 {
00164 if (e->type() == QEvent::FocusIn)
00165 {
00166 m_boxframe->setFrameStyle(QFrame::Panel | QFrame::Raised);
00167 }
00168 else if (e->type() == QEvent::FocusOut)
00169 {
00170 m_boxframe->setFrameStyle(QFrame::Panel | QFrame::Sunken);
00171 }
00172 else if (e->type() == QEvent::KeyPress)
00173 {
00174 if (NULL != m_tv)
00175 {
00176 QKeyEvent* k = (QKeyEvent*)e;
00177 qApp->unlock();
00178 m_tv->ProcessKeypress(k);
00179 qApp->lock();
00180 }
00181 }
00182
00183 return false;
00184 }
00185
00186 void ManualBox::killPlayer(void)
00187 {
00188 m_timer->stop();
00189 while (m_timer->isActive())
00190 usleep(50);
00191
00192 if (NULL != m_tv)
00193 {
00194 m_tv->StopEmbeddingOutput();
00195 qApp->unlock();
00196 delete m_tv;
00197 qApp->lock();
00198 m_tv = NULL;
00199 }
00200 }
00201
00202 void ManualBox::startPlayer(void)
00203 {
00204 if (NULL == m_tv)
00205 {
00206 tvstarting = true;
00207
00208 m_tv = new TV();
00209 if (!m_tv->Init(false))
00210 {
00211 VERBOSE(VB_IMPORTANT, "Experienced fatal error initialzing "
00212 "TV class in ManualBox::startPlayer().");
00213 delete m_tv;
00214 m_tv = 0;
00215 tvstarting = false;
00216 return;
00217 }
00218
00219
00220 m_tv->EmbedOutput(m_pixlabel->winId(), 0, 0, (int)(320 * wmult),
00221 (int)(240 * hmult));
00222 if (m_tv->LiveTV(true))
00223 {
00224 qApp->unlock();
00225 while (m_tv->GetState() == kState_ChangingState)
00226 {
00227 usleep(50);
00228 qApp->processEvents();
00229 }
00230 qApp->lock();
00231 setActiveWindow();
00232 m_wasRecording = !m_tv->IsRecording();
00233 }
00234 else
00235 {
00236 qApp->unlock();
00237 delete m_tv;
00238 qApp->lock();
00239 m_tv = NULL;
00240 emit dismissWindow();
00241 }
00242
00243 tvstarting = false;
00244 }
00245 }
00246
00247 void ManualBox::timeout(void)
00248 {
00249 if (tvstarting)
00250 return;
00251
00252 startPlayer();
00253 if (NULL != m_tv)
00254 {
00255 if (m_wasRecording != m_tv->IsRecording())
00256 {
00257 if (m_tv->IsRecording())
00258 {
00259 m_startButton->setEnabled(false);
00260 m_stopButton->setEnabled(true);
00261 m_title->setEnabled(false);
00262 m_subtitle->setEnabled(false);
00263 m_duration->setEnabled(false);
00264 m_stopButton->setFocus();
00265 m_refreshTimer->stop();
00266 m_wasRecording = true;
00267 }
00268 else
00269 {
00270 m_stopButton->setEnabled(false);
00271 m_title->setEnabled(true);
00272 m_subtitle->setEnabled(true);
00273 m_duration->setEnabled(true);
00274 m_startButton->setEnabled(!m_title->text().isEmpty());
00275 m_title->setFocus();
00276 m_refreshTimer->start(2000);
00277 m_wasRecording = false;
00278 }
00279 }
00280 }
00281 }
00282
00283 void ManualBox::refreshTimeout(void)
00284 {
00285 if (tvstarting)
00286 return;
00287
00288 if (NULL != m_tv)
00289 {
00290 #if 0
00291 QString dummy;
00292 QString title;
00293 QString subtitle;
00294
00295 m_tv->GetChannelInfo(NULL, title, subtitle, m_descString,
00296 m_categoryString, m_startString, dummy,
00297 dummy, dummy, dummy,
00298 m_chanidString, dummy, dummy, dummy,
00299 dummy, dummy, dummy);
00300
00301 if (m_lastStarttime != m_startString || m_lastChanid != m_chanidString)
00302 {
00303
00304 m_title->setText(title);
00305 m_subtitle->setText(subtitle);
00306 m_startButton->setEnabled(!m_title->text().isEmpty());
00307 m_lastStarttime = m_startString;
00308 m_lastChanid = m_chanidString;
00309 }
00310 #endif
00311 }
00312 }
00313
00314 void ManualBox::textChanged(const QString &title)
00315 {
00316 m_startButton->setEnabled(!title.isEmpty());
00317 }
00318
00319 void ManualBox::stopClicked(void)
00320 {
00321 if (NULL != m_tv)
00322 {
00323 m_tv->FinishRecording();
00324 }
00325 }
00326
00327 void ManualBox::startClicked(void)
00328 {
00329 ProgramInfo progInfo;
00330
00331 m_startButton->setEnabled(false);
00332
00333 progInfo.title = m_title->text();
00334 progInfo.subtitle = m_subtitle->text();
00335 progInfo.description = m_descString;
00336 progInfo.category = m_categoryString;
00337 progInfo.chanid = m_chanidString;
00338
00339 QDateTime now = QDateTime::currentDateTime();
00340
00341 now = now.addSecs(-now.time().second());
00342 progInfo.startts = now;
00343 progInfo.endts = now.addSecs(m_duration->value() * 60);
00344
00345 progInfo.Save();
00346
00347 progInfo.ApplyRecordStateChange(kSingleRecord);
00348 }
00349