[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: kiconloader.cpp, Help needed
From: James Richard Tyrer <tyrerj () acm ! org>
Date: 2007-07-28 21:43:15
Message-ID: 46ABB873.6090108 () acm ! org
[Download RAW message or body]
I am having some difficulty understanding this code. Specifically, the
attached which is from KDE4 trunk.
The documentation for "iconPath" says:
QString KIconLoader::iconPath ( const QString & name,
int group_or_size,
bool canReturnNull = false
) const
Returns the path of an icon.
Parameters:
name The name of the icon, without extension. If an absolute path is
supplied for this parameter, iconPath will return it directly.
group_or_size If positive, search icons whose size is specified by the
icon group group_or_size. If negative, search icons whose size is -
group_or_size. See K3Icon::Group and K3Icon::StdSizes
canReturnNull Can return a null string? If not, a path to the
"unknown" icon will be returned.
Returns:
the path of an icon, can be null or the "unknown" icon when not
found, depending on canReturnNull.
-------------------------------------------------------------------------
Since I can't figure out the code and after reading this, it appears to
me that the code is wrong.
Specifically, the documentation says that the icon name is to be
supplied _without_ extension. However, KIconLoader::findMatchingIcon
adds a path before calling it.
Obviously, KIconLoader::findMatchingIcon is called with an icon name
without an extension so it would seem that it could simply pass it on
to: KIconLoader::iconPath.
I, therefore, suggest the attached patch which would greatly speed up
the code. Or do I have it wrong?
If KIconLoader::findMatchingIcon must be called with an icon name
without extension then Line 618:
QString name = removeIconExtension( _name );
is redundant.
--
JRT
["kiconloader.txt" (text/plain)]
LIME 558:
K3Icon KIconLoader::findMatchingIcon(const QString& name, int size) const
{
const_cast<KIconLoader*>(this)->initIconThemes();
K3Icon icon;
const char * const ext[4] = { ".png", ".svgz", ".svg", ".xpm" };
/* JRT: To follow the XDG spec, the order in which we look for an
icon 1s:
png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
next theme in inheritance tree : png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
next theme in inheritance tree : png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
and so on
*/
foreach(KIconThemeNode *themeNode, d->links)
{
for (int i = 0 ; i < 4 ; i++)
{
icon = themeNode->theme->iconPath(name + ext[i], size, K3Icon::MatchExact);
if (icon.isValid())
return icon;
}
for (int i = 0 ; i < 4 ; i++)
{
icon = themeNode->theme->iconPath(name + ext[i], size, K3Icon::MatchBest);
if (icon.isValid())
return icon;
}
}
return icon;
}
* * * * * * * * * * * * * *
Line: 614:
QString KIconLoader::iconPath(const QString& _name, int group_or_size,
bool canReturnNull) const
{
if (!const_cast<KIconLoader*>(this)->initIconThemes()) {
return QString();
}
if (!QDir::isRelativePath(_name))
return _name;
QString name = removeIconExtension( _name );
QString path;
if (group_or_size == K3Icon::User)
{
static const QString &png_ext = KGlobal::staticQString(".png");
static const QString &xpm_ext = KGlobal::staticQString(".xpm");
path = d->mpDirs->findResource("appicon", name + png_ext);
static const QString &svgz_ext = KGlobal::staticQString(".svgz");
static const QString &svg_ext = KGlobal::staticQString(".svg");
if (path.isEmpty())
path = d->mpDirs->findResource("appicon", name + svgz_ext);
if (path.isEmpty())
path = d->mpDirs->findResource("appicon", name + svg_ext);
if (path.isEmpty())
path = d->mpDirs->findResource("appicon", name + xpm_ext);
return path;
}
["kiconloader.svn-diff" (text/plain)]
Index: kiconloader.cpp
===================================================================
--- kiconloader.cpp (revision 693510)
+++ kiconloader.cpp (working copy)
@@ -576,19 +576,13 @@ K3Icon KIconLoader::findMatchingIcon(con
*/
foreach(KIconThemeNode *themeNode, d->links)
{
- for (int i = 0 ; i < 4 ; i++)
- {
icon = themeNode->theme->iconPath(name + ext[i], size, K3Icon::MatchExact);
if (icon.isValid())
return icon;
- }
- for (int i = 0 ; i < 4 ; i++)
- {
icon = themeNode->theme->iconPath(name + ext[i], size, K3Icon::MatchBest);
if (icon.isValid())
return icon;
- }
}
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic