MCPcopy Create free account
hub / github.com/RGAA-Software/GoDesk / LoadAvatar

Method LoadAvatar

src/render_panel/gr_workspace.cpp:837–872  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

835 }
836
837 void GrWorkspace::LoadAvatar() {
838 context_->PostTask([=, this]() {
839 auto avatar_path = user_mgr_->GetAvatarPath();
840 if (avatar_path.starts_with("./")) {
841 avatar_path = avatar_path.substr(1);
842 }
843 auto avatar_url_path = std::format("https://{}:{}{}?appkey={}", settings_->GetSpvrServerHost(), settings_->GetSpvrServerPort(), avatar_path, grApp->GetAppkey());
844 auto target_avatar_path = settings_->GetGrDataCachePath() + "/" + user_mgr_->GetUserId() + + "." + FileUtil::GetFileSuffix(avatar_path);
845 LOGI("Cached avatar path: {}", target_avatar_path);
846 if (File::Exists(target_avatar_path)) {
847 LOGI("Load local avatar first");
848 context_->PostUITask([=, this]() {
849 this->SetAvatar(target_avatar_path);
850 });
851 }
852
853 auto target_avatar_cache_path = settings_->GetGrDataCachePath() + "/" + user_mgr_->GetUserId() + + "_cache." + FileUtil::GetFileSuffix(avatar_path);
854 auto file = File::OpenForWriteB(target_avatar_cache_path);
855 auto r = HttpClient::Download(avatar_url_path, [=, this](const std::string& d) {
856 file->Append(d);
857 });
858 if (r.status == 200) {
859 LOGI("Load avatar from server and refresh it!");
860 file->Close();
861 File::Delete(target_avatar_path);
862 FileUtil::ReName(target_avatar_cache_path, target_avatar_path);
863 File::Delete(target_avatar_cache_path);
864 context_->PostUITask([=, this]() {
865 this->SetAvatar(target_avatar_path);
866 });
867 }
868 else {
869 file->Close();
870 }
871 });
872 }
873
874 void GrWorkspace::SetAvatar(const std::string& filepath) {
875 auto pixmap = QPixmap::fromImage(QImage(filepath.c_str()));

Callers 1

LoginMethod · 0.95

Calls 10

SetAvatarMethod · 0.95
GetAvatarPathMethod · 0.80
GetSpvrServerHostMethod · 0.80
GetSpvrServerPortMethod · 0.80
GetAppkeyMethod · 0.80
GetGrDataCachePathMethod · 0.80
GetUserIdMethod · 0.80
CloseMethod · 0.80
PostTaskMethod · 0.45
PostUITaskMethod · 0.45

Tested by

no test coverage detected