NEW:Fixed some mall issues

Change-Id: I1f9105a1a7089457f4ecb327cb5db43ca0d39f4e
(cherry picked from commit 975bdcf64f88b4f1e7c0e03abd9dfba6c32c00fe)
This commit is contained in:
tao wang 2022-10-31 22:22:49 +08:00 committed by Lane.Wei
parent 2406cc35b6
commit 75e960f999
6 changed files with 78 additions and 30 deletions

View file

@ -4915,10 +4915,15 @@ void GUI_App::open_mall_page_dialog()
if (getAgent() && mainframe) {
getAgent()->get_model_mall_home_url(&url);
ModelMallDialog modelMallDialog;
modelMallDialog.go_to_mall(url);
modelMallDialog.ShowModal();
}
if (!m_mall_home_dialog) {
m_mall_home_dialog = new ModelMallDialog();
m_mall_home_dialog->go_to_mall(url);
}
else {
m_mall_home_dialog->go_to_mall(url);
}
m_mall_home_dialog->Show();
}
}
void GUI_App::open_publish_page_dialog()
@ -4927,9 +4932,14 @@ void GUI_App::open_publish_page_dialog()
if (getAgent() && mainframe) {
getAgent()->get_model_publish_url(&url);
ModelMallDialog modelMallDialog;
modelMallDialog.go_to_publish(url);
modelMallDialog.ShowModal();
if (!m_mall_publish_dialog) {
m_mall_publish_dialog = new ModelMallDialog();
m_mall_publish_dialog->go_to_mall(url);
}
else {
m_mall_publish_dialog->go_to_publish(url);
}
m_mall_publish_dialog->Show();
}
}

View file

@ -63,6 +63,7 @@ class NotificationManager;
struct GUI_InitParams;
class ParamsDialog;
class HMSQuery;
class ModelMallDialog;
enum FileType
@ -463,7 +464,10 @@ public:
ParamsDialog* params_dialog();
Model& model();
NotificationManager * notification_manager();
//BBS
ModelMallDialog* m_mall_home_dialog{ nullptr };
ModelMallDialog* m_mall_publish_dialog{ nullptr };
void load_url(wxString url);
void open_mall_page_dialog();
void open_publish_page_dialog();

View file

@ -26,6 +26,10 @@ namespace GUI {
wxBoxSizer* m_sizer_main = new wxBoxSizer(wxVERTICAL);
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0);
m_web_control_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, MODEL_MALL_PAGE_CONTROL_SIZE, wxTAB_TRAVERSAL);
m_web_control_panel->SetBackgroundColour(*wxWHITE);
m_web_control_panel->SetSize(MODEL_MALL_PAGE_CONTROL_SIZE);
@ -55,6 +59,13 @@ namespace GUI {
m_control_forward->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCursor(wxCURSOR_HAND)); });
m_control_forward->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCursor(wxCURSOR_ARROW)); });
auto m_control_refresh = new ScalableButton(m_web_control_panel, wxID_ANY, "mall_control_refresh", wxEmptyString, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, true);
m_control_refresh->SetBackgroundColour(*wxWHITE);
m_control_refresh->SetSize(wxSize(FromDIP(25), FromDIP(30)));
m_control_refresh->SetMinSize(wxSize(FromDIP(25), FromDIP(30)));
m_control_refresh->SetMaxSize(wxSize(FromDIP(25), FromDIP(30)));
m_control_refresh->Bind(wxEVT_LEFT_DOWN, &ModelMallDialog::on_refresh, this);
#ifdef __APPLE__
m_control_back->SetToolTip(_L("Click to return (Command + Left Arrow)"));
@ -73,6 +84,7 @@ namespace GUI {
m_sizer_web_control->Add( m_control_back, 0, wxALIGN_CENTER | wxLEFT, FromDIP(26) );
m_sizer_web_control->Add(m_control_forward, 0, wxALIGN_CENTER | wxLEFT, FromDIP(26));
m_sizer_web_control->Add(m_control_refresh, 0, wxALIGN_CENTER | wxLEFT, FromDIP(26));
//m_sizer_web_control->Add(m_button1, 0, wxALIGN_CENTER|wxLEFT, 5);
//m_sizer_web_control->Add(m_textCtrl1, 0, wxALIGN_CENTER|wxLEFT, 5);
@ -100,6 +112,10 @@ namespace GUI {
Centre(wxBOTH);
Bind(wxEVT_SHOW, &ModelMallDialog::on_show, this);
Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {
this->Hide();
});
}
@ -131,7 +147,7 @@ namespace GUI {
std::string filename = "";
if (j["data"].contains("filename"))
download_url = j["data"]["filename"].get<std::string>();
filename = j["data"]["filename"].get<std::string>();
if (download_url.empty()) return;
wxGetApp().plater()->request_model_download(download_url, filename);
@ -149,9 +165,22 @@ namespace GUI {
void ModelMallDialog::on_show(wxShowEvent& event)
{
if (event.IsShown()) {
Centre(wxBOTH);
}
else {
go_to_url(m_url);
}
event.Skip();
}
void ModelMallDialog::on_refresh(wxMouseEvent& evt)
{
if (!m_browser->GetCurrentURL().empty()) {
m_browser->Reload();
}
}
void ModelMallDialog::on_back(wxMouseEvent& evt)
{
if (m_browser->CanGoBack()) {
@ -181,15 +210,21 @@ namespace GUI {
void ModelMallDialog::go_to_mall(wxString url)
{
//show_control(true);
//m_browser->ClearHistory();
/*if (!url.empty() && m_homepage_url.empty()) {
m_homepage_url = url;
}*/
if(url.empty())return;
m_url = url;
go_to_url(url);
}
void ModelMallDialog::go_to_publish(wxString url)
{
//show_control(true);
//m_browser->ClearHistory();
/*if (!url.empty() && m_publish_url.empty()) {
m_publish_url = url;
}*/
if(url.empty())return;
m_url = url;
go_to_url(url);
}

View file

@ -56,9 +56,11 @@ namespace Slic3r { namespace GUI {
void show_control(bool show);
void go_to_mall(wxString url);
void go_to_publish(wxString url);
void on_refresh(wxMouseEvent& evt);
public:
wxPanel* m_web_control_panel{nullptr};
wxWebView* m_browser{nullptr};
wxString m_url;
};
}} // namespace Slic3r::GUI

View file

@ -7158,7 +7158,7 @@ int Plater::save_project(bool saveAs)
void Plater::import_model_id(const std::string& download_info)
{
std::string download_url = "";
wxString filename = "";
std::string filename = "";
auto selection_data_arr = wxSplit(download_info, '|');
@ -7207,17 +7207,6 @@ void Plater::import_model_id(const std::string& download_info)
std::string http_body;
msg = _L("prepare 3mf file...");
//BBLProfile* profile = new BBLProfile();
//profile->profile_id = profile_id;
//profile->model_id = model_id;
//res = m_agent->get_profile_3mf(profile);
/*if (res < 0 && profile->url.empty() && profile->md5.empty()) {
wxString error_msg = wxString::Format(_devL("get_des,err:code=%u,msg=%s"), http_code, http_body);
msg = _L("Import project failed, Please try again!") + error_msg;
return;
}*/
//filename = from_u8(profile->filename);
//filename = from_u8(fs::path(download_url).filename().string());
//gets the number of files with the same name
std::vector<wxString> vecFiles;
@ -7225,19 +7214,20 @@ void Plater::import_model_id(const std::string& download_info)
target_path = fs::path(wxGetApp().app_config->get("download_path"));
//filename = from_u8(fs::path(download_url).filename().string());
try
{
vecFiles.clear();
wxString extension = fs::path(filename).extension().c_str();
auto name = filename.substr(0, filename.length() - extension.length() - 1);
for (const auto& iter : boost::filesystem::directory_iterator(target_path))
{
if (boost::filesystem::is_directory(iter.path()))
continue;
wxString sFile = iter.path().filename().string().c_str();
if ( strstr(sFile.c_str(), filename.c_str()) != NULL) {
if (strstr(sFile.c_str(), name.c_str()) != NULL) {
vecFiles.push_back(sFile);
}
@ -7252,8 +7242,8 @@ void Plater::import_model_id(const std::string& download_info)
//update filename
if (is_already_exist && vecFiles.size() >= 1) {
wxString extension = fs::path(filename).extension().c_str();
wxString name = filename.SubString(0, filename.length() - extension.length() - 1);
filename = wxString::Format("%s(%d)%s",name, vecFiles.size() + 1, extension);
wxString name = filename.substr(0, filename.length() - extension.length() - 1);
filename = wxString::Format("%s(%d)%s", name, vecFiles.size() + 1, extension).ToStdString();
}
@ -7266,6 +7256,10 @@ void Plater::import_model_id(const std::string& download_info)
boost::uuids::uuid uuid = boost::uuids::random_generator()();
std::string unique = to_string(uuid).substr(0, 6);
if (filename.empty()) {
filename = "untitled.3mf";
}
//target_path /= (boost::format("%1%_%2%.3mf") % filename % unique).str();
target_path /= filename.c_str();
fs::path tmp_path = target_path;