22 #include <tdeapplication.h>
23 #include <kiconloader.h>
24 #include <kmimetype.h>
26 #include <kprotocolinfo.h>
28 #include "konq_pixmapprovider.h"
30 KonqPixmapProvider * KonqPixmapProvider::s_self = 0L;
32 KonqPixmapProvider * KonqPixmapProvider::self()
35 s_self =
new KonqPixmapProvider( kapp,
"KonqPixmapProvider" );
40 KonqPixmapProvider::KonqPixmapProvider( TQObject *parent,
const char *name )
46 KonqPixmapProvider::~KonqPixmapProvider()
55 TQString KonqPixmapProvider::iconNameFor(
const TQString& url )
57 TQMapIterator<TQString,TQString> it = iconMap.find( url );
59 if ( it != iconMap.end() ) {
61 if ( !icon.isEmpty() ) {
66 if ( url.isEmpty() ) {
68 icon = KMimeType::mimeType(
"inode/directory" )->KServiceType::icon();
69 Q_ASSERT( !icon.isEmpty() );
74 if ( url.at(0) ==
'~' )
75 u.setPath( KShell::tildeExpand( url ) );
76 else if ( url.at(0) ==
'/' )
81 icon = KMimeType::iconForURL( u );
87 iconMap.insert( url, icon );
92 TQPixmap KonqPixmapProvider::pixmapFor(
const TQString& url,
int size )
94 return loadIcon( url, iconNameFor( url ), size );
97 void KonqPixmapProvider::load( TDEConfig *kc,
const TQString& key )
101 list = kc->readPathListEntry( key );
102 TQStringList::Iterator it = list.begin();
104 while ( it != list.end() ) {
106 if ( ++it == list.end() )
109 iconMap.insert( url, icon );
117 void KonqPixmapProvider::save( TDEConfig *kc,
const TQString& key,
118 const TQStringList& items )
121 TQStringList::ConstIterator it = items.begin();
122 TQMapConstIterator<TQString,TQString> mit;
123 while ( it != items.end() ) {
124 mit = iconMap.find( *it );
125 if ( mit != iconMap.end() ) {
126 list.append( mit.key() );
127 list.append( mit.data() );
132 kc->writePathEntry( key, list );
135 void KonqPixmapProvider::notifyChange(
bool isHost, TQString hostOrURL,
138 for ( TQMapIterator<TQString,TQString> it = iconMap.begin();
142 KURL url( it.key() );
143 if ( url.protocol().startsWith(
"http") &&
144 ( ( isHost && url.host() == hostOrURL ) ||
145 ( url.host() + url.path() == hostOrURL ) ) )
149 TQString icon = isHost ? KMimeType::favIconForURL( url ) : iconName;
150 if ( !icon.isEmpty() )
158 void KonqPixmapProvider::clear()
163 TQPixmap KonqPixmapProvider::loadIcon(
const TQString& url,
const TQString& icon,
166 if ( size <= TDEIcon::SizeSmall )
167 return SmallIcon( icon, size );
170 if ( url.at(0) ==
'/' )
178 if ( url.startsWith(
"http:/" ) && icon.startsWith(
"favicons/") ) {
179 TQPixmap small = SmallIcon( icon, size );
180 big = TDEGlobal::iconLoader()->loadIcon( KProtocolInfo::icon(
"http"),
181 TDEIcon::Panel, size );
183 int x = big.width() - small.width();
187 TQBitmap mask = *big.mask();
189 small.mask() ?
const_cast<TQBitmap *
>(small.mask()) : &small, 0, 0,
190 small.width(), small.height(),
191 small.mask() ? OrROP : SetROP );
195 bitBlt( &big, x, y, &small );
199 big = TDEGlobal::iconLoader()->loadIcon( icon, TDEIcon::Panel, size );
Maintains a list of custom icons per URL.