• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_pixmapprovider.cc
1 /* This file is part of the KDE project
2  Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <tqbitmap.h>
21 
22 #include <kapplication.h>
23 #include <kiconloader.h>
24 #include <kmimetype.h>
25 #include <kshell.h>
26 #include <kprotocolinfo.h>
27 
28 #include "konq_pixmapprovider.h"
29 
30 KonqPixmapProvider * KonqPixmapProvider::s_self = 0L;
31 
32 KonqPixmapProvider * KonqPixmapProvider::self()
33 {
34  if ( !s_self )
35  s_self = new KonqPixmapProvider( TQT_TQOBJECT(kapp), "KonqPixmapProvider" );
36 
37  return s_self;
38 }
39 
40 KonqPixmapProvider::KonqPixmapProvider( TQObject *parent, const char *name )
41  : KPixmapProvider(),
42  KonqFavIconMgr( parent, name )
43 {
44 }
45 
46 KonqPixmapProvider::~KonqPixmapProvider()
47 {
48  s_self = 0L;
49 }
50 
51 // at first, tries to find the iconname in the cache
52 // if not available, tries to find the pixmap for the mimetype of url
53 // if that fails, gets the icon for the protocol
54 // finally, inserts the url/icon pair into the cache
55 TQString KonqPixmapProvider::iconNameFor( const TQString& url )
56 {
57  TQMapIterator<TQString,TQString> it = iconMap.find( url );
58  TQString icon;
59  if ( it != iconMap.end() ) {
60  icon = it.data();
61  if ( !icon.isEmpty() )
62  return icon;
63  }
64 
65  if ( url.isEmpty() ) {
66  // Use the folder icon for the empty URL
67  icon = KMimeType::mimeType( "inode/directory" )->KServiceType::icon();
68  Q_ASSERT( !icon.isEmpty() );
69  }
70  else
71  {
72  KURL u;
73  if ( url.at(0) == '~' )
74  u.setPath( KShell::tildeExpand( url ) );
75  else if ( url.at(0) == '/' )
76  u.setPath( url );
77  else
78  u = url;
79 
80  icon = KMimeType::iconForURL( u );
81  //Q_ASSERT( !icon.isEmpty() );
82  }
83 
84 
85  // cache the icon found for url
86  iconMap.insert( url, icon );
87 
88  return icon;
89 }
90 
91 TQPixmap KonqPixmapProvider::pixmapFor( const TQString& url, int size )
92 {
93  return loadIcon( url, iconNameFor( url ), size );
94 }
95 
96 void KonqPixmapProvider::load( KConfig *kc, const TQString& key )
97 {
98  iconMap.clear();
99  TQStringList list;
100  list = kc->readPathListEntry( key );
101  TQStringList::Iterator it = list.begin();
102  TQString url, icon;
103  while ( it != list.end() ) {
104  url = (*it);
105  if ( ++it == list.end() )
106  break;
107  icon = (*it);
108  iconMap.insert( url, icon );
109 
110  ++it;
111  }
112 }
113 
114 // only saves the cache for the given list of items to prevent the cache
115 // from growing forever.
116 void KonqPixmapProvider::save( KConfig *kc, const TQString& key,
117  const TQStringList& items )
118 {
119  TQStringList list;
120  TQStringList::ConstIterator it = items.begin();
121  TQMapConstIterator<TQString,TQString> mit;
122  while ( it != items.end() ) {
123  mit = iconMap.find( *it );
124  if ( mit != iconMap.end() ) {
125  list.append( mit.key() );
126  list.append( mit.data() );
127  }
128 
129  ++it;
130  }
131  kc->writePathEntry( key, list );
132 }
133 
134 void KonqPixmapProvider::notifyChange( bool isHost, TQString hostOrURL,
135  TQString iconName )
136 {
137  for ( TQMapIterator<TQString,TQString> it = iconMap.begin();
138  it != iconMap.end();
139  ++it )
140  {
141  KURL url( it.key() );
142  if ( url.protocol().startsWith("http") &&
143  ( ( isHost && url.host() == hostOrURL ) ||
144  ( url.host() + url.path() == hostOrURL ) ) )
145  {
146  // For host default-icons still query the favicon manager to get
147  // the correct icon for pages that have an own one.
148  TQString icon = isHost ? KMimeType::favIconForURL( url ) : iconName;
149  if ( !icon.isEmpty() )
150  *it = icon;
151  }
152  }
153 
154  emit changed();
155 }
156 
157 void KonqPixmapProvider::clear()
158 {
159  iconMap.clear();
160 }
161 
162 TQPixmap KonqPixmapProvider::loadIcon( const TQString& url, const TQString& icon,
163  int size )
164 {
165  if ( size <= KIcon::SizeSmall )
166  return SmallIcon( icon, size );
167 
168  KURL u;
169  if ( url.at(0) == '/' )
170  u.setPath( url );
171  else
172  u = url;
173 
174  TQPixmap big;
175 
176  // favicon? => blend the favicon in the large
177  if ( url.startsWith( "http:/" ) && icon.startsWith("favicons/") ) {
178  TQPixmap small = SmallIcon( icon, size );
179  big = KGlobal::iconLoader()->loadIcon( KProtocolInfo::icon("http"),
180  KIcon::Panel, size );
181 
182  int x = big.width() - small.width();
183  int y = 0;
184 
185  if ( big.mask() ) {
186  TQBitmap mask = *big.mask();
187  bitBlt( &mask, x, y,
188  small.mask() ? TQT_TQPIXMAP(const_cast<TQBitmap *>(small.mask())) : &small, 0, 0,
189  small.width(), small.height(),
190  small.mask() ? OrROP : SetROP );
191  big.setMask( mask );
192  }
193 
194  bitBlt( &big, x, y, &small );
195  }
196 
197  else // not a favicon..
198  big = KGlobal::iconLoader()->loadIcon( icon, KIcon::Panel, size );
199 
200  return big;
201 }

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for libkonq by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |