1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2017 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 | #ifndef BLURAY_SUPPORT
|
---|
59 | bluray_widget->hide();
|
---|
60 | bluray_sep->hide();
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | updateDriveCombos();
|
---|
64 |
|
---|
65 | retranslateStrings();
|
---|
66 | }
|
---|
67 |
|
---|
68 | PrefDrives::~PrefDrives()
|
---|
69 | {
|
---|
70 | }
|
---|
71 |
|
---|
72 | QString PrefDrives::sectionName() {
|
---|
73 | return tr("Drives");
|
---|
74 | }
|
---|
75 |
|
---|
76 | QPixmap PrefDrives::sectionIcon() {
|
---|
77 | return Images::icon("pref_devices");
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | void PrefDrives::retranslateStrings() {
|
---|
82 | retranslateUi(this);
|
---|
83 |
|
---|
84 | cdrom_drive_icon->setPixmap( Images::icon("cdrom_drive") );
|
---|
85 | dvd_drive_icon->setPixmap( Images::icon("dvd_drive") );
|
---|
86 | #ifdef BLURAY_SUPPORT
|
---|
87 | bluray_drive_icon->setPixmap( Images::icon("bluray_drive") );
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | createHelp();
|
---|
91 | }
|
---|
92 |
|
---|
93 | void PrefDrives::updateDriveCombos(bool detect_cd_devices) {
|
---|
94 | qDebug("PrefDrives::updateDriveCombos: detect_cd_devices: %d", detect_cd_devices);
|
---|
95 |
|
---|
96 | // Save current values
|
---|
97 | QString current_dvd_device = dvdDevice();
|
---|
98 | QString current_cd_device = cdromDevice();
|
---|
99 | #ifdef BLURAY_SUPPORT
|
---|
100 | QString current_bluray_device = blurayDevice();
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | dvd_device_combo->clear();
|
---|
104 | cdrom_device_combo->clear();
|
---|
105 | #ifdef BLURAY_SUPPORT
|
---|
106 | bluray_device_combo->clear();
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | // DVD device combo
|
---|
110 | // In windows, insert the drives letters
|
---|
111 | #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
---|
112 | QFileInfoList list = QDir::drives();
|
---|
113 | for (int n = 0; n < list.size(); n++) {
|
---|
114 | QString s = list[n].filePath();
|
---|
115 | bool is_cd_device = true;
|
---|
116 | if (detect_cd_devices) is_cd_device = isCDDevice(s);
|
---|
117 | if (is_cd_device) {
|
---|
118 | if (s.endsWith("/")) s = s.remove( s.length()-1,1);
|
---|
119 | dvd_device_combo->addItem( s );
|
---|
120 | cdrom_device_combo->addItem( s );
|
---|
121 | #ifdef BLURAY_SUPPORT
|
---|
122 | bluray_device_combo->addItem( s );
|
---|
123 | #endif
|
---|
124 | }
|
---|
125 | }
|
---|
126 | #else
|
---|
127 | QDir dev_dir("/dev");
|
---|
128 | QStringList devices = dev_dir.entryList( QStringList() << "dvd*" << "cdrom*" << "cdrw*" << "sr*" << "cdrecorder*" << "acd[0-9]*" << "cd[0-9]*",
|
---|
129 | QDir::Files | QDir::System | QDir::Readable);
|
---|
130 | for (int n=0; n < devices.count(); n++) {
|
---|
131 | QString device_name = "/dev/" + devices[n];
|
---|
132 | qDebug("PrefDrives::PrefDrives: device found: '%s'", device_name.toUtf8().constData());
|
---|
133 | dvd_device_combo->addItem(device_name);
|
---|
134 | cdrom_device_combo->addItem(device_name);
|
---|
135 | #ifdef BLURAY_SUPPORT
|
---|
136 | bluray_device_combo->addItem(device_name);
|
---|
137 | #endif
|
---|
138 | }
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | // Restore previous values
|
---|
142 | setDVDDevice( current_dvd_device );
|
---|
143 | setCDRomDevice( current_cd_device );
|
---|
144 | #ifdef BLURAY_SUPPORT
|
---|
145 | setBlurayDevice( current_bluray_device );
|
---|
146 | #endif
|
---|
147 | }
|
---|
148 |
|
---|
149 | void PrefDrives::setData(Preferences * pref) {
|
---|
150 | setDVDDevice( pref->dvd_device );
|
---|
151 | setCDRomDevice( pref->cdrom_device );
|
---|
152 | #ifdef BLURAY_SUPPORT
|
---|
153 | setBlurayDevice( pref->bluray_device );
|
---|
154 | #endif
|
---|
155 |
|
---|
156 | #if DVDNAV_SUPPORT
|
---|
157 | setUseDVDNav( pref->use_dvdnav );
|
---|
158 | #endif
|
---|
159 | }
|
---|
160 |
|
---|
161 | void PrefDrives::getData(Preferences * pref) {
|
---|
162 | requires_restart = false;
|
---|
163 |
|
---|
164 | pref->dvd_device = dvdDevice();
|
---|
165 | pref->cdrom_device = cdromDevice();
|
---|
166 | #ifdef BLURAY_SUPPORT
|
---|
167 | pref->bluray_device = blurayDevice();
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | #if DVDNAV_SUPPORT
|
---|
171 | pref->use_dvdnav = useDVDNav();
|
---|
172 | #endif
|
---|
173 | }
|
---|
174 |
|
---|
175 | void PrefDrives::setDVDDevice( QString dir ) {
|
---|
176 | dvd_device_combo->setCurrentText( dir );
|
---|
177 | }
|
---|
178 |
|
---|
179 | QString PrefDrives::dvdDevice() {
|
---|
180 | return dvd_device_combo->currentText();
|
---|
181 | }
|
---|
182 |
|
---|
183 | #ifdef BLURAY_SUPPORT
|
---|
184 | void PrefDrives::setBlurayDevice( QString dir ) {
|
---|
185 | bluray_device_combo->setCurrentText( dir );
|
---|
186 | }
|
---|
187 |
|
---|
188 | QString PrefDrives::blurayDevice() {
|
---|
189 | return bluray_device_combo->currentText();
|
---|
190 | }
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | void PrefDrives::setCDRomDevice( QString dir ) {
|
---|
194 | cdrom_device_combo->setCurrentText( dir );
|
---|
195 | }
|
---|
196 |
|
---|
197 | QString PrefDrives::cdromDevice() {
|
---|
198 | return cdrom_device_combo->currentText();
|
---|
199 | }
|
---|
200 |
|
---|
201 | #if DVDNAV_SUPPORT
|
---|
202 | void PrefDrives::setUseDVDNav(bool b) {
|
---|
203 | use_dvdnav_check->setChecked(b);
|
---|
204 | }
|
---|
205 |
|
---|
206 | bool PrefDrives::useDVDNav() {
|
---|
207 | return use_dvdnav_check->isChecked();
|
---|
208 | }
|
---|
209 | #endif
|
---|
210 |
|
---|
211 | void PrefDrives::on_check_drives_button_clicked() {
|
---|
212 | qDebug("PrefDrives::on_check_drives_button_clicked");
|
---|
213 | updateDriveCombos(true);
|
---|
214 | }
|
---|
215 |
|
---|
216 | void PrefDrives::createHelp() {
|
---|
217 | clearHelp();
|
---|
218 |
|
---|
219 | setWhatsThis(cdrom_device_combo, tr("CD device"),
|
---|
220 | tr("Choose your CDROM device. It will be used to play "
|
---|
221 | "VCDs and Audio CDs.") );
|
---|
222 |
|
---|
223 | setWhatsThis(dvd_device_combo, tr("DVD device"),
|
---|
224 | tr("Choose your DVD device. It will be used to play DVDs.") );
|
---|
225 |
|
---|
226 | #if DVDNAV_SUPPORT
|
---|
227 | setWhatsThis(use_dvdnav_check, tr("Enable DVD menus"),
|
---|
228 | tr("If this option is checked, SMPlayer will play DVDs using "
|
---|
229 | "dvdnav. Requires a version of MPlayer with dvdnav "
|
---|
230 | "support.") +"<br>" +
|
---|
231 | tr("<b>Note 1</b>: cache will be disabled, this can affect performance.") +"<br>"+
|
---|
232 | tr("<b>Note 2</b>: you may want to assign the action "
|
---|
233 | "\"activate option in DVD menus\" to one of the mouse buttons.") + "<br>"+
|
---|
234 | tr("<b>Note 3</b>: this feature is under development, expect a lot of "
|
---|
235 | "issues with it."));
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | #ifdef BLURAY_SUPPORT
|
---|
239 | setWhatsThis(bluray_device_combo, tr("Blu-ray device"),
|
---|
240 | tr("Choose your Blu-ray device. It will be used to play Blu-ray discs.") );
|
---|
241 | #endif
|
---|
242 | }
|
---|
243 |
|
---|
244 | #include "moc_prefdrives.cpp"
|
---|