1 /* Copyright 2009 Thomas McGuire <mcguire@kde.org>
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Library General Public License as published
5 by the Free Software Foundation; either version 2 of the License or
6 ( at your option ) version 3 or, at the discretion of KDE e.V.
7 ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
9 This library 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
19 #include "iconnamecache.h"
22 #include <KIconLoader>
24 namespace MessageViewer
{
25 K_GLOBAL_STATIC( IconNameCache
, s_iconNameCache
)
27 IconNameCache
* IconNameCache::instance()
29 return s_iconNameCache
;
32 bool IconNameCache::Entry::operator < ( const Entry
&other
) const
34 const int fileNameCompare
= fileName
.compare( other
.fileName
);
35 if ( fileNameCompare
!= 0 )
36 return fileNameCompare
< 0;
38 return size
< other
.size
;
41 QString
IconNameCache::iconPath( const QString
&name
, int size
) const
44 entry
.fileName
= name
;
47 if ( mCachedEntries
.contains( entry
) )
48 return mCachedEntries
.value( entry
);
50 const QString fileName
= KIconLoader::global()->iconPath( name
, size
);
51 mCachedEntries
.insert( entry
, fileName
);