Ticket #3077: default-cd.diff

File default-cd.diff, 19.3 KB (added by Nigel, 14 years ago)

MythMedia based auto-selection

  • src/mythplugins/mythmusic/mythmusic/cdrip.cpp

     
    167163    sendEvent(ST_TRACK_PROGRESS, 0);
    168164
    169165    QString textstatus;
    170     QString cddevice = gContext->GetSetting("CDDevice");
     166    QString cddevice = MediaMonitor::defaultCDdevice();
    171167    QString encodertype = gContext->GetSetting("EncoderType");
    172168    bool mp3usevbr = gContext->GetNumSetting("Mp3UseVBR", 0);
    173169
     
    734730
    735731void Ripper::scanCD(void)
    736732{
    737     QString cddevice = gContext->GetSetting("CDDevice");
     733    QString cddevice = MediaMonitor::defaultCDdevice();
    738734
    739735    int cdrom_fd = cd_init_device((char*)cddevice.ascii());
    740736    if (cdrom_fd == -1)
     
    11441140
    11451141void Ripper::ejectCD()
    11461142{
    1147     QString cddevice = gContext->GetSetting("CDDevice");
     1143    QString cddevice = MediaMonitor::defaultCDdevice();
    11481144    bool bEjectCD = gContext->GetNumSetting("EjectCDAfterRipping",1);
    11491145    if (bEjectCD)
    11501146    {
  • src/mythplugins/mythmusic/mythmusic/cddecoder.cpp

     
    1313#include "metadata.h"
    1414
    1515#include <mythtv/mythcontext.h>
     16#include <mythtv/mythmediamonitor.h>
    1617
    1718CdDecoder::CdDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
    1819                     AudioOutput *o)
     
    4041
    4142    settracknum = -1;
    4243
    43     devicename = gContext->GetSetting("CDDevice");
     44    devicename = MediaMonitor::defaultCDdevice();
    4445}
    4546
    4647CdDecoder::~CdDecoder(void)
  • src/mythplugins/mytharchive/mytharchive/archivesettings.cpp

     
    5050    return gc;
    5151};
    5252
    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 
    6253static HostLineEdit *MythArchiveDVDPlayerCmd()
    6354{
    6455    HostLineEdit *gc = new HostLineEdit("MythArchiveDVDPlayerCmd");
     
    276267    vcg1->addChild(MythArchiveShareDir());
    277268    vcg1->addChild(PALNTSC());
    278269    vcg1->addChild(MythArchiveFileFilter());
    279     vcg1->addChild(MythArchiveDVDLocation());
    280270    vcg1->addChild(MythArchiveDVDPlayerCmd());
    281271    addChild(vcg1);
    282272
  • src/mythplugins/mytharchive/mytharchivehelper/main.cpp

     
    2323// MythTV headers
    2424#include <mythtv/mythcontext.h>
    2525#include <mythtv/util.h>
    26 #include <mythtv/mythcontext.h>
     26#include <mythtv/mythmediamonitor.h>
    2727#include <mythtv/exitcodes.h>
    2828#include <mythtv/mythdbcon.h>
    2929#include <ffmpeg/avcodec.h>
     
    164164
    165165int burnISOImage(int mediaType, bool bEraseDVDRW, bool nativeFormat)
    166166{
    167     QString dvdDrive = gContext->GetSetting("MythArchiveDVDLocation", "/dev/dvd");
     167    QString dvdDrive = MediaMonitor::defaultDVDwriter();
    168168    VERBOSE(VB_JOBQUEUE, "Burning ISO image to " + dvdDrive);
    169169
    170170    QString tempDirectory = getTempDirectory();
  • src/mythplugins/mythvideo/mtd/mtd.cpp

     
    1616
    1717#include <mythtv/util.h>
    1818#include <mythtv/mythcontext.h>
     19#include <mythtv/mythmediamonitor.h>
    1920
    2021#include "mtd.h"
    2122#include "logging.h"
     
    173174    //  timer to query whether the thread is done or not
    174175    //
    175176       
    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();
    182178    dvd_probe = new DVDProbe(dvd_device);
    183179    disc_checking_thread = new DiscCheckingThread(this, dvd_probe, dvd_drive_access, titles_mutex);
    184180    disc_checking_thread->start();
     
    678674
    679675    QString file_name = dir_and_file.section("/", -1, -1);
    680676
     677    QString dvd_device = MediaMonitor::defaultDVDdevice();
    681678
    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 
    689679    //
    690680    //  OK, we are ready to launch this job
    691681    //
  • src/mythplugins/mythvideo/mythvideo/globalsettings.cpp

     
    272272
    273273// General Settings
    274274
    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 
    297275HostComboBox *SetOnInsertDVD()
    298276{
    299277    HostComboBox *gc = new HostComboBox("DVDOnInsertDVD");
     
    557535            new VerticalConfigurationGroup(false);
    558536    general3->setLabel(QObject::tr("General Settings (%1/%2)")
    559537                       .arg(3).arg(pages));
    560     general3->addChild(SetDVDDevice());
    561     general3->addChild(SetVCDDevice());
    562538    general3->addChild(SetOnInsertDVD());
    563539    general3->addChild(SetDVDDriveSpeed());
    564540    general3->addChild(new DVDBookmarkSettings());
  • src/mythplugins/mythvideo/mythvideo/main.cpp

     
    1717#include <mythtv/lcddevice.h>
    1818#include <mythtv/libmythui/myththemedmenu.h>
    1919#include <mythtv/mythpluginapi.h>
     20#include <mythtv/mythmediamonitor.h>
    2021#include <mythtv/mythmedia.h>
    2122#include <mythtv/util.h>
    2223
     
    251252                //
    252253                //  Need to do device substitution
    253254                //
    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);
    277258            }
    278259            myth_system(command_string);
    279260            gContext->GetMainWindow()->raise();
     
    296277        QString dvd_device = gDVDdevice;
    297278
    298279        if (dvd_device.isNull())
    299             dvd_device = gContext->GetSetting("DVDDeviceLocation");
     280            dvd_device = MediaMonitor::defaultDVDdevice();
    300281
    301         if(dvd_device.length() < 1)
    302         {
    303             //
    304             //  RTF README
    305             //
    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 
    318282        gContext->addCurrentLocation("playdvd");
    319283
    320284        if ((command_string.find("internal", 0, false) > -1) ||
  • src/mythplugins/mythvideo/mythvideo/dvdripbox.cpp

     
    1414using namespace std;
    1515
    1616#include <mythtv/mythcontext.h>
     17#include <mythtv/mythmediamonitor.h>
    1718#include <mythtv/uitypes.h>
    1819
    1920#include "dvdripbox.h"
     
    138139    //  timer to query whether the thread is done or not
    139140    //
    140141       
    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();
    147143    dvd_info = NULL;
    148144    disc_checking_timer = new QTimer();
    149145    disc_checking_timer->start(600);
  • src/mythplugins/mythvideo/mythvideo/titledialog.cpp

     
    1717
    1818#include <mythtv/util.h>
    1919#include <mythtv/uitypes.h>
     20#include <mythtv/mythmediamonitor.h>
    2021
    2122#include "titledialog.h"
    2223
     
    324325        return;
    325326    }
    326327
    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();
    333329   
    334330    int audio_track = 1;
    335331    int channels = 2;
  • src/mythtv/libs/libmyth/mythmediamonitor.h

     
    6868
    6969    void MonitorRegisterExtensions(uint mediaType, const QString &extensions);
    7070
     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
    7177    virtual QStringList GetCDROMBlockDevices(void) = 0;
    7278
    7379  public slots:
     
    7985    virtual bool AddDevice(MythMediaDevice* pDevice) = 0;
    8086    bool RemoveDevice(const QString &dev);
    8187
     88    static QString   defaultDevice(const QString setting, const QString label);
     89    MythMediaDevice *selectDrivePopup(const QString label, bool mounted=false);
     90
    8291  protected:
    8392    QMutex                       m_DevicesLock;
    8493    QValueList<MythMediaDevice*> m_Devices;
  • src/mythtv/libs/libmyth/mythmediamonitor.cpp

     
    9595    return str;
    9696}
    9797
     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 */
     104MythMediaDevice * 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
    98157/** \fn MediaMonitor::ChooseAndEjectMedia(void)
    99158 *  \brief Unmounts and ejects removable media devices.
    100159 *
     
    105164 */
    106165void MediaMonitor::ChooseAndEjectMedia(void)
    107166{
    108     MythMediaDevice *selected = NULL;
     167    MythMediaDevice *selected;
    109168
    110     QMutexLocker locker(&m_DevicesLock);
    111169
    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);
    120171
    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)
    147173    {
    148174        MythPopupBox::showOkPopup(gContext->GetMainWindow(),
    149175                                  "nothing to eject ",
    150176                                  tr("No devices to eject"));
     177        return;
    151178    }
    152179
    153     if (!selected)
    154         return;
    155 
    156180    bool doEject = false;
    157181    int   status = selected->getStatus();
    158182    QString  dev = DevName(selected);
     
    161185    {
    162186        VERBOSE(VB_MEDIA,
    163187                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        }
    165198    }
    166199    else if (MEDIASTAT_MOUNTED == status)
    167200    {
    168201        VERBOSE(VB_MEDIA, QString("Disk %1 is mounted? Unmounting").arg(dev));
    169202        selected->unmount();
    170203
    171         if (selected->isMounted(true))
     204        if (selected->isMounted(true) == MEDIAERR_FAILED)
    172205        {
    173206            MythPopupBox::showOkPopup(gContext->GetMainWindow(),
    174207                                      "eject unmount fail",
     
    430463        pMedia->clearData();
    431464    }
    432465}
     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
     479QString 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 */
     504QString 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 */
     518QString 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 */
     532QString 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 */
     549QString 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}