From 92ed81a1fe16bb1496fbda984a42114c2eec59fd Mon Sep 17 00:00:00 2001 From: Hombre Date: Wed, 2 Jan 2019 22:39:49 +0100 Subject: [PATCH] Non used svg2png cache folders are now deleted when exiting RT see #3547 --- rtgui/guiutils.cc | 10 --------- rtgui/main.cc | 1 - rtgui/rtscalable.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++ rtgui/rtscalable.h | 4 +++- rtgui/rtwindow.cc | 2 ++ 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index a2fe46531..bdd5f65d9 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -898,18 +898,8 @@ bool MyExpander::on_toggle(GdkEventButton* event) if (!useEnabled) { if (isVisible) { statusImage->set(closedImage->get_surface()); - if (closedImage->get_surface().operator bool()) { - Cairo::RefPtr p = closedImage->get_surface(); - int w = p->get_width(); - int h = p->get_height(); - } } else { statusImage->set(openedImage->get_surface()); - if (openedImage->get_surface().operator bool()) { - Cairo::RefPtr p = openedImage->get_surface(); - int w = p->get_width(); - int h = p->get_height(); - } } } diff --git a/rtgui/main.cc b/rtgui/main.cc index c84f074dd..4bfbdaf5a 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -356,7 +356,6 @@ RTWindow *create_rt_window() } } if (!css.empty()) { - printf("CSS: %s\nfontScale: %.5f\n\n", css.c_str(), fontScale); try { cssForced = Gtk::CssProvider::create(); cssForced->load_from_data (css); diff --git a/rtgui/rtscalable.cc b/rtgui/rtscalable.cc index 91f3f37d4..55b784009 100644 --- a/rtgui/rtscalable.cc +++ b/rtgui/rtscalable.cc @@ -74,6 +74,60 @@ void RTScalable::init(Gtk::Window *window) direction = window->get_direction(); } +void RTScalable::deleteDir(const Glib::ustring& path) +{ + int error = 0; + try { + + Glib::Dir dir (path); + + // Removing the directory content + for (auto entry = dir.begin(); entry != dir.end(); ++entry) { + error |= g_remove (Glib::build_filename (path, *entry).c_str()); + } + + if (error != 0 && options.rtSettings.verbose) { + std::cerr << "Failed to delete all entries in '" << path << "': " << g_strerror(errno) << std::endl; + } + + } catch (Glib::Error&) { + error = 1; + } + + // Removing the directory itself + if (!error) { + try { + + error = g_remove (path.c_str()); + + } catch (Glib::Error&) {} + } +} + +void RTScalable::cleanup() +{ + Glib::ustring imagesCacheFolder = Glib::build_filename (options.cacheBaseDir, "svg2png"); + Glib::ustring sDPI = Glib::ustring::compose("%1", (int)getTweakedDPI()); + + try { + Glib::Dir dir(imagesCacheFolder); + + for (Glib::DirIterator entry = dir.begin(); entry != dir.end(); ++entry) { + const Glib::ustring fileName = *entry; + const Glib::ustring filePath = Glib::build_filename(imagesCacheFolder, fileName); + if (fileName == "." || fileName == ".." || !Glib::file_test(filePath, Glib::FILE_TEST_IS_DIR)) { + continue; + } + + if (fileName != sDPI) { + deleteDir(filePath); + } + } + } catch (Glib::Exception&) { + } + +} + /* * This function try to find the svg file converted to png in a cache and return * the Cairo::ImageSurface. If it can't find it, it will generate it. diff --git a/rtgui/rtscalable.h b/rtgui/rtscalable.h index 872fc2674..a932038f2 100644 --- a/rtgui/rtscalable.h +++ b/rtgui/rtscalable.h @@ -29,15 +29,17 @@ class RTScalable static double dpi; static int scale; static Gtk::TextDirection direction; // cached value for text-direction + static void deleteDir(const Glib::ustring& path); protected: static void setDPInScale (const double newDPI, const int newScale); static Cairo::RefPtr loadImage(const Glib::ustring &fname, double dpi); - Gtk::TextDirection getDirection(); + static Gtk::TextDirection getDirection(); public: static void init(Gtk::Window *window); + static void cleanup(); static double getDPI (); static double getTweakedDPI (); // The returned value is tweaked DPI to adapt to main the font size. Maybe not an ideal solution. static int getScale (); diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index 96b9ad914..ee5947632 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -321,6 +321,8 @@ RTWindow::~RTWindow() if (fpanel) { delete fpanel; } + + RTScalable::cleanup(); } void RTWindow::on_realize ()