00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qbitmap.h>
00021
00022 #include <kapplication.h>
00023 #include <kiconloader.h>
00024 #include <kmimetype.h>
00025 #include <kshell.h>
00026 #include <kprotocolinfo.h>
00027
00028 #include "konq_pixmapprovider.h"
00029
00030 KonqPixmapProvider * KonqPixmapProvider::s_self = 0L;
00031
00032 KonqPixmapProvider * KonqPixmapProvider::self()
00033 {
00034 if ( !s_self )
00035 s_self = new KonqPixmapProvider( kapp, "KonqPixmapProvider" );
00036
00037 return s_self;
00038 }
00039
00040 KonqPixmapProvider::KonqPixmapProvider( QObject *parent, const char *name )
00041 : KPixmapProvider(),
00042 KonqFavIconMgr( parent, name )
00043 {
00044 }
00045
00046 KonqPixmapProvider::~KonqPixmapProvider()
00047 {
00048 s_self = 0L;
00049 }
00050
00051
00052
00053
00054
00055 QString KonqPixmapProvider::iconNameFor( const QString& url )
00056 {
00057 QMapIterator<QString,QString> it = iconMap.find( url );
00058 QString icon;
00059 if ( it != iconMap.end() ) {
00060 icon = it.data();
00061 if ( !icon.isEmpty() )
00062 return icon;
00063 }
00064
00065 if ( url.isEmpty() ) {
00066
00067 icon = KMimeType::mimeType( "inode/directory" )->KServiceType::icon();
00068 Q_ASSERT( !icon.isEmpty() );
00069 }
00070 else
00071 {
00072 KURL u;
00073 if ( url.at(0) == '~' )
00074 u.setPath( KShell::tildeExpand( url ) );
00075 else if ( url.at(0) == '/' )
00076 u.setPath( url );
00077 else
00078 u = url;
00079
00080 icon = KMimeType::iconForURL( u );
00081 Q_ASSERT( !icon.isEmpty() );
00082 }
00083
00084
00085
00086 iconMap.insert( url, icon );
00087
00088 return icon;
00089 }
00090
00091 QPixmap KonqPixmapProvider::pixmapFor( const QString& url, int size )
00092 {
00093 return loadIcon( url, iconNameFor( url ), size );
00094 }
00095
00096 void KonqPixmapProvider::load( KConfig *kc, const QString& key )
00097 {
00098 iconMap.clear();
00099 QStringList list;
00100 list = kc->readPathListEntry( key );
00101 QStringList::Iterator it = list.begin();
00102 QString url, icon;
00103 while ( it != list.end() ) {
00104 url = (*it);
00105 if ( ++it == list.end() )
00106 break;
00107 icon = (*it);
00108 iconMap.insert( url, icon );
00109
00110 ++it;
00111 }
00112 }
00113
00114
00115
00116 void KonqPixmapProvider::save( KConfig *kc, const QString& key,
00117 const QStringList& items )
00118 {
00119 QStringList list;
00120 QStringList::ConstIterator it = items.begin();
00121 QMapConstIterator<QString,QString> mit;
00122 while ( it != items.end() ) {
00123 mit = iconMap.find( *it );
00124 if ( mit != iconMap.end() ) {
00125 list.append( mit.key() );
00126 list.append( mit.data() );
00127 }
00128
00129 ++it;
00130 }
00131 kc->writePathEntry( key, list );
00132 }
00133
00134 void KonqPixmapProvider::notifyChange( bool isHost, QString hostOrURL,
00135 QString iconName )
00136 {
00137 for ( QMapIterator<QString,QString> it = iconMap.begin();
00138 it != iconMap.end();
00139 ++it )
00140 {
00141 KURL url( it.key() );
00142 if ( url.protocol().startsWith("http") &&
00143 ( ( isHost && url.host() == hostOrURL ) ||
00144 ( url.host() + url.path() == hostOrURL ) ) )
00145 {
00146
00147
00148 QString icon = isHost ? KMimeType::favIconForURL( url ) : iconName;
00149 if ( !icon.isEmpty() )
00150 *it = icon;
00151 }
00152 }
00153
00154 emit changed();
00155 }
00156
00157 void KonqPixmapProvider::clear()
00158 {
00159 iconMap.clear();
00160 }
00161
00162 QPixmap KonqPixmapProvider::loadIcon( const QString& url, const QString& icon,
00163 int size )
00164 {
00165 if ( size <= KIcon::SizeSmall )
00166 return SmallIcon( icon, size );
00167
00168 KURL u;
00169 if ( url.at(0) == '/' )
00170 u.setPath( url );
00171 else
00172 u = url;
00173
00174 QPixmap big;
00175
00176
00177 if ( url.startsWith( "http:/" ) && icon.startsWith("favicons/") ) {
00178 QPixmap small = SmallIcon( icon, size );
00179 big = KGlobal::iconLoader()->loadIcon( KProtocolInfo::icon("http"),
00180 KIcon::Panel, size );
00181
00182 int x = big.width() - small.width();
00183 int y = 0;
00184
00185 if ( big.mask() ) {
00186 QBitmap mask = *big.mask();
00187 bitBlt( &mask, x, y,
00188 small.mask() ? const_cast<QBitmap *>(small.mask()) : &small, 0, 0,
00189 small.width(), small.height(),
00190 small.mask() ? OrROP : SetROP );
00191 big.setMask( mask );
00192 }
00193
00194 bitBlt( &big, x, y, &small );
00195 }
00196
00197 else
00198 big = KGlobal::iconLoader()->loadIcon( icon, KIcon::Panel, size );
00199
00200 return big;
00201 }