| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net>
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | #include "prefdrives.h"
|
|---|
| 21 | #include "images.h"
|
|---|
| 22 | #include "preferences.h"
|
|---|
| 23 |
|
|---|
| 24 | #include <QFile>
|
|---|
| 25 | #include <QFileInfoList>
|
|---|
| 26 | #include <QDir>
|
|---|
| 27 |
|
|---|
| 28 | #ifdef Q_OS_WIN
|
|---|
| 29 | #include <windows.h>
|
|---|
| 30 |
|
|---|
| 31 | bool isCDDevice(QString drive) {
|
|---|
| 32 | unsigned int r = GetDriveTypeW((LPCWSTR) drive.utf16());
|
|---|
| 33 | qDebug("isCDDevice: '%s' r: %d", drive.toUtf8().data(), r);
|
|---|
| 34 | return (r == DRIVE_CDROM);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | #endif
|
|---|
| 38 |
|
|---|
| 39 | #ifdef Q_OS_OS2 // fixme SCS
|
|---|
| 40 | bool isCDDevice(QString drive) {
|
|---|
| 41 | return true;
|
|---|
| 42 | }
|
|---|
| 43 | #endif
|
|---|
| 44 |
|
|---|
| 45 | PrefDrives::PrefDrives(QWidget * parent, Qt::WindowFlags f)
|
|---|
| 46 | : PrefWidget(parent, f )
|
|---|
| 47 | {
|
|---|
| 48 | setupUi(this);
|
|---|
| 49 |
|
|---|
| 50 | #if !DVDNAV_SUPPORT
|
|---|
| 51 | use_dvdnav_check->hide();
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | #ifndef Q_OS_WIN
|
|---|
| 55 | check_drives_button->hide();
|
|---|
| 56 | #endif
|
|---|
| 57 |
|
|---|
| 58 | updateDriveCombos();
|
|---|
| 59 |
|
|---|
| 60 | retranslateStrings();
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | PrefDrives::~PrefDrives()
|
|---|
| 64 | {
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | QString PrefDrives::sectionName() {
|
|---|
| 68 | return tr("Drives");
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | QPixmap PrefDrives::sectionIcon() {
|
|---|
| 72 | return Images::icon("pref_devices", 22);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | void PrefDrives::retranslateStrings() {
|
|---|
| 77 | retranslateUi(this);
|
|---|
| 78 |
|
|---|
| 79 | cdrom_drive_icon->setPixmap( Images::icon("cdrom_drive") );
|
|---|
| 80 | dvd_drive_icon->setPixmap( Images::icon("dvd_drive") );
|
|---|
| 81 |
|
|---|
| 82 | createHelp();
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void PrefDrives::updateDriveCombos(bool detect_cd_devices) {
|
|---|
| 86 | qDebug("PrefDrives::updateDriveCombos: detect_cd_devices: %d", detect_cd_devices);
|
|---|
| 87 |
|
|---|
| 88 | // Save current values
|
|---|
| 89 | QString current_dvd_device = dvdDevice();
|
|---|
| 90 | QString current_cd_device = cdromDevice();
|
|---|
| 91 |
|
|---|
| 92 | dvd_device_combo->clear();
|
|---|
| 93 | cdrom_device_combo->clear();
|
|---|
| 94 |
|
|---|
| 95 | // DVD device combo
|
|---|
| 96 | // In windows, insert the drives letters
|
|---|
| 97 | #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
|---|
| 98 | QFileInfoList list = QDir::drives();
|
|---|
| 99 | for (int n = 0; n < list.size(); n++) {
|
|---|
| 100 | QString s = list[n].filePath();
|
|---|
| 101 | bool is_cd_device = true;
|
|---|
| 102 | if (detect_cd_devices) is_cd_device = isCDDevice(s);
|
|---|
| 103 | if (is_cd_device) {
|
|---|
| 104 | if (s.endsWith("/")) s = s.remove( s.length()-1,1);
|
|---|
| 105 | dvd_device_combo->addItem( s );
|
|---|
| 106 | cdrom_device_combo->addItem( s );
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 | #else
|
|---|
| 110 | QDir dev_dir("/dev");
|
|---|
| 111 | QStringList devices = dev_dir.entryList( QStringList() << "dvd*" << "cdrom*" << "cdrw*" << "sr*" << "cdrecorder*" << "acd[0-9]*" << "cd[0-9]*",
|
|---|
| 112 | QDir::Files | QDir::System | QDir::Readable);
|
|---|
| 113 | for (int n=0; n < devices.count(); n++) {
|
|---|
| 114 | QString device_name = "/dev/" + devices[n];
|
|---|
| 115 | qDebug("PrefDrives::PrefDrives: device found: '%s'", device_name.toUtf8().constData());
|
|---|
| 116 | dvd_device_combo->addItem(device_name);
|
|---|
| 117 | cdrom_device_combo->addItem(device_name);
|
|---|
| 118 | }
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | // Restore previous values
|
|---|
| 122 | setDVDDevice( current_dvd_device );
|
|---|
| 123 | setCDRomDevice( current_cd_device );
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | void PrefDrives::setData(Preferences * pref) {
|
|---|
| 127 | setDVDDevice( pref->dvd_device );
|
|---|
| 128 | setCDRomDevice( pref->cdrom_device );
|
|---|
| 129 |
|
|---|
| 130 | #if DVDNAV_SUPPORT
|
|---|
| 131 | setUseDVDNav( pref->use_dvdnav );
|
|---|
| 132 | #endif
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | void PrefDrives::getData(Preferences * pref) {
|
|---|
| 136 | requires_restart = false;
|
|---|
| 137 |
|
|---|
| 138 | pref->dvd_device = dvdDevice();
|
|---|
| 139 | pref->cdrom_device = cdromDevice();
|
|---|
| 140 |
|
|---|
| 141 | #if DVDNAV_SUPPORT
|
|---|
| 142 | pref->use_dvdnav = useDVDNav();
|
|---|
| 143 | #endif
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | void PrefDrives::setDVDDevice( QString dir ) {
|
|---|
| 147 | dvd_device_combo->setCurrentText( dir );
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | QString PrefDrives::dvdDevice() {
|
|---|
| 151 | return dvd_device_combo->currentText();
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | void PrefDrives::setCDRomDevice( QString dir ) {
|
|---|
| 155 | cdrom_device_combo->setCurrentText( dir );
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | QString PrefDrives::cdromDevice() {
|
|---|
| 159 | return cdrom_device_combo->currentText();
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | #if DVDNAV_SUPPORT
|
|---|
| 163 | void PrefDrives::setUseDVDNav(bool b) {
|
|---|
| 164 | use_dvdnav_check->setChecked(b);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | bool PrefDrives::useDVDNav() {
|
|---|
| 168 | return use_dvdnav_check->isChecked();
|
|---|
| 169 | }
|
|---|
| 170 | #endif
|
|---|
| 171 |
|
|---|
| 172 | void PrefDrives::on_check_drives_button_clicked() {
|
|---|
| 173 | qDebug("PrefDrives::on_check_drives_button_clicked");
|
|---|
| 174 | updateDriveCombos(true);
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | void PrefDrives::createHelp() {
|
|---|
| 178 | clearHelp();
|
|---|
| 179 |
|
|---|
| 180 | setWhatsThis(cdrom_device_combo, tr("CD device"),
|
|---|
| 181 | tr("Choose your CDROM device. It will be used to play "
|
|---|
| 182 | "VCDs and Audio CDs.") );
|
|---|
| 183 |
|
|---|
| 184 | setWhatsThis(dvd_device_combo, tr("DVD device"),
|
|---|
| 185 | tr("Choose your DVD device. It will be used to play DVDs.") );
|
|---|
| 186 |
|
|---|
| 187 | #if DVDNAV_SUPPORT
|
|---|
| 188 | setWhatsThis(use_dvdnav_check, tr("Enable DVD menus"),
|
|---|
| 189 | tr("If this option is checked, smplayer will play DVDs using "
|
|---|
| 190 | "dvdnav. Requires a recent version of mplayer compiled with dvdnav "
|
|---|
| 191 | "support.") +"<br>" +
|
|---|
| 192 | tr("<b>Note 1</b>: cache will be disabled, this can affect performance.") +"<br>"+
|
|---|
| 193 | tr("<b>Note 2</b>: you may want to assign the action "
|
|---|
| 194 | "\"activate option in DVD menus\" to one of the mouse buttons.") + "<br>"+
|
|---|
| 195 | tr("<b>Note 3</b>: this feature is under development, expect a lot of "
|
|---|
| 196 | "issues with it."));
|
|---|
| 197 | #endif
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | #include "moc_prefdrives.cpp"
|
|---|