Beispiel #1
0
void
AsyncCDDBPLookup::parseCDInfoData()
{
    CDInfo info;

    if (info.load( cdInfoBuffer_ ))
    {
        info.set( QLatin1String( "category" ), category_ );
        info.set( QLatin1String( "discid" ), discid_ );
        info.set( QLatin1String( "source" ), QLatin1String( "freedb" ) );
        cdInfoList_.append( info );
    }

    cdInfoBuffer_.clear();
}
Beispiel #2
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;
  }
Beispiel #3
0
    void
  HTTPLookup::jobFinished()
  {
    QStringList lineList = QString::fromUtf8(data_).split( QLatin1String( "\n" ), QString::SkipEmptyParts );
    QStringList::ConstIterator it = lineList.constBegin();

    switch ( state_ )
    {
      case WaitingForQueryResponse:

        if ( it != lineList.constEnd() )
        {
          QString line( *it );

          result_ = parseQuery( line );

          switch ( result_ )
          {
            case Success:

              if ( !block_ )
                emit queryReady();
              break;

            case MultipleRecordFound:

              ++it;
              while ( it != lineList.constEnd() )
              {
                QString line( *it );

                if ( QLatin1Char( '.' ) == line[ 0 ] )
                {
                  result_ = Success;

                  if ( !block_ )
                    emit queryReady();
                  break;
                }

                parseExtraMatch( line );
                ++it;
              }

              break;

            case ServerError:
            case NoRecordFound:
              if ( !block_ )
                emit queryReady();

              return;
              break;

            default:

              break;
          }

        }

        break;

      case WaitingForReadResponse:

        {
          CDInfo info;

          if ( info.load( QString::fromUtf8(data_) ) )
          {
            info.set( QLatin1String( "category" ), category_ );
            info.set( QLatin1String( "discid" ), discid_ );
            info.set( QLatin1String( "source" ), QLatin1String( "freedb" ) );
            cdInfoList_.append( info );
          }

          if ( !block_ )
            emit readReady();
        }

        return;

        break;

      default:

        break;
    }

    result_ = Success;
  }