source: smplayer/trunk/src/prefdrives.cpp@ 104

Last change on this file since 104 was 93, checked in by Silvan Scherrer, 15 years ago

smplayer: 0.6.9

File size: 5.5 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
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
31bool isCDDevice(QString drive) {
32 if (QSysInfo::WindowsVersion >= QSysInfo::WV_NT) {
33 unsigned int r = GetDriveTypeW((LPCWSTR) drive.utf16());
34 qDebug("isCDDevice: '%s' r: %d", drive.toUtf8().data(), r);
35 return (r == DRIVE_CDROM);
36 } else {
37 //Win98
38 return true;
39 }
40}
41
42#endif
43
44#ifdef Q_OS_OS2 // fixme SCS
45bool isCDDevice(QString drive) {
46 return true;
47}
48#endif
49
50PrefDrives::PrefDrives(QWidget * parent, Qt::WindowFlags f)
51 : PrefWidget(parent, f )
52{
53 setupUi(this);
54
55#if !DVDNAV_SUPPORT
56 use_dvdnav_check->hide();
57#endif
58
59#ifndef Q_OS_WIN
60 check_drives_button->hide();
61#endif
62
63 updateDriveCombos();
64
65 retranslateStrings();
66}
67
68PrefDrives::~PrefDrives()
69{
70}
71
72QString PrefDrives::sectionName() {
73 return tr("Drives");
74}
75
76QPixmap PrefDrives::sectionIcon() {
77 return Images::icon("pref_devices");
78}
79
80
81void 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
87 createHelp();
88}
89
90void PrefDrives::updateDriveCombos(bool detect_cd_devices) {
91 qDebug("PrefDrives::updateDriveCombos: detect_cd_devices: %d", detect_cd_devices);
92
93 // Save current values
94 QString current_dvd_device = dvdDevice();
95 QString current_cd_device = cdromDevice();
96
97 dvd_device_combo->clear();
98 cdrom_device_combo->clear();
99
100 // DVD device combo
101 // In windows, insert the drives letters
102#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
103 QFileInfoList list = QDir::drives();
104 for (int n = 0; n < list.size(); n++) {
105 QString s = list[n].filePath();
106 bool is_cd_device = true;
107 if (detect_cd_devices) is_cd_device = isCDDevice(s);
108 if (is_cd_device) {
109 if (s.endsWith("/")) s = s.remove( s.length()-1,1);
110 dvd_device_combo->addItem( s );
111 cdrom_device_combo->addItem( s );
112 }
113 }
114#else
115 QDir dev_dir("/dev");
116 QStringList devices = dev_dir.entryList( QStringList() << "dvd*" << "cdrom*" << "cdrw*" << "sr*" << "cdrecorder*" << "acd[0-9]*" << "cd[0-9]*",
117 QDir::Files | QDir::System | QDir::Readable);
118 for (int n=0; n < devices.count(); n++) {
119 QString device_name = "/dev/" + devices[n];
120 qDebug("PrefDrives::PrefDrives: device found: '%s'", device_name.toUtf8().constData());
121 dvd_device_combo->addItem(device_name);
122 cdrom_device_combo->addItem(device_name);
123 }
124#endif
125
126 // Restore previous values
127 setDVDDevice( current_dvd_device );
128 setCDRomDevice( current_cd_device );
129}
130
131void PrefDrives::setData(Preferences * pref) {
132 setDVDDevice( pref->dvd_device );
133 setCDRomDevice( pref->cdrom_device );
134
135#if DVDNAV_SUPPORT
136 setUseDVDNav( pref->use_dvdnav );
137#endif
138}
139
140void PrefDrives::getData(Preferences * pref) {
141 requires_restart = false;
142
143 pref->dvd_device = dvdDevice();
144 pref->cdrom_device = cdromDevice();
145
146#if DVDNAV_SUPPORT
147 pref->use_dvdnav = useDVDNav();
148#endif
149}
150
151void PrefDrives::setDVDDevice( QString dir ) {
152 dvd_device_combo->setCurrentText( dir );
153}
154
155QString PrefDrives::dvdDevice() {
156 return dvd_device_combo->currentText();
157}
158
159void PrefDrives::setCDRomDevice( QString dir ) {
160 cdrom_device_combo->setCurrentText( dir );
161}
162
163QString PrefDrives::cdromDevice() {
164 return cdrom_device_combo->currentText();
165}
166
167#if DVDNAV_SUPPORT
168void PrefDrives::setUseDVDNav(bool b) {
169 use_dvdnav_check->setChecked(b);
170}
171
172bool PrefDrives::useDVDNav() {
173 return use_dvdnav_check->isChecked();
174}
175#endif
176
177void PrefDrives::on_check_drives_button_clicked() {
178 qDebug("PrefDrives::on_check_drives_button_clicked");
179 updateDriveCombos(true);
180}
181
182void PrefDrives::createHelp() {
183 clearHelp();
184
185 setWhatsThis(cdrom_device_combo, tr("CD device"),
186 tr("Choose your CDROM device. It will be used to play "
187 "VCDs and Audio CDs.") );
188
189 setWhatsThis(dvd_device_combo, tr("DVD device"),
190 tr("Choose your DVD device. It will be used to play DVDs.") );
191
192#if DVDNAV_SUPPORT
193 setWhatsThis(use_dvdnav_check, tr("Enable DVD menus"),
194 tr("If this option is checked, smplayer will play DVDs using "
195 "dvdnav. Requires a recent version of mplayer compiled with dvdnav "
196 "support.") +"<br>" +
197 tr("<b>Note 1</b>: cache will be disabled, this can affect performance.") +"<br>"+
198 tr("<b>Note 2</b>: you may want to assign the action "
199 "\"activate option in DVD menus\" to one of the mouse buttons.") + "<br>"+
200 tr("<b>Note 3</b>: this feature is under development, expect a lot of "
201 "issues with it."));
202#endif
203}
204
205#include "moc_prefdrives.cpp"
Note: See TracBrowser for help on using the repository browser.