| 1 | #include <qhbox.h> |
| 2 | #include <qvbox.h> |
| 3 | |
| 4 | #include "playbackbox.h" |
| 5 | #include "dvdwizardpage.h" |
| 6 | #include "dvdwizard.h" |
| 7 | |
| 8 | DVDWizardData::DVDWizardData() |
| 9 | { |
| 10 | recordings.clear(); |
| 11 | dvdtype = Autoplay; |
| 12 | } |
| 13 | |
| 14 | ProgramInfo *DVDWizardData::getProgramInfo(QString &filename) |
| 15 | { |
| 16 | /* iterate over all selected recordings */ |
| 17 | QValueVector<ProgramInfo>::iterator it; |
| 18 | for (it = recordings.begin(); it != recordings.end(); it++) |
| 19 | { |
| 20 | if ((*it).GetRecordFilename(gContext->GetFilePrefix()) == filename) |
| 21 | return &(*it); |
| 22 | } |
| 23 | |
| 24 | return NULL; |
| 25 | } |
| 26 | |
| 27 | DVDWizardPage::DVDWizardPage(DVDWizardData *data, QWidget * parent, |
| 28 | const char * name) : QGroupBox(parent, name) |
| 29 | { |
| 30 | setHeading(QObject::tr("DVD Authoring Wizard")); |
| 31 | setBackgroundOrigin(QWidget::WindowOrigin); |
| 32 | |
| 33 | float wmult = 0, hmult = 0; |
| 34 | gContext->GetScreenSettings(wmult, hmult); |
| 35 | |
| 36 | new QVBoxLayout(this, (int)(10 * hmult)); |
| 37 | |
| 38 | m_data = data; |
| 39 | |
| 40 | next_page = NULL; |
| 41 | } |
| 42 | |
| 43 | DVDWizardPage::~DVDWizardPage() |
| 44 | { |
| 45 | if (next_page) delete next_page; |
| 46 | } |
| 47 | |
| 48 | QString DVDWizardPage::heading() |
| 49 | { |
| 50 | return m_heading; |
| 51 | } |
| 52 | |
| 53 | void DVDWizardPage::setHeading(const QString &h) |
| 54 | { |
| 55 | m_heading = h; |
| 56 | } |
| 57 | |
| 58 | DVDWizardPage *DVDWizardPage::nextPage() |
| 59 | { |
| 60 | if (modified() || !next_page) |
| 61 | { |
| 62 | if (next_page) delete next_page; |
| 63 | next_page = generateNextPage(); |
| 64 | } |
| 65 | |
| 66 | return next_page; |
| 67 | } |
| 68 | |
| 69 | DVDWizardPageIntro::DVDWizardPageIntro(DVDWizardData *data) |
| 70 | : DVDWizardPage(data, NULL, "intro") |
| 71 | { |
| 72 | MythLabel *intro = new MythLabel(QObject::tr("This wizard will walk you " |
| 73 | "through the steps of creating a DVD from " |
| 74 | "recordings. The recordings must be in a " |
| 75 | "DVD compliant MPEG2 format with NAV " |
| 76 | "packets. The MPEG2 profile of the " |
| 77 | "mythtranscode program generates compliant " |
| 78 | "files."), this); |
| 79 | layout()->add(intro); |
| 80 | |
| 81 | if (gContext->GetSetting("DVDWizardDir").isEmpty()) |
| 82 | { |
| 83 | MythLabel *warn = new MythLabel(QObject::tr("WARNING: You have not set " |
| 84 | "the scratch directory for creating " |
| 85 | "DVDs. Go to Setup->General->DVD Wizard " |
| 86 | "and set the directory. If you continue " |
| 87 | "the files and directories (dvd_dir, " |
| 88 | "dvd.xml, dvd.iso will be created and " |
| 89 | "subsequently deleted in the current " |
| 90 | "working directory. This may " |
| 91 | "inadvertently result in data loss."), |
| 92 | this); |
| 93 | layout()->add(warn); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | DVDWizardPageSelectRecordings::DVDWizardPageSelectRecordings(DVDWizardData *data) |
| 98 | : DVDWizardPage(data, NULL, "selrec") |
| 99 | { |
| 100 | setHeading(QObject::tr("Select Recordings")); |
| 101 | MythLabel *intro = new MythLabel(QObject::tr("Select all the recordings " |
| 102 | "that you want on the DVD. The indicators " |
| 103 | "at the bottom of the screen show an " |
| 104 | "estimate of the amount of space used on " |
| 105 | "the DVD. The selected recordings should " |
| 106 | "be in DVD compliant MPEG2 format."), this); |
| 107 | layout()->add(intro); |
| 108 | |
| 109 | QHBox *hbox = new QHBox(this); |
| 110 | hbox->setSpacing(layout()->spacing()); |
| 111 | hbox->setBackgroundOrigin(QWidget::WindowOrigin); |
| 112 | |
| 113 | rec = new MythListBox(hbox); |
| 114 | rec->setFocusPolicy(QWidget::NoFocus); |
| 115 | rec->setBackgroundOrigin(QWidget::WindowOrigin); |
| 116 | rec->setHelpText(QObject::tr("Select a recording to remove from the list.")); |
| 117 | |
| 118 | QVBox *vbox = new QVBox(hbox); |
| 119 | vbox->setBackgroundOrigin(QWidget::WindowOrigin); |
| 120 | |
| 121 | add = new MythPushButton(QObject::tr("Add"), vbox); |
| 122 | add->setBackgroundOrigin(QWidget::WindowOrigin); |
| 123 | add->setHelpText(QObject::tr("Add a recording to the list.")); |
| 124 | remove = new MythPushButton(QObject::tr("Remove"), vbox); |
| 125 | remove->setBackgroundOrigin(QWidget::WindowOrigin); |
| 126 | remove->setHelpText(QObject::tr("Remove a recording from the list.")); |
| 127 | |
| 128 | layout()->add(hbox); |
| 129 | |
| 130 | connect(rec, SIGNAL(changeHelpText(QString)), this, SIGNAL(changeHelpText(QString))); |
| 131 | connect(add, SIGNAL(changeHelpText(QString)), this, SIGNAL(changeHelpText(QString))); |
| 132 | connect(remove, SIGNAL(changeHelpText(QString)), this, SIGNAL(changeHelpText(QString))); |
| 133 | |
| 134 | connect(add, SIGNAL(clicked()), this, SLOT(addRecording())); |
| 135 | connect(remove, SIGNAL(clicked()), this, SLOT(removeRecording())); |
| 136 | rec->installEventFilter(this); |
| 137 | |
| 138 | dvdSize = 0; |
| 139 | sldvd = new MythLabel("", this); |
| 140 | layout()->add(sldvd); |
| 141 | dldvd = new MythLabel("", this); |
| 142 | layout()->add(dldvd); |
| 143 | adjustSize(0); |
| 144 | } |
| 145 | |
| 146 | DVDWizardPageSelectRecordings::~DVDWizardPageSelectRecordings() |
| 147 | { |
| 148 | rec->removeEventFilter(this); |
| 149 | } |
| 150 | |
| 151 | void DVDWizardPageSelectRecordings::entered() |
| 152 | { |
| 153 | if (m_data->recordings.count() == 0) |
| 154 | { |
| 155 | MythWizard *w = dynamic_cast<MythWizard *>(parent()->parent()); |
| 156 | if (w) |
| 157 | w->setNextEnabled(this, false); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void DVDWizardPageSelectRecordings::adjustSize(long long delta) |
| 162 | { |
| 163 | dvdSize += delta; |
| 164 | |
| 165 | sldvd->setText(QObject::tr("%1 of 4700MB (%2%) used on Single Layer disc") |
| 166 | .arg(dvdSize/(1024*1024)).arg(dvdSize/47000000LL)); |
| 167 | dldvd->setText(QObject::tr("%1 of 9400MB (%2%) used on Dual Layer disc") |
| 168 | .arg(dvdSize/(1024*1024)).arg(dvdSize/94000000LL)); |
| 169 | } |
| 170 | |
| 171 | void DVDWizardPageSelectRecordings::addRecording() |
| 172 | { |
| 173 | PlaybackBox pbb(PlaybackBox::Select, gContext->GetMainWindow(), |
| 174 | "tvplayselect"); |
| 175 | |
| 176 | if (pbb.exec() == QDialog::Accepted) |
| 177 | { |
| 178 | adjustSize(pbb.getSelected().filesize); |
| 179 | m_data->recordings.append(pbb.getSelected()); |
| 180 | rec->insertItem(m_data->recordings.last().title + " " + |
| 181 | m_data->recordings.last().subtitle); |
| 182 | dataChanged = true; |
| 183 | |
| 184 | MythWizard *w = dynamic_cast<MythWizard *>(parent()->parent()); |
| 185 | if (w) |
| 186 | w->setNextEnabled(this, true); |
| 187 | } |
| 188 | /* this doesn't seem to work */ |
| 189 | add->setFocus(); |
| 190 | } |
| 191 | |
| 192 | void DVDWizardPageSelectRecordings::removeRecording() |
| 193 | { |
| 194 | rec->setFocusPolicy(QWidget::WheelFocus); |
| 195 | rec->setFocus(); |
| 196 | } |
| 197 | |
| 198 | bool DVDWizardPageSelectRecordings::eventFilter(QObject *obj, QEvent *e) |
| 199 | { |
| 200 | bool handled = false; |
| 201 | QStringList actions; |
| 202 | if ((e->type() == QEvent::KeyPress) && (obj == rec)) |
| 203 | { |
| 204 | if (gContext->GetMainWindow()->TranslateKeyPress("qt", (QKeyEvent *)e, actions)) |
| 205 | { |
| 206 | for (unsigned int i = 0; i < actions.size() && !handled; i++) |
| 207 | { |
| 208 | QString action = actions[i]; |
| 209 | handled = true; |
| 210 | |
| 211 | if (action == "SELECT") |
| 212 | { |
| 213 | adjustSize(-m_data->recordings[rec->currentItem()].filesize); |
| 214 | m_data->recordings.erase(m_data->recordings.begin() + rec->currentItem()); |
| 215 | rec->removeItem(rec->currentItem()); |
| 216 | rec->setFocusPolicy(QWidget::NoFocus); |
| 217 | remove->setFocus(); |
| 218 | dataChanged = true; |
| 219 | |
| 220 | if (m_data->recordings.count() == 0) |
| 221 | { |
| 222 | MythWizard *w = dynamic_cast<MythWizard *>(parent()->parent()); |
| 223 | if (w) |
| 224 | w->setNextEnabled(this, false); |
| 225 | } |
| 226 | } |
| 227 | else if (action == "ESCAPE") |
| 228 | { |
| 229 | rec->setFocusPolicy(QWidget::NoFocus); |
| 230 | remove->setFocus(); |
| 231 | } |
| 232 | else |
| 233 | handled = false; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | return handled; |
| 238 | } |
| 239 | |
| 240 | DVDWizardPageAutoPlayDVD::DVDWizardPageAutoPlayDVD(DVDWizardData *data) : DVDWizardPage(data, NULL, "autoplay") |
| 241 | { |
| 242 | setHeading(QObject::tr("Autoplay DVD")); |
| 243 | |
| 244 | MythLabel *text = new MythLabel(QObject::tr("Would you like to create an " |
| 245 | "autoplay DVD. Autoplay DVDs do not have " |
| 246 | "menus and will start to play automatically " "when inserted into the DVD Player. This " |
| 247 | "option is good for movies and discs which " |
| 248 | "will be used by children. If you selected " |
| 249 | "multiple recordings they will play back to " |
| 250 | "back."), this); |
| 251 | layout()->add(text); |
| 252 | |
| 253 | QHBox *hbox = new QHBox(this); |
| 254 | hbox->setBackgroundOrigin(QWidget::WindowOrigin); |
| 255 | hbox->setSpacing(layout()->spacing()); |
| 256 | |
| 257 | new MythLabel(QObject::tr("What type of DVD do you want to create?"), hbox); |
| 258 | dvd_type = new MythComboBox(false, hbox); |
| 259 | dvd_type->setBackgroundOrigin(QWidget::WindowOrigin); |
| 260 | dvd_type->insertItem(QObject::tr("Autoplay DVD")); |
| 261 | dvd_type->insertItem(QObject::tr("Menu based DVD")); |
| 262 | dvd_type->setHelpText(QObject::tr("Select the type of DVD to create.")); |
| 263 | layout()->add(hbox); |
| 264 | |
| 265 | connect(dvd_type, SIGNAL(changeHelpText(QString)), this, SIGNAL(changeHelpText(QString))); |
| 266 | } |
| 267 | |
| 268 | DVDWizardPage *DVDWizardPageAutoPlayDVD::generateNextPage() |
| 269 | { |
| 270 | m_data->dvdtype = (DVDWizardData::DVDType)dvd_type->currentItem(); |
| 271 | |
| 272 | if (m_data->dvdtype == DVDWizardData::Autoplay) // Autoplay DVD |
| 273 | { |
| 274 | return new DVDWizardPageGenerateXML(m_data); |
| 275 | } |
| 276 | else if (m_data->dvdtype == DVDWizardData::MenuBased) // Menu based DVD |
| 277 | { |
| 278 | return NULL; |
| 279 | } |
| 280 | else |
| 281 | return NULL; |
| 282 | } |
| 283 | |
| 284 | bool DVDWizardPageAutoPlayDVD::modified() |
| 285 | { |
| 286 | return (m_data->dvdtype != dvd_type->currentItem()); |
| 287 | } |
| 288 | |
| 289 | DVDWizardPageGenerateXML::DVDWizardPageGenerateXML(DVDWizardData *data) : DVDWizardPage(data, NULL, "generate xml") |
| 290 | { |
| 291 | generateXML(); |
| 292 | |
| 293 | MythLabel *text = new MythLabel(QObject::tr("The DVD structure has been " |
| 294 | "defined. Select next to generate the DVD " |
| 295 | "filesystem."), this); |
| 296 | layout()->add(text); |
| 297 | } |
| 298 | |
| 299 | void DVDWizardPageGenerateXML::generateXML() |
| 300 | { |
| 301 | QDomDocument doc; |
| 302 | QDomElement root = doc.createElement("dvdauthor"); |
| 303 | root.setAttribute("dest", "dvd_dir"); |
| 304 | doc.appendChild(root); |
| 305 | |
| 306 | if (m_data->dvdtype == DVDWizardData::Autoplay) |
| 307 | { |
| 308 | /* empty menu */ |
| 309 | root.appendChild(doc.createElement("vmgm")); |
| 310 | |
| 311 | QDomElement titleset = doc.createElement("titleset"); |
| 312 | root.appendChild(titleset); |
| 313 | |
| 314 | QDomElement titles = doc.createElement("titles"); |
| 315 | titleset.appendChild(titles); |
| 316 | |
| 317 | m_data->titlesetSize.resize(1, 0); |
| 318 | m_data->titlesetSize[0] = 0; |
| 319 | |
| 320 | /* iterate over all selected recordings */ |
| 321 | int titleCount = 1; |
| 322 | QValueVector<ProgramInfo>::iterator it = m_data->recordings.begin(); |
| 323 | while (it != m_data->recordings.end()) |
| 324 | { |
| 325 | QDomElement pgc = doc.createElement("pgc"); |
| 326 | titles.appendChild(pgc); |
| 327 | |
| 328 | QDomElement vob = doc.createElement("vob"); |
| 329 | vob.setAttribute("file", (*it).GetRecordFilename(gContext->GetFilePrefix()).ascii()); |
| 330 | pgc.appendChild(vob); |
| 331 | |
| 332 | m_data->titlesetSize[0] += (*it).filesize; |
| 333 | |
| 334 | it++; |
| 335 | titleCount++; |
| 336 | |
| 337 | /* add a jump to the next title */ |
| 338 | QDomElement post = doc.createElement("post"); |
| 339 | pgc.appendChild(post); |
| 340 | if (it != m_data->recordings.end()) |
| 341 | post.appendChild(doc.createTextNode("jump title " + QString::number(titleCount) + " chapter 1;")); |
| 342 | else |
| 343 | post.appendChild(doc.createTextNode("exit;")); |
| 344 | |
| 345 | } |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | cerr << "Not yet defined\n"; |
| 350 | } |
| 351 | |
| 352 | cout << doc.toString().ascii() << endl; |
| 353 | |
| 354 | /* Output XML file for dvdauthor */ |
| 355 | QFile file(gContext->GetSetting("DVDWizardDir").append("/dvd.xml")); |
| 356 | if (file.open(IO_WriteOnly)) |
| 357 | { |
| 358 | QTextStream stream(&file); |
| 359 | stream << doc.toString(); |
| 360 | file.close(); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | DVDWizardPageGenerateFS::DVDWizardPageGenerateFS(DVDWizardData *data) |
| 365 | : DVDWizardPage(data, NULL, "generate fs") |
| 366 | { |
| 367 | MythLabel *text = new MythLabel(QObject::tr("Generating the DVD filesystem."), this); |
| 368 | layout()->add(text); |
| 369 | |
| 370 | output = new MythListBox(this); |
| 371 | output->setFocusPolicy(QWidget::NoFocus); |
| 372 | output->setBackgroundOrigin(QWidget::WindowOrigin); |
| 373 | layout()->add(output); |
| 374 | |
| 375 | status = new MythLabel(QObject::tr("Executing dvdauthor..."), this); |
| 376 | layout()->add(status); |
| 377 | |
| 378 | task = new QProgressBar(100, this); |
| 379 | task->setBackgroundOrigin(QWidget::WindowOrigin); |
| 380 | layout()->add(task); |
| 381 | |
| 382 | QHBox *hbox = new QHBox(this); |
| 383 | hbox->setBackgroundOrigin(QWidget::WindowOrigin); |
| 384 | hbox->setSpacing(layout()->spacing()); |
| 385 | |
| 386 | text = new MythLabel(QObject::tr("Overall progress"), hbox); |
| 387 | overall = new QProgressBar(0, hbox); |
| 388 | overall->setBackgroundOrigin(QWidget::WindowOrigin); |
| 389 | layout()->add(hbox); |
| 390 | |
| 391 | p = NULL; |
| 392 | } |
| 393 | |
| 394 | DVDWizardPageGenerateFS::~DVDWizardPageGenerateFS() |
| 395 | { |
| 396 | if (p) |
| 397 | p->kill(); |
| 398 | } |
| 399 | |
| 400 | void DVDWizardPageGenerateFS::goingBack() |
| 401 | { |
| 402 | if (p) |
| 403 | { |
| 404 | if (p->isRunning()) |
| 405 | p->tryTerminate(); |
| 406 | } |
| 407 | task->reset(); |
| 408 | overall->reset(); |
| 409 | } |
| 410 | |
| 411 | void DVDWizardPageGenerateFS::entered() |
| 412 | { |
| 413 | if (p) |
| 414 | cerr << "This shouldn't be\n"; |
| 415 | |
| 416 | /* disable next button */ |
| 417 | MythWizard *w = dynamic_cast<MythWizard *>(parent()->parent()); |
| 418 | if (w) |
| 419 | w->setNextEnabled(this, false); |
| 420 | |
| 421 | /* clear list box */ |
| 422 | output->clear(); |
| 423 | |
| 424 | /* make sure that dvd_dir is not there */ |
| 425 | QString command = QString("rm -rf ") + gContext->GetSetting("DVDWizardDir") + QString("/dvd_dir"); |
| 426 | myth_system(command); |
| 427 | |
| 428 | /* calculate the estimated size of the DVD */ |
| 429 | /* iterate over all selected recordings */ |
| 430 | dvdSize = 0; |
| 431 | QValueVector<long long>::iterator it; |
| 432 | for (it = m_data->titlesetSize.begin(); it != m_data->titlesetSize.end(); it++) |
| 433 | { |
| 434 | dvdSize += ((*it) / (1024*1024)); |
| 435 | } |
| 436 | |
| 437 | /* calculate the total progress */ |
| 438 | /* value is in megabytes of data processed */ |
| 439 | // currently counts |
| 440 | // - dvdauthor VOBU |
| 441 | // - dvdauthor fixing (NAV packets) |
| 442 | // - mkisofs |
| 443 | overall->setProgress(-1, 3*dvdSize); |
| 444 | |
| 445 | /* base Progress */ |
| 446 | /* overall progress = baseProgress + task progress */ |
| 447 | baseProgress = 0; |
| 448 | |
| 449 | /* start the dvdauthor process */ |
| 450 | p = new QProcess(QString("dvdauthor"), this); |
| 451 | p->setCommunication(QProcess::Stderr); |
| 452 | p->setWorkingDirectory(gContext->GetSetting("DVDWizardDir")); |
| 453 | p->addArgument("-x"); |
| 454 | p->addArgument("dvd.xml"); |
| 455 | |
| 456 | connect(p, SIGNAL(readyReadStderr()), this, SLOT(readProcDVDAuthor())); |
| 457 | connect(p, SIGNAL(processExited()), this, SLOT(procExited())); |
| 458 | |
| 459 | p->start(); |
| 460 | } |
| 461 | |
| 462 | void DVDWizardPageGenerateFS::readProcDVDAuthor() |
| 463 | { |
| 464 | int index; |
| 465 | |
| 466 | pOutput.append(p->readStderr()); |
| 467 | |
| 468 | QRegExp sep("[\r\n]"); |
| 469 | |
| 470 | index = pOutput.find(sep); |
| 471 | while (index != -1) |
| 472 | { |
| 473 | QString s = pOutput.left(index); |
| 474 | pOutput.remove(0, index+1); |
| 475 | |
| 476 | if (s.startsWith("STAT: ")) |
| 477 | { |
| 478 | s.remove(0, 6); |
| 479 | |
| 480 | if (s.startsWith("Picking VTS ")) |
| 481 | { |
| 482 | s.remove(0, 12); |
| 483 | currentTitleset = s.toInt(); |
| 484 | status->setText(QObject::tr("Generating Titleset %1") |
| 485 | .arg(currentTitleset)); |
| 486 | task->setProgress(0, 2*m_data->titlesetSize[currentTitleset-1] / (1024*1024)); |
| 487 | } |
| 488 | /* else if (s.startsWith("Processing ")) |
| 489 | { |
| 490 | }*/ |
| 491 | else if (s.startsWith("VOBU ")) |
| 492 | { |
| 493 | int taskProgress = s.section(' ', 3, 3).remove("MB,").toInt(); |
| 494 | task->setProgress(taskProgress); |
| 495 | overall->setProgress(baseProgress + taskProgress); |
| 496 | } |
| 497 | else if (s.startsWith("fixing VOBU at ")) |
| 498 | { |
| 499 | int taskProgress = s.section(' ', 3, 3).remove("MB").toInt() + task->totalSteps()/2; |
| 500 | task->setProgress(taskProgress); |
| 501 | overall->setProgress(baseProgress + taskProgress); |
| 502 | } |
| 503 | else if (s.startsWith("fixed ")) |
| 504 | { |
| 505 | task->setProgress(task->totalSteps()); |
| 506 | baseProgress += task->totalSteps(); |
| 507 | overall->setProgress(baseProgress); |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | cerr << s.ascii() << endl; |
| 512 | output->insertItem(s); |
| 513 | } |
| 514 | } |
| 515 | else if (s.startsWith("ERR: ")) |
| 516 | { |
| 517 | s.remove(0, 5); |
| 518 | status->setText(s); |
| 519 | } |
| 520 | |
| 521 | index = pOutput.find(sep); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | void DVDWizardPageGenerateFS::readProcMkisofs() |
| 526 | { |
| 527 | while (p->canReadLineStderr()) |
| 528 | { |
| 529 | QString s = p->readLineStderr(); |
| 530 | |
| 531 | QRegExp rxp("\\d{0,1}\\d{0,1}\\d\\.\\d\\d%"); |
| 532 | if (s.contains(rxp)) |
| 533 | { |
| 534 | s = s.section(' ', 1, 1); |
| 535 | |
| 536 | if (s.endsWith("%")) |
| 537 | { |
| 538 | float percent = s.left(s.length()-1).toFloat(); |
| 539 | int taskProgress = (int)(percent * dvdSize / 100); |
| 540 | task->setProgress(taskProgress); |
| 541 | overall->setProgress(baseProgress + taskProgress); |
| 542 | } |
| 543 | } |
| 544 | else if (s.contains("extents written")) |
| 545 | { |
| 546 | task->setProgress(task->totalSteps()); |
| 547 | baseProgress += task->totalSteps(); |
| 548 | overall->setProgress(baseProgress); |
| 549 | } |
| 550 | else |
| 551 | { |
| 552 | cerr << "Got line \"" << s.ascii() << '"' << endl; |
| 553 | output->insertItem(s); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void DVDWizardPageGenerateFS::procExited() |
| 559 | { |
| 560 | if (p->normalExit()) |
| 561 | { |
| 562 | QString progname = p->arguments()[0]; |
| 563 | |
| 564 | if (progname == "dvdauthor") |
| 565 | { |
| 566 | if (p->exitStatus() == 0) |
| 567 | { |
| 568 | /* dvdauthor finished, start mkisofs */ |
| 569 | |
| 570 | p->deleteLater(); |
| 571 | |
| 572 | p = new QProcess(QString("mkisofs"), this); |
| 573 | p->setCommunication(QProcess::Stderr); |
| 574 | p->setWorkingDirectory(gContext->GetSetting("DVDWizardDir")); |
| 575 | p->addArgument("-dvd-video"); |
| 576 | p->addArgument("-o"); |
| 577 | p->addArgument("dvd.iso"); |
| 578 | p->addArgument("dvd_dir"); |
| 579 | |
| 580 | connect(p, SIGNAL(readyReadStderr()), this, SLOT(readProcMkisofs())); |
| 581 | connect(p, SIGNAL(processExited()), this, SLOT(procExited())); |
| 582 | |
| 583 | p->start(); |
| 584 | |
| 585 | status->setText(QObject::tr("Generating iso image...")); |
| 586 | task->setProgress(0, dvdSize); |
| 587 | } |
| 588 | else |
| 589 | { |
| 590 | /* dvdauthor failed */ |
| 591 | cerr << "dvdauthor exited with " << p->exitStatus() << endl; |
| 592 | |
| 593 | p->deleteLater(); |
| 594 | p = NULL; |
| 595 | } |
| 596 | } |
| 597 | else if (progname == "mkisofs") |
| 598 | { |
| 599 | if (p->exitStatus() == 0) |
| 600 | { |
| 601 | //readProcMkisofs(); |
| 602 | task->reset(); |
| 603 | status->setText(QObject::tr("DVD finished generating. Select 'Next' " |
| 604 | "to continue")); |
| 605 | |
| 606 | p->deleteLater(); |
| 607 | p = NULL; |
| 608 | |
| 609 | /* delete dvd_dir */ |
| 610 | QString command = QString("rm -rf ") + gContext->GetSetting("DVDWizardDir") + QString("/dvd_dir"); |
| 611 | myth_system(command); |
| 612 | |
| 613 | /* enable next button */ |
| 614 | MythWizard *w = dynamic_cast<MythWizard *>(parent()->parent()); |
| 615 | if (w) |
| 616 | { |
| 617 | w->setNextEnabled(this, true); |
| 618 | w->nextButton()->setFocus(); |
| 619 | } |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | /* mkisofs failed */ |
| 624 | cerr << "mkisofs exited with " << p->exitStatus() << endl; |
| 625 | |
| 626 | p->deleteLater(); |
| 627 | p = NULL; |
| 628 | } |
| 629 | } |
| 630 | else |
| 631 | { |
| 632 | cerr << "Program " << progname.ascii() << " exited normally.\n"; |
| 633 | |
| 634 | p->deleteLater(); |
| 635 | p = NULL; |
| 636 | } |
| 637 | } |
| 638 | else |
| 639 | { |
| 640 | status->setText(QObject::tr("Child process exit error, check stderr.")); |
| 641 | cerr << "Program: " << p->arguments().join(" ").ascii() << endl; |
| 642 | cerr << "Exit code: " << p->exitStatus() << endl; |
| 643 | |
| 644 | p->deleteLater(); |
| 645 | p = NULL; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | DVDWizardPageBurnDVD::DVDWizardPageBurnDVD(DVDWizardData *data) : DVDWizardPage(data, NULL, "burn") |
| 650 | { |
| 651 | MythLabel *text = new MythLabel(QObject::tr("Burning the DVD."), this); |
| 652 | layout()->add(text); |
| 653 | |
| 654 | instructions = new MythLabel(QObject::tr("Ensure that a blank DVD is the " |
| 655 | "DVD burner and select 'Burn' to start burning " |
| 656 | "the image to disc."), this); |
| 657 | |
| 658 | layout()->add(instructions); |
| 659 | |
| 660 | progress = new QProgressBar(100, this); |
| 661 | progress->setBackgroundOrigin(QWidget::WindowOrigin); |
| 662 | layout()->add(progress); |
| 663 | |
| 664 | burn = new MythPushButton("Burn", this); |
| 665 | layout()->add(burn); |
| 666 | |
| 667 | connect(burn, SIGNAL(clicked()), this, SLOT(startBurn())); |
| 668 | |
| 669 | p = NULL; |
| 670 | } |
| 671 | |
| 672 | DVDWizardPageBurnDVD::~DVDWizardPageBurnDVD() |
| 673 | { |
| 674 | if (p) |
| 675 | p->kill(); |
| 676 | } |
| 677 | |
| 678 | void DVDWizardPageBurnDVD::entered() |
| 679 | { |
| 680 | progress->reset(); |
| 681 | } |
| 682 | |
| 683 | void DVDWizardPageBurnDVD::readProc() |
| 684 | { |
| 685 | while (p->canReadLineStderr()) |
| 686 | { |
| 687 | QString s = p->readLineStderr(); |
| 688 | |
| 689 | QRegExp rxp("\\d{0,1}\\d{0,1}\\d\\.\\d%"); |
| 690 | if (s.contains(rxp)) |
| 691 | { |
| 692 | s.remove(0, s.find(rxp)); |
| 693 | s = s.left(s.find('%')); |
| 694 | |
| 695 | progress->setProgress((int)s.toFloat()); |
| 696 | } |
| 697 | else |
| 698 | cerr << s.ascii() << endl; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | void DVDWizardPageBurnDVD::procExited() |
| 703 | { |
| 704 | if (p->normalExit() && (p->exitStatus() == 0)) |
| 705 | { |
| 706 | burn->setEnabled(true); |
| 707 | burn->setFocus(); |
| 708 | |
| 709 | instructions->setText(QObject::tr("Burn completed sucessfully. Insert a " |
| 710 | "new DVD and select 'Burn' to burn another, " |
| 711 | "otherwise select 'Next' to continue.")); |
| 712 | |
| 713 | p->deleteLater(); |
| 714 | p = NULL; |
| 715 | } |
| 716 | else |
| 717 | { |
| 718 | burn->setEnabled(true); |
| 719 | burn->setFocus(); |
| 720 | |
| 721 | instructions->setText(QObject::tr("Burn failed. Insert a new DVD and " |
| 722 | "select 'Burn' to try again, otherwise select " |
| 723 | "'Next' to continue.")); |
| 724 | |
| 725 | p->deleteLater(); |
| 726 | p = NULL; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | void DVDWizardPageBurnDVD::startBurn() |
| 731 | { |
| 732 | burn->setDisabled(true); |
| 733 | |
| 734 | /* reset progress bar */ |
| 735 | progress->setProgress(0); |
| 736 | |
| 737 | p = new QProcess(QString("growisofs"), this); |
| 738 | p->setCommunication(QProcess::Stderr); |
| 739 | p->setWorkingDirectory(gContext->GetSetting("DVDWizardDir")); |
| 740 | p->addArgument("-dvd-compat"); |
| 741 | p->addArgument("-Z"); |
| 742 | p->addArgument(gContext->GetSetting("DVDDevice") + QString("dvd.iso")); |
| 743 | connect(p, SIGNAL(readyReadStderr()), this, SLOT(readProc())); |
| 744 | connect(p, SIGNAL(processExited()), this, SLOT(procExited())); |
| 745 | |
| 746 | p->start(); |
| 747 | } |
| 748 | |
| 749 | DVDWizardPageLast::DVDWizardPageLast(DVDWizardData *data) |
| 750 | : DVDWizardPage(data, NULL, "last") |
| 751 | { |
| 752 | MythLabel *text = new MythLabel(QObject::tr("Congratulations the DVD has " |
| 753 | "now been sucessfully authored."), this); |
| 754 | layout()->add(text); |
| 755 | } |
| 756 | |
| 757 | DVDWizardPageLast::~DVDWizardPageLast() |
| 758 | { |
| 759 | /* clean up temp files */ |
| 760 | /* this deletes everything in the gContext->GetSetting("DVDWizardDir") directory */ |
| 761 | |
| 762 | QString command = QString("rm -rf ") + gContext->GetSetting("DVDWizardDir"); |
| 763 | myth_system(command + QString("/dvd_dir")); |
| 764 | myth_system(command + QString("/dvd.xml")); |
| 765 | myth_system(command + QString("/dvd.iso")); |
| 766 | } |
| 767 | |
| 768 | MythLabel::MythLabel(const QString & text, QWidget * parent, const char * name, WFlags f) |
| 769 | : QLabel(text, parent, name, f) |
| 770 | { |
| 771 | setBackgroundOrigin(QWidget::WindowOrigin); |
| 772 | setAlignment(Qt::WordBreak | Qt::AlignLeft | Qt::AlignTop); |
| 773 | } |
| 774 | |