00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 using namespace std;
00012
00013 #include <qlayout.h>
00014 #include <qlabel.h>
00015 #include <qframe.h>
00016 #include <qregexp.h>
00017
00018 #include <mythtv/util.h>
00019 #include <mythtv/uitypes.h>
00020 #include <mythtv/mythmediamonitor.h>
00021
00022 #include "titledialog.h"
00023
00024 TitleDialog::TitleDialog(QSocket *a_socket,
00025 QString d_name,
00026 QPtrList<DVDTitleInfo> *titles,
00027 MythMainWindow *parent,
00028 QString window_name,
00029 QString theme_filename,
00030 const char* name)
00031 :MythThemedDialog(parent, window_name, theme_filename, name)
00032 {
00033
00034 name_editor = NULL;
00035 socket_to_mtd = a_socket;
00036 disc_name = d_name;
00037 if(disc_name.length() < 1)
00038 {
00039 disc_name = tr("Unknown");
00040 }
00041 dvd_titles = titles;
00042
00043 wireUpTheme();
00044 assignFirstFocus();
00045
00046
00047
00048
00049
00050 uint longest = 0;
00051 uint longest_time = 0;
00052 current_title = NULL;
00053
00054 for(uint i = 0; i < dvd_titles->count(); i++)
00055 {
00056 if(dvd_titles->at(i)->getPlayLength() >= longest_time)
00057 {
00058 longest = i;
00059 longest_time = dvd_titles->at(i)->getPlayLength();
00060 current_title = dvd_titles->at(i);
00061 }
00062 }
00063
00064 for(uint i = 0; i < dvd_titles->count(); i++)
00065 {
00066 if(dvd_titles->at(i) == current_title)
00067 {
00068 dvd_titles->at(i)->setName(disc_name);
00069 dvd_titles->at(i)->setSelected(true);
00070 }
00071 else
00072 {
00073 dvd_titles->at(i)->setName(QString(tr("%1 - Title %2")).arg(disc_name).arg(i + 1));
00074 }
00075 }
00076
00077 showCurrentTitle();
00078
00079 }
00080
00081 void TitleDialog::showCurrentTitle()
00082 {
00083
00084
00085
00086 if(current_title)
00087 {
00088
00089
00090
00091
00092
00093 if(playlength_text)
00094 {
00095 playlength_text->SetText(current_title->getTimeString());
00096 }
00097 if(ripcheck)
00098 {
00099 ripcheck->setState(current_title->getSelected());
00100 }
00101 if(name_editor)
00102 {
00103 name_editor->setText(current_title->getName());
00104 }
00105 if(audio_select)
00106 {
00107 audio_select->cleanOut();
00108 QPtrList<DVDAudioInfo> *audio_tracks = current_title->getAudioTracks();
00109 for(uint j = 0; j < audio_tracks->count(); j++)
00110 {
00111 audio_select->addItem(j + 1, audio_tracks->at(j)->getAudioString());
00112 }
00113 audio_select->setToItem(current_title->getAudio());
00114 }
00115 if(quality_select)
00116 {
00117 quality_select->cleanOut();
00118 quality_select->addItem(-1, tr("ISO Image"));
00119 quality_select->addItem(0, tr("Perfect"));
00120 QString q_string = QString("SELECT name,intid FROM dvdtranscode "
00121 "WHERE input = %1 ;")
00122 .arg(current_title->getInputID());
00123
00124 MSqlQuery a_query(MSqlQuery::InitCon());
00125 a_query.exec(q_string);
00126
00127 if(a_query.isActive() && a_query.size() > 0)
00128 {
00129 while(a_query.next())
00130 {
00131 quality_select->addItem(a_query.value(1).toInt(), a_query.value(0).toString());
00132 }
00133 }
00134 quality_select->setToItem(current_title->getQuality());
00135 }
00136
00137 if(subtitle_select)
00138 {
00139 subtitle_select->cleanOut();
00140 subtitle_select->addItem(-1, tr("None"));
00141 QPtrList<DVDSubTitleInfo> *subtitles = current_title->getSubTitles();
00142 for(uint j = 0; j < subtitles->count(); ++j)
00143 {
00144 subtitle_select->addItem(subtitles->at(j)->getID(), subtitles->at(j)->getName());
00145 }
00146 subtitle_select->setToItem(current_title->getSubTitle());
00147 }
00148
00149 if(ripacthree)
00150 {
00151 ripacthree->setState(current_title->getAC3());
00152 }
00153 if(numb_titles_text)
00154 {
00155 numb_titles_text->SetText(QString(tr("Title %1 of %2")).arg(current_title->getTrack()).arg(dvd_titles->count()));
00156 }
00157 }
00158 else
00159 {
00160 cerr << "titledialog.o: Hmmmm .... should not have shown you this dialog." << endl;
00161 }
00162 }
00163
00164 void TitleDialog::keyPressEvent(QKeyEvent *e)
00165 {
00166 bool handled = false;
00167 QStringList actions;
00168 gContext->GetMainWindow()->TranslateKeyPress("DVD", e, actions);
00169
00170 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00171 {
00172 QString action = actions[i];
00173 handled = true;
00174
00175 if (action == "PAGEDOWN")
00176 {
00177 if (next_title_button)
00178 next_title_button->push();
00179 }
00180 else if (action == "PAGEUP")
00181 {
00182 if (prev_title_button)
00183 prev_title_button->push();
00184 }
00185 else if (action == "UP")
00186 nextPrevWidgetFocus(false);
00187 else if (action == "DOWN")
00188 nextPrevWidgetFocus(true);
00189 else if (action == "SELECT")
00190 activateCurrent();
00191 else if (action == "1" || action == "2" || action == "3" ||
00192 action == "4" || action == "5" || action == "6" ||
00193 action == "7" || action == "8" || action == "9")
00194 {
00195 gotoTitle(action.toInt());
00196 }
00197 else if (action == "LEFT")
00198 prev_title_button->push();
00199 else if (action == "RIGHT")
00200 next_title_button->push();
00201 else
00202 handled = false;
00203 }
00204
00205 if (!handled)
00206 MythThemedDialog::keyPressEvent(e);
00207 }
00208
00209 void TitleDialog::nextTitle()
00210 {
00211 dvd_titles->find(current_title);
00212 current_title = dvd_titles->next();
00213 if(!current_title)
00214 {
00215 current_title = dvd_titles->first();
00216 }
00217 showCurrentTitle();
00218 }
00219
00220 void TitleDialog::prevTitle()
00221 {
00222 dvd_titles->find(current_title);
00223 current_title = dvd_titles->prev();
00224 if(!current_title)
00225 {
00226 current_title = dvd_titles->last();
00227 }
00228 showCurrentTitle();
00229 }
00230
00231 void TitleDialog::gotoTitle(uint title_number)
00232 {
00233 for(uint i = 0; i < dvd_titles->count(); i++)
00234 {
00235 if(dvd_titles->at(i)->getTrack() == title_number)
00236 {
00237 current_title = dvd_titles->at(i);
00238 i = dvd_titles->count() + 1;
00239 showCurrentTitle();
00240 }
00241 }
00242 }
00243
00244 void TitleDialog::setQuality(int which_quality)
00245 {
00246 current_title->setQuality(which_quality);
00247 }
00248
00249 void TitleDialog::setSubTitle(int which_subtitle)
00250 {
00251 current_title->setSubTitle(which_subtitle);
00252 }
00253
00254 void TitleDialog::setAudio(int audio_index)
00255 {
00256 current_title->setAudio(audio_index);
00257 }
00258
00259 void TitleDialog::toggleTitle(bool on_or_off)
00260 {
00261 current_title->setSelected(on_or_off);
00262
00263
00264
00265
00266
00267
00268 int numb_selected = 0;
00269 for(uint i = 0; i < dvd_titles->count(); i++)
00270 {
00271 if(dvd_titles->at(i)->getSelected())
00272 {
00273 ++numb_selected;
00274 }
00275 }
00276 if(!ripaway_button)
00277 {
00278 return;
00279 }
00280 if(numb_selected == 0)
00281 {
00282 if(ripaway_button->GetContext() != -2)
00283 {
00284 ripaway_button->allowFocus(false);
00285 ripaway_button->SetContext(-2);
00286 ripaway_button->refresh();
00287 }
00288 return;
00289 }
00290 if(ripaway_button->GetContext() != -1)
00291 {
00292 ripaway_button->SetContext(-1);
00293 ripaway_button->allowFocus(true);
00294 }
00295 ripaway_button->refresh();
00296 }
00297
00298 void TitleDialog::changeName(QString new_name)
00299 {
00300 current_title->setName(new_name);
00301 }
00302
00303 void TitleDialog::toggleAC3(bool on_or_off)
00304 {
00305 current_title->setAC3(on_or_off);
00306 }
00307
00308 void TitleDialog::viewTitle()
00309 {
00310 QString player_string = gContext->GetSetting("TitlePlayCommand");
00311 if(player_string.length() < 1)
00312 {
00313 cerr << "titledialog.o: No title player command defined" << endl;
00314 return;
00315 }
00316
00317 QString dvd_device = MediaMonitor::defaultDVDdevice();
00318
00319 int audio_track = 1;
00320 int channels = 2;
00321 if(current_title)
00322 {
00323 audio_track = current_title->getAudio();
00324 DVDAudioInfo *audio_in_question = current_title->getAudioTrack(audio_track - 1);
00325 if(audio_in_question)
00326 {
00327 channels = audio_in_question->getChannels();
00328 }
00329 }
00330
00331 if(player_string.contains("mplayer"))
00332 {
00333
00334
00335
00336 audio_track += 127;
00337 }
00338
00339 player_string = player_string.replace(QRegExp("%d"), dvd_device);
00340 player_string = player_string.replace(QRegExp("%t"), QString("%1").arg(current_title->getTrack()));
00341 player_string = player_string.replace(QRegExp("%a"), QString("%1").arg(audio_track));
00342 player_string = player_string.replace(QRegExp("%c"), QString("%1").arg(channels));
00343
00344 if(current_title->getSubTitle() > -1)
00345 {
00346 QString player_append = gContext->GetSetting("SubTitleCommand");
00347 if(player_append.length() > 1)
00348 {
00349 player_append = player_append.replace(QRegExp("%s"), QString("%1").arg(current_title->getSubTitle()));
00350 player_string += " ";
00351 player_string += player_append;
00352 }
00353 }
00354
00355
00356 myth_system(player_string);
00357 gContext->GetMainWindow()->raise();
00358 gContext->GetMainWindow()->setActiveWindow();
00359
00360 }
00361
00362 void TitleDialog::ripTitles()
00363 {
00364
00365
00366
00367
00368
00369
00370
00371 for(uint i = 0; i < dvd_titles->count(); i++)
00372 {
00373 if(dvd_titles->at(i)->getSelected())
00374 {
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 QString destination_directory =
00399 gContext->GetSetting("mythdvd.LocalRipDirectory");
00400
00401 if (!destination_directory.length())
00402 {
00403
00404 QStringList videodirs =
00405 QStringList::split(":", gContext->
00406 GetSetting("VideoStartupDir"),
00407 false);
00408 if (videodirs.size())
00409 destination_directory = videodirs[0];
00410 }
00411
00412 if(destination_directory.length() < 1)
00413 {
00414 cerr << "titledialog.o: I can't rip, as I have nowhere to put finished files. MythVideo installed?" << endl;
00415 return;
00416 }
00417
00418 QString final_dir_and_file = destination_directory + "/" + dvd_titles->at(i)->getName();
00419
00420 QString job_string = QString("job dvd %1 %2 %3 %4 %5 %6")
00421 .arg(dvd_titles->at(i)->getTrack())
00422 .arg(dvd_titles->at(i)->getAudio())
00423 .arg(dvd_titles->at(i)->getQuality())
00424 .arg(dvd_titles->at(i)->getAC3())
00425 .arg(dvd_titles->at(i)->getSubTitle())
00426 .arg(final_dir_and_file);
00427
00428 QTextStream os(socket_to_mtd);
00429 os << job_string << "\n" ;
00430 }
00431 }
00432 reject();
00433 }
00434
00435 void TitleDialog::wireUpTheme()
00436 {
00437 ripcheck = getUICheckBoxType("ripcheck");
00438 if(ripcheck)
00439 {
00440 connect(ripcheck, SIGNAL(pushed(bool)), this, SLOT(toggleTitle(bool)));
00441 }
00442
00443 next_title_button = getUIPushButtonType("next_title_button");
00444 if(next_title_button)
00445 {
00446 next_title_button->allowFocus(false);
00447 connect(next_title_button, SIGNAL(pushed()), this, SLOT(nextTitle()));
00448 }
00449
00450 prev_title_button = getUIPushButtonType("prev_title_button");
00451 if(prev_title_button)
00452 {
00453 prev_title_button->allowFocus(false);
00454 connect(prev_title_button, SIGNAL(pushed()), this, SLOT(prevTitle()));
00455 }
00456
00457 playlength_text = getUITextType("playlength_text");
00458
00459 name_editor = getUIRemoteEditType("name_edit");
00460 if(name_editor)
00461 {
00462 name_editor->createEdit(this);
00463 connect(name_editor, SIGNAL(textChanged(QString)),
00464 this, SLOT(changeName(QString)));
00465 }
00466
00467 ripaway_button = getUITextButtonType("ripaway_button");
00468 if(ripaway_button)
00469 {
00470 ripaway_button->setText(tr("Begin Ripping"));
00471 connect(ripaway_button, SIGNAL(pushed()), this, SLOT(ripTitles()));
00472 }
00473
00474 audio_select = getUISelectorType("audio_select");
00475 if(audio_select)
00476 {
00477 connect(audio_select, SIGNAL(pushed(int)), this, SLOT(setAudio(int)));
00478 }
00479
00480 quality_select = getUISelectorType("quality_select");
00481 if(quality_select)
00482 {
00483 connect(quality_select, SIGNAL(pushed(int)), this, SLOT(setQuality(int)));
00484 }
00485
00486 subtitle_select = getUISelectorType("subtitle_select");
00487 if(subtitle_select)
00488 {
00489 connect(subtitle_select, SIGNAL(pushed(int)), this, SLOT(setSubTitle(int)));
00490 }
00491 ripacthree = getUICheckBoxType("ripacthree");
00492 if(ripacthree)
00493 {
00494 connect(ripacthree, SIGNAL(pushed(bool)), this, SLOT(toggleAC3(bool)));
00495 }
00496
00497 view_button = getUIPushButtonType("view_button");
00498 if(view_button)
00499 {
00500 connect(view_button, SIGNAL(pushed()), this, SLOT(viewTitle()));
00501 }
00502
00503 numb_titles_text = getUITextType("numb_titles_text");
00504 buildFocusList();
00505 }
00506
00507 TitleDialog::~TitleDialog()
00508 {
00509 if (name_editor)
00510 {
00511 name_editor->deleteLater();
00512 name_editor = NULL;
00513 }
00514 }
00515