]> granicus.if.org Git - transmission/commitdiff
(trunk qt) readability changes to the favicon cache
authorCharles Kerr <charles@transmissionbt.com>
Sun, 25 Jul 2010 17:42:43 +0000 (17:42 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 25 Jul 2010 17:42:43 +0000 (17:42 +0000)
qt/favicon.cc
qt/favicon.h

index 611159efbe30ea22ddecfc6b7342a6846eb32bcf..092fa985ee932c4330c7d42bc1c7cf17b4373cb7 100644 (file)
@@ -10,8 +10,6 @@
  * $Id$
  */
 
-#include <iostream>
-
 #include <QDesktopServices>
 #include <QDir>
 #include <QNetworkAccessManager>
 ****
 ***/
 
-QString
-Favicons :: getCacheDir( )
-{
-    const QString base = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
-    return QDir( base ).absoluteFilePath( "favicons" );
-};
-
-
 Favicons :: Favicons( )
 {
     myNAM = new QNetworkAccessManager( );
@@ -47,6 +37,13 @@ Favicons :: ~Favicons( )
 ****
 ***/
 
+QString
+Favicons :: getCacheDir( )
+{
+    const QString base = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
+    return QDir( base ).absoluteFilePath( "favicons" );
+}
+
 void
 Favicons :: ensureCacheDirHasBeenScanned( )
 {
@@ -58,6 +55,7 @@ Favicons :: ensureCacheDirHasBeenScanned( )
    
         QDir cacheDir( getCacheDir( ) );
         cacheDir.mkpath( cacheDir.absolutePath( ) );
+
         QStringList files = cacheDir.entryList( QDir::Files|QDir::Readable );
         foreach( QString file, files ) {
             QPixmap pixmap;
@@ -90,22 +88,20 @@ Favicons :: find( const QUrl& url )
 }
 
 void
-Favicons :: add( const QUrl& url_in )
+Favicons :: add( const QUrl& url )
 {
     ensureCacheDirHasBeenScanned( );
 
-    const QString host = getHost(url_in);
-    if( !myPixmaps.contains(host) && !myPending.contains(host) )
+    const QString host = getHost( url );
+    if( !myPixmaps.contains( host ) && !myPending.contains( host ) )
     {
-        const int IMAGE_TYPES = 4;
-        const QString image_types[IMAGE_TYPES] = { "ico", "png", "gif", "jpg" };
-
         myPending.append( host ); 
-        for( int i=0; i<IMAGE_TYPES; ++i )
-        {
-            QString url( "http://" + host + "/favicon." + image_types[i]);
-            myNAM->get( QNetworkRequest( url ) );
-        }
+
+        const QString path = "http://" + host + "/favicon.";
+        QStringList suffixes;
+        suffixes << "ico" << "png" << "gif" << "jpg";
+        foreach( QString suffix, suffixes )
+            myNAM->get( QNetworkRequest( path + suffix ) );
     }
 }
 
@@ -113,13 +109,11 @@ void
 Favicons :: onRequestFinished( QNetworkReply * reply )
 {
     const QString host = reply->url().host();
-
     myPending.removeAll( host );
 
-    const QByteArray content = reply->readAll( );
-
     QPixmap pixmap;
 
+    const QByteArray content = reply->readAll( );
     if( !reply->error( ) )
         pixmap.loadFromData( content );
 
index 15698b7e98a522cef4304b1a0df3a1ac84c6916f..dc6ee09324b65358781093531f7e36f59e8a661a 100644 (file)
@@ -51,7 +51,6 @@ class Favicons: public QObject
         QString getHost( const QUrl& url );
 
         QString getCacheDir( );
-
         void ensureCacheDirHasBeenScanned( );
 
     private slots: