210
214
AudioCDEncoder *AudioCDProtocol::determineEncoder(const QString & filename)
212
216
int len = filename.length();
213
int pos = filename.lastIndexOf('.');
217
int pos = filename.lastIndexOf( QLatin1Char( '.' ));
214
218
return encoderFromExtension(filename.right(len - pos));
217
221
static void setDeviceToCd(KCompactDisc *cd, struct cdrom_drive *drive)
219
223
#if defined(HAVE_CDDA_IOCTL_DEVICE)
220
cd->setDevice(drive->ioctl_device_name, 50, false);
224
cd->setDevice(QLatin1String( drive->ioctl_device_name ), 50, false);
221
225
#elif defined(__FreeBSD__) || defined(__DragonFly__)
222
226
// FreeBSD's cdparanoia as of january 5th 2006 has rather broken
223
227
// support for non-SCSI devices. Although it finds ATA cdroms just
303
307
// Determine what file or folder that is wanted.
304
d->fname = url.fileName(KUrl::ObeyTrailingSlash);
305
QString dname = url.directory(KUrl::AppendTrailingSlash);
306
if (!dname.isEmpty() && dname[0] == '/')
307
dname = dname.mid(1);
309
// Kong issue where they send dirs as files, double check
310
/* A hack, for when konqi wants to list the directory audiocd:/Bla
311
it really submits this URL, instead of audiocd:/Bla/ to us. We could
312
send (in listDir) the UDSEntry::UDS_NAME as "Bla/" for directories, but then
313
konqi shows them as "Bla//" in the status line. */
314
// See if it is an encoder directory
315
AudioCDEncoder *encoder;
316
for (int i = encoders.size()-1; i >= 0; --i) {
317
encoder = encoders.at(i);
318
if(encoder->type() == d->fname){
324
// Other Hard coded directories
325
if (dname.isEmpty() && (d->fname == d->s_info || d->fname == d->s_fullCD ))
333
// See which directory they want
308
QString path = url.path();
309
if (!path.isEmpty() && path[0] == QLatin1Char( '/' ))
312
d->req_allTracks = false;
314
// See which file and directory they want
315
QString remainingDirPath;
334
316
d->which_dir = Unknown;
335
for (int i = encoders.size()-1; i >= 0; --i) {
336
encoder = encoders.at(i);
337
if(encoder->type() == dname){
338
d->which_dir = EncoderDir;
339
d->encoder_dir_type = encoder;
343
if ( Unknown == d->which_dir ){
346
else if (dname == d->s_info)
348
else if (dname == d->s_fullCD)
349
d->which_dir = FullCD;
317
if (path.isEmpty()) {
319
d->encoder_dir_type = encoderTypeWAV;
320
remainingDirPath = d->templateFileLocation;
321
d->fname = QString();
323
for (int i = encoders.size()-1; i >= 0; --i) {
324
AudioCDEncoder *encoder = encoders.at(i);
325
QString encoderFileLocation = encoder->type();
326
if (!d->templateFileLocation.isEmpty()) encoderFileLocation = encoderFileLocation + QLatin1String( "/" ) + d->templateFileLocation;
327
if (path == encoder->type()) {
328
d->which_dir = EncoderDir;
329
d->encoder_dir_type = encoder;
330
remainingDirPath = encoderFileLocation.mid(path.length());
331
d->fname = QString();
333
} else if (encoderFileLocation.startsWith(path)) {
334
d->which_dir = SubDir;
335
d->encoder_dir_type = encoder;
336
remainingDirPath = encoderFileLocation.mid(path.length());
337
d->fname = QString();
339
} else if (path.startsWith(encoderFileLocation)) {
340
d->which_dir = SubDir;
341
d->encoder_dir_type = encoder;
342
remainingDirPath = QString();
343
d->fname = path.mid(encoderFileLocation.length() + 1);
345
} else if (path.startsWith(encoder->type())) {
346
d->which_dir = EncoderDir;
347
d->encoder_dir_type = encoder;
348
remainingDirPath = QString();
349
d->fname = path.mid(encoder->type().length() + 1);
352
if ( Unknown == d->which_dir ) {
353
if (path.startsWith(d->s_info)) {
355
d->fname = path.mid(d->s_info.length() + 1);
356
} else if (path.startsWith(d->s_fullCD)) {
357
d->which_dir = FullCD;
358
d->fname = path.mid(d->s_fullCD.length() + 1);
359
d->req_allTracks = true;
360
} else if (d->templateFileLocation.startsWith(path)) {
361
d->which_dir = SubDir;
362
d->encoder_dir_type = encoderTypeWAV;
363
remainingDirPath = d->templateFileLocation.mid(path.length());
364
d->fname = QString();
365
} else if (path.startsWith(d->templateFileLocation)) {
366
d->encoder_dir_type = encoderTypeWAV;
367
remainingDirPath = QString();
368
d->fname = path.mid(d->templateFileLocation.length() + 1);
370
d->encoder_dir_type = encoderTypeWAV;
371
remainingDirPath = QString();
376
if (!remainingDirPath.isEmpty() && remainingDirPath[0] == QLatin1Char( '/' ))
377
remainingDirPath = remainingDirPath.mid(1);
378
d->child_dir = remainingDirPath.split(QLatin1String( "/" )).first();
352
380
// See if the url is a track
353
381
d->req_track = -1;
429
454
if( d->fname.contains(i18n(CDDB_INFORMATION))){
431
if(d->fname != QString("%1.txt").arg(i18n(CDDB_INFORMATION))){
432
choice= d->fname.section('_',1,1).section('.',0,0).toInt();
456
if(d->fname != QString::fromLatin1("%1.txt").arg(i18n(CDDB_INFORMATION))){
457
choice= d->fname.section(QLatin1Char( '_' ),1,1).section(QLatin1Char( '.' ),0,0).toInt();
435
460
CDInfoList::iterator it;
436
461
bool found = false;
437
462
for ( it = d->cddbList.begin(); it != d->cddbList.end(); ++it ){
438
463
if(count == choice){
439
mimeType("text/html");
464
mimeType(QLatin1String( "text/html" ));
440
465
data(QByteArray( (*it).toString().toLatin1() ));
441
466
// send an empty QByteArray to signal end of data.
442
467
data(QByteArray());
616
639
for ( it = d->cddbList.begin(); it != d->cddbList.end(); ++it ){
617
640
(*it).toString();
619
app_file(entry, QString("%1.txt").arg(i18n(CDDB_INFORMATION)), ((*it).toString().length())+1);
642
app_file(entry, QString::fromLatin1("%1.txt").arg(i18n(CDDB_INFORMATION)), ((*it).toString().length())+1);
621
app_file(entry, QString("%1_%2.txt").arg(i18n(CDDB_INFORMATION)).arg(count), ((*it).toString().length())+1);
644
app_file(entry, QString::fromLatin1("%1_%2.txt").arg(i18n(CDDB_INFORMATION)).arg(count), ((*it).toString().length())+1);
623
646
listEntry(entry, false);
626
649
if( count == 1 ) {
627
app_file(entry, QString("%1: %2.txt").arg(i18n(CDDB_INFORMATION)).arg(KCDDB::resultToString(d->cddbResult)), 0);
650
app_file(entry, QString::fromLatin1("%1: %2.txt").arg(i18n(CDDB_INFORMATION)).arg(KCDDB::resultToString(d->cddbResult)), 0);
629
652
listEntry(entry, false);
635
656
if (d->which_dir == Root){
656
677
// Now fill in the tracks for the current directory
657
if (list_tracks && d->which_dir == FullCD) {
658
// if we're listing the "full CD" subdirectory :
659
if ( (d->which_dir == FullCD) ) {
660
AudioCDEncoder *encoder;
661
for (int i = encoders.size()-1; i >= 0; --i) {
662
encoder = encoders.at(i);
663
if (d->cddbResult != KCDDB::Success)
664
addEntry(d->s_fullCD, encoder, drive, -1);
666
addEntry(d->templateAlbumName, encoder, drive, -1);
678
if (d->which_dir == FullCD) {
679
AudioCDEncoder *encoder;
680
for (int i = encoders.size()-1; i >= 0; --i) {
681
encoder = encoders.at(i);
682
if (d->cddbResult != KCDDB::Success)
683
addEntry(d->s_fullCD, encoder, drive, -1);
685
addEntry(d->templateAlbumName, encoder, drive, -1);
671
if (list_tracks && d->which_dir != FullCD) {
672
// listing another dir than the "FullCD" one.
673
for (uint trackNumber = 1; trackNumber <= d->tracks; trackNumber++)
689
if (d->which_dir == SubDir || d->which_dir == Root || d->which_dir == EncoderDir) {
690
if (d->child_dir.isEmpty() || d->which_dir == Root || d->which_dir == EncoderDir)
676
if (!d->trackIsAudio[trackNumber-1])
692
// we are at the end of the hierarchy, list the tracks
693
for (uint trackNumber = 1; trackNumber <= d->tracks; trackNumber++)
696
if (!d->trackIsAudio[trackNumber-1])
679
switch (d->which_dir) {
681
addEntry(d->templateTitles[trackNumber - 1],
682
encoderTypeWAV, drive, trackNumber);
699
switch (d->which_dir) {
703
addEntry(d->templateTitles[trackNumber - 1],
704
d->encoder_dir_type, drive, trackNumber);
709
error(KIO::ERR_INTERNAL, url.path());
686
addEntry(d->templateTitles[trackNumber - 1],
687
d->encoder_dir_type, drive, trackNumber);
692
error(KIO::ERR_INTERNAL, url.path());
716
if (!d->child_dir.isEmpty())
718
app_dir(entry, d->child_dir, 1);
719
listEntry(entry, false);
699
723
totalSize(entry.count());
951
975
QString query(QUrl::fromPercentEncoding(url.query().toAscii()));
953
if (query.isEmpty() || query[0] != '?')
977
if (query.isEmpty() || query[0] != QLatin1Char( '?' ))
956
980
query = query.mid(1); // Strip leading '?'.
958
const QStringList tokens(query.split('&',QString::SkipEmptyParts));
982
const QStringList tokens(query.split(QLatin1Char( '&' ),QString::SkipEmptyParts));
960
984
for (QStringList::ConstIterator it(tokens.constBegin()); it != tokens.constEnd(); ++it)
962
986
const QString token(*it);
964
int equalsPos = token.indexOf('=');
988
int equalsPos = token.indexOf(QLatin1Char( '=' ));
965
989
if (-1 == equalsPos)
1021
1047
// The default track filename template
1022
const KConfigGroup groupFileName( config, "FileName" );
1048
const KConfigGroup groupFileName( config, "FileName" );
1023
1049
d->fileNameTemplate = groupFileName.readEntry("file_name_template", "%{trackartist} - %{number} - %{title}");
1024
d->albumTemplate = groupFileName.readEntry("album_template", "%{albumartist} - %{albumtitle}");
1050
d->albumNameTemplate = groupFileName.readEntry("album_name_template", "%{albumartist} - %{albumtitle}");
1051
if (groupFileName.readEntry("show_file_location", false))
1052
d->fileLocationTemplate = groupFileName.readEntry("file_location_template", QString());
1054
d->fileLocationTemplate = QString();
1025
1055
d->rsearch = groupFileName.readEntry("regexp_search");
1026
1056
d->rreplace = groupFileName.readEntry("regexp_replace");
1027
1057
// if the regular expressions are enclosed in qoutes. remove them
1028
1058
// otherwise it is not possible to search for a space " ", since an empty (only spaces) value is not
1029
1059
// supported by KConfig, so the space has to be qouted, but then here the regexp searches really for " "
1030
1060
// instead of just the space. Alex
1031
QRegExp qoutedString("^\".*\"$");
1061
QRegExp qoutedString( QLatin1String( "^\".*\"$" ));
1032
1062
if (qoutedString.exactMatch(d->rsearch))
1034
1064
d->rsearch=d->rsearch.mid(1, d->rsearch.length()-2);
1074
1104
d->templateTitles.clear();
1075
1105
for (uint i = 0; i < d->tracks; i++) {
1076
1106
QHash<QString, QString> macros;
1077
macros["albumartist"] = info.get(Artist).toString();
1078
macros["albumtitle"] = info.get(Title).toString();
1079
macros["title"] = info.track(i).get(Title).toString();
1080
macros["trackartist"] = info.track(i).get(Artist).toString();
1107
macros[QLatin1String( "albumartist" )] = info.get(Artist).toString();
1108
macros[QLatin1String( "albumtitle" )] = info.get(Title).toString();
1109
macros[QLatin1String( "title" )] = info.track(i).get(Title).toString();
1110
macros[QLatin1String( "trackartist" )] = info.track(i).get(Artist).toString();
1082
macros["number"] = n.sprintf("%02d", i + 1);
1112
macros[QLatin1String( "number" )] = n.sprintf("%02d", i + 1);
1083
1113
//macros["number"] = QString("%1").arg(i+1, 2, 10);
1084
macros["genre"] = info.get(Genre).toString();
1085
macros["year"] = info.get(Year).toString();
1114
macros[QLatin1String( "genre" )] = info.get(Genre).toString();
1115
macros[QLatin1String( "year" )] = info.get(Year).toString();
1087
QString title = KMacroExpander::expandMacros(d->fileNameTemplate, macros, '%').replace('/', QLatin1String("%2F"));
1117
QString title = KMacroExpander::expandMacros(d->fileNameTemplate, macros, QLatin1Char( '%' )).replace(QLatin1Char( '/' ), QLatin1String("%2F"));
1088
1118
title.replace( QRegExp(d->rsearch), d->rreplace );
1089
1119
d->templateTitles.append(title);
1092
1122
QHash<QString, QString> macros;
1093
macros["albumartist"] = info.get(Artist).toString();
1094
macros["albumtitle"] = info.get(Title).toString();
1095
macros["genre"] = info.get(Genre).toString();
1096
macros["year"] = info.get(Year).toString();
1097
d->templateAlbumName = KMacroExpander::expandMacros(d->albumTemplate, macros, '%').replace('/', QLatin1String("%2F"));
1123
macros[QLatin1String( "albumartist" )] = info.get(Artist).toString();
1124
macros[QLatin1String( "albumtitle" )] = info.get(Title).toString();
1125
macros[QLatin1String( "genre" )] = info.get(Genre).toString();
1126
macros[QLatin1String( "year" )] = info.get(Year).toString();
1127
d->templateAlbumName = KMacroExpander::expandMacros(d->albumNameTemplate, macros, QLatin1Char( '%' )).replace(QLatin1Char( '/' ), QLatin1String("%2F"));
1098
1128
d->templateAlbumName.replace( QRegExp(d->rsearch), d->rreplace );
1130
d->templateFileLocation = KMacroExpander::expandMacros(d->fileLocationTemplate, macros, QLatin1Char( '%' ));
1102
* Based upon the cdparinoia ripping application
1134
* Based upon the cdparanoia ripping application
1103
1135
* Only output BAD stuff
1104
1136
* The higher the paranoia_read_limited_error the worse the problem is
1105
1137
* FYI: PARANOIA_CB_READ & PARANOIA_CB_VERIFY happen continusly when ripping