mirror of
https://github.com/uowuo/abaddon.git
synced 2024-11-10 06:00:10 +00:00
add menu item to clear image cache
This commit is contained in:
parent
dda203376d
commit
bafd2fa25a
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user