added file existence check

This commit is contained in:
Dordovel 2022-11-29 09:00:12 +03:00
parent da3d9533d1
commit 7671ccfbc6

View File

@ -10,6 +10,7 @@
#include "gdkmm/cursor.h" #include "gdkmm/cursor.h"
#include "gdkmm/event.h" #include "gdkmm/event.h"
#include "gdkmm/types.h" #include "gdkmm/types.h"
#include "glibmm/fileutils.h"
#include "sigc++/functors/mem_fun.h" #include "sigc++/functors/mem_fun.h"
#include "sigc++/functors/ptr_fun.h" #include "sigc++/functors/ptr_fun.h"
@ -106,8 +107,12 @@ void User::init_default_user_avatar(int width, int height) {
} }
void User::init_user_avatar(const std::string& path, int width, int height) { void User::init_user_avatar(const std::string& path, int width, int height) {
if (Glib::file_test(path, Glib::FILE_TEST_EXISTS)) {
Glib::RefPtr<Gdk::Pixbuf> pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height); Glib::RefPtr<Gdk::Pixbuf> pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height);
AIconLabel::image_.set(pixbuf_); AIconLabel::image_.set(pixbuf_);
} else {
AIconLabel::box_.remove(AIconLabel::image_);
}
} }
auto User::update() -> void { auto User::update() -> void {