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

« back to all changes in this revision

Viewing changes to libkcddb/cdinfo.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:
51
51
 
52
52
        while (tmpValue.length() > maxLength)
53
53
        {
54
 
          lines += QString("%1=%2\n").arg(name,tmpValue.left(maxLength));
 
54
            lines += QString::fromLatin1("%1=%2\n").arg(name,tmpValue.left(maxLength));
55
55
          tmpValue = tmpValue.mid(maxLength);
56
56
        }
57
57
 
58
 
        lines += QString("%1=%2\n").arg(name,tmpValue);
 
58
        lines += QString::fromLatin1("%1=%2\n").arg(name,tmpValue);
59
59
 
60
60
        return lines;
61
61
      }
67
67
      escape( const QString &value )
68
68
      {
69
69
        QString s = value;
70
 
        s.replace( "\\", "\\\\" );
71
 
        s.replace( "\n", "\\n" );
72
 
        s.replace( "\t", "\\t" );
 
70
        s.replace( QLatin1String( "\\" ), QLatin1String( "\\\\" ) );
 
71
        s.replace( QLatin1String( "\n" ), QLatin1String( "\\n" ) );
 
72
        s.replace( QLatin1String( "\t" ), QLatin1String( "\\t" ) );
73
73
 
74
74
        return s;
75
75
      }
82
82
      {
83
83
        QString s = value;
84
84
 
85
 
        s.replace( "\\n", "\n" );
86
 
        s.replace( "\\t", "\t" );
87
 
        s.replace( "\\\\", "\\" );
 
85
        s.replace( QLatin1String( "\\n" ), QLatin1String( "\n" ) );
 
86
        s.replace( QLatin1String( "\\t" ), QLatin1String( "\t" ) );
 
87
        s.replace( QLatin1String( "\\\\" ), QLatin1String( "\\" ) );
88
88
 
89
89
        return s;
90
90
      }
99
99
      {
100
100
        switch(type){
101
101
          case(Title):
102
 
            return get("title");
 
102
            return get(QLatin1String( "title" ));
103
103
          case(Comment):
104
 
            return get("comment");
 
104
            return get(QLatin1String( "comment" ));
105
105
          case(Artist):
106
 
            return get("artist");
 
106
            return get(QLatin1String( "artist" ));
107
107
          case(Genre):
108
 
            return get("genre");
 
108
            return get(QLatin1String( "genre" ));
109
109
          case(Year):
110
 
            return get("year");
 
110
            return get(QLatin1String( "year" ));
111
111
          case(Length):
112
 
            return get("length");
 
112
            return get(QLatin1String( "length" ));
113
113
          case(Category):
114
 
            return get("category");
 
114
            return get(QLatin1String( "category" ));
115
115
        }
116
116
        return QVariant();
117
117
      }
120
120
      set(const QString& type, const QVariant &d)
121
121
      {
122
122
        //kDebug() << "set: " << type << ", " << d.toString();
123
 
        if(type.contains(QRegExp( "^T.*_.*$" ) )){
 
123
        if(type.contains(QRegExp( QLatin1String( "^T.*_.*$" )) )){
124
124
          kDebug(60010) << "Error: custom cdinfo::set data can not start with T and contain a _";
125
125
          return;
126
126
        }
127
 
        if(type.toUpper() == "DTITLE"){
 
127
        if(type.toUpper() == QLatin1String( "DTITLE" )){
128
128
          kDebug(60010) << "Error: type: DTITLE is reserved and can not be set.";
129
129
          return;
130
130
        }
137
137
        switch(type)
138
138
        {
139
139
          case(Title):
140
 
            set("title", d);
 
140
            set(QLatin1String( "title" ), d);
141
141
            return;
142
142
          case(Comment):
143
 
            set("comment", d);
 
143
            set(QLatin1String( "comment" ), d);
144
144
            return;
145
145
          case(Artist):
146
 
            set("artist", d);
 
146
            set(QLatin1String( "artist" ), d);
147
147
            return;
148
148
          case(Genre):
149
 
            set("genre", d);
 
149
            set(QLatin1String( "genre" ), d);
150
150
            return;
151
151
          case(Year):
152
 
            set("year", d);
 
152
            set(QLatin1String( "year" ), d);
153
153
            return;
154
154
          case(Length):
155
 
            set("length", d);
 
155
            set(QLatin1String( "length" ), d);
156
156
            return;
157
157
          case(Category):
158
 
            set("category", d);
 
158
            set(QLatin1String( "category" ), d);
159
159
            return;
160
160
        }
161
161
 
225
225
  QString TrackInfo::toString() const {
226
226
    QString out;
227
227
    bool ok;
228
 
    int track = get("tracknumber").toInt(&ok);
 
228
    int track = get(QLatin1String( "tracknumber" )).toInt(&ok);
229
229
    if(!ok)
230
230
      kDebug(60010) << "Warning toString() on a track that doesn't have track number assigned.";
231
231
    QMap<QString, QVariant>::const_iterator i = d->data.constBegin();
232
232
    while (i != d->data.constEnd()) {
233
 
        if(i.key() != "COMMENT" && i.key() != "TITLE" && i.key() != "ARTIST" && i.key() != "TRACKNUMBER") {
234
 
          out += d->createLine(QString("T%1_%2").arg(i.key()).arg(track),i.value().toString());
 
233
        if(i.key() != QLatin1String( "COMMENT" ) && i.key() != QLatin1String( "TITLE" ) && i.key() != QLatin1String( "ARTIST" ) && i.key() != QLatin1String( "TRACKNUMBER" )) {
 
234
            out += d->createLine(QString::fromLatin1("T%1_%2").arg(i.key()).arg(track),i.value().toString());
235
235
        }
236
236
        ++i;
237
237
    }
256
256
  CDInfo::CDInfo()
257
257
    : d(new CDInfoPrivate())
258
258
  {
259
 
    set("revision", 0);
 
259
    set(QLatin1String( "revision" ), 0);
260
260
  }
261
261
 
262
262
  CDInfo::CDInfo(const CDInfo& clone)
281
281
    bool
282
282
  CDInfo::load(const QString & string)
283
283
  {
284
 
    return load(string.split('\n',QString::SkipEmptyParts));
 
284
    return load(string.split(QLatin1Char( '\n' ),QString::SkipEmptyParts));
285
285
  }
286
286
 
287
287
    bool
294
294
 
295
295
    QStringList::ConstIterator it = lineList.begin();
296
296
 
297
 
    QRegExp rev("# Revision: (\\d+)");
298
 
    QRegExp eol("[\r\n]");
 
297
    QRegExp rev(QLatin1String( "# Revision: (\\d+)" ));
 
298
    QRegExp eol(QLatin1String( "[\r\n]" ));
299
299
 
300
300
    while ( it != lineList.end() )
301
301
    {
302
302
      QString line(*it);
303
 
      line.replace(eol,"");
 
303
      line.replace(eol,QLatin1String( "" ));
304
304
      ++it;
305
305
 
306
306
      if (rev.indexIn(line) != -1)
307
307
      {
308
 
        set("revision", rev.cap(1).toUInt());
 
308
        set(QLatin1String( "revision" ), rev.cap(1).toUInt());
309
309
        continue;
310
310
      }
311
311
 
312
 
      QStringList tokenList = KStringHandler::perlSplit('=', line, 2);
 
312
      QStringList tokenList = KStringHandler::perlSplit(QLatin1Char( '=' ), line, 2);
313
313
 
314
314
      if (2 != tokenList.count())
315
315
      {
319
319
      QString key = tokenList[0].trimmed();
320
320
      QString value = d->unescape ( tokenList[1] );
321
321
 
322
 
      if ( "DTITLE" == key )
 
322
      if ( QLatin1String( "DTITLE" ) == key )
323
323
      {
324
324
        dtitle += value;
325
325
      }
326
 
      else if ( key.startsWith("TTITLE") )
 
326
      else if ( key.startsWith(QLatin1String( "TTITLE" )) )
327
327
      {
328
328
        uint trackNumber = key.mid(6).toUInt();
329
329
 
331
331
        ti.set(Title, ti.get(Title).toString().append(value));
332
332
      }
333
333
 
334
 
      else if ( "EXTD" == key )
 
334
      else if ( QLatin1String( "EXTD" ) == key )
335
335
      {
336
336
        d->append(Comment, value);
337
337
      }
338
 
      else if ( "DGENRE" == key )
 
338
      else if ( QLatin1String( "DGENRE" ) == key )
339
339
      {
340
340
        d->append(Genre, value);
341
341
      }
342
 
      else if ( "DYEAR" == key )
 
342
      else if ( QLatin1String( "DYEAR" ) == key )
343
343
      {
344
344
        set(Year, value);
345
345
      }
346
 
      else if ( key.startsWith("EXTT") )
 
346
      else if ( key.startsWith(QLatin1String( "EXTT" )) )
347
347
      {
348
348
        uint trackNumber = key.mid( 4 ).toUInt();
349
349
 
352
352
        QString extt = track(trackNumber).get(Comment).toString();
353
353
        track(trackNumber).set(Comment, extt+value );
354
354
      }
355
 
      else if ( key.startsWith("T") )
 
355
      else if ( key.startsWith(QLatin1String( "T" )) )
356
356
      {
357
357
        // Custom Track data
358
 
        uint trackNumber = key.mid( key.indexOf('_')+1 ).toUInt();
 
358
        uint trackNumber = key.mid( key.indexOf(QLatin1Char( '_' ))+1 ).toUInt();
359
359
        checkTrack( trackNumber );
360
360
 
361
 
        QRegExp data(QString("^T.*_%1$").arg(trackNumber));
 
361
        QRegExp data(QString::fromLatin1("^T.*_%1$").arg(trackNumber));
362
362
        if  ( key.contains( data ) )
363
363
        {
364
 
          QString k = key.mid(1, key.indexOf('_')-1);
 
364
          QString k = key.mid(1, key.indexOf(QLatin1Char( '_' ))-1);
365
365
          TrackInfo& ti = track(trackNumber);
366
366
          ti.set( k, ti.get(k).toString().append(value) );
367
367
        }
373
373
      }
374
374
    }
375
375
 
376
 
    int slashPos = dtitle.indexOf(" / ");
 
376
    int slashPos = dtitle.indexOf(QLatin1String( " / " ));
377
377
 
378
378
    if (-1 == slashPos)
379
379
    {
390
390
    bool isSampler = true;
391
391
    for (TrackInfoList::Iterator it = d->trackInfoList.begin(); it != d->trackInfoList.end(); ++it)
392
392
    {
393
 
      if (!(*it).get(Title).toString().contains(" / "))
 
393
      if (!(*it).get(Title).toString().contains(QLatin1String( " / " )))
394
394
      {
395
395
        isSampler = false;
396
396
      }
399
399
    {
400
400
      if (isSampler)
401
401
      {
402
 
        int delimiter = (*it).get(Title).toString().indexOf(" / ");
 
402
        int delimiter = (*it).get(Title).toString().indexOf(QLatin1String( " / " ));
403
403
        (*it).set(Artist, (*it).get(Title).toString().left(delimiter));
404
404
        (*it).set(Title, (*it).get(Title).toString().mid(delimiter + 3));
405
405
      }
410
410
    }
411
411
 
412
412
    if ( get(Genre).toString().isEmpty() )
413
 
      set(Genre, "Unknown");
 
413
      set(Genre, QLatin1String( "Unknown" ));
414
414
 
415
 
    kDebug(60010) << "Loaded CDInfo for " << get("discid").toString();
 
415
    kDebug(60010) << "Loaded CDInfo for " << get(QLatin1String( "discid" )).toString();
416
416
 
417
417
    return true;
418
418
  }
422
422
  {
423
423
    QString s;
424
424
 
425
 
    if (get("revision") != 0)
426
 
      s += "# Revision: " + get("revision").toString() + '\n';
 
425
    if (get(QLatin1String( "revision" )) != 0)
 
426
      s += QLatin1String( "# Revision: " ) + get(QLatin1String( "revision" )).toString() + QLatin1Char( '\n' );
427
427
 
428
428
    // If we are submiting make it a fully compliant CDDB entry
429
429
    if (submit)
430
430
    {
431
 
      s += "#\n";
432
 
      s += QString("# Submitted via: %1 %2\n").arg(CDDB::clientName(),
 
431
      s += QLatin1String( "#\n" );
 
432
      s += QString::fromLatin1("# Submitted via: %1 %2\n").arg(CDDB::clientName(),
433
433
        CDDB::clientVersion());
434
434
    }
435
435
 
436
 
    s += d->createLine("DISCID", get("discid").toString() );
 
436
    s += d->createLine(QLatin1String( "DISCID" ), get(QLatin1String( "discid" )).toString() );
437
437
    QString artist = get(Artist).toString();
438
 
    s += d->createLine("DTITLE", artist + " / " + get(Title).toString() );
 
438
    s += d->createLine(QLatin1String( "DTITLE" ), artist + QLatin1String( " / " ) + get(Title).toString() );
439
439
    int year = get(Year).toInt();
440
 
    s += "DYEAR=" + (0 == year ? QString::null : QString::number(year)) + '\n'; //krazy:exclude=nullstrassign for old broken gcc
441
 
    if (get(Genre) == "Unknown")
442
 
      s += d->createLine("DGENRE", "");
 
440
    s += QLatin1String( "DYEAR=" ) + (0 == year ? QString::null : QString::number(year)) + QLatin1Char( '\n' ); //krazy:exclude=nullstrassign for old broken gcc
 
441
    if (get(Genre) == QLatin1String( "Unknown" ))
 
442
      s += d->createLine(QLatin1String( "DGENRE" ), QString());
443
443
    else
444
 
      s += d->createLine("DGENRE",get(Genre).toString());
 
444
      s += d->createLine(QLatin1String( "DGENRE" ),get(Genre).toString());
445
445
 
446
446
    for (int i = 0; i < d->trackInfoList.count(); ++i){
447
447
      QString trackTitle = d->trackInfoList[i].get(Title).toString();
448
448
      QString trackArtist = d->trackInfoList[i].get(Artist).toString();
449
449
      if(trackArtist != artist && !trackArtist.isEmpty())
450
 
        s += d->createLine(QString("TTITLE%1").arg(i), QString("%1 / %2").arg(trackArtist).arg(trackTitle));
 
450
          s += d->createLine(QString::fromLatin1("TTITLE%1").arg(i), QString::fromLatin1("%1 / %2").arg(trackArtist).arg(trackTitle));
451
451
      else
452
 
        s += d->createLine(QString("TTITLE%1").arg(i), trackTitle);
 
452
          s += d->createLine(QString::fromLatin1("TTITLE%1").arg(i), trackTitle);
453
453
    }
454
454
 
455
 
    s += d->createLine(QString("EXTD"), get(Comment).toString());
 
455
    s += d->createLine(QLatin1String("EXTD"), get(Comment).toString());
456
456
 
457
457
    for (int i = 0; i < d->trackInfoList.count(); ++i)
458
 
      s += d->createLine(QString("EXTT%1").arg(i), d->trackInfoList[i].get(Comment).toString());
 
458
        s += d->createLine(QString::fromLatin1("EXTT%1").arg(i), d->trackInfoList[i].get(Comment).toString());
459
459
 
460
460
    if (submit)
461
461
    {
462
 
      s += d->createLine("PLAYORDER", "");
 
462
      s += d->createLine(QLatin1String( "PLAYORDER" ), QString());
463
463
      return s;
464
464
    }
465
465
 
466
 
    s += d->createLine("PLAYORDER", get("playorder").toString() );
 
466
    s += d->createLine(QLatin1String( "PLAYORDER" ), get(QLatin1String( "playorder" )).toString() );
467
467
 
468
468
    // Custom track data
469
469
    for (int i = 0; i < d->trackInfoList.count(); ++i)
471
471
 
472
472
    QStringList cddbKeywords;
473
473
    cddbKeywords
474
 
      << "DISCID"
475
 
      << "ARTIST"
476
 
      << "TITLE"
477
 
      << "COMMENT"
478
 
      << "YEAR"
479
 
      << "GENRE"
480
 
      << "PLAYORDER"
481
 
      << "CATEGORY"
482
 
      << "REVISION";
 
474
      << QLatin1String( "DISCID" )
 
475
      << QLatin1String( "ARTIST" )
 
476
      << QLatin1String( "TITLE" )
 
477
      << QLatin1String( "COMMENT" )
 
478
      << QLatin1String( "YEAR" )
 
479
      << QLatin1String( "GENRE" )
 
480
      << QLatin1String( "PLAYORDER" )
 
481
      << QLatin1String( "CATEGORY" )
 
482
      << QLatin1String( "REVISION" );
483
483
 
484
484
    // Custom disc data
485
485
    QMap<QString, QVariant>::const_iterator i = d->data.constBegin();
486
486
    while (i != d->data.constEnd()){
487
 
      if (!cddbKeywords.contains(i.key()) && i.key() != "SOURCE")
 
487
      if (!cddbKeywords.contains(i.key()) && i.key() != QLatin1String( "SOURCE" ))
488
488
      {
489
489
        s+= d->createLine(i.key(), i.value().toString());
490
490
      }
517
517
    while ( d->trackInfoList.count() <= trackNumber ){
518
518
      int count = d->trackInfoList.count();
519
519
      d->trackInfoList.append(TrackInfo());
520
 
      d->trackInfoList[count].set("tracknumber", count);
 
520
      d->trackInfoList[count].set(QLatin1String( "tracknumber" ), count);
521
521
    }
522
522
  }
523
523
 
531
531
    bool
532
532
  CDInfo::isValid() const
533
533
  {
534
 
    QString discid = get("DISCID").toString();
 
534
    QString discid = get(QLatin1String( "DISCID" )).toString();
535
535
    if (discid.isEmpty())
536
536
      return false;
537
537
 
538
 
    if (discid == "0")
 
538
    if (discid == QLatin1String( "0" ))
539
539
      return false;
540
540
 
541
541
    return true;