Changeset 11053 for trunk/qt/favicon.cc


Ignore:
Timestamp:
Jul 25, 2010, 5:42:43 PM (12 years ago)
Author:
charles
Message:

(trunk qt) readability changes to the favicon cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/favicon.cc

    r11052 r11053  
    1111 */
    1212
    13 #include <iostream>
    14 
    1513#include <QDesktopServices>
    1614#include <QDir>
     
    2422****
    2523***/
    26 
    27 QString
    28 Favicons :: getCacheDir( )
    29 {
    30     const QString base = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
    31     return QDir( base ).absoluteFilePath( "favicons" );
    32 };
    33 
    3424
    3525Favicons :: Favicons( )
     
    4838***/
    4939
     40QString
     41Favicons :: getCacheDir( )
     42{
     43    const QString base = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
     44    return QDir( base ).absoluteFilePath( "favicons" );
     45}
     46
    5047void
    5148Favicons :: ensureCacheDirHasBeenScanned( )
     
    5956        QDir cacheDir( getCacheDir( ) );
    6057        cacheDir.mkpath( cacheDir.absolutePath( ) );
     58
    6159        QStringList files = cacheDir.entryList( QDir::Files|QDir::Readable );
    6260        foreach( QString file, files ) {
     
    9189
    9290void
    93 Favicons :: add( const QUrl& url_in )
     91Favicons :: add( const QUrl& url )
    9492{
    9593    ensureCacheDirHasBeenScanned( );
    9694
    97     const QString host = getHost(url_in);
    98     if( !myPixmaps.contains(host) && !myPending.contains(host) )
     95    const QString host = getHost( url );
     96    if( !myPixmaps.contains( host ) && !myPending.contains( host ) )
    9997    {
    100         const int IMAGE_TYPES = 4;
    101         const QString image_types[IMAGE_TYPES] = { "ico", "png", "gif", "jpg" };
     98        myPending.append( host );
    10299
    103         myPending.append( host );
    104         for( int i=0; i<IMAGE_TYPES; ++i )
    105         {
    106             QString url( "http://" + host + "/favicon." + image_types[i]);
    107             myNAM->get( QNetworkRequest( url ) );
    108         }
     100        const QString path = "http://" + host + "/favicon.";
     101        QStringList suffixes;
     102        suffixes << "ico" << "png" << "gif" << "jpg";
     103        foreach( QString suffix, suffixes )
     104            myNAM->get( QNetworkRequest( path + suffix ) );
    109105    }
    110106}
     
    114110{
    115111    const QString host = reply->url().host();
    116 
    117112    myPending.removeAll( host );
    118 
    119     const QByteArray content = reply->readAll( );
    120113
    121114    QPixmap pixmap;
    122115
     116    const QByteArray content = reply->readAll( );
    123117    if( !reply->error( ) )
    124118        pixmap.loadFromData( content );
Note: See TracChangeset for help on using the changeset viewer.