Non used svg2png cache folders are now deleted when exiting RT
see #3547
This commit is contained in:
parent
4ee5c96392
commit
92ed81a1fe
@ -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<Cairo::ImageSurface> 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<Cairo::ImageSurface> p = openedImage->get_surface();
|
||||
int w = p->get_width();
|
||||
int h = p->get_height();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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<Cairo::ImageSurface> 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 ();
|
||||
|
@ -321,6 +321,8 @@ RTWindow::~RTWindow()
|
||||
if (fpanel) {
|
||||
delete fpanel;
|
||||
}
|
||||
|
||||
RTScalable::cleanup();
|
||||
}
|
||||
|
||||
void RTWindow::on_realize ()
|
||||
|
Loading…
x
Reference in New Issue
Block a user