~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kioslave/audiocd/audiocd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
extern "C"
30
30
{
31
31
        //cdda_interface.h in cdparanoia 10.2 has a member called 'private' which the C++ compiler doesn't like
32
 
        #define private _private   
 
32
        #define private _private
33
33
        #include <cdda_interface.h>
34
34
        #include <cdda_paranoia.h>
35
35
        #undef private
98
98
        Info, // CDDB info
99
99
        Root, // The root directory, shows all these :)
100
100
        FullCD, // Show a single file containing all of the data
101
 
        EncoderDir // A directory created by an encoder
 
101
        EncoderDir, // The root directory created by an encoder
 
102
        SubDir // A directory created from the Album name configuration
102
103
};
103
104
 
104
105
class AudioCDProtocol::Private {
114
115
                req_track = -1;
115
116
                cddbUserChoice = -1;
116
117
        }
117
 
        
 
118
 
118
119
        bool tocsAreDifferent(struct cdrom_drive *drive)
119
120
        {
120
121
                if (tracks != (uint)drive->tracks) return true;
121
122
                for (int i = 0; i < drive->tracks; ++i)
122
123
                {
123
 
                        if (disc_toc[i].dwStartSector != drive->disc_toc[i].dwStartSector || 
 
124
                        if (disc_toc[i].dwStartSector != drive->disc_toc[i].dwStartSector ||
124
125
                            disc_toc[i].bFlags != drive->disc_toc[i].bFlags ||
125
126
                            disc_toc[i].bTrack != drive->disc_toc[i].bTrack) return true;
126
127
                }
127
128
                return false;
128
129
        }
129
 
        
 
130
 
130
131
        void setToc(struct cdrom_drive *drive)
131
132
        {
132
133
                for (int i = 0; i < drive->tracks; ++i)
142
143
        Which_dir which_dir;
143
144
        int req_track;
144
145
        QString fname;
 
146
        QString child_dir;
145
147
        AudioCDEncoder *encoder_dir_type;
146
148
 
147
149
        // Misc settings
166
168
 
167
169
        // Template for ..
168
170
        QString fileNameTemplate; // URL settable
169
 
        QString albumTemplate; // URL settable
 
171
        QString albumNameTemplate; // URL settable
 
172
        QString fileLocationTemplate;  // URL settable
170
173
        QString rsearch;
171
174
        QString rreplace;
172
175
 
173
176
        // Current strings for this CD and or cddb selection
174
177
        QStringList templateTitles;
175
178
        QString templateAlbumName;
 
179
        QString templateFileLocation;
176
180
};
177
181
 
178
182
int paranoia_read_limited_error;
184
188
 
185
189
        // Add encoders
186
190
        AudioCDEncoder::findAllPlugins(this, encoders);
187
 
        encoderTypeCDA = encoderFromExtension(".cda");
188
 
        encoderTypeWAV = encoderFromExtension(".wav");
 
191
        encoderTypeCDA = encoderFromExtension(QLatin1String( ".cda" ));
 
192
        encoderTypeWAV = encoderFromExtension(QLatin1String( ".wav" ));
189
193
}
190
194
 
191
195
AudioCDProtocol::~AudioCDProtocol()
200
204
        AudioCDEncoder *encoder;
201
205
        for (int i = encoders.size()-1; i >= 0; --i) {
202
206
            encoder = encoders.at(i);
203
 
            if(QString(".")+encoder->fileType() == extension)
 
207
            if(QLatin1String(".")+QLatin1String( encoder->fileType() ) == extension)
204
208
                return encoder;
205
209
        }
206
210
        Q_ASSERT(false);
210
214
AudioCDEncoder *AudioCDProtocol::determineEncoder(const QString & filename)
211
215
{
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));
215
219
}
216
220
 
217
221
static void setDeviceToCd(KCompactDisc *cd, struct cdrom_drive *drive)
218
222
{
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
231
235
                // user selected value, even if there is none.
232
236
                //
233
237
                kWarning(7117) << "Found an ATAPI device, assuming it is the one specified by the user.";
234
 
                cd->setDevice( d->device );
 
238
                cd->setDevice( drive->cdda_device_name );
235
239
        }
236
240
        else
237
241
        {
285
289
                KCompactDisc cd(KCompactDisc::Asynchronous);
286
290
                setDeviceToCd(&cd, drive);
287
291
                d->setToc(drive);
288
 
                
 
292
 
289
293
                d->tracks = cd.tracks();
290
294
                for(uint i=0; i< cd.tracks(); i++)
291
295
                        d->trackIsAudio[i] = cd.isAudio(i+1);
301
305
        }
302
306
 
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);
308
 
 
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){
319
 
                dname = d->fname;
320
 
                d->fname = "";
321
 
                break;
322
 
            }
323
 
        }
324
 
        // Other Hard coded directories
325
 
        if (dname.isEmpty() && (d->fname == d->s_info || d->fname == d->s_fullCD ))
326
 
        {
327
 
                dname = d->fname;
328
 
                d->fname = "";
329
 
        }
330
 
        // end hack
331
 
 
332
 
 
333
 
        // See which directory they want
 
308
        QString path = url.path();
 
309
        if (!path.isEmpty() && path[0] == QLatin1Char( '/' ))
 
310
                path = path.mid(1);
 
311
 
 
312
        d->req_allTracks = false;
 
313
 
 
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;
340
 
                        break;
341
 
                }
342
 
        }
343
 
        if ( Unknown == d->which_dir ){
344
 
                if (dname.isEmpty())
345
 
                        d->which_dir = Root;
346
 
                else if (dname == d->s_info)
347
 
                        d->which_dir = Info;
348
 
                else if (dname == d->s_fullCD)
349
 
                        d->which_dir = FullCD;
350
 
        }
 
317
        if (path.isEmpty()) {
 
318
                d->which_dir = Root;
 
319
                d->encoder_dir_type = encoderTypeWAV;
 
320
                remainingDirPath = d->templateFileLocation;
 
321
                d->fname = QString();
 
322
        } else {
 
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();
 
332
                                break;
 
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();
 
338
                                break;
 
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);
 
344
                                break;
 
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);
 
350
                        }
 
351
                }
 
352
                if ( Unknown == d->which_dir ) {
 
353
                        if (path.startsWith(d->s_info)) {
 
354
                                d->which_dir = 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);
 
369
                        } else  {
 
370
                                d->encoder_dir_type = encoderTypeWAV;
 
371
                                remainingDirPath = QString();
 
372
                                d->fname = path;
 
373
                        }
 
374
                }
 
375
        }
 
376
        if (!remainingDirPath.isEmpty() && remainingDirPath[0] == QLatin1Char( '/' ))
 
377
                remainingDirPath = remainingDirPath.mid(1);
 
378
        d->child_dir = remainingDirPath.split(QLatin1String( "/" )).first();
351
379
 
352
380
        // See if the url is a track
353
381
        d->req_track = -1;
355
383
                QString name(d->fname);
356
384
 
357
385
                // Remove extension
358
 
                int dot = name.lastIndexOf('.');
 
386
                int dot = name.lastIndexOf( QLatin1Char( '.' ));
359
387
                if (dot >= 0)
360
388
                        name.truncate(dot);
361
389
 
393
421
        if (d->req_track >= (int)d->tracks)
394
422
                d->req_track = -1;
395
423
 
396
 
        // Are we in the directory that lists "full CD" files?
397
 
        d->req_allTracks = (dname.contains(d->s_fullCD));
398
 
 
399
 
        kDebug(7117) << "dir=" << dname << " file=" << d->fname
 
424
        kDebug(7117) << "path=" << path << " file=" << d->fname
400
425
                << " req_track=" << d->req_track << " which_dir=" << d->which_dir << " full CD?=" << d->req_allTracks << endl;
401
426
        return drive;
402
427
}
428
453
 
429
454
        if( d->fname.contains(i18n(CDDB_INFORMATION))){
430
455
                uint choice = 1;
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();
433
458
                }
434
459
                uint count = 1;
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());
446
471
                        }
447
472
                        count++;
448
473
                }
449
 
                if(!found && d->fname.contains(i18n(CDDB_INFORMATION)+':')){
450
 
                        mimeType("text/html");
 
474
                if(!found && d->fname.contains(i18n(CDDB_INFORMATION)+QLatin1Char( ':' ))){
 
475
                        mimeType(QLatin1String( "text/html" ));
451
476
                        //data(QCString( d->fname.latin1() ));
452
477
                        // send an empty QByteArray to signal end of data.
453
478
                        data(QByteArray());
487
512
                        // YES => the title of the file is the title of the CD
488
513
                        info.track(track-1).set(Title, info.get(Title));
489
514
                }
490
 
                encoder->fillSongInfo(info, track, "");
 
515
                encoder->fillSongInfo(info, track, QString());
491
516
        }
492
517
        long totalByteCount = CD_FRAMESIZE_RAW * (lastSector - firstSector + 1);
493
518
        long time_secs = (8 * totalByteCount) / (44100 * 2 * 16);
531
556
 
532
557
        UDSEntry entry;
533
558
 
534
 
        entry.insert( KIO::UDSEntry::UDS_NAME, url.fileName().replace('/', QLatin1String("%2F") ));
 
559
        entry.insert( KIO::UDSEntry::UDS_NAME, url.fileName().replace(QLatin1Char( '/' ), QLatin1String("%2F") ));
535
560
 
536
561
        entry.insert( KIO::UDSEntry::UDS_FILE_TYPE,isFile ? S_IFREG : S_IFDIR);
537
562
 
568
593
        e.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
569
594
        e.insert( KIO::UDSEntry::UDS_ACCESS, 0400);
570
595
        e.insert( KIO::UDSEntry::UDS_SIZE, s);
571
 
        e.insert( KIO::UDSEntry::UDS_MIME_TYPE, QString("inode/directory"));
 
596
        e.insert( KIO::UDSEntry::UDS_MIME_TYPE, QLatin1String("inode/directory"));
572
597
}
573
598
 
574
599
static void app_file(UDSEntry& e, const QString & n, size_t s, const QString &mimetype = QString())
607
632
        generateTemplateTitles();
608
633
 
609
634
        UDSEntry entry;
610
 
        // If the tracks should be listed in this directory
611
 
        bool list_tracks = true;
612
635
 
613
636
        if (d->which_dir == Info){
614
637
                CDInfoList::iterator it;
616
639
                for ( it = d->cddbList.begin(); it != d->cddbList.end(); ++it ){
617
640
                        (*it).toString();
618
641
                        if(count == 1)
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);
620
643
                        else
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);
622
645
                        count++;
623
646
                        listEntry(entry, false);
624
647
                }
625
648
                // Error
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);
628
651
                        count++;
629
652
                        listEntry(entry, false);
630
653
                }
631
 
 
632
 
                list_tracks = false;
633
654
        }
634
655
 
635
656
        if (d->which_dir == Root){
654
675
        }
655
676
 
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);
665
 
                                else
666
 
                                        addEntry(d->templateAlbumName, encoder, drive, -1);
667
 
                        }
 
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);
 
684
                        else
 
685
                                addEntry(d->templateAlbumName, encoder, drive, -1);
668
686
                }
669
687
        }
670
688
 
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)
674
691
                {
675
 
                        // Skip data tracks
676
 
                        if (!d->trackIsAudio[trackNumber-1])
677
 
                                continue;
 
692
                        // we are at the end of the hierarchy, list the tracks
 
693
                        for (uint trackNumber = 1; trackNumber <= d->tracks; trackNumber++)
 
694
                        {
 
695
                                // Skip data tracks
 
696
                                if (!d->trackIsAudio[trackNumber-1])
 
697
                                        continue;
678
698
 
679
 
                        switch (d->which_dir) {
680
 
                                case Root:{
681
 
                                        addEntry(d->templateTitles[trackNumber - 1],
682
 
                                                encoderTypeWAV, drive, trackNumber);
683
 
                                        break;
 
699
                                switch (d->which_dir) {
 
700
                                        case EncoderDir:
 
701
                                        case SubDir:
 
702
                                        case Root:
 
703
                                                addEntry(d->templateTitles[trackNumber - 1],
 
704
                                                        d->encoder_dir_type, drive, trackNumber);
 
705
                                                break;
 
706
                                        case Info:
 
707
                                        case Unknown:
 
708
                                        default:
 
709
                                                error(KIO::ERR_INTERNAL, url.path());
 
710
                                                cdda_close(drive);
 
711
                                                return;
684
712
                                }
685
 
                                case EncoderDir:
686
 
                                        addEntry(d->templateTitles[trackNumber - 1],
687
 
                                                d->encoder_dir_type, drive, trackNumber);
688
 
                                        break;
689
 
                                case Info:
690
 
                                case Unknown:
691
 
                                default:
692
 
                                        error(KIO::ERR_INTERNAL, url.path());
693
 
                                        cdda_close(drive);
694
 
                                        return;
695
713
                        }
696
714
                }
 
715
 
 
716
                if (!d->child_dir.isEmpty())
 
717
                {
 
718
                        app_dir(entry, d->child_dir, 1);
 
719
                        listEntry(entry, false);
 
720
                }
697
721
        }
698
722
 
699
723
        totalSize(entry.count());
721
745
                theFileSize = fileSize(firstSector, lastSector, encoder);
722
746
        }
723
747
        UDSEntry entry;
724
 
        app_file(entry, trackTitle + QString(".")+encoder->fileType(), theFileSize, encoder->mimeType());
 
748
        app_file(entry, trackTitle + QLatin1String(".")+QLatin1String( encoder->fileType() ), theFileSize, QLatin1String( encoder->mimeType() ));
725
749
        listEntry(entry, false);
726
750
}
727
751
 
742
766
 
743
767
        struct cdrom_drive * drive = 0;
744
768
 
745
 
        if (!device.isEmpty() && device != "/")
 
769
        if (!device.isEmpty() && device != "/" )
746
770
                drive = cdda_identify(device, CDDA_MESSAGE_PRINTIT, 0);
747
771
        else
748
772
        {
859
883
                        QString errMsg = i18n( "Could not read %1: encoding failed", fileName );
860
884
                        QString details = encoder->lastErrorMessage();
861
885
                        if ( !details.isEmpty() )
862
 
                            errMsg += '\n' + details;
 
886
                            errMsg += QLatin1Char( '\n' ) + details;
863
887
                        error( ERR_SLAVE_DEFINED, errMsg );
864
888
                        break;
865
889
                }
950
974
 
951
975
        QString query(QUrl::fromPercentEncoding(url.query().toAscii()));
952
976
 
953
 
        if (query.isEmpty() || query[0] != '?')
 
977
        if (query.isEmpty() || query[0] != QLatin1Char( '?' ))
954
978
                return;
955
979
 
956
980
        query = query.mid(1); // Strip leading '?'.
957
981
 
958
 
        const QStringList tokens(query.split('&',QString::SkipEmptyParts));
 
982
        const QStringList tokens(query.split(QLatin1Char( '&' ),QString::SkipEmptyParts));
959
983
 
960
984
        for (QStringList::ConstIterator it(tokens.constBegin()); it != tokens.constEnd(); ++it)
961
985
        {
962
986
                const QString token(*it);
963
987
 
964
 
                int equalsPos = token.indexOf('=');
 
988
                int equalsPos = token.indexOf(QLatin1Char( '=' ));
965
989
                if (-1 == equalsPos)
966
990
                        continue;
967
991
 
975
999
                else if (attribute == QLatin1String("fileNameTemplate"))
976
1000
                        d->fileNameTemplate = value;
977
1001
                else if (attribute == QLatin1String("albumNameTemplate"))
978
 
                        d->albumTemplate = value;
 
1002
                        d->albumNameTemplate = value;
 
1003
                else if (attribute == QLatin1String("fileLocationTemplate"))
 
1004
                        d->fileLocationTemplate = value;
979
1005
                else if (attribute == QLatin1String("cddbChoice"))
980
1006
                        d->cddbUserChoice = value.toInt();
981
1007
                else if (attribute == QLatin1String("niceLevel")){
1019
1045
        }
1020
1046
 
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());
 
1053
        else
 
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))
1033
1063
        {
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();
1081
1111
                QString n;
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();
1086
1116
 
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);
1090
1120
        }
1091
1121
 
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 );
 
1129
 
 
1130
        d->templateFileLocation = KMacroExpander::expandMacros(d->fileLocationTemplate, macros, QLatin1Char( '%' ));
1099
1131
}
1100
1132
 
1101
1133
/**
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