23 #include <QNetworkReply> 
   28     , mContentLoaded( false )
 
   35   if ( mReply && mReply->isRunning() )
 
   42     mReply->deleteLater();
 
   48   QUrl nextUrlToFetch = url;
 
   49   mContentLoaded = 
false;
 
   52   QNetworkRequest request( nextUrlToFetch );
 
   58     mReply->deleteLater();
 
   63   connect( mReply, SIGNAL( 
finished() ), 
this, SLOT( contentLoaded() ) );
 
   68   if ( !mContentLoaded )
 
   78   if ( !mContentLoaded || !mReply )
 
   83   QByteArray array = mReply->readAll();
 
   86   QTextCodec* codec = codecForHtml( array );
 
   87   return codec->toUnicode( array );
 
   90 QTextCodec* QgsNetworkContentFetcher::codecForHtml( QByteArray& array )
 const 
   97   QTextCodec* codec = QTextCodec::codecForUtfText( array, 0 );
 
  104   QByteArray header = array.left( 1024 ).toLower();
 
  105   int pos = header.indexOf( 
"meta charset=" );
 
  108     pos += int( strlen( 
"meta charset=" ) ) + 1;
 
  109     int pos2 = header.indexOf( 
'\"', pos );
 
  110     QByteArray cs = header.mid( pos, pos2 - pos );
 
  111     codec = QTextCodec::codecForName( cs );
 
  119   codec = QTextCodec::codecForHtml( array, codec );
 
  126   return QTextCodec::codecForName( 
"UTF-8" );
 
  129 void QgsNetworkContentFetcher::contentLoaded( 
bool ok )
 
  133   if ( mReply->error() != QNetworkReply::NoError )
 
  135     QgsMessageLog::logMessage( 
tr( 
"HTTP fetch %1 failed with error %2" ).arg( mReply->url().toString() ).arg( mReply->errorString() ) );
 
  136     mContentLoaded = 
true;
 
  141   QVariant redirect = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
 
  142   if ( redirect.isNull() )
 
  145     QVariant status = mReply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
 
  146     if ( !status.isNull() && status.toInt() >= 400 )
 
  150     mContentLoaded = 
true;
 
  156   mReply->deleteLater();