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

libkonq

  • libkonq
konq_pixmapprovider.cpp
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 <tdeapplication.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( tdeApp, "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 
66  if ( url.isEmpty() ) {
67  // Use the folder icon for the empty URL
68  icon = KMimeType::mimeType( "inode/directory" )->KServiceType::icon();
69  Q_ASSERT( !icon.isEmpty() );
70  }
71  else
72  {
73  KURL u;
74  if ( url.at(0) == '~' )
75  u.setPath( KShell::tildeExpand( url ) );
76  else if ( url.at(0) == '/' )
77  u.setPath( url );
78  else
79  u = url;
80 
81  icon = KMimeType::iconForURL( u );
82  //Q_ASSERT( !icon.isEmpty() );
83  }
84 
85 
86  // cache the icon found for url
87  iconMap.insert( url, icon );
88 
89  return icon;
90 }
91 
92 TQPixmap KonqPixmapProvider::pixmapFor( const TQString& url, int size )
93 {
94  return loadIcon( url, iconNameFor( url ), size );
95 }
96 
97 void KonqPixmapProvider::load( TDEConfig *kc, const TQString& key )
98 {
99  iconMap.clear();
100  TQStringList list;
101  list = kc->readPathListEntry( key );
102  TQStringList::Iterator it = list.begin();
103  TQString url, icon;
104  while ( it != list.end() ) {
105  url = (*it);
106  if ( ++it == list.end() )
107  break;
108  icon = (*it);
109  iconMap.insert( url, icon );
110 
111  ++it;
112  }
113 }
114 
115 // only saves the cache for the given list of items to prevent the cache
116 // from growing forever.
117 void KonqPixmapProvider::save( TDEConfig *kc, const TQString& key,
118  const TQStringList& items )
119 {
120  TQStringList list;
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() );
128  }
129 
130  ++it;
131  }
132  kc->writePathEntry( key, list );
133 }
134 
135 void KonqPixmapProvider::notifyChange( bool isHost, TQString hostOrURL,
136  TQString iconName )
137 {
138  for ( TQMapIterator<TQString,TQString> it = iconMap.begin();
139  it != iconMap.end();
140  ++it )
141  {
142  KURL url( it.key() );
143  if ( url.protocol().startsWith("http") &&
144  ( ( isHost && url.host() == hostOrURL ) ||
145  ( url.host() + url.path() == hostOrURL ) ) )
146  {
147  // For host default-icons still query the favicon manager to get
148  // the correct icon for pages that have an own one.
149  TQString icon = isHost ? KMimeType::favIconForURL( url ) : iconName;
150  if ( !icon.isEmpty() )
151  *it = icon;
152  }
153  }
154 
155  emit changed();
156 }
157 
158 void KonqPixmapProvider::clear()
159 {
160  iconMap.clear();
161 }
162 
163 TQPixmap KonqPixmapProvider::loadIcon( const TQString& url, const TQString& icon,
164  int size )
165 {
166  if ( size <= TDEIcon::SizeSmall )
167  return SmallIcon( icon, size );
168 
169  KURL u;
170  if ( url.at(0) == '/' )
171  u.setPath( url );
172  else
173  u = url;
174 
175  TQPixmap big;
176 
177  // favicon? => blend the favicon in the large
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 );
182 
183  int x = big.width() - small.width();
184  int y = 0;
185 
186  if ( big.mask() ) {
187  TQBitmap mask = *big.mask();
188  bitBlt( &mask, x, y,
189  small.mask() ? const_cast<TQBitmap *>(small.mask()) : &small, 0, 0,
190  small.width(), small.height(),
191  small.mask() ? OrROP : SetROP );
192  big.setMask( mask );
193  }
194 
195  bitBlt( &big, x, y, &small );
196  }
197 
198  else // not a favicon..
199  big = TDEGlobal::iconLoader()->loadIcon( icon, TDEIcon::Panel, size );
200 
201  return big;
202 }
KonqFavIconMgr
Maintains a list of custom icons per URL.
Definition: konq_faviconmgr.h:31

libkonq

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

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.8.13
This website is maintained by Timothy Pearson.