Ticket #3077: default-cd.diff
File default-cd.diff, 19.3 KB (added by , 17 years ago) |
---|
-
src/mythplugins/mythmusic/mythmusic/cdrip.cpp
167 163 sendEvent(ST_TRACK_PROGRESS, 0); 168 164 169 165 QString textstatus; 170 QString cddevice = gContext->GetSetting("CDDevice");166 QString cddevice = MediaMonitor::defaultCDdevice(); 171 167 QString encodertype = gContext->GetSetting("EncoderType"); 172 168 bool mp3usevbr = gContext->GetNumSetting("Mp3UseVBR", 0); 173 169 … … 734 730 735 731 void Ripper::scanCD(void) 736 732 { 737 QString cddevice = gContext->GetSetting("CDDevice");733 QString cddevice = MediaMonitor::defaultCDdevice(); 738 734 739 735 int cdrom_fd = cd_init_device((char*)cddevice.ascii()); 740 736 if (cdrom_fd == -1) … … 1144 1140 1145 1141 void Ripper::ejectCD() 1146 1142 { 1147 QString cddevice = gContext->GetSetting("CDDevice");1143 QString cddevice = MediaMonitor::defaultCDdevice(); 1148 1144 bool bEjectCD = gContext->GetNumSetting("EjectCDAfterRipping",1); 1149 1145 if (bEjectCD) 1150 1146 { -
src/mythplugins/mythmusic/mythmusic/cddecoder.cpp
13 13 #include "metadata.h" 14 14 15 15 #include <mythtv/mythcontext.h> 16 #include <mythtv/mythmediamonitor.h> 16 17 17 18 CdDecoder::CdDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 18 19 AudioOutput *o) … … 40 41 41 42 settracknum = -1; 42 43 43 devicename = gContext->GetSetting("CDDevice");44 devicename = MediaMonitor::defaultCDdevice(); 44 45 } 45 46 46 47 CdDecoder::~CdDecoder(void) -
src/mythplugins/mytharchive/mytharchive/archivesettings.cpp
50 50 return gc; 51 51 }; 52 52 53 static HostLineEdit *MythArchiveDVDLocation()54 {55 HostLineEdit *gc = new HostLineEdit("MythArchiveDVDLocation");56 gc->setLabel(QObject::tr("Location of DVD"));57 gc->setValue("/dev/dvd");58 gc->setHelpText(QObject::tr("Which DVD drive to use when burning discs."));59 return gc;60 };61 62 53 static HostLineEdit *MythArchiveDVDPlayerCmd() 63 54 { 64 55 HostLineEdit *gc = new HostLineEdit("MythArchiveDVDPlayerCmd"); … … 276 267 vcg1->addChild(MythArchiveShareDir()); 277 268 vcg1->addChild(PALNTSC()); 278 269 vcg1->addChild(MythArchiveFileFilter()); 279 vcg1->addChild(MythArchiveDVDLocation());280 270 vcg1->addChild(MythArchiveDVDPlayerCmd()); 281 271 addChild(vcg1); 282 272 -
src/mythplugins/mytharchive/mytharchivehelper/main.cpp
23 23 // MythTV headers 24 24 #include <mythtv/mythcontext.h> 25 25 #include <mythtv/util.h> 26 #include <mythtv/myth context.h>26 #include <mythtv/mythmediamonitor.h> 27 27 #include <mythtv/exitcodes.h> 28 28 #include <mythtv/mythdbcon.h> 29 29 #include <ffmpeg/avcodec.h> … … 164 164 165 165 int burnISOImage(int mediaType, bool bEraseDVDRW, bool nativeFormat) 166 166 { 167 QString dvdDrive = gContext->GetSetting("MythArchiveDVDLocation", "/dev/dvd");167 QString dvdDrive = MediaMonitor::defaultDVDwriter(); 168 168 VERBOSE(VB_JOBQUEUE, "Burning ISO image to " + dvdDrive); 169 169 170 170 QString tempDirectory = getTempDirectory(); -
src/mythplugins/mythvideo/mtd/mtd.cpp
16 16 17 17 #include <mythtv/util.h> 18 18 #include <mythtv/mythcontext.h> 19 #include <mythtv/mythmediamonitor.h> 19 20 20 21 #include "mtd.h" 21 22 #include "logging.h" … … 173 174 // timer to query whether the thread is done or not 174 175 // 175 176 176 QString dvd_device = gContext->GetSetting("DVDDeviceLocation"); 177 if(dvd_device.length() < 1) 178 { 179 cerr << "dvdripbox.o: Can't get a value for DVD device location. Did you run setup?" << endl; 180 exit(0); 181 } 177 QString dvd_device = MediaMonitor::defaultDVDdevice(); 182 178 dvd_probe = new DVDProbe(dvd_device); 183 179 disc_checking_thread = new DiscCheckingThread(this, dvd_probe, dvd_drive_access, titles_mutex); 184 180 disc_checking_thread->start(); … … 678 674 679 675 QString file_name = dir_and_file.section("/", -1, -1); 680 676 677 QString dvd_device = MediaMonitor::defaultDVDdevice(); 681 678 682 QString dvd_device = gContext->GetSetting("DVDDeviceLocation");683 if(dvd_device.length() < 1)684 {685 emit writeToLog("crapity crap crap - all set to launch a dvd job and you don't have a dvd device defined");686 return;687 }688 689 679 // 690 680 // OK, we are ready to launch this job 691 681 // -
src/mythplugins/mythvideo/mythvideo/globalsettings.cpp
272 272 273 273 // General Settings 274 274 275 HostLineEdit *SetVCDDevice()276 {277 HostLineEdit *gc = new HostLineEdit("VCDDeviceLocation");278 gc->setLabel(QObject::tr("Location of VCD device"));279 gc->setValue("/dev/cdrom");280 gc->setHelpText(QObject::tr("This device must exist, and the user "281 "running MythDVD needs to have read permission "282 "on the device."));283 return gc;284 }285 286 HostLineEdit *SetDVDDevice()287 {288 HostLineEdit *gc = new HostLineEdit("DVDDeviceLocation");289 gc->setLabel(QObject::tr("Location of DVD device"));290 gc->setValue("/dev/dvd");291 gc->setHelpText(QObject::tr("This device must exist, and the user "292 "running MythDVD needs to have read permission "293 "on the device."));294 return gc;295 }296 297 275 HostComboBox *SetOnInsertDVD() 298 276 { 299 277 HostComboBox *gc = new HostComboBox("DVDOnInsertDVD"); … … 557 535 new VerticalConfigurationGroup(false); 558 536 general3->setLabel(QObject::tr("General Settings (%1/%2)") 559 537 .arg(3).arg(pages)); 560 general3->addChild(SetDVDDevice());561 general3->addChild(SetVCDDevice());562 538 general3->addChild(SetOnInsertDVD()); 563 539 general3->addChild(SetDVDDriveSpeed()); 564 540 general3->addChild(new DVDBookmarkSettings()); -
src/mythplugins/mythvideo/mythvideo/main.cpp
17 17 #include <mythtv/lcddevice.h> 18 18 #include <mythtv/libmythui/myththemedmenu.h> 19 19 #include <mythtv/mythpluginapi.h> 20 #include <mythtv/mythmediamonitor.h> 20 21 #include <mythtv/mythmedia.h> 21 22 #include <mythtv/util.h> 22 23 … … 251 252 // 252 253 // Need to do device substitution 253 254 // 254 QString vcd_device = gContext->GetSetting("VCDDeviceLocation"); 255 if(vcd_device.length() < 1) 256 { 257 // 258 // RTF README 259 // 260 DialogBox *no_device_dialog = 261 new DialogBox(gContext->GetMainWindow(), 262 QObject::tr("\n\nYou have no VCD Device defined.")); 263 no_device_dialog-> 264 AddButton(QObject::tr("OK, I'll go run Setup")); 265 no_device_dialog->exec(); 266 267 delete no_device_dialog; 268 gContext->removeCurrentLocation(); 269 270 return; 271 } 272 else 273 { 274 command_string = 275 command_string.replace(QRegExp("%d"), vcd_device); 276 } 255 QString vcd_device = MediaMonitor::defaultVCDdevice(); 256 command_string 257 = command_string.replace(QRegExp("%d"), vcd_device); 277 258 } 278 259 myth_system(command_string); 279 260 gContext->GetMainWindow()->raise(); … … 296 277 QString dvd_device = gDVDdevice; 297 278 298 279 if (dvd_device.isNull()) 299 dvd_device = gContext->GetSetting("DVDDeviceLocation");280 dvd_device = MediaMonitor::defaultDVDdevice(); 300 281 301 if(dvd_device.length() < 1)302 {303 //304 // RTF README305 //306 DialogBox *no_device_dialog =307 new DialogBox(gContext->GetMainWindow(),308 QObject::tr("\n\nYou have no DVD Device defined."));309 no_device_dialog->AddButton(QObject::tr("OK, I'll go run Setup"));310 no_device_dialog->exec();311 312 delete no_device_dialog;313 gContext->removeCurrentLocation();314 315 return;316 }317 318 282 gContext->addCurrentLocation("playdvd"); 319 283 320 284 if ((command_string.find("internal", 0, false) > -1) || -
src/mythplugins/mythvideo/mythvideo/dvdripbox.cpp
14 14 using namespace std; 15 15 16 16 #include <mythtv/mythcontext.h> 17 #include <mythtv/mythmediamonitor.h> 17 18 #include <mythtv/uitypes.h> 18 19 19 20 #include "dvdripbox.h" … … 138 139 // timer to query whether the thread is done or not 139 140 // 140 141 141 QString dvd_device = gContext->GetSetting("DVDDeviceLocation"); 142 if(dvd_device.length() < 1) 143 { 144 cerr << "dvdripbox.o: Can't get a value for DVD device location. Did you run setup?" << endl; 145 exit(0); 146 } 142 QString dvd_device = MediaMonitor::defaultDVDdevice(); 147 143 dvd_info = NULL; 148 144 disc_checking_timer = new QTimer(); 149 145 disc_checking_timer->start(600); -
src/mythplugins/mythvideo/mythvideo/titledialog.cpp
17 17 18 18 #include <mythtv/util.h> 19 19 #include <mythtv/uitypes.h> 20 #include <mythtv/mythmediamonitor.h> 20 21 21 22 #include "titledialog.h" 22 23 … … 324 325 return; 325 326 } 326 327 327 QString dvd_device = gContext->GetSetting("DVDDeviceLocation"); 328 if(dvd_device.length() < 1) 329 { 330 cerr << "titledialog.o: No DVD device defined" << endl; 331 return; 332 } 328 QString dvd_device = MediaMonitor::defaultDVDdevice(); 333 329 334 330 int audio_track = 1; 335 331 int channels = 2; -
src/mythtv/libs/libmyth/mythmediamonitor.h
68 68 69 69 void MonitorRegisterExtensions(uint mediaType, const QString &extensions); 70 70 71 // Plugins should use these if they need to access optical disks: 72 static QString defaultCDdevice(); 73 static QString defaultVCDdevice(); 74 static QString defaultDVDdevice(); 75 static QString defaultWriter(); 76 71 77 virtual QStringList GetCDROMBlockDevices(void) = 0; 72 78 73 79 public slots: … … 79 85 virtual bool AddDevice(MythMediaDevice* pDevice) = 0; 80 86 bool RemoveDevice(const QString &dev); 81 87 88 static QString defaultDevice(const QString setting, const QString label); 89 MythMediaDevice *selectDrivePopup(const QString label, bool mounted=false); 90 82 91 protected: 83 92 QMutex m_DevicesLock; 84 93 QValueList<MythMediaDevice*> m_Devices; -
src/mythtv/libs/libmyth/mythmediamonitor.cpp
95 95 return str; 96 96 } 97 97 98 /** 99 * \brief Popup a dialog box for the user to select one drive. 100 * 101 * Has to iterate through all devices to check if any are suitable, 102 * prevent drawing a list if there is only one drive, et cetera 103 */ 104 MythMediaDevice * MediaMonitor::selectDrivePopup(const QString label, 105 bool listMounted) 106 { 107 QValueList <MythMediaDevice *> drives; 108 QValueList <MythMediaDevice *>::iterator it = m_Devices.begin(); 109 QMutexLocker locker(&m_DevicesLock); 110 111 //while (it != m_Devices.end()) 112 for (it = m_Devices.begin(); it != m_Devices.end(); ++it) 113 { 114 // We can't currently tell if a MediaMonitor device is a CD/DVD, 115 // but if the device is ejectable that's probably safe. 116 // Caller can also request mounted drives to be listed: 117 118 if ((*it)->getAllowEject() || (listMounted && (*it)->isMounted())) 119 drives.append(*it); 120 121 //it++; 122 } 123 124 if (drives.count() == 0) 125 { 126 VERBOSE(VB_MEDIA, "MediaMonitor::selectDrivePopup(" 127 + label + ") - No suitable devices"); 128 return NULL; 129 } 130 131 if (drives.count() == 1) 132 { 133 VERBOSE(VB_MEDIA, "MediaMonitor::selectDrivePopup(" 134 + label + ") - One suitable device"); 135 return drives.front(); 136 } 137 138 MythPopupBox box(gContext->GetMainWindow(), "select drive"); 139 box.addLabel(label); 140 //it = drives.begin(); 141 //while (it != drives.end()) 142 // box.addButton(DevName(*it++)); 143 for (it = drives.begin(); it != drives.end(); ++it) 144 box.addButton(DevName(*it)); 145 146 box.addButton(tr("Cancel"))->setFocus(); 147 148 int ret = box.ExecPopup(); 149 150 if ((uint)ret < drives.count()) 151 return drives[ret]; 152 153 return NULL; 154 } 155 156 98 157 /** \fn MediaMonitor::ChooseAndEjectMedia(void) 99 158 * \brief Unmounts and ejects removable media devices. 100 159 * … … 105 164 */ 106 165 void MediaMonitor::ChooseAndEjectMedia(void) 107 166 { 108 MythMediaDevice *selected = NULL;167 MythMediaDevice *selected; 109 168 110 QMutexLocker locker(&m_DevicesLock);111 169 112 if (m_Devices.count() == 1) 113 { 114 if (m_Devices.first()->getAllowEject()) 115 selected = m_Devices.first(); 116 } 117 else if (m_Devices.count() > 1) 118 { 119 MythPopupBox ejectbox(gContext->GetMainWindow(), "eject media"); 170 selected = selectDrivePopup(tr("Select removable media to eject"), true); 120 171 121 ejectbox.addLabel(tr("Select removable media to eject")); 122 123 QValueList <MythMediaDevice *> shownDevices; 124 QValueList <MythMediaDevice *>::iterator it = m_Devices.begin(); 125 while (it != m_Devices.end()) 126 { 127 // if the device is ejectable (ie a CD or DVD device) 128 // or if it is mounted (ie a USB memory stick) 129 // then add it to the list of choices 130 if ((*it)->getAllowEject() || (*it)->isMounted(true)) 131 { 132 shownDevices.append(*it); 133 ejectbox.addButton(DevName(*it)); 134 } 135 136 it++; 137 } 138 139 ejectbox.addButton(tr("Cancel"))->setFocus(); 140 141 int ret = ejectbox.ExecPopup(); 142 143 if ((uint)ret < shownDevices.count()) 144 selected = shownDevices[ret]; 145 } 146 else 172 if (!selected) 147 173 { 148 174 MythPopupBox::showOkPopup(gContext->GetMainWindow(), 149 175 "nothing to eject ", 150 176 tr("No devices to eject")); 177 return; 151 178 } 152 179 153 if (!selected)154 return;155 156 180 bool doEject = false; 157 181 int status = selected->getStatus(); 158 182 QString dev = DevName(selected); … … 161 185 { 162 186 VERBOSE(VB_MEDIA, 163 187 QString("Disk %1's tray is OPEN. Closing tray").arg(dev)); 164 selected->eject(false); 188 189 if (selected->eject(false)) 190 { 191 QString msg = "Unable to work out if %1 is open or closed."; 192 193 msg += "\nYou may have to use the eject button on its tray."; 194 MythPopupBox::showOkPopup(gContext->GetMainWindow(), 195 "eject close-tray fail", 196 tr(msg).arg(dev)); 197 } 165 198 } 166 199 else if (MEDIASTAT_MOUNTED == status) 167 200 { 168 201 VERBOSE(VB_MEDIA, QString("Disk %1 is mounted? Unmounting").arg(dev)); 169 202 selected->unmount(); 170 203 171 if (selected->isMounted(true) )204 if (selected->isMounted(true) == MEDIAERR_FAILED) 172 205 { 173 206 MythPopupBox::showOkPopup(gContext->GetMainWindow(), 174 207 "eject unmount fail", … … 430 463 pMedia->clearData(); 431 464 } 432 465 } 466 467 /* 468 * These methods return the user's preferred devices for playing and burning 469 * CDs and DVDs. Traditionally we had a database setting to remember this, 470 * but that is a bit wasteful when most users only have one drive. 471 * 472 * To make it a bit more beginner friendly, if no database default exists, 473 * or if it contins "default", the code tries to guess the correct drive, 474 * or put a dialog box up if there are several valid options. 475 * 476 * Ideally, these would return a MythMediaDevice * instead of a QString 477 */ 478 479 QString MediaMonitor::defaultDevice(QString dbSetting, QString label) 480 { 481 QString device = gContext->GetSetting(dbSetting); 482 483 // No settings database defaults. Try to choose one: 484 if (device.isEmpty() || device == "default") 485 { 486 if (!c_monitor) 487 c_monitor = GetMediaMonitor(); 488 489 if (c_monitor) 490 { 491 MythMediaDevice *d = c_monitor->selectDrivePopup(label); 492 493 if (d) 494 return d->getDevicePath(); 495 } 496 } 497 498 return device; 499 } 500 501 /** 502 * CDDevice, user-selected drive, or /dev/cdrom 503 */ 504 QString MediaMonitor::defaultCDdevice() 505 { 506 QString device = defaultDevice("CDDevice", 507 tr("Select a CD drive")); 508 if (device.length()) 509 return device; 510 511 // Last resort: 512 return "/dev/cdrom"; 513 } 514 515 /** 516 * VCDDeviceLocation, user-selected drive, or /dev/cdrom 517 */ 518 QString MediaMonitor::defaultVCDdevice() 519 { 520 QString device = defaultDevice("VCDDeviceLocation", 521 tr("Select a VCD drive")); 522 if (device.length()) 523 return device; 524 525 // Last resort: 526 return "/dev/cdrom"; 527 } 528 529 /** 530 * DVDDeviceLocation, user-selected drive, or /dev/dvd 531 */ 532 QString MediaMonitor::defaultDVDdevice() 533 { 534 QString device = defaultDevice("DVDDeviceLocation", 535 tr("Select a DVD drive")); 536 if (device.length()) 537 return device; 538 539 // Last resort: 540 return "/dev/dvd"; 541 } 542 543 /** 544 * \brief MythArchiveDVDLocation, user-selected drive, or /dev/dvd 545 * 546 * This should also look for drives with blanks or RWs in them, 547 * but Nigel hasn't worked out how to do this tidily (yet). 548 */ 549 QString MediaMonitor::defaultWriter() 550 { 551 QString device = defaultDevice("MythArchiveDVDLocation", 552 tr("Select a DVD writer")); 553 if (device.length()) 554 return device; 555 556 // Absolute last resort: 557 return "/dev/dvd"; 558 }