Exemple #1
0
    CDInfoList
  Cache::lookup( const QString &cddbId )
  {
    kdDebug(60010) << "Looking up " << cddbId << " in CDDB cache" << endl;

    CDInfoList infoList;
    Config c;
    c.readConfig();
    QStringList cddbCacheDirs = c.cacheLocations();

    for (QStringList::Iterator cddbCacheDir = cddbCacheDirs.begin();
        cddbCacheDir != cddbCacheDirs.end(); ++cddbCacheDir)
    {
      QDir dir( *cddbCacheDir );
      QStringList dirList = dir.entryList( QDir::Dirs );

      QStringList::ConstIterator it = dirList.begin();

      while ( it != dirList.end() )
      {
        QString category( *it );
        if ( category[ 0 ] != '.' )
        {
          QFile f( *cddbCacheDir + "/" + category + "/" + cddbId );
          if ( f.exists() && f.open(IO_ReadOnly) )
          {
              QTextStream ts(&f);
              ts.setEncoding(QTextStream::UnicodeUTF8);
              QString cddbData = ts.read();
              f.close();
              CDInfo info;
              info.load(cddbData);
              info.category = category;

              infoList.append( info );
          }
        }
        ++it;
      }
    }

    return infoList;
  }