1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/* smplayer, GUI front-end for mplayer.
Copyright (C) 2006-2018 Ricardo Villalba <rvm@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "discname.h"
#include <QRegExp>
QString DiscName::joinDVD(int title, const QString & device, bool use_dvdnav) {
return join(use_dvdnav ? DVDNAV : DVD, title, device);
}
QString DiscName::join(const DiscData & d) {
QString s = d.protocol + "://";
/* if (d.title > 0) */ s += QString::number(d.title);
if (!d.device.isEmpty()) s+= "/" + removeTrailingSlash(d.device);
qDebug("DiscName::join: result: '%s'", s.toUtf8().constData());
return s;
}
QString DiscName::join(Disc type, int title, const QString & device) {
QString protocol;
switch (type) {
case DVD: protocol = "dvd"; break;
case DVDNAV: protocol = "dvdnav"; break;
case VCD: protocol = "vcd"; break;
case CDDA: protocol = "cdda"; break;
case BLURAY: protocol = "br"; break;
}
return join( DiscData(protocol, title, device) );
}
DiscData DiscName::split(const QString & disc_url, bool * ok) {
qDebug("DiscName::split: disc_url: '%s'", disc_url.toUtf8().constData());
QRegExp rx1("^(dvd|dvdnav|vcd|cdda|br)://(\\d+)/(.*)");
QRegExp rx2("^(dvd|dvdnav|vcd|cdda|br)://(\\d+)");
QRegExp rx3("^(dvd|dvdnav|vcd|cdda|br):///(.*)");
QRegExp rx4("^(dvd|dvdnav|vcd|cdda|br):(.*)");
DiscData d;
bool success = false;
if (rx1.indexIn(disc_url) != -1) {
d.protocol = rx1.cap(1);
d.title = rx1.cap(2).toInt();
d.device = rx1.cap(3);
success = true;
}
else
if (rx2.indexIn(disc_url) != -1) {
d.protocol = rx2.cap(1);
d.title = rx2.cap(2).toInt();
d.device = "";
success = true;
}
else
if (rx3.indexIn(disc_url) != -1) {
d.protocol = rx3.cap(1);
d.title = 0;
d.device = rx3.cap(2);
success = true;
}
else
if (rx4.indexIn(disc_url) != -1) {
d.protocol = rx4.cap(1);
d.title = 0;
d.device ="";
success = true;
}
if (!d.device.isEmpty()) d.device = removeTrailingSlash(d.device);
if (success) {
qDebug("DiscName::split: protocol: '%s'", d.protocol.toUtf8().constData());
qDebug("DiscName::split: title: '%d'", d.title);
qDebug("DiscName::split: device: '%s'", d.device.toUtf8().constData());
} else {
qWarning("DiscName::split: no match in regular expression");
}
if (ok != 0) (*ok) = success;
return d;
}
// This functions remove the trailing "/" from the device
// with one exception: from Windows drives letters (D:/ E:/...)
QString DiscName::removeTrailingSlash(const QString & device) {
QString dev = device;
if (dev.endsWith("/")) {
#ifdef Q_OS_WIN
QRegExp r("^[A-Z]:/$");
int pos = r.indexIn(dev);
//qDebug("DiscName::removeTrailingSlash: drive check: '%s': regexp: %d", dev.toUtf8().data(), pos);
if (pos == -1)
#endif
dev = dev.remove( dev.length()-1, 1);
}
return dev;
}
#if DISCNAME_TEST
void DiscName::test() {
DiscData d;
d = split( "vcd://1//dev/dvd/" );
d = split( "vcd://1/E:/" );
d = split( "vcd://5" );
d = split( "vcd://" );
d = split( "vcd:////dev/dvdrecorder" );
d = split( "dvd://1//dev/dvd" );
d = split( "dvd://1/E:" );
d = split( "dvd://5" );
d = split( "dvd://" );
d = split( "dvd:" );
d = split( "dvd:////dev/dvdrecorder" );
d = split( "cdda://1//dev/dvd" );
d = split( "cdda://1/E:" );
d = split( "cdda://5" );
d = split( "cdda://" );
d = split( "cdda:////dev/dvdrecorder" );
d = split( "dvdnav://1//dev/dvd" );
d = split( "dvdnav://1/D:/" );
d = split( "dvdnav://5" );
d = split( "dvdnav://" );
d = split( "dvdnav:////dev/dvdrecorder/" );
d = split( "br://1//dev/dvd" );
d = split( "br://1/D:/" );
d = split( "br://5" );
d = split( "br://" );
d = split( "br:////dev/dvdrecorder/" );
QString s;
s = join( DVD, 4, "/dev/dvd/" );
s = join( DVD, 2, "E:" );
s = join( DVD, 3, "E:/" );
s = join( DVDNAV, 5, "/dev/dvdrecorder" );
s = join( VCD, 1, "/dev/cdrom" );
s = join( CDDA, 10, "/dev/cdrom" );
s = joinDVD( 1, "/dev/cdrom", false );
s = joinDVD( 2, "/dev/cdrom/", true );
s = joinDVD( 3, "", true );
s = join( VCD, 3, "" );
s = join( BLURAY, 2, "/dev/cdrom");
}
#endif
|