From 3711a6df5e03e55707adf550e94c7e7745d71aa6 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 5 Feb 2011 08:04:11 -0500 Subject: [PATCH] Clear from cache - for selected thumbnails (issue 386) --- rtdata/languages/default | 3 +++ rtgui/cachemanager.cc | 18 ++++++++++++++++++ rtgui/cachemanager.h | 1 + rtgui/filebrowser.cc | 26 +++++++++++++++++++++++++- rtgui/filebrowser.h | 4 ++++ rtgui/filecatalog.cc | 13 +++++++++++++ rtgui/filecatalog.h | 1 + 7 files changed, 65 insertions(+), 1 deletion(-) diff --git a/rtdata/languages/default b/rtdata/languages/default index 2c1baca6e..e25755284 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -55,6 +55,9 @@ FILEBROWSER_AUTODARKFRAME;Auto dark frame FILEBROWSER_AUTOFLATFIELD;Auto flat field FILEBROWSER_BROWSEPATHBUTTONHINT;Click to browse to the chosen path FILEBROWSER_BROWSEPATHHINT;Type path to browse (Ctrl-o set focus,Ctrl-Enter to browse in File Browser) +FILEBROWSER_CACHE;Cache +FILEBROWSER_CACHECLEARFROMPARTIAL;Clear from cache - partial +FILEBROWSER_CACHECLEARFROMFULL;Clear from cache - full FILEBROWSER_CLEARPROFILE;Clear profile FILEBROWSER_COPYPROFILE;Copy profile FILEBROWSER_CURRENT_NAME;Current name: diff --git a/rtgui/cachemanager.cc b/rtgui/cachemanager.cc index 21f73223a..bdfa5179a 100644 --- a/rtgui/cachemanager.cc +++ b/rtgui/cachemanager.cc @@ -152,6 +152,7 @@ void CacheManager::deleteEntry (const Glib::ustring& fname) { if (r==openEntries.end() && md5!="") { safe_g_remove (getCacheFileName ("data", fname, md5) + ".txt"); safe_g_remove (getCacheFileName ("profiles", fname, md5) + paramFileExtension); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust16"); safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust"); safe_g_remove (getCacheFileName ("images", fname, md5) + ".jpg"); safe_g_remove (getCacheFileName ("aehistograms", fname, md5)); @@ -163,6 +164,7 @@ void CacheManager::deleteEntry (const Glib::ustring& fname) { if (md5!="") { safe_g_remove (getCacheFileName ("data", fname, md5) + ".txt"); safe_g_remove (getCacheFileName ("profiles", fname, md5) + paramFileExtension); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust16"); safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust"); safe_g_remove (getCacheFileName ("images", fname, md5) + ".jpg"); safe_g_remove (getCacheFileName ("aehistograms", fname, md5)); @@ -171,6 +173,20 @@ void CacheManager::deleteEntry (const Glib::ustring& fname) { } } +void CacheManager::clearFromCache (const Glib::ustring& fname, bool leavenotrace) { + std::string md5 = getMD5 (fname); + if (md5!="") { + if (leavenotrace){ + safe_g_remove (getCacheFileName ("data", fname, md5) + ".txt"); + safe_g_remove (getCacheFileName ("profiles", fname, md5) + paramFileExtension); + } + safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust16"); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".cust"); + safe_g_remove (getCacheFileName ("images", fname, md5) + ".jpg"); + safe_g_remove (getCacheFileName ("aehistograms", fname, md5)); + safe_g_remove (getCacheFileName ("embprofiles", fname, md5) + ".icc"); + } +} void CacheManager::renameEntry (const std::string& oldfilename, const std::string& oldmd5, const std::string& newfilename) { @@ -179,6 +195,7 @@ void CacheManager::renameEntry (const std::string& oldfilename, const std::strin std::string newmd5 = getMD5 (newfilename); safe_g_rename (getCacheFileName ("profiles", oldfilename, oldmd5) + paramFileExtension, (getCacheFileName ("profiles", newfilename, newmd5) + paramFileExtension).c_str()); + safe_g_rename (getCacheFileName ("images", oldfilename, oldmd5) + ".cust16", getCacheFileName ("images", newfilename, newmd5) + ".cust16"); safe_g_rename (getCacheFileName ("images", oldfilename, oldmd5) + ".cust", getCacheFileName ("images", newfilename, newmd5) + ".cust"); safe_g_rename (getCacheFileName ("images", oldfilename, oldmd5) + ".jpg", getCacheFileName ("images", newfilename, newmd5) + ".jpg"); safe_g_rename (getCacheFileName ("aehistograms", oldfilename, oldmd5), getCacheFileName ("aehistograms", newfilename, newmd5)); @@ -291,6 +308,7 @@ void CacheManager::applyCacheSizeLimitation () { std::sort (flist.begin(), flist.end()); while (flist.size() > options.maxCacheEntries) { safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "data"), flist.front().fname) + ".txt"); + safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".cust16"); safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".cust"); safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "images"), flist.front().fname) + ".jpg"); safe_g_remove (Glib::build_filename (Glib::build_filename (baseDir, "aehistograms"), flist.front().fname)); diff --git a/rtgui/cachemanager.h b/rtgui/cachemanager.h index 983c2acbd..d0571401a 100644 --- a/rtgui/cachemanager.h +++ b/rtgui/cachemanager.h @@ -59,6 +59,7 @@ class CacheManager { void clearAll (); void clearThumbImages (); void clearProfiles (); + void clearFromCache(const Glib::ustring& fname, bool leavenotrace); void applyCacheSizeLimitation (); diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index cb91f2a45..36df5b775 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -3,6 +3,7 @@ * * Copyright (c) 2004-2010 Gabor Horvath * Copyright (c) 2011 Oliver Duis + * Copyright (c) 2011 Michael Ezra * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -75,6 +76,8 @@ FileBrowser::FileBrowser () pmenu->attach (*(partpasteprof = new Gtk::MenuItem (M("FILEBROWSER_PARTIALPASTEPROFILE"))), 0, 1, p, p+1); p++; pmenu->attach (*(applyprof = new Gtk::MenuItem (M("FILEBROWSER_APPLYPROFILE"))), 0, 1, p, p+1); p++; pmenu->attach (*(clearprof = new Gtk::MenuItem (M("FILEBROWSER_CLEARPROFILE"))), 0, 1, p, p+1); p++; + pmenu->attach (*(cachemenu = new Gtk::MenuItem (M("FILEBROWSER_CACHE"))), 0, 1, p, p+1); p++; + pmenu->show_all (); pmaccelgroup = Gtk::AccelGroup::create (); @@ -109,7 +112,8 @@ FileBrowser::FileBrowser () pasteprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), pasteprof)); partpasteprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), partpasteprof)); applyprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), applyprof)); - clearprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), clearprof)); + clearprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), clearprof)); + cachemenu->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), cachemenu)); } void FileBrowser::rightClicked (ThumbBrowserEntryBase* entry) { @@ -143,6 +147,16 @@ void FileBrowser::rightClicked (ThumbBrowserEntryBase* entry) { } applyprof->set_submenu (*applmenu); + // build cache sub menu + p = 0; + Gtk::Menu* cachesubmenu = Gtk::manage (new Gtk::Menu ()); + cachesubmenu->attach (*(clearFromCache = new Gtk::MenuItem (M("FILEBROWSER_CACHECLEARFROMPARTIAL"))), 0, 1, p, p+1); p++; + cachesubmenu->attach (*(clearFromCacheFull = new Gtk::MenuItem (M("FILEBROWSER_CACHECLEARFROMFULL"))), 0, 1, p, p+1); p++; + clearFromCache->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), clearFromCache)); + clearFromCacheFull->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), clearFromCacheFull)); + cachesubmenu->show_all (); + cachemenu->set_submenu (*cachesubmenu); + pmenu->popup (3, this->eventTime); } @@ -402,6 +416,16 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) { mselected[i]->thumbnail->clearProcParams (FILEBROWSER); queue_draw (); } + else if (m==clearFromCache) { + for (int i=0; iclearFromCacheRequested (mselected, false); + //queue_draw (); + } + else if (m==clearFromCacheFull) { + for (int i=0; iclearFromCacheRequested (mselected, true); + //queue_draw (); + } } void FileBrowser::copyProfile () { diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index ac084f4f9..9508f0a8e 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -36,6 +36,7 @@ class FileBrowserListener { virtual void renameRequested (std::vector tbe) {} virtual void deleteRequested (std::vector tbe, bool inclBatchProcessed) {} virtual void selectionChanged (std::vector tbe) {} + virtual void clearFromCacheRequested(std::vector tbe, bool leavenotrace) {} }; struct FileBrowserIdleHelper { @@ -70,6 +71,9 @@ class FileBrowser : public ThumbBrowserBase, public LWButtonListener { Gtk::MenuItem* partpasteprof; Gtk::MenuItem* applyprof; Gtk::MenuItem* clearprof; + Gtk::MenuItem* cachemenu; + Gtk::MenuItem* clearFromCache; + Gtk::MenuItem* clearFromCacheFull; Gtk::Menu* pmenu; Gtk::Menu* profmenu; Glib::RefPtr pmaccelgroup; diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index a46b88667..cf57c1464 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -2,6 +2,7 @@ * This file is part of RawTherapee. * * Copyright (c) 2004-2010 Gabor Horvath + * Copyright (c) 2011 Michael Ezra * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -657,6 +658,18 @@ void FileCatalog::renameRequested (std::vector tbe) { */ } +void FileCatalog::clearFromCacheRequested (std::vector tbe, bool leavenotrace) { + + if (tbe.size()==0) + return; + + for (unsigned int i=0; ifilename; + // remove from cache + cacheMgr->clearFromCache (fname,leavenotrace); + } +} + void FileCatalog::categoryButtonToggled (Gtk::ToggleButton* b) { //was control key pressed diff --git a/rtgui/filecatalog.h b/rtgui/filecatalog.h index 434f3b60e..b9c295761 100644 --- a/rtgui/filecatalog.h +++ b/rtgui/filecatalog.h @@ -164,6 +164,7 @@ class FileCatalog : public Gtk::VBox, void deleteRequested (std::vector tbe, bool inclBatchProcessed); void developRequested (std::vector tbe); void renameRequested (std::vector tbe); + void clearFromCacheRequested(std::vector tbe, bool leavenotrace); void selectionChanged (std::vector tbe); void emptyTrash (); bool trashIsEmpty ();