1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
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.
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.
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
22
QString DiscName::joinDVD(int title, const QString & device, bool use_dvdnav) {
23
return join(use_dvdnav ? DVDNAV : DVD, title, device);
26
QString DiscName::join(const DiscData & d) {
27
QString s = d.protocol + "://";
28
if (d.title > 0) s += QString::number(d.title);
29
if (!d.device.isEmpty()) s+= "/" + removeTrailingSlash(d.device);
31
qDebug("DiscName::join: result: '%s'", s.toUtf8().constData());
35
QString DiscName::join(Disc type, int title, const QString & device) {
38
case DVD: protocol = "dvd"; break;
39
case DVDNAV: protocol = "dvdnav"; break;
40
case VCD: protocol = "vcd"; break;
41
case CDDA: protocol = "cdda"; break;
43
return join( DiscData(protocol, title, device) );
46
DiscData DiscName::split(const QString & disc_url, bool * ok) {
47
qDebug("DiscName::split: disc_url: '%s'", disc_url.toUtf8().constData());
49
QRegExp rx1("^(dvd|dvdnav|vcd|cdda)://(\\d+)/(.*)");
50
QRegExp rx2("^(dvd|dvdnav|vcd|cdda)://(\\d+)");
51
QRegExp rx3("^(dvd|dvdnav|vcd|cdda):///(.*)");
52
QRegExp rx4("^(dvd|dvdnav|vcd|cdda):(.*)");
58
if (rx1.indexIn(disc_url) != -1) {
59
d.protocol = rx1.cap(1);
60
d.title = rx1.cap(2).toInt();
61
d.device = rx1.cap(3);
65
if (rx2.indexIn(disc_url) != -1) {
66
d.protocol = rx2.cap(1);
67
d.title = rx2.cap(2).toInt();
72
if (rx3.indexIn(disc_url) != -1) {
73
d.protocol = rx3.cap(1);
75
d.device = rx3.cap(2);
79
if (rx4.indexIn(disc_url) != -1) {
80
d.protocol = rx4.cap(1);
86
if (!d.device.isEmpty()) d.device = removeTrailingSlash(d.device);
89
qDebug("DiscName::split: protocol: '%s'", d.protocol.toUtf8().constData());
90
qDebug("DiscName::split: title: '%d'", d.title);
91
qDebug("DiscName::split: device: '%s'", d.device.toUtf8().constData());
93
qWarning("DiscName::split: no match in regular expression");
96
if (ok != 0) (*ok) = success;
101
// This functions remove the trailing "/" from the device
102
// with one exception: from Windows drives letters (D:/ E:/...)
103
QString DiscName::removeTrailingSlash(const QString & device) {
104
QString dev = device;
106
if (dev.endsWith("/")) {
108
QRegExp r("^[A-Z]:/$");
109
int pos = r.indexIn(dev);
110
//qDebug("DiscName::removeTrailingSlash: drive check: '%s': regexp: %d", dev.toUtf8().data(), pos);
113
dev = dev.remove( dev.length()-1, 1);
120
void DiscName::test() {
122
d = split( "vcd://1//dev/dvd/" );
123
d = split( "vcd://1/E:/" );
124
d = split( "vcd://5" );
125
d = split( "vcd://" );
126
d = split( "vcd:////dev/dvdrecorder" );
128
d = split( "dvd://1//dev/dvd" );
129
d = split( "dvd://1/E:" );
130
d = split( "dvd://5" );
131
d = split( "dvd://" );
133
d = split( "dvd:////dev/dvdrecorder" );
135
d = split( "cdda://1//dev/dvd" );
136
d = split( "cdda://1/E:" );
137
d = split( "cdda://5" );
138
d = split( "cdda://" );
139
d = split( "cdda:////dev/dvdrecorder" );
141
d = split( "dvdnav://1//dev/dvd" );
142
d = split( "dvdnav://1/D:/" );
143
d = split( "dvdnav://5" );
144
d = split( "dvdnav://" );
145
d = split( "dvdnav:////dev/dvdrecorder/" );
148
s = join( DVD, 4, "/dev/dvd/" );
149
s = join( DVD, 2, "E:" );
150
s = join( DVD, 3, "E:/" );
151
s = join( DVDNAV, 5, "/dev/dvdrecorder" );
152
s = join( VCD, 1, "/dev/cdrom" );
153
s = join( CDDA, 10, "/dev/cdrom" );
154
s = joinDVD( 1, "/dev/cdrom", false );
155
s = joinDVD( 2, "/dev/cdrom/", true );
156
s = joinDVD( 3, "", true );
157
s = join( VCD, 3, "" );