Prefer elficon metadata to (often incorrect) system string matching

pull/16/head
Timothy Pearson 13 years ago
parent b477a57673
commit 783973a7d6

@ -179,94 +179,110 @@ TQString KURIFilterData::iconName()
TQString exeName = m_pURI.url(); TQString exeName = m_pURI.url();
exeName = exeName.mid( exeName.findRev( '/' ) + 1 ); // strip path if given exeName = exeName.mid( exeName.findRev( '/' ) + 1 ); // strip path if given
KService::Ptr service = KService::serviceByDesktopName( exeName ); KService::Ptr service = KService::serviceByDesktopName( exeName );
if (service && service->icon() != TQString::fromLatin1( "unknown" )) #ifndef HAVE_ELFICON
m_strIconName = service->icon();
// Try to find an icon with the same name as the binary (useful for non-tde apps) // Try to find an icon with the same name as the binary (useful for non-tde apps)
// FIXME: We should only do this if the binary is in the system path somewhere, // FIXME: We should only do this if the binary is in the system path somewhere,
// otherwise TDE could end up showing system icons for user binaries // otherwise TDE could end up showing system icons for user binaries
else if ( !KGlobal::iconLoader()->loadIcon( exeName, KIcon::NoGroup, 16, KIcon::DefaultState, 0, true ).isNull() ) if (service && service->icon() != TQString::fromLatin1( "unknown" )) {
m_strIconName = service->icon();
}
else if ( !KGlobal::iconLoader()->loadIcon( exeName, KIcon::NoGroup, 16, KIcon::DefaultState, 0, true ).isNull() ) {
m_strIconName = exeName; m_strIconName = exeName;
}
else { else {
// not found, try to load from elf file (if supported) // use default
// otherwise use default m_strIconName = TQString::fromLatin1("exec");
}
#else // HAVE_ELFICON
// Try to find an icon with the same name as the binary (useful for non-tde apps)
// FIXME: We should only do this if the binary is in the system path somewhere,
// otherwise TDE could end up showing system icons for user binaries
if (service && service->icon() != TQString::fromLatin1( "unknown" )) {
m_strIconName = service->icon();
}
else if ( !KGlobal::iconLoader()->loadIcon( exeName, KIcon::NoGroup, 16, KIcon::DefaultState, 0, true ).isNull() ) {
m_strIconName = exeName;
}
else {
// use default
m_strIconName = TQString::fromLatin1("exec"); m_strIconName = TQString::fromLatin1("exec");
#ifdef HAVE_ELFICON }
// Check for an embedded icon // Try to load from elf file (if supported)
unsigned int icon_size; // Check for an embedded icon
libr_icon *icon = NULL; unsigned int icon_size;
libr_file *handle = NULL; libr_icon *icon = NULL;
libr_access_t access = LIBR_READ; libr_file *handle = NULL;
char libr_can_continue = 1; libr_access_t access = LIBR_READ;
char libr_can_continue = 1;
if((handle = libr_open(const_cast<char*>(m_pURI.path().ascii()), access)) == NULL)
{ if((handle = libr_open(const_cast<char*>(m_pURI.path().ascii()), access)) == NULL)
kdWarning() << "failed to open file" << m_pURI.path() << endl; {
libr_can_continue = 0; kdWarning() << "failed to open file" << m_pURI.path() << endl;
} libr_can_continue = 0;
}
if (libr_can_continue == 1) {
icon_size = 32; // FIXME: Is this a reasonable size request for all possible usages of kurifilter?
icon = libr_icon_geticon_bysize(handle, icon_size);
if (libr_can_continue == 1) { if (libr_can_continue == 1) {
icon_size = 32; // FIXME: Is this a reasonable size request for all possible usages of kurifilter? // See if the embedded icon name matches any icon file names already on the system
icon = libr_icon_geticon_bysize(handle, icon_size); // If it does, use the system icon instead of the embedded one
int iconresnamefound = 0;
if (libr_can_continue == 1) { iconentry *entry = NULL;
// See if the embedded icon name matches any icon file names already on the system iconlist icons;
// If it does, use the system icon instead of the embedded one if(!get_iconlist(handle, &icons))
int iconresnamefound = 0; {
iconentry *entry = NULL; // Failed to obtain a list of ELF icons
iconlist icons; kdWarning() << "failed to obtain ELF icon: " << libr_errmsg() << endl;
if(!get_iconlist(handle, &icons))
{ // See if there is a system icon we can use
// Failed to obtain a list of ELF icons TQString sysIconName = elf_get_resource(handle, ".metadata_sysicon");
kdWarning() << "failed to obtain ELF icon: " << libr_errmsg() << endl; if (!sysIconName.isEmpty()) {
if (KGlobal::iconLoader()->iconPath(sysIconName.ascii(), 0, true) != "") {
// See if there is a system icon we can use m_strIconName = sysIconName;
TQString sysIconName = elf_get_resource(handle, ".metadata_sysicon");
if (!sysIconName.isEmpty()) {
if (KGlobal::iconLoader()->iconPath(sysIconName.ascii(), 0, true) != "") {
m_strIconName = sysIconName;
}
} }
libr_close(handle);
libr_can_continue = 0;
} }
else {
while((entry = get_nexticon(&icons, entry)) != NULL) libr_close(handle);
libr_can_continue = 0;
}
else {
while((entry = get_nexticon(&icons, entry)) != NULL)
{
if(icon == NULL)
{ {
if(icon == NULL) // Try loading this icon as fallback
{ icon = libr_icon_geticon_byname(handle, entry->name);
// Try loading this icon as fallback }
icon = libr_icon_geticon_byname(handle, entry->name); if (KGlobal::iconLoader()->iconPath(entry->name, 0, true) != "") {
} iconresnamefound = 1;
if (KGlobal::iconLoader()->iconPath(entry->name, 0, true) != "") { m_strIconName = entry->name;
iconresnamefound = 1; break;
m_strIconName = entry->name;
break;
}
} }
} }
}
if (libr_can_continue == 1) { if (libr_can_continue == 1) {
if ((iconresnamefound == 0) && (icon)) { if ((iconresnamefound == 0) && (icon)) {
// Extract the embedded icon // Extract the embedded icon
size_t icon_data_length; size_t icon_data_length;
char* icondata = libr_icon_malloc(icon, &icon_data_length); char* icondata = libr_icon_malloc(icon, &icon_data_length);
m_customIconPixmap.loadFromData(static_cast<uchar*>(static_cast<void*>(icondata)), icon_data_length); // EVIL CAST m_customIconPixmap.loadFromData(static_cast<uchar*>(static_cast<void*>(icondata)), icon_data_length); // EVIL CAST
if (icon_size != 0) { if (icon_size != 0) {
TQImage ip = m_customIconPixmap.convertToImage(); TQImage ip = m_customIconPixmap.convertToImage();
ip = ip.smoothScale(icon_size, icon_size); ip = ip.smoothScale(icon_size, icon_size);
m_customIconPixmap.convertFromImage(ip); m_customIconPixmap.convertFromImage(ip);
}
free(icondata);
libr_icon_close(icon);
} }
free(icondata);
libr_close(handle); libr_icon_close(icon);
} }
libr_close(handle);
} }
} }
}
#endif // HAVE_ELFICON #endif // HAVE_ELFICON
}
break; break;
} }
case KURIFilterData::HELP: case KURIFilterData::HELP:

Loading…
Cancel
Save