00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <tqbitmap.h>
00021
00022 #include <tdeapplication.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( TQT_TQOBJECT(kapp), "KonqPixmapProvider" );
00036
00037 return s_self;
00038 }
00039
00040 KonqPixmapProvider::KonqPixmapProvider( TQObject *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 TQString KonqPixmapProvider::iconNameFor( const TQString& url )
00056 {
00057 TQMapIterator<TQString,TQString> it = iconMap.find( url );
00058 TQString icon;
00059 if ( it != iconMap.end() ) {
00060 icon = it.data();
00061 if ( !icon.isEmpty() ) {
00062 return icon;
00063 }
00064 }
00065
00066 if ( url.isEmpty() ) {
00067
00068 icon = KMimeType::mimeType( "inode/directory" )->KServiceType::icon();
00069 Q_ASSERT( !icon.isEmpty() );
00070 }
00071 else
00072 {
00073 KURL u;
00074 if ( url.at(0) == '~' )
00075 u.setPath( KShell::tildeExpand( url ) );
00076 else if ( url.at(0) == '/' )
00077 u.setPath( url );
00078 else
00079 u = url;
00080
00081 icon = KMimeType::iconForURL( u );
00082
00083 }
00084
00085
00086
00087 iconMap.insert( url, icon );
00088
00089 return icon;
00090 }
00091
00092 TQPixmap KonqPixmapProvider::pixmapFor( const TQString& url, int size )
00093 {
00094 return loadIcon( url, iconNameFor( url ), size );
00095 }
00096
00097 void KonqPixmapProvider::load( TDEConfig *kc, const TQString& key )
00098 {
00099 iconMap.clear();
00100 TQStringList list;
00101 list = kc->readPathListEntry( key );
00102 TQStringList::Iterator it = list.begin();
00103 TQString url, icon;
00104 while ( it != list.end() ) {
00105 url = (*it);
00106 if ( ++it == list.end() )
00107 break;
00108 icon = (*it);
00109 iconMap.insert( url, icon );
00110
00111 ++it;
00112 }
00113 }
00114
00115
00116
00117 void KonqPixmapProvider::save( TDEConfig *kc, const TQString& key,
00118 const TQStringList& items )
00119 {
00120 TQStringList list;
00121 TQStringList::ConstIterator it = items.begin();
00122 TQMapConstIterator<TQString,TQString> mit;
00123 while ( it != items.end() ) {
00124 mit = iconMap.find( *it );
00125 if ( mit != iconMap.end() ) {
00126 list.append( mit.key() );
00127 list.append( mit.data() );
00128 }
00129
00130 ++it;
00131 }
00132 kc->writePathEntry( key, list );
00133 }
00134
00135 void KonqPixmapProvider::notifyChange( bool isHost, TQString hostOrURL,
00136 TQString iconName )
00137 {
00138 for ( TQMapIterator<TQString,TQString> it = iconMap.begin();
00139 it != iconMap.end();
00140 ++it )
00141 {
00142 KURL url( it.key() );
00143 if ( url.protocol().startsWith("http") &&
00144 ( ( isHost && url.host() == hostOrURL ) ||
00145 ( url.host() + url.path() == hostOrURL ) ) )
00146 {
00147
00148
00149 TQString icon = isHost ? KMimeType::favIconForURL( url ) : iconName;
00150 if ( !icon.isEmpty() )
00151 *it = icon;
00152 }
00153 }
00154
00155 emit changed();
00156 }
00157
00158 void KonqPixmapProvider::clear()
00159 {
00160 iconMap.clear();
00161 }
00162
00163 TQPixmap KonqPixmapProvider::loadIcon( const TQString& url, const TQString& icon,
00164 int size )
00165 {
00166 if ( size <= TDEIcon::SizeSmall )
00167 return SmallIcon( icon, size );
00168
00169 KURL u;
00170 if ( url.at(0) == '/' )
00171 u.setPath( url );
00172 else
00173 u = url;
00174
00175 TQPixmap big;
00176
00177
00178 if ( url.startsWith( "http:/" ) && icon.startsWith("favicons/") ) {
00179 TQPixmap small = SmallIcon( icon, size );
00180 big = TDEGlobal::iconLoader()->loadIcon( KProtocolInfo::icon("http"),
00181 TDEIcon::Panel, size );
00182
00183 int x = big.width() - small.width();
00184 int y = 0;
00185
00186 if ( big.mask() ) {
00187 TQBitmap mask = *big.mask();
00188 bitBlt( &mask, x, y,
00189 small.mask() ? TQT_TQPIXMAP(const_cast<TQBitmap *>(small.mask())) : &small, 0, 0,
00190 small.width(), small.height(),
00191 small.mask() ? OrROP : SetROP );
00192 big.setMask( mask );
00193 }
00194
00195 bitBlt( &big, x, y, &small );
00196 }
00197
00198 else
00199 big = TDEGlobal::iconLoader()->loadIcon( icon, TDEIcon::Panel, size );
00200
00201 return big;
00202 }