00001
00002 #include <cstdlib>
00003
00004
00005 #include <unistd.h>
00006
00007
00008 #include <qapplication.h>
00009
00010
00011 #include "mythcontext.h"
00012 #include "mythdbcon.h"
00013 #include "lcddevice.h"
00014 #include "tv.h"
00015 #include "programinfo.h"
00016 #include "uitypes.h"
00017 #include "compat.h"
00018
00019 #include "welcomedialog.h"
00020 #include "welcomesettings.h"
00021
00022 #define UPDATE_STATUS_INTERVAL 30000
00023 #define UPDATE_SCREEN_INTERVAL 15000
00024
00025
00026 WelcomeDialog::WelcomeDialog(MythMainWindow *parent,
00027 QString window_name,
00028 QString theme_filename,
00029 const char* name)
00030 :MythThemedDialog(parent, window_name, theme_filename, name)
00031 {
00032 LCD::SetupLCD();
00033
00034 if (class LCD *lcd = LCD::Get())
00035 lcd->switchToTime();
00036
00037 gContext->addListener(this);
00038
00039 m_installDir = gContext->GetInstallPrefix();
00040 m_preRollSeconds = gContext->GetNumSetting("RecordPreRoll");
00041 m_idleWaitForRecordingTime =
00042 gContext->GetNumSetting("idleWaitForRecordingTime", 15);
00043
00044 m_timeFormat = gContext->GetSetting("TimeFormat", "h:mm AP");
00045 m_dateFormat = gContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
00046 m_dateFormat.replace("\\n", "\n");
00047
00048
00049 m_bWillShutdown = (gContext->GetNumSetting("idleTimeoutSecs", 0) != 0);
00050 m_secondsToShutdown = -1;
00051
00052 wireUpTheme();
00053 assignFirstFocus();
00054
00055 m_updateStatusTimer = new QTimer(this);
00056 connect(m_updateStatusTimer, SIGNAL(timeout()), this,
00057 SLOT(updateStatus()));
00058 m_updateStatusTimer->start(UPDATE_STATUS_INTERVAL);
00059
00060 m_updateScreenTimer = new QTimer(this);
00061 connect(m_updateScreenTimer, SIGNAL(timeout()), this,
00062 SLOT(updateScreen()));
00063
00064 m_timeTimer = new QTimer(this);
00065 connect(m_timeTimer, SIGNAL(timeout()), this,
00066 SLOT(updateTime()));
00067 m_timeTimer->start(1000);
00068
00069 m_tunerList.setAutoDelete(true);
00070 m_scheduledList.setAutoDelete(true);
00071
00072 popup = NULL;
00073
00074 checkConnectionToServer();
00075 }
00076
00077 void WelcomeDialog::startFrontend(void)
00078 {
00079 QString startFECmd = gContext->GetSetting("MythWelcomeStartFECmd",
00080 m_installDir + "/bin/mythfrontend");
00081
00082 myth_system(startFECmd.ascii());
00083 updateAll();
00084 }
00085
00086 void WelcomeDialog::startFrontendClick(void)
00087 {
00088
00089 QTimer::singleShot(500, this, SLOT(startFrontend()));
00090 }
00091
00092 DialogCode WelcomeDialog::exec(void)
00093 {
00094
00095
00096 int state = system(m_installDir + "/bin/mythshutdown --startup");
00097
00098 if (WIFEXITED(state))
00099 state = WEXITSTATUS(state);
00100
00101 VERBOSE(VB_GENERAL, "mythshutdown --startup returned: " << state);
00102
00103 bool bAutoStartFrontend = gContext->GetNumSetting("AutoStartFrontend", 1);
00104
00105 if (state == 1 && bAutoStartFrontend)
00106 startFrontend();
00107
00108
00109 updateAll();
00110
00111 setResult(kDialogCodeRejected);
00112
00113 Show();
00114
00115 do
00116 {
00117 qApp->processEvents();
00118 usleep(250000);
00119 } while (!result());
00120
00121 return kDialogCodeAccepted;
00122 }
00123
00124 void WelcomeDialog::customEvent(QCustomEvent *e)
00125 {
00126 if ((MythEvent::Type)(e->type()) == MythEvent::MythEventMessage)
00127 {
00128 MythEvent *me = (MythEvent *) e;
00129
00130 if (me->Message().left(21) == "RECORDING_LIST_CHANGE")
00131 {
00132 VERBOSE(VB_GENERAL, "MythWelcome received a RECORDING_LIST_CHANGE event");
00133
00134 QMutexLocker lock(&m_RecListUpdateMuxtex);
00135
00136 if (pendingRecListUpdate())
00137 {
00138 VERBOSE(VB_GENERAL, " [deferred to pending handler]");
00139 }
00140 else
00141 {
00142
00143 QTimer::singleShot(500, this, SLOT(updateRecordingList()));
00144 setPendingRecListUpdate(true);
00145 }
00146 }
00147 else if (me->Message().left(15) == "SCHEDULE_CHANGE")
00148 {
00149 VERBOSE(VB_GENERAL, "MythWelcome received a SCHEDULE_CHANGE event");
00150
00151 QMutexLocker lock(&m_SchedUpdateMuxtex);
00152
00153 if (pendingSchedUpdate())
00154 {
00155 VERBOSE(VB_GENERAL, " [deferred to pending handler]");
00156 }
00157 else
00158 {
00159 QTimer::singleShot(500, this, SLOT(updateScheduledList()));
00160 setPendingSchedUpdate(true);
00161 }
00162 }
00163 else if (me->Message().left(18) == "SHUTDOWN_COUNTDOWN")
00164 {
00165
00166 QString secs = me->Message().mid(19);
00167 m_secondsToShutdown = secs.toInt();
00168 updateStatusMessage();
00169 updateScreen();
00170 }
00171 else if (me->Message().left(12) == "SHUTDOWN_NOW")
00172 {
00173 VERBOSE(VB_GENERAL, "MythWelcome received a SHUTDOWN_NOW event");
00174 if (gContext->IsFrontendOnly())
00175 {
00176
00177
00178 if (gContext->GetNumSetting("ShutdownWithMasterBE", 0) == 1)
00179 {
00180 VERBOSE(VB_GENERAL, "MythWelcome is shutting this computer down now");
00181 QString poweroff_cmd = gContext->GetSetting("MythShutdownPowerOff", "");
00182 if (poweroff_cmd != "")
00183 system(poweroff_cmd.ascii());
00184 }
00185 }
00186 }
00187 }
00188 }
00189
00190 void WelcomeDialog::keyPressEvent(QKeyEvent *e)
00191 {
00192 bool handled = false;
00193
00194 QStringList actions;
00195 gContext->GetMainWindow()->TranslateKeyPress("Welcome", e, actions);
00196
00197 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00198 {
00199 QString action = actions[i];
00200 handled = true;
00201
00202 if (action == "ESCAPE")
00203 {
00204 return;
00205 }
00206 else if (action == "MENU")
00207 {
00208 showPopup();
00209 }
00210 else if (action == "NEXTVIEW")
00211 {
00212 accept();
00213 }
00214 else if (action == "SELECT")
00215 {
00216 activateCurrent();
00217 }
00218 else if (action == "INFO")
00219 {
00220 MythWelcomeSettings settings;
00221 if (kDialogCodeAccepted == settings.exec())
00222 {
00223 RemoteSendMessage("CLEAR_SETTINGS_CACHE");
00224 updateStatus();
00225 updateScreen();
00226
00227 m_dateFormat = gContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
00228 m_dateFormat.replace("\\n", "\n");
00229 }
00230 }
00231 else if (action == "SHOWSETTINGS")
00232 {
00233 MythShutdownSettings settings;
00234 if (kDialogCodeAccepted == settings.exec())
00235 RemoteSendMessage("CLEAR_SETTINGS_CACHE");
00236 }
00237 else if (action == "0")
00238 {
00239 int statusCode = system(m_installDir + "/bin/mythshutdown --status 0");
00240 if (WIFEXITED(statusCode))
00241 statusCode = WEXITSTATUS(statusCode);
00242
00243
00244 if (statusCode & 16)
00245 system(m_installDir + "/bin/mythshutdown --unlock");
00246 else
00247 system(m_installDir + "/bin/mythshutdown --lock");
00248
00249 updateStatusMessage();
00250 updateScreen();
00251 }
00252 else if (action == "STARTXTERM")
00253 {
00254 QString cmd = gContext->GetSetting("MythShutdownXTermCmd", "");
00255 if (cmd != "")
00256 {
00257 system(cmd);
00258 }
00259 }
00260 else if (action == "STARTSETUP")
00261 {
00262 system(m_installDir + "/bin/mythtv-setup");
00263 }
00264 else
00265 handled = false;
00266 }
00267
00268 if (!handled)
00269 MythThemedDialog::keyPressEvent(e);
00270 }
00271
00272 UITextType* WelcomeDialog::getTextType(QString name)
00273 {
00274 UITextType* type = getUITextType(name);
00275
00276 if (!type)
00277 {
00278 cout << "ERROR: Failed to find '" << name << "' UI element in theme file\n"
00279 << "Bailing out!" << endl;
00280 exit(0);
00281 }
00282
00283 return type;
00284 }
00285
00286 void WelcomeDialog::wireUpTheme()
00287 {
00288 m_status_text = getTextType("status_text");
00289 m_recording_text = getTextType("recording_text");
00290 m_scheduled_text = getTextType("scheduled_text");
00291 m_time_text = getTextType("time_text");
00292 m_date_text = getTextType("date_text");
00293
00294 m_warning_text = getTextType("conflicts_text");
00295 m_warning_text->hide();
00296
00297 m_startfrontend_button = getUITextButtonType("startfrontend_button");
00298 if (m_startfrontend_button)
00299 {
00300 m_startfrontend_button->setText(tr("Start Frontend"));
00301 connect(m_startfrontend_button, SIGNAL(pushed()), this,
00302 SLOT(startFrontendClick()));
00303 }
00304 else
00305 {
00306 cout << "ERROR: Failed to find 'startfrontend_button' "
00307 << "UI element in theme file\n"
00308 << "Bailing out!" << endl;
00309 exit(0);
00310 }
00311
00312 buildFocusList();
00313 }
00314
00315 void WelcomeDialog::closeDialog()
00316 {
00317 done(kDialogCodeAccepted);
00318 }
00319
00320 WelcomeDialog::~WelcomeDialog()
00321 {
00322 gContext->removeListener(this);
00323
00324 if (m_updateStatusTimer)
00325 delete m_updateStatusTimer;
00326
00327 if (m_updateScreenTimer)
00328 delete m_updateScreenTimer;
00329
00330 if (m_timeTimer)
00331 delete m_timeTimer;
00332 }
00333
00334 void WelcomeDialog::updateTime(void)
00335 {
00336 QString s = QTime::currentTime().toString(m_timeFormat);
00337
00338 if (s != m_time_text->GetText())
00339 m_time_text->SetText(s);
00340
00341 s = QDateTime::currentDateTime().toString(m_dateFormat);
00342
00343 if (s != m_date_text->GetText())
00344 m_date_text->SetText(s);
00345 }
00346
00347 void WelcomeDialog::updateStatus(void)
00348 {
00349 checkConnectionToServer();
00350
00351 updateStatusMessage();
00352 }
00353
00354 void WelcomeDialog::updateScreen(void)
00355 {
00356 QString status;
00357
00358 if (!gContext->IsConnectedToMaster())
00359 {
00360 m_recording_text->SetText(tr("Cannot connect to server!"));
00361 m_scheduled_text->SetText(tr("Cannot connect to server!"));
00362 m_warning_text->hide();
00363 }
00364 else
00365 {
00366
00367 if (m_isRecording)
00368 {
00369 if (m_screenTunerNo >= m_tunerList.count())
00370 m_screenTunerNo = 0;
00371
00372 TunerStatus *tuner = m_tunerList.at(m_screenTunerNo);
00373
00374 if (tuner->isRecording)
00375 {
00376 status = QObject::tr("Tuner %1 is recording:\n")
00377 .arg(tuner->id);
00378 status += QDeepCopy<QString>(tuner->channame);
00379 status += "\n" + QDeepCopy<QString>(tuner->title);
00380 if (!tuner->subtitle.isEmpty())
00381 status += "\n("+QDeepCopy<QString>(tuner->subtitle)+")";
00382 status += "\n" + tuner->startTime.toString(m_timeFormat) +
00383 " " + tr("to") + " " + tuner->endTime.toString(m_timeFormat);
00384 }
00385 else
00386 {
00387 status = QObject::tr("Tuner %1 is not recording")
00388 .arg(tuner->id);
00389 }
00390
00391 if (m_screenTunerNo < m_tunerList.count() - 1)
00392 m_screenTunerNo++;
00393 else
00394 m_screenTunerNo = 0;
00395 }
00396 else
00397 status = tr("There are no recordings currently taking place");
00398
00399 m_recording_text->SetText(status);
00400
00401
00402 if (m_scheduledList.count() > 0)
00403 {
00404 if (m_screenScheduledNo >= m_scheduledList.count())
00405 m_screenScheduledNo = 0;
00406
00407 ProgramDetail *prog = m_scheduledList.at(m_screenScheduledNo);
00408
00409
00410
00411 status = prog->channel + "\n";
00412 status += prog->title;
00413 if (prog->subtitle != "")
00414 status += "\n(" + prog->subtitle + ")";
00415
00416 QString dateFormat = gContext->GetSetting("DateFormat", "ddd dd MMM yyyy");
00417 status += "\n" + prog->startTime.toString(dateFormat + " (" + m_timeFormat) +
00418 " " + tr("to") + " " + prog->endTime.toString(m_timeFormat + ")");
00419
00420 if (m_screenScheduledNo < m_scheduledList.count() - 1)
00421 m_screenScheduledNo++;
00422 else
00423 m_screenScheduledNo = 0;
00424 }
00425 else
00426 status = tr("There are no scheduled recordings");
00427
00428 m_scheduled_text->SetText(status);
00429 }
00430
00431
00432 if (m_statusList.count() == 0)
00433 status = tr("Please Wait ...");
00434 else
00435 {
00436 if (m_statusListNo >= m_statusList.count())
00437 m_statusListNo = 0;
00438
00439 status = m_statusList[m_statusListNo];
00440 if (m_statusList.count() > 1)
00441 status += "...";
00442 m_status_text->SetText(status);
00443
00444 if (m_statusListNo < m_statusList.count() - 1)
00445 m_statusListNo++;
00446 else
00447 m_statusListNo = 0;
00448 }
00449
00450 m_updateScreenTimer->start(UPDATE_SCREEN_INTERVAL, true);
00451 }
00452
00453
00454 void WelcomeDialog::runMythFillDatabase()
00455 {
00456 QString command;
00457
00458 QString mfpath = gContext->GetSetting("MythFillDatabasePath",
00459 "mythfilldatabase");
00460 QString mfarg = gContext->GetSetting("MythFillDatabaseArgs", "");
00461 QString mflog = gContext->GetSetting("MythFillDatabaseLog",
00462 "/var/log/mythfilldatabase.log");
00463
00464 if (mflog == "")
00465 command = QString("%1 %2").arg(mfpath).arg(mfarg);
00466 else
00467 command = QString("%1 %2 >>%3 2>&1").arg(mfpath).arg(mfarg).arg(mflog);
00468
00469 command += "&";
00470
00471 VERBOSE(VB_GENERAL, "Grabbing EPG data using command:\n" << command);
00472
00473 myth_system(command.ascii());
00474 }
00475
00476 void WelcomeDialog::updateAll(void)
00477 {
00478 updateRecordingList();
00479 updateScheduledList();
00480 }
00481
00482 bool WelcomeDialog::updateRecordingList()
00483 {
00484 {
00485
00486
00487 QMutexLocker lock(&m_RecListUpdateMuxtex);
00488 setPendingRecListUpdate(false);
00489 }
00490
00491 m_tunerList.clear();
00492 m_isRecording = false;
00493 m_screenTunerNo = 0;
00494
00495 if (!gContext->IsConnectedToMaster())
00496 return false;
00497
00498 m_isRecording = RemoteGetRecordingStatus(&m_tunerList, true);
00499
00500 return true;
00501 }
00502
00503 bool WelcomeDialog::updateScheduledList()
00504 {
00505 {
00506
00507
00508 QMutexLocker lock(&m_SchedUpdateMuxtex);
00509 setPendingSchedUpdate(false);
00510 }
00511
00512 m_scheduledList.clear();
00513 m_screenScheduledNo = 0;
00514
00515 if (!gContext->IsConnectedToMaster())
00516 {
00517 updateStatusMessage();
00518 return false;
00519 }
00520
00521 m_nextRecordingStart = QDateTime();
00522
00523 ProgramList *progList = new ProgramList(true);
00524 ProgramInfo *progInfo;
00525
00526 if (progList->FromScheduler(m_hasConflicts))
00527 {
00528 if (progList->count() > 0)
00529 {
00530
00531 for (progInfo = progList->first(); progInfo; progInfo = progList->next())
00532 {
00533 if (progInfo->recstatus == rsWillRecord)
00534 {
00535 if (m_nextRecordingStart.isNull() ||
00536 m_nextRecordingStart > progInfo->recstartts)
00537 {
00538 m_nextRecordingStart = progInfo->recstartts;
00539 }
00540 }
00541 }
00542
00543
00544 for (progInfo = progList->first(); progInfo; progInfo = progList->next())
00545 {
00546 if (progInfo->recstatus == rsWillRecord)
00547 {
00548 if (progInfo->recstartts == m_nextRecordingStart)
00549 {
00550 ProgramDetail *prog = new ProgramDetail;
00551 prog->channel = progInfo->channame;
00552 prog->title = progInfo->title;
00553 prog->subtitle = progInfo->subtitle;
00554 prog->startTime = progInfo->recstartts;
00555 prog->endTime = progInfo->recendts;
00556 m_scheduledList.append(prog);
00557 }
00558 }
00559 }
00560 }
00561 }
00562
00563 delete progList;
00564
00565 updateStatus();
00566 updateScreen();
00567
00568 return true;
00569 }
00570
00571 void WelcomeDialog::updateStatusMessage(void)
00572 {
00573 m_statusList.clear();
00574
00575 QDateTime curtime = QDateTime::currentDateTime();
00576
00577 if (!m_isRecording && !m_nextRecordingStart.isNull() &&
00578 curtime.secsTo(m_nextRecordingStart) -
00579 m_preRollSeconds < m_idleWaitForRecordingTime * 60)
00580 {
00581 m_statusList.append(tr("MythTV is about to start recording."));
00582 }
00583
00584 if (m_isRecording)
00585 {
00586 m_statusList.append(tr("MythTV is busy recording."));
00587 }
00588
00589 int statusCode = system(m_installDir + "/bin/mythshutdown --status 0");
00590 if (WIFEXITED(statusCode))
00591 statusCode = WEXITSTATUS(statusCode);
00592
00593 if (statusCode & 1)
00594 m_statusList.append(tr("MythTV is busy transcoding."));
00595 if (statusCode & 2)
00596 m_statusList.append(tr("MythTV is busy flagging commercials."));
00597 if (statusCode & 4)
00598 m_statusList.append(tr("MythTV is busy grabbing EPG data."));
00599 if (statusCode & 16)
00600 m_statusList.append(tr("MythTV is locked by a user."));
00601 if (statusCode & 32)
00602 m_statusList.append(tr("MythTV has running or pending jobs."));
00603 if (statusCode & 64)
00604 m_statusList.append(tr("MythTV is in a daily wakeup/shutdown period."));
00605 if (statusCode & 128)
00606 m_statusList.append(tr("MythTV is about to start a wakeup/shutdown period."));
00607
00608 if (m_statusList.count() == 0)
00609 {
00610 if (m_bWillShutdown && m_secondsToShutdown != -1)
00611 m_statusList.append(tr("MythTV is idle and will shutdown in %1 seconds.")
00612 .arg(m_secondsToShutdown));
00613 else
00614 m_statusList.append(tr("MythTV is idle."));
00615 }
00616
00617 if (m_hasConflicts)
00618 m_warning_text->show();
00619 else
00620 m_warning_text->hide();
00621 }
00622
00623 bool WelcomeDialog::checkConnectionToServer(void)
00624 {
00625 m_updateStatusTimer->stop();
00626
00627 bool bRes = false;
00628
00629 if (gContext->IsConnectedToMaster())
00630 bRes = true;
00631 else
00632 {
00633 if (gContext->ConnectToMasterServer(false))
00634 {
00635 bRes = true;
00636 updateAll();
00637 }
00638 else
00639 updateScreen();
00640 }
00641
00642 if (bRes)
00643 m_updateStatusTimer->start(UPDATE_STATUS_INTERVAL);
00644 else
00645 m_updateStatusTimer->start(5000);
00646
00647 return bRes;
00648 }
00649
00650 void WelcomeDialog::showPopup(void)
00651 {
00652 if (popup)
00653 return;
00654
00655 popup = new MythPopupBox(gContext->GetMainWindow(), "Menu");
00656
00657 QButton *topButton;
00658 QLabel *label = popup->addLabel(tr("Menu"), MythPopupBox::Large, false);
00659 label->setAlignment(Qt::AlignCenter | Qt::WordBreak);
00660
00661 int statusCode = system(m_installDir + "/bin/mythshutdown --status 0");
00662 if (WIFEXITED(statusCode))
00663 statusCode = WEXITSTATUS(statusCode);
00664
00665 if (statusCode & 16)
00666 topButton = popup->addButton(tr("Unlock Shutdown"), this,
00667 SLOT(unlockShutdown()));
00668 else
00669 topButton = popup->addButton(tr("Lock Shutdown"), this,
00670 SLOT(lockShutdown()));
00671
00672 popup->addButton(tr("Run mythfilldatabase"), this,
00673 SLOT(runEPGGrabber()));
00674 popup->addButton(tr("Shutdown Now"), this,
00675 SLOT(shutdownNow()));
00676 popup->addButton(tr("Exit"), this,
00677 SLOT(closeDialog()));
00678 popup->addButton(tr("Cancel"), popup, SLOT(reject()));
00679
00680 popup->ShowPopup(this, SLOT(donePopup(int)));
00681
00682 topButton->setFocus();
00683 }
00684
00685 void WelcomeDialog::donePopup(int r)
00686 {
00687 if (MythDialog::Rejected == r)
00688 cancelPopup();
00689 }
00690
00691 void WelcomeDialog::cancelPopup(void)
00692 {
00693 if (!popup)
00694 return;
00695
00696 popup->hide();
00697 popup->deleteLater();
00698 popup = NULL;
00699 setActiveWindow();
00700 }
00701
00702 void WelcomeDialog::lockShutdown(void)
00703 {
00704 cancelPopup();
00705 system(m_installDir + "/bin/mythshutdown --lock");
00706 updateStatusMessage();
00707 updateScreen();
00708 }
00709
00710 void WelcomeDialog::unlockShutdown(void)
00711 {
00712 cancelPopup();
00713 system(m_installDir + "/bin/mythshutdown --unlock");
00714 updateStatusMessage();
00715 updateScreen();
00716 }
00717
00718 void WelcomeDialog::runEPGGrabber(void)
00719 {
00720 cancelPopup();
00721 runMythFillDatabase();
00722 sleep(1);
00723 updateStatusMessage();
00724 updateScreen();
00725 }
00726
00727 void WelcomeDialog::shutdownNow(void)
00728 {
00729 cancelPopup();
00730
00731
00732 if (gContext->IsFrontendOnly())
00733 {
00734 VERBOSE(VB_GENERAL, "MythWelcome is shutting this computer down now");
00735 QString poweroff_cmd = gContext->GetSetting("MythShutdownPowerOff", "");
00736 if (poweroff_cmd != "")
00737 system(poweroff_cmd.ascii());
00738 return;
00739 }
00740
00741
00742 if (m_isRecording)
00743 {
00744 MythPopupBox::showOkPopup(gContext->GetMainWindow(), "Cannot shutdown",
00745 tr("Cannot shutdown because MythTV is currently recording"));
00746 return;
00747 }
00748
00749 QDateTime curtime = QDateTime::currentDateTime();
00750
00751
00752 if (!m_nextRecordingStart.isNull() &&
00753 curtime.secsTo(m_nextRecordingStart) -
00754 m_preRollSeconds < m_idleWaitForRecordingTime * 60)
00755 {
00756 MythPopupBox::showOkPopup(gContext->GetMainWindow(), "Cannot shutdown",
00757 tr("Cannot shutdown because MythTV is about to start recording"));
00758 return;
00759 }
00760
00761
00762 int statusCode = system(m_installDir + "/bin/mythshutdown --status 0");
00763 if (WIFEXITED(statusCode))
00764 statusCode = WEXITSTATUS(statusCode);
00765
00766 if (statusCode & 128)
00767 {
00768 MythPopupBox::showOkPopup(gContext->GetMainWindow(), "Cannot shutdown",
00769 tr("Cannot shutdown because MythTV is about to start "
00770 "a wakeup/shutdown period."));
00771 return;
00772 }
00773
00774
00775 if (!m_nextRecordingStart.isNull())
00776 {
00777 QDateTime restarttime = m_nextRecordingStart.addSecs((-1) * m_preRollSeconds);
00778
00779 int add = gContext->GetNumSetting("StartupSecsBeforeRecording", 240);
00780 if (add)
00781 restarttime = restarttime.addSecs((-1) * add);
00782
00783 QString wakeup_timeformat = gContext->GetSetting("WakeupTimeFormat",
00784 "yyyy-MM-ddThh:mm");
00785 QString setwakeup_cmd = gContext->GetSetting("SetWakeuptimeCommand",
00786 "echo \'Wakeuptime would "
00787 "be $time if command "
00788 "set.\'");
00789
00790 if (wakeup_timeformat == "time_t")
00791 {
00792 QString time_ts;
00793 setwakeup_cmd.replace("$time",
00794 time_ts.setNum(restarttime.toTime_t()));
00795 }
00796 else
00797 setwakeup_cmd.replace("$time",
00798 restarttime.toString(wakeup_timeformat));
00799
00800 if (!setwakeup_cmd.isEmpty())
00801 system(setwakeup_cmd.ascii());
00802 }
00803
00804
00805 system("sudo " + m_installDir + "/bin/mythshutdown --shutdown");
00806 }
00807