summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--filecache.cpp5
-rw-r--r--filecache.hpp1
-rw-r--r--imgmanager.cpp4
-rw-r--r--imgmanager.hpp1
-rw-r--r--windows/mainwindow.cpp6
-rw-r--r--windows/mainwindow.hpp1
6 files changed, 18 insertions, 0 deletions
diff --git a/filecache.cpp b/filecache.cpp
index 9f9f718..c0b2f36 100644
--- a/filecache.cpp
+++ b/filecache.cpp
@@ -17,6 +17,11 @@ Cache::~Cache() {
fprintf(stderr, "error removing tmp dir\n");
}
+void Cache::ClearCache() {
+ for (const auto &path : std::filesystem::directory_iterator(m_tmp_path))
+ std::filesystem::remove_all(path);
+}
+
std::string Cache::GetCachedName(std::string str) {
uint32_t out;
MurmurHash3_x86_32(str.c_str(), str.size(), 0, &out);
diff --git a/filecache.hpp b/filecache.hpp
index 394b8ca..0826fc0 100644
--- a/filecache.hpp
+++ b/filecache.hpp
@@ -17,6 +17,7 @@ public:
using callback_type = std::function<void(std::string)>;
void GetFileFromURL(std::string url, callback_type cb);
std::string GetPathIfCached(std::string url);
+ void ClearCache();
private:
std::string GetCachedName(std::string str);
diff --git a/imgmanager.cpp b/imgmanager.cpp
index c1c67fd..8d23144 100644
--- a/imgmanager.cpp
+++ b/imgmanager.cpp
@@ -9,6 +9,10 @@ Cache &ImageManager::GetCache() {
return m_cache;
}
+void ImageManager::ClearCache() {
+ m_cache.ClearCache();
+}
+
Glib::RefPtr<Gdk::Pixbuf> ImageManager::ReadFileToPixbuf(std::string path) {
const auto &data = ReadWholeFile(path);
if (data.size() == 0) return Glib::RefPtr<Gdk::Pixbuf>(nullptr);
diff --git a/imgmanager.hpp b/imgmanager.hpp
index f665a7b..eb8a590 100644
--- a/imgmanager.hpp
+++ b/imgmanager.hpp
@@ -14,6 +14,7 @@ public:
using callback_type = sigc::slot<void(Glib::RefPtr<Gdk::Pixbuf>)>;
Cache &GetCache();
+ void ClearCache();
void LoadFromURL(std::string url, callback_type cb);
// animations need dimensions before loading since there is no (easy) way to scale a PixbufAnimation
void LoadAnimationFromURL(std::string url, int w, int h, callback_anim_type cb);
diff --git a/windows/mainwindow.cpp b/windows/mainwindow.cpp
index 248595a..a09309f 100644
--- a/windows/mainwindow.cpp
+++ b/windows/mainwindow.cpp
@@ -31,8 +31,10 @@ MainWindow::MainWindow()
m_menu_file.set_submenu(m_menu_file_sub);
m_menu_file_reload_settings.set_label("Reload Settings");
m_menu_file_reload_css.set_label("Reload CSS");
+ m_menu_file_clear_cache.set_label("Clear file cache");
m_menu_file_sub.append(m_menu_file_reload_settings);
m_menu_file_sub.append(m_menu_file_reload_css);
+ m_menu_file_sub.append(m_menu_file_clear_cache);
m_menu_bar.append(m_menu_file);
m_menu_bar.append(m_menu_discord);
@@ -66,6 +68,10 @@ MainWindow::MainWindow()
m_signal_action_reload_settings.emit();
});
+ m_menu_file_clear_cache.signal_activate().connect([this] {
+ Abaddon::Get().GetImageManager().ClearCache();
+ });
+
m_content_box.set_hexpand(true);
m_content_box.set_vexpand(true);
m_content_box.show();
diff --git a/windows/mainwindow.hpp b/windows/mainwindow.hpp
index 241851e..747cc73 100644
--- a/windows/mainwindow.hpp
+++ b/windows/mainwindow.hpp
@@ -85,4 +85,5 @@ protected:
Gtk::Menu m_menu_file_sub;
Gtk::MenuItem m_menu_file_reload_settings;
Gtk::MenuItem m_menu_file_reload_css;
+ Gtk::MenuItem m_menu_file_clear_cache;
};