Changeset 11053
- Timestamp:
- Jul 25, 2010, 5:42:43 PM (12 years ago)
- Location:
- trunk/qt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/favicon.cc
r11052 r11053 11 11 */ 12 12 13 #include <iostream>14 15 13 #include <QDesktopServices> 16 14 #include <QDir> … … 24 22 **** 25 23 ***/ 26 27 QString28 Favicons :: getCacheDir( )29 {30 const QString base = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );31 return QDir( base ).absoluteFilePath( "favicons" );32 };33 34 24 35 25 Favicons :: Favicons( ) … … 48 38 ***/ 49 39 40 QString 41 Favicons :: getCacheDir( ) 42 { 43 const QString base = QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); 44 return QDir( base ).absoluteFilePath( "favicons" ); 45 } 46 50 47 void 51 48 Favicons :: ensureCacheDirHasBeenScanned( ) … … 59 56 QDir cacheDir( getCacheDir( ) ); 60 57 cacheDir.mkpath( cacheDir.absolutePath( ) ); 58 61 59 QStringList files = cacheDir.entryList( QDir::Files|QDir::Readable ); 62 60 foreach( QString file, files ) { … … 91 89 92 90 void 93 Favicons :: add( const QUrl& url _in)91 Favicons :: add( const QUrl& url ) 94 92 { 95 93 ensureCacheDirHasBeenScanned( ); 96 94 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 ) ) 99 97 { 100 const int IMAGE_TYPES = 4; 101 const QString image_types[IMAGE_TYPES] = { "ico", "png", "gif", "jpg" }; 98 myPending.append( host ); 102 99 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 ) ); 109 105 } 110 106 } … … 114 110 { 115 111 const QString host = reply->url().host(); 116 117 112 myPending.removeAll( host ); 118 119 const QByteArray content = reply->readAll( );120 113 121 114 QPixmap pixmap; 122 115 116 const QByteArray content = reply->readAll( ); 123 117 if( !reply->error( ) ) 124 118 pixmap.loadFromData( content ); -
trunk/qt/favicon.h
r11052 r11053 52 52 53 53 QString getCacheDir( ); 54 55 54 void ensureCacheDirHasBeenScanned( ); 56 55
Note: See TracChangeset
for help on using the changeset viewer.