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:27:34 +00:00
parent c13303e9d9
commit 667b8f8856
2 changed files with 68 additions and 8 deletions

View File

@ -174,6 +174,65 @@ FileIconView::FileIconView(int X, int Y, int W, int H, char*label) : edelib::Exp
} }
// Try various names and sizes for icons
Fl_Image* FileIconView::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_MEDIUM);
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_TINY);
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_MEDIUM, edelib::ICON_SIZE_MEDIUM);
}
}
// 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 manipulating items // Methods for manipulating 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)
@ -235,10 +294,9 @@ void FileIconView::insert(int row, FileItem *item) {
b->tooltip(strdup(tooltip.c_str())); b->tooltip(strdup(tooltip.c_str()));
b->user_data(strdup(item->realpath.c_str())); b->user_data(strdup(item->realpath.c_str()));
// Set icon // Don't crash if try_icon returns nothing
edelib::String icon = edelib::IconTheme::get(item->icon.c_str(),edelib::ICON_SIZE_MEDIUM); Fl_Image *tmp = try_icon(item->icon);
if (icon=="") icon = edelib::IconTheme::get("empty",edelib::ICON_SIZE_MEDIUM,edelib::ICON_CONTEXT_MIMETYPE); //in crystalsvg "misc" is better... if (tmp) b->image(tmp);
b->image(Fl_Shared_Image::get(icon.c_str()));
#ifdef USE_FLU_WRAP_GROUP #ifdef USE_FLU_WRAP_GROUP
Flu_Wrap_Group::insert(*b,row); Flu_Wrap_Group::insert(*b,row);
@ -284,10 +342,9 @@ void FileIconView::update(FileItem *item) {
edelib::String tooltip = _("Name: ")+item->name+_("\nSize: ")+item->size+_("\nType: ")+item->description+_("\nDate: ")+item->date+_("\nPermissions: ")+item->permissions; edelib::String tooltip = _("Name: ")+item->name+_("\nSize: ")+item->size+_("\nType: ")+item->description+_("\nDate: ")+item->date+_("\nPermissions: ")+item->permissions;
w->tooltip(strdup(tooltip.c_str())); w->tooltip(strdup(tooltip.c_str()));
// Set icon // Don't crash if try_icon returns nothing
edelib::String icon = edelib::IconTheme::get(item->icon.c_str(),edelib::ICON_SIZE_MEDIUM); Fl_Image *tmp = try_icon(item->icon);
if (icon=="") icon = edelib::IconTheme::get("empty",edelib::ICON_SIZE_MEDIUM,edelib::ICON_CONTEXT_MIMETYPE); //in crystalsvg "misc" is better... if (tmp) w->image(tmp);
w->image(Fl_Shared_Image::get(icon.c_str()));
w->redraw(); w->redraw();
} }

View File

@ -77,6 +77,9 @@ 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);
public: public: