source: smplayer/trunk/src/discname.cpp@ 167

Last change on this file since 167 was 165, checked in by Silvan Scherrer, 11 years ago

SMPlayer: update trunk to latest 0.8.7

  • Property svn:eol-style set to LF
File size: 4.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 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#include "discname.h"
20#include <QRegExp>
21
22QString DiscName::joinDVD(int title, const QString & device, bool use_dvdnav) {
23 return join(use_dvdnav ? DVDNAV : DVD, title, device);
24}
25
26QString 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);
30
31 qDebug("DiscName::join: result: '%s'", s.toUtf8().constData());
32 return s;
33}
34
35QString DiscName::join(Disc type, int title, const QString & device) {
36 QString protocol;
37 switch (type) {
38 case DVD: protocol = "dvd"; break;
39 case DVDNAV: protocol = "dvdnav"; break;
40 case VCD: protocol = "vcd"; break;
41 case CDDA: protocol = "cdda"; break;
42 case BLURAY: protocol = "br"; break;
43 }
44 return join( DiscData(protocol, title, device) );
45}
46
47DiscData DiscName::split(const QString & disc_url, bool * ok) {
48 qDebug("DiscName::split: disc_url: '%s'", disc_url.toUtf8().constData());
49
50 QRegExp rx1("^(dvd|dvdnav|vcd|cdda|br)://(\\d+)/(.*)");
51 QRegExp rx2("^(dvd|dvdnav|vcd|cdda|br)://(\\d+)");
52 QRegExp rx3("^(dvd|dvdnav|vcd|cdda|br):///(.*)");
53 QRegExp rx4("^(dvd|dvdnav|vcd|cdda|br):(.*)");
54
55 DiscData d;
56
57 bool success = false;
58
59 if (rx1.indexIn(disc_url) != -1) {
60 d.protocol = rx1.cap(1);
61 d.title = rx1.cap(2).toInt();
62 d.device = rx1.cap(3);
63 success = true;
64 }
65 else
66 if (rx2.indexIn(disc_url) != -1) {
67 d.protocol = rx2.cap(1);
68 d.title = rx2.cap(2).toInt();
69 d.device = "";
70 success = true;
71 }
72 else
73 if (rx3.indexIn(disc_url) != -1) {
74 d.protocol = rx3.cap(1);
75 d.title = 0;
76 d.device = rx3.cap(2);
77 success = true;
78 }
79 else
80 if (rx4.indexIn(disc_url) != -1) {
81 d.protocol = rx4.cap(1);
82 d.title = 0;
83 d.device ="";
84 success = true;
85 }
86
87 if (!d.device.isEmpty()) d.device = removeTrailingSlash(d.device);
88
89 if (success) {
90 qDebug("DiscName::split: protocol: '%s'", d.protocol.toUtf8().constData());
91 qDebug("DiscName::split: title: '%d'", d.title);
92 qDebug("DiscName::split: device: '%s'", d.device.toUtf8().constData());
93 } else {
94 qWarning("DiscName::split: no match in regular expression");
95 }
96
97 if (ok != 0) (*ok) = success;
98
99 return d;
100}
101
102// This functions remove the trailing "/" from the device
103// with one exception: from Windows drives letters (D:/ E:/...)
104QString DiscName::removeTrailingSlash(const QString & device) {
105 QString dev = device;
106
107 if (dev.endsWith("/")) {
108#ifdef Q_OS_WIN
109 QRegExp r("^[A-Z]:/$");
110 int pos = r.indexIn(dev);
111 //qDebug("DiscName::removeTrailingSlash: drive check: '%s': regexp: %d", dev.toUtf8().data(), pos);
112 if (pos == -1)
113#endif
114 dev = dev.remove( dev.length()-1, 1);
115 }
116
117 return dev;
118}
119
120#if DISCNAME_TEST
121void DiscName::test() {
122 DiscData d;
123 d = split( "vcd://1//dev/dvd/" );
124 d = split( "vcd://1/E:/" );
125 d = split( "vcd://5" );
126 d = split( "vcd://" );
127 d = split( "vcd:////dev/dvdrecorder" );
128
129 d = split( "dvd://1//dev/dvd" );
130 d = split( "dvd://1/E:" );
131 d = split( "dvd://5" );
132 d = split( "dvd://" );
133 d = split( "dvd:" );
134 d = split( "dvd:////dev/dvdrecorder" );
135
136 d = split( "cdda://1//dev/dvd" );
137 d = split( "cdda://1/E:" );
138 d = split( "cdda://5" );
139 d = split( "cdda://" );
140 d = split( "cdda:////dev/dvdrecorder" );
141
142 d = split( "dvdnav://1//dev/dvd" );
143 d = split( "dvdnav://1/D:/" );
144 d = split( "dvdnav://5" );
145 d = split( "dvdnav://" );
146 d = split( "dvdnav:////dev/dvdrecorder/" );
147
148 d = split( "br://1//dev/dvd" );
149 d = split( "br://1/D:/" );
150 d = split( "br://5" );
151 d = split( "br://" );
152 d = split( "br:////dev/dvdrecorder/" );
153
154 QString s;
155 s = join( DVD, 4, "/dev/dvd/" );
156 s = join( DVD, 2, "E:" );
157 s = join( DVD, 3, "E:/" );
158 s = join( DVDNAV, 5, "/dev/dvdrecorder" );
159 s = join( VCD, 1, "/dev/cdrom" );
160 s = join( CDDA, 10, "/dev/cdrom" );
161 s = joinDVD( 1, "/dev/cdrom", false );
162 s = joinDVD( 2, "/dev/cdrom/", true );
163 s = joinDVD( 3, "", true );
164 s = join( VCD, 3, "" );
165 s = join( BLURAY, 2, "/dev/cdrom");
166}
167#endif
Note: See TracBrowser for help on using the repository browser.