<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>libkonq Library: konq_pixmapprovider.cc Source File (libkonq Library)</title> <link href="../../common/doxygen.css" rel="stylesheet" type="text/css"> </head> <div class="header"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td rowspan="2" width="92"> <a href="../../index.html" title="The API documentation main page"><img src="../../common/docheadergears.png" style="border:0px;" alt=""></a> </td> <td width="95%"> <h1>libkonq Library API Documentation</h1> </td> </tr> <tr> <td valign="bottom"> <table class="links" border=0 cellspacing=0> <tr> <td><a href="index.html">Overview</a></td> <td><a href="hierarchy.html" title="Inheritance list, sorted roughly alphabetically">Class Hierarchy</a></td> <td><a href="classes.html" title="Alphabetical list of classes">Classes</a></td> <td><a href="annotated.html" title="Classes, structs, unions and interfaces with brief descriptions">Classes (annotated)</a></td> <td><a href="functions.html" title="Documented class members with links to the classes they belong to">Members</a></td> <td><a href="namespaces.html" title="All documented namespaces with brief descriptions">Namespaces</a></td> <td><a href="files.html" title="A list of all documented files with brief descriptions">Source Files</a></td> </tr> </table> </td></tr></table> </div> <div id="hgrad"></div> <div class="text"> <!-- Generated by Doxygen 1.4.4 --> <h1>konq_pixmapprovider.cc</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* This file is part of the KDE project</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org></span> <a name="l00003"></a>00003 <span class="comment"></span> <a name="l00004"></a>00004 <span class="comment"> This program is free software; you can redistribute it and/or</span> <a name="l00005"></a>00005 <span class="comment"> modify it under the terms of the GNU General Public</span> <a name="l00006"></a>00006 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00007"></a>00007 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00008"></a>00008 <span class="comment"></span> <a name="l00009"></a>00009 <span class="comment"> This program is distributed in the hope that it will be useful,</span> <a name="l00010"></a>00010 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00011"></a>00011 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00012"></a>00012 <span class="comment"> General Public License for more details.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment"> You should have received a copy of the GNU General Public License</span> <a name="l00015"></a>00015 <span class="comment"> along with this program; see the file COPYING. If not, write to</span> <a name="l00016"></a>00016 <span class="comment"> the Free Software Foundation, Inc., 59 Temple Place - Suite 330,</span> <a name="l00017"></a>00017 <span class="comment"> Boston, MA 02111-1307, USA.</span> <a name="l00018"></a>00018 <span class="comment">*/</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#include <qbitmap.h></span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include <kapplication.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#include <kiconloader.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <kmimetype.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <kprotocolinfo.h></span> <a name="l00026"></a>00026 <a name="l00027"></a>00027 <span class="preprocessor">#include "konq_pixmapprovider.h"</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <a class="code" href="classKonqPixmapProvider.html">KonqPixmapProvider</a> * KonqPixmapProvider::s_self = 0L; <a name="l00030"></a>00030 <a name="l00031"></a><a class="code" href="classKonqPixmapProvider.html#e0">00031</a> <a class="code" href="classKonqPixmapProvider.html">KonqPixmapProvider</a> * <a class="code" href="classKonqPixmapProvider.html#e0">KonqPixmapProvider::self</a>() <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <span class="keywordflow">if</span> ( !s_self ) <a name="l00034"></a>00034 s_self = <span class="keyword">new</span> <a class="code" href="classKonqPixmapProvider.html#b0">KonqPixmapProvider</a>( kapp, <span class="stringliteral">"KonqPixmapProvider"</span> ); <a name="l00035"></a>00035 <a name="l00036"></a>00036 <span class="keywordflow">return</span> s_self; <a name="l00037"></a>00037 } <a name="l00038"></a>00038 <a name="l00039"></a><a class="code" href="classKonqPixmapProvider.html#b0">00039</a> <a class="code" href="classKonqPixmapProvider.html#b0">KonqPixmapProvider::KonqPixmapProvider</a>( QObject *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name ) <a name="l00040"></a>00040 : KPixmapProvider(), <a name="l00041"></a>00041 <a class="code" href="classKonqFavIconMgr.html">KonqFavIconMgr</a>( parent, name ) <a name="l00042"></a>00042 { <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <a name="l00045"></a><a class="code" href="classKonqPixmapProvider.html#a0">00045</a> <a class="code" href="classKonqPixmapProvider.html#a0">KonqPixmapProvider::~KonqPixmapProvider</a>() <a name="l00046"></a>00046 { <a name="l00047"></a>00047 s_self = 0L; <a name="l00048"></a>00048 } <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="comment">// at first, tries to find the iconname in the cache</span> <a name="l00051"></a>00051 <span class="comment">// if not available, tries to find the pixmap for the mimetype of url</span> <a name="l00052"></a>00052 <span class="comment">// if that fails, gets the icon for the protocol</span> <a name="l00053"></a>00053 <span class="comment">// finally, inserts the url/icon pair into the cache</span> <a name="l00054"></a><a class="code" href="classKonqPixmapProvider.html#a5">00054</a> QString <a class="code" href="classKonqPixmapProvider.html#a5">KonqPixmapProvider::iconNameFor</a>( <span class="keyword">const</span> QString& url ) <a name="l00055"></a>00055 { <a name="l00056"></a>00056 QMapIterator<QString,QString> it = iconMap.find( url ); <a name="l00057"></a>00057 QString icon; <a name="l00058"></a>00058 <span class="keywordflow">if</span> ( it != iconMap.end() ) { <a name="l00059"></a>00059 icon = it.data(); <a name="l00060"></a>00060 <span class="keywordflow">if</span> ( !icon.isEmpty() ) <a name="l00061"></a>00061 <span class="keywordflow">return</span> icon; <a name="l00062"></a>00062 } <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="keywordflow">if</span> ( url.isEmpty() ) { <a name="l00065"></a>00065 <span class="comment">// Use the folder icon for the empty URL</span> <a name="l00066"></a>00066 icon = KMimeType::mimeType( <span class="stringliteral">"inode/directory"</span> )->KServiceType::icon(); <a name="l00067"></a>00067 } <a name="l00068"></a>00068 <span class="keywordflow">else</span> <a name="l00069"></a>00069 { <a name="l00070"></a>00070 KURL u; <a name="l00071"></a>00071 <span class="keywordflow">if</span> ( url.at(0) == <span class="charliteral">'/'</span> ) <a name="l00072"></a>00072 u.setPath( url ); <a name="l00073"></a>00073 <span class="keywordflow">else</span> <a name="l00074"></a>00074 u = url; <a name="l00075"></a>00075 <a name="l00076"></a>00076 icon = KMimeType::iconForURL( u ); <a name="l00077"></a>00077 } <a name="l00078"></a>00078 <a name="l00079"></a>00079 Q_ASSERT( !icon.isEmpty() ); <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="comment">// cache the icon found for url</span> <a name="l00082"></a>00082 iconMap.insert( url, icon ); <a name="l00083"></a>00083 <a name="l00084"></a>00084 <span class="keywordflow">return</span> icon; <a name="l00085"></a>00085 } <a name="l00086"></a>00086 <a name="l00087"></a><a class="code" href="classKonqPixmapProvider.html#a1">00087</a> QPixmap <a class="code" href="classKonqPixmapProvider.html#a1">KonqPixmapProvider::pixmapFor</a>( <span class="keyword">const</span> QString& url, <span class="keywordtype">int</span> size ) <a name="l00088"></a>00088 { <a name="l00089"></a>00089 <span class="keywordflow">return</span> <a class="code" href="classKonqPixmapProvider.html#b2">loadIcon</a>( url, <a class="code" href="classKonqPixmapProvider.html#a5">iconNameFor</a>( url ), size ); <a name="l00090"></a>00090 } <a name="l00091"></a>00091 <a name="l00092"></a><a class="code" href="classKonqPixmapProvider.html#a2">00092</a> <span class="keywordtype">void</span> <a class="code" href="classKonqPixmapProvider.html#a2">KonqPixmapProvider::load</a>( KConfig *kc, <span class="keyword">const</span> QString& key ) <a name="l00093"></a>00093 { <a name="l00094"></a>00094 iconMap.clear(); <a name="l00095"></a>00095 QStringList list; <a name="l00096"></a>00096 list = kc->readPathListEntry( key ); <a name="l00097"></a>00097 QStringList::Iterator it = list.begin(); <a name="l00098"></a>00098 QString url, icon; <a name="l00099"></a>00099 <span class="keywordflow">while</span> ( it != list.end() ) { <a name="l00100"></a>00100 url = (*it); <a name="l00101"></a>00101 <span class="keywordflow">if</span> ( ++it == list.end() ) <a name="l00102"></a>00102 <span class="keywordflow">break</span>; <a name="l00103"></a>00103 icon = (*it); <a name="l00104"></a>00104 iconMap.insert( url, icon ); <a name="l00105"></a>00105 <a name="l00106"></a>00106 ++it; <a name="l00107"></a>00107 } <a name="l00108"></a>00108 } <a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="comment">// only saves the cache for the given list of items to prevent the cache</span> <a name="l00111"></a>00111 <span class="comment">// from growing forever.</span> <a name="l00112"></a><a class="code" href="classKonqPixmapProvider.html#a3">00112</a> <span class="keywordtype">void</span> <a class="code" href="classKonqPixmapProvider.html#a3">KonqPixmapProvider::save</a>( KConfig *kc, <span class="keyword">const</span> QString& key, <a name="l00113"></a>00113 <span class="keyword">const</span> QStringList& items ) <a name="l00114"></a>00114 { <a name="l00115"></a>00115 QStringList list; <a name="l00116"></a>00116 QStringList::ConstIterator it = items.begin(); <a name="l00117"></a>00117 QMapConstIterator<QString,QString> mit; <a name="l00118"></a>00118 <span class="keywordflow">while</span> ( it != items.end() ) { <a name="l00119"></a>00119 mit = iconMap.find( *it ); <a name="l00120"></a>00120 <span class="keywordflow">if</span> ( mit != iconMap.end() ) { <a name="l00121"></a>00121 list.append( mit.key() ); <a name="l00122"></a>00122 list.append( mit.data() ); <a name="l00123"></a>00123 } <a name="l00124"></a>00124 <a name="l00125"></a>00125 ++it; <a name="l00126"></a>00126 } <a name="l00127"></a>00127 kc->writePathEntry( key, list ); <a name="l00128"></a>00128 } <a name="l00129"></a>00129 <a name="l00130"></a><a class="code" href="classKonqPixmapProvider.html#b1">00130</a> <span class="keywordtype">void</span> <a class="code" href="classKonqPixmapProvider.html#b1">KonqPixmapProvider::notifyChange</a>( <span class="keywordtype">bool</span> isHost, QString hostOrURL, <a name="l00131"></a>00131 QString iconName ) <a name="l00132"></a>00132 { <a name="l00133"></a>00133 <span class="keywordflow">for</span> ( QMapIterator<QString,QString> it = iconMap.begin(); <a name="l00134"></a>00134 it != iconMap.end(); <a name="l00135"></a>00135 ++it ) <a name="l00136"></a>00136 { <a name="l00137"></a>00137 KURL url( it.key() ); <a name="l00138"></a>00138 <span class="keywordflow">if</span> ( url.protocol().startsWith(<span class="stringliteral">"http"</span>) && <a name="l00139"></a>00139 ( ( isHost && url.host() == hostOrURL ) || <a name="l00140"></a>00140 ( url.host() + url.path() == hostOrURL ) ) ) <a name="l00141"></a>00141 { <a name="l00142"></a>00142 <span class="comment">// For host default-icons still query the favicon manager to get</span> <a name="l00143"></a>00143 <span class="comment">// the correct icon for pages that have an own one.</span> <a name="l00144"></a>00144 QString icon = isHost ? KMimeType::favIconForURL( url ) : iconName; <a name="l00145"></a>00145 <span class="keywordflow">if</span> ( !icon.isEmpty() ) <a name="l00146"></a>00146 *it = icon; <a name="l00147"></a>00147 } <a name="l00148"></a>00148 } <a name="l00149"></a>00149 <a name="l00150"></a>00150 emit changed(); <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <a name="l00153"></a><a class="code" href="classKonqPixmapProvider.html#a4">00153</a> <span class="keywordtype">void</span> <a class="code" href="classKonqPixmapProvider.html#a4">KonqPixmapProvider::clear</a>() <a name="l00154"></a>00154 { <a name="l00155"></a>00155 iconMap.clear(); <a name="l00156"></a>00156 } <a name="l00157"></a>00157 <a name="l00158"></a><a class="code" href="classKonqPixmapProvider.html#b2">00158</a> QPixmap <a class="code" href="classKonqPixmapProvider.html#b2">KonqPixmapProvider::loadIcon</a>( <span class="keyword">const</span> QString& url, <span class="keyword">const</span> QString& icon, <a name="l00159"></a>00159 <span class="keywordtype">int</span> size ) <a name="l00160"></a>00160 { <a name="l00161"></a>00161 <span class="keywordflow">if</span> ( size <= KIcon::SizeSmall ) <a name="l00162"></a>00162 <span class="keywordflow">return</span> SmallIcon( icon, size ); <a name="l00163"></a>00163 <a name="l00164"></a>00164 KURL u; <a name="l00165"></a>00165 <span class="keywordflow">if</span> ( url.at(0) == <span class="charliteral">'/'</span> ) <a name="l00166"></a>00166 u.setPath( url ); <a name="l00167"></a>00167 <span class="keywordflow">else</span> <a name="l00168"></a>00168 u = url; <a name="l00169"></a>00169 <a name="l00170"></a>00170 QPixmap big; <a name="l00171"></a>00171 <a name="l00172"></a>00172 <span class="comment">// favicon? => blend the favicon in the large</span> <a name="l00173"></a>00173 <span class="keywordflow">if</span> ( url.startsWith( <span class="stringliteral">"http:/"</span> ) && icon.startsWith(<span class="stringliteral">"favicons/"</span>) ) { <a name="l00174"></a>00174 QPixmap small = SmallIcon( icon, size ); <a name="l00175"></a>00175 big = KGlobal::iconLoader()->loadIcon( KProtocolInfo::icon(<span class="stringliteral">"http"</span>), <a name="l00176"></a>00176 KIcon::Panel, size ); <a name="l00177"></a>00177 <a name="l00178"></a>00178 <span class="keywordtype">int</span> x = big.width() - small.width(); <a name="l00179"></a>00179 <span class="keywordtype">int</span> y = 0; <a name="l00180"></a>00180 <a name="l00181"></a>00181 <span class="keywordflow">if</span> ( big.mask() ) { <a name="l00182"></a>00182 QBitmap mask = *big.mask(); <a name="l00183"></a>00183 bitBlt( &mask, x, y, <a name="l00184"></a>00184 small.mask() ? const_cast<QBitmap *>(small.mask()) : &small, 0, 0, <a name="l00185"></a>00185 small.width(), small.height(), <a name="l00186"></a>00186 small.mask() ? OrROP : SetROP ); <a name="l00187"></a>00187 big.setMask( mask ); <a name="l00188"></a>00188 } <a name="l00189"></a>00189 <a name="l00190"></a>00190 bitBlt( &big, x, y, &small ); <a name="l00191"></a>00191 } <a name="l00192"></a>00192 <a name="l00193"></a>00193 <span class="keywordflow">else</span> <span class="comment">// not a favicon..</span> <a name="l00194"></a>00194 big = KGlobal::iconLoader()->loadIcon( icon, KIcon::Panel, size ); <a name="l00195"></a>00195 <a name="l00196"></a>00196 <span class="keywordflow">return</span> big; <a name="l00197"></a>00197 } </pre></div></div> <div id="bottom-nav"> <img src="../../common/bottom2.png" align="right" height="59" width="227" alt="KDE Logo"> </div> <div class="bottom"> This file is part of the documentation for libkonq Library Version 3.4.2. </div> <div class="bottom" style="color:#cccccc"> Documentation copyright © 1996-2004 the KDE developers.<br> Generated on Wed Jun 14 19:05:21 2006 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.4.4 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2003 </div> </body> </html>