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