Try very hard to find icon of different name/size if the exact match

doesn't exist
This commit is contained in:
Vedran Ljubovic 2008-10-29 11:17:11 +00:00
parent 9956ff980f
commit c13303e9d9
2 changed files with 67 additions and 8 deletions

View File

@ -173,6 +173,64 @@ FileDetailsView::FileDetailsView(int X, int Y, int W, int H, char*label) : EDE_B
} }
// Try various names and sizes for icons
Fl_Image* FileDetailsView::try_icon(edelib::String icon_name) {
edelib::String icon_path;
edelib::String tmpname;
fprintf (stderr, "-- Trying %s\n", icon_name.c_str());
icon_path = edelib::IconTheme::get(icon_name.c_str(), edelib::ICON_SIZE_TINY);
if (icon_path!="")
return Fl_Shared_Image::get(icon_path.c_str());
// Because edelib doesn't resample icons, we need to do that manually
icon_path = edelib::IconTheme::get(icon_name.c_str(),edelib::ICON_SIZE_SMALL);
if (icon_path=="") icon_path = edelib::IconTheme::get(icon_name.c_str(),edelib::ICON_SIZE_MEDIUM);
if (icon_path=="") icon_path = edelib::IconTheme::get(icon_name.c_str(),edelib::ICON_SIZE_LARGE);
if (icon_path=="") icon_path = edelib::IconTheme::get(icon_name.c_str(),edelib::ICON_SIZE_HUGE);
if (icon_path=="") icon_path = edelib::IconTheme::get(icon_name.c_str(),edelib::ICON_SIZE_ENORMOUS);
if (icon_path!="") {
Fl_Image *temp = Fl_Shared_Image::get(icon_path.c_str());
if (temp) {
return temp->copy(edelib::ICON_SIZE_TINY, edelib::ICON_SIZE_TINY);
}
}
// Try Gnome icons
if (icon_name.substr(0,11) != "gnome-mime-") {
tmpname = "gnome-mime-";
tmpname += icon_name;
Fl_Image *tmpimage = try_icon(tmpname);
if (tmpimage) return tmpimage;
// Try generic icons without last part
if (icon_name.find('-',0) != edelib::String::npos) {
tmpname = icon_name.substr(0,icon_name.find('-',0));
tmpimage = try_icon(tmpname);
if (tmpimage) return tmpimage;
// Replace text with txt
if (tmpname == "text") {
tmpimage = try_icon("txt");
if (tmpimage) return tmpimage;
}
}
// No icon found for this mimetype, we're trying a generic "file" icon
// (in crystalsvg "misc" looks better...)
if (icon_name != "empty") {
return try_icon("empty");
}
}
// Not even generic icon is found :(
return 0;
}
// Methods for mainpulating items // Methods for mainpulating items
// They are named similarly to browser methods, except that they take // They are named similarly to browser methods, except that they take
// struct FileItem (defined in EDE_FileView.h) // struct FileItem (defined in EDE_FileView.h)
@ -188,10 +246,9 @@ void FileDetailsView::insert(int row, FileItem *item) {
bucket.add(realpath); bucket.add(realpath);
EDEBUG(DBG "value: %s\n", value.c_str()); EDEBUG(DBG "value: %s\n", value.c_str());
// Get icon // Don't crash if try_icon returns nothing
edelib::String icon = edelib::IconTheme::get(item->icon.c_str(),edelib::ICON_SIZE_TINY); Fl_Image *tmp = try_icon(item->icon);
if (icon=="") icon = edelib::IconTheme::get("empty",edelib::ICON_SIZE_TINY,edelib::ICON_CONTEXT_MIMETYPE); //in crystalsvg "misc" is better... if (tmp) set_icon(row, tmp);
set_icon(row, Fl_Shared_Image::get(icon.c_str()));
} }
@ -216,10 +273,9 @@ void FileDetailsView::update(FileItem *item) {
bucket.add(realpath); bucket.add(realpath);
EDEBUG(DBG "value: %s\n", value.c_str()); EDEBUG(DBG "value: %s\n", value.c_str());
// Get icon // Don't crash if try_icon returns nothing
edelib::String icon = edelib::IconTheme::get(item->icon.c_str(),edelib::ICON_SIZE_TINY); Fl_Image *tmp = try_icon(item->icon);
if (icon=="") icon = edelib::IconTheme::get("empty",edelib::ICON_SIZE_TINY,edelib::ICON_CONTEXT_MIMETYPE); //in crystalsvg "misc" is better... if (tmp) set_icon(row, tmp);
set_icon(row, Fl_Shared_Image::get(icon.c_str()));
} }
// This method is needed because update() uses path to find item in list // This method is needed because update() uses path to find item in list

View File

@ -16,6 +16,7 @@
#include <FL/Fl_Input.H> #include <FL/Fl_Input.H>
#include <FL/Fl_Image.H>
#include <edelib/String.h> #include <edelib/String.h>
@ -54,6 +55,8 @@ private:
// This is called to actually rename file (when user presses Enter in editbox) // This is called to actually rename file (when user presses Enter in editbox)
void finish_rename(); void finish_rename();
// Try various names and sizes for icons
Fl_Image* try_icon(edelib::String icon_name);
// Find row number corresponding to realpath (encoded in data()) // Find row number corresponding to realpath (encoded in data())
int findrow(edelib::String realpath) { int findrow(edelib::String realpath) {