summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f396e4b)
raw | patch | inline | side by side (parent: f396e4b)
author | Jon A. Cruz <jon@joncruz.org> | |
Sat, 18 Dec 2010 06:22:17 +0000 (22:22 -0800) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Sat, 18 Dec 2010 06:22:17 +0000 (22:22 -0800) |
Perform work only when cache loading is enabled.
src/widgets/icon.cpp | patch | blob | history |
diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp
index d8d68461440cdd645711b0c514bbe62c62fa1476..70dee457c961b7e03a786c4563902b18ad73bdae 100644 (file)
--- a/src/widgets/icon.cpp
+++ b/src/widgets/icon.cpp
@@ -1198,6 +1198,19 @@ void Inkscape::queueIconPrerender( Glib::ustring const &name, Inkscape::IconSize
}
}
+static std::map<unsigned, Glib::ustring> sizePaths;
+
+static std::string getDestDir( unsigned psize )
+{
+ if ( sizePaths.find(psize) == sizePaths.end() ) {
+ gchar *tmp = g_strdup_printf("%dx%d", psize, psize);
+ sizePaths[psize] = tmp;
+ g_free(tmp);
+ }
+
+ return sizePaths[psize];
+}
+
// returns true if icon needed preloading, false if nothing was done
bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize)
{
if (dump) {
g_message("prerender_icon [%s] %d:%d", name, lsize, psize);
}
- // In file encoding:
- std::string iconCacheDir = Glib::build_filename(Glib::build_filename(Glib::get_user_cache_dir(), "inkscape"), "icons");
- std::string potentialFile = Glib::build_filename( iconCacheDir, name );
- potentialFile += ".png";
-
+
+ std::string potentialFile;
bool dataLoaded = false;
- if ( useCache && Glib::file_test(potentialFile, Glib::FILE_TEST_EXISTS) && Glib::file_test(potentialFile, Glib::FILE_TEST_IS_REGULAR) ) {
- Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file(potentialFile);
- if (pb) {
- dataLoaded = true;
- GdkPixbuf *obj = pb->gobj();
- g_object_ref(obj);
- pb_cache[key] = obj;
- addToIconSet(obj, name, lsize, psize);
- loadNeeded = true;
- if (internalNames.find(name) == internalNames.end()) {
- internalNames.insert(name);
+ if ( useCache ) {
+ // In file encoding:
+ std::string iconCacheDir = Glib::build_filename(Glib::build_filename(Glib::get_user_cache_dir(), "inkscape"), "icons");
+ std::string subpart = getDestDir(psize);
+ if (subpart.empty()) {
+ g_message("Is empty");
+ }
+ std::string subdir = Glib::build_filename( iconCacheDir, subpart );
+ if ( !Glib::file_test(subdir, Glib::FILE_TEST_EXISTS) ) {
+ g_message("NEED SUB OF [%s]", subdir.c_str());
+ g_mkdir_with_parents( subdir.c_str(), 0x1ED );
+ }
+ potentialFile = Glib::build_filename( subdir, name );
+ potentialFile += ".png";
+
+ if ( Glib::file_test(potentialFile, Glib::FILE_TEST_EXISTS) && Glib::file_test(potentialFile, Glib::FILE_TEST_IS_REGULAR) ) {
+ Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file(potentialFile);
+ if (pb) {
+ dataLoaded = true;
+ GdkPixbuf *obj = pb->gobj();
+ g_object_ref(obj);
+ pb_cache[key] = obj;
+ addToIconSet(obj, name, lsize, psize);
+ loadNeeded = true;
+ if (internalNames.find(name) == internalNames.end()) {
+ internalNames.insert(name);
+ }
}
}
}
@@ -1284,7 +1310,6 @@ static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, u
// did we already load this icon at this scale/size?
GdkPixbuf* pb = get_cached_pixbuf(key);
if (!pb) {
- g_message("YYYYYYYYYYYYY YYYYYYYYYYYYYYY two load_svg_pixels(%s, %d, %d)", name, lsize, psize);
guchar *px = load_svg_pixels(name, lsize, psize);
if (px) {
pb = gdk_pixbuf_new_from_data(px, GDK_COLORSPACE_RGB, TRUE, 8,