mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
Upload changes
PrusaLink: Use PUT or POST based on information read during test connection (upload-by-put). If put - do additional GET for storage_list and let user to choose where to upload or show name if only 1 is possible. Allow PrusaLink for MK2.5 and MK2.5S. PrusaConnect: New host type PrusaConnect inherited from PrusaLink class with filled host address, disabled http diggest. After upload read header information - status message and pass it to notification and Printhost upload dialog via events, this message can be shown as warning notification and is recieved in localized lang. Pass accept-language shortcut in upload header. 3 option to upload. (upload, to queue, to print) Upload Notification: Showing status text, changes in text, not showing close button, Completed state on special call (not 100%) and other design changes. Right panel: Open URL button.
This commit is contained in:
parent
13deee3c8f
commit
9df97e004d
20 changed files with 1530 additions and 204 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "NotificationManager.hpp"
|
||||
#include "ExtraRenderers.hpp"
|
||||
#include "format.hpp"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
@ -35,11 +36,14 @@ namespace GUI {
|
|||
|
||||
static const char *CONFIG_KEY_PATH = "printhost_path";
|
||||
static const char *CONFIG_KEY_GROUP = "printhost_group";
|
||||
static const char* CONFIG_KEY_STORAGE = "printhost_storage";
|
||||
|
||||
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUploadActions post_actions, const wxArrayString &groups)
|
||||
: MsgDialog(static_cast<wxWindow*>(wxGetApp().mainframe), _L("Send to print"), _L("Upload to Printer Host with the following filename:"),0)
|
||||
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUploadActions post_actions, const wxArrayString &groups, const wxArrayString& storage)
|
||||
: MsgDialog(static_cast<wxWindow*>(wxGetApp().mainframe), _L("Send G-Code to printer host"), _L("Upload to Printer Host with the following filename:"), 0) // Set style = 0 to avoid default creation of the "OK" button.
|
||||
// All buttons will be added later in this constructor
|
||||
, txt_filename(new wxTextCtrl(this, wxID_ANY))
|
||||
, combo_groups(!groups.IsEmpty() ? new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, groups, wxCB_READONLY) : nullptr)
|
||||
, combo_storage(storage.GetCount() > 1 ? new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, storage, wxCB_READONLY) : nullptr)
|
||||
, post_upload_action(PrintHostPostUploadAction::None)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
|
@ -50,9 +54,8 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
auto *label_dir_hint = new wxStaticText(this, wxID_ANY, _L("Use forward slashes ( / ) as a directory separator if needed."));
|
||||
label_dir_hint->Wrap(CONTENT_WIDTH * wxGetApp().em_unit());
|
||||
|
||||
content_sizer->Add(txt_filename, 0, wxEXPAND | wxALL, FromDIP(10));
|
||||
content_sizer->Add(FromDIP(10), FromDIP(10), 0, 0);
|
||||
content_sizer->Add(label_dir_hint, 0, 0, FromDIP(10));
|
||||
content_sizer->Add(txt_filename, 0, wxEXPAND);
|
||||
content_sizer->Add(label_dir_hint);
|
||||
content_sizer->AddSpacer(VERT_SPACING);
|
||||
|
||||
if (combo_groups != nullptr) {
|
||||
|
@ -65,6 +68,23 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
combo_groups->SetValue(recent_group);
|
||||
}
|
||||
|
||||
if (combo_storage != nullptr) {
|
||||
// PrusaLink specific: User needs to choose a storage
|
||||
auto* label_group = new wxStaticText(this, wxID_ANY, _L("Upload to storage:"));
|
||||
content_sizer->Add(label_group);
|
||||
content_sizer->Add(combo_storage, 0, wxBOTTOM, 2 * VERT_SPACING);
|
||||
combo_storage->SetValue(storage.front());
|
||||
wxString recent_storage = from_u8(app_config->get("recent", CONFIG_KEY_STORAGE));
|
||||
if (!recent_storage.empty())
|
||||
combo_storage->SetValue(recent_storage);
|
||||
} else if (storage.GetCount() == 1){
|
||||
// PrusaLink specific: Show which storage has been detected.
|
||||
auto* label_group = new wxStaticText(this, wxID_ANY, _L("Upload to storage: ") + storage.front());
|
||||
content_sizer->Add(label_group);
|
||||
m_preselected_storage = storage.front();
|
||||
}
|
||||
|
||||
|
||||
wxString recent_path = from_u8(app_config->get("recent", CONFIG_KEY_PATH));
|
||||
if (recent_path.Length() > 0 && recent_path[recent_path.Length() - 1] != '/') {
|
||||
recent_path += '/';
|
||||
|
@ -75,9 +95,9 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
const auto stem_len = stem.Length();
|
||||
|
||||
txt_filename->SetValue(recent_path);
|
||||
txt_filename->SetFocus();
|
||||
|
||||
m_valid_suffix = recent_path.substr(recent_path.find_last_of('.'));
|
||||
|
||||
if (size_t extension_start = recent_path.find_last_of('.'); extension_start != std::string::npos)
|
||||
m_valid_suffix = recent_path.substr(extension_start);
|
||||
// .gcode suffix control
|
||||
auto validate_path = [this](const wxString &path) -> bool {
|
||||
if (! path.Lower().EndsWith(m_valid_suffix.Lower())) {
|
||||
|
@ -88,13 +108,24 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
return true;
|
||||
};
|
||||
|
||||
auto* btn_upload = add_button(wxID_YES, false, _L("Upload"));
|
||||
btn_upload->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
|
||||
auto* btn_ok = add_button(wxID_OK, true, _L("Upload"));
|
||||
btn_ok->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
|
||||
if (validate_path(txt_filename->GetValue())) {
|
||||
post_upload_action = PrintHostPostUploadAction::None;
|
||||
EndDialog(wxID_OK);
|
||||
}
|
||||
});
|
||||
txt_filename->SetFocus();
|
||||
|
||||
if (post_actions.has(PrintHostPostUploadAction::QueuePrint)) {
|
||||
auto* btn_print = add_button(wxID_ADD, false, _L("Upload to Queue"));
|
||||
btn_print->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
|
||||
if (validate_path(txt_filename->GetValue())) {
|
||||
post_upload_action = PrintHostPostUploadAction::QueuePrint;
|
||||
EndDialog(wxID_OK);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (post_actions.has(PrintHostPostUploadAction::StartPrint)) {
|
||||
auto* btn_print = add_button(wxID_YES, false, _L("Upload and Print"));
|
||||
|
@ -108,7 +139,7 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
|
||||
if (post_actions.has(PrintHostPostUploadAction::StartSimulation)) {
|
||||
// Using wxID_MORE as a button identifier to be different from the other buttons, wxID_MORE has no other meaning here.
|
||||
auto* btn_simulate = add_button(wxID_MORE, false, _L("Simulate"));
|
||||
auto* btn_simulate = add_button(wxID_MORE, false, _L("Upload and Simulate"));
|
||||
btn_simulate->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
|
||||
if (validate_path(txt_filename->GetValue())) {
|
||||
post_upload_action = PrintHostPostUploadAction::StartSimulation;
|
||||
|
@ -117,7 +148,7 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
});
|
||||
}
|
||||
|
||||
add_button(wxID_CANCEL,false, L("Cancel"));
|
||||
add_button(wxID_CANCEL);
|
||||
finalize();
|
||||
|
||||
#ifdef __linux__
|
||||
|
@ -135,6 +166,7 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
|
|||
// Another similar case where the function only works with EVT_SHOW + CallAfter,
|
||||
// this time on Mac.
|
||||
CallAfter([=]() {
|
||||
txt_filename->SetInsertionPoint(0);
|
||||
txt_filename->SetSelection(recent_path_len, recent_path_len + stem_len);
|
||||
});
|
||||
});
|
||||
|
@ -160,6 +192,13 @@ std::string PrintHostSendDialog::group() const
|
|||
}
|
||||
}
|
||||
|
||||
std::string PrintHostSendDialog::storage() const
|
||||
{
|
||||
if (!combo_storage)
|
||||
return GUI::format("%1%", m_preselected_storage);
|
||||
return boost::nowide::narrow(combo_storage->GetValue());
|
||||
}
|
||||
|
||||
void PrintHostSendDialog::EndModal(int ret)
|
||||
{
|
||||
if (ret == wxID_OK) {
|
||||
|
@ -178,6 +217,10 @@ void PrintHostSendDialog::EndModal(int ret)
|
|||
wxString group = combo_groups->GetValue();
|
||||
app_config->set("recent", CONFIG_KEY_GROUP, into_u8(group));
|
||||
}
|
||||
if (combo_storage != nullptr) {
|
||||
wxString storage = combo_storage->GetValue();
|
||||
app_config->set("recent", CONFIG_KEY_STORAGE, into_u8(storage));
|
||||
}
|
||||
}
|
||||
|
||||
MsgDialog::EndModal(ret);
|
||||
|
@ -188,6 +231,7 @@ void PrintHostSendDialog::EndModal(int ret)
|
|||
wxDEFINE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event);
|
||||
wxDEFINE_EVENT(EVT_PRINTHOST_ERROR, PrintHostQueueDialog::Event);
|
||||
wxDEFINE_EVENT(EVT_PRINTHOST_CANCEL, PrintHostQueueDialog::Event);
|
||||
wxDEFINE_EVENT(EVT_PRINTHOST_INFO, PrintHostQueueDialog::Event);
|
||||
|
||||
PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_id)
|
||||
: wxEvent(winid, eventType)
|
||||
|
@ -203,7 +247,14 @@ PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_
|
|||
PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_id, wxString error)
|
||||
: wxEvent(winid, eventType)
|
||||
, job_id(job_id)
|
||||
, error(std::move(error))
|
||||
, status(std::move(error))
|
||||
{}
|
||||
|
||||
PrintHostQueueDialog::Event::Event(wxEventType eventType, int winid, size_t job_id, wxString tag, wxString status)
|
||||
: wxEvent(winid, eventType)
|
||||
, job_id(job_id)
|
||||
, tag(std::move(tag))
|
||||
, status(std::move(status))
|
||||
{}
|
||||
|
||||
wxEvent *PrintHostQueueDialog::Event::Clone() const
|
||||
|
@ -216,16 +267,17 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent)
|
|||
, on_progress_evt(this, EVT_PRINTHOST_PROGRESS, &PrintHostQueueDialog::on_progress, this)
|
||||
, on_error_evt(this, EVT_PRINTHOST_ERROR, &PrintHostQueueDialog::on_error, this)
|
||||
, on_cancel_evt(this, EVT_PRINTHOST_CANCEL, &PrintHostQueueDialog::on_cancel, this)
|
||||
, on_info_evt(this, EVT_PRINTHOST_INFO, &PrintHostQueueDialog::on_info, this)
|
||||
{
|
||||
const auto em = GetTextExtent("m").x;
|
||||
|
||||
auto *topsizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
std::vector<int> widths;
|
||||
widths.reserve(6);
|
||||
widths.reserve(7);
|
||||
if (!load_user_data(UDT_COLS, widths)) {
|
||||
widths.clear();
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
for (size_t i = 0; i < 7; i++)
|
||||
widths.push_back(-1);
|
||||
}
|
||||
|
||||
|
@ -246,9 +298,10 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent)
|
|||
job_list->AppendProgressColumn(_L("Progress"), wxDATAVIEW_CELL_INERT, widths[1], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
|
||||
append_text_column(_L("Status"),widths[2]);
|
||||
append_text_column(_L("Host"), widths[3]);
|
||||
append_text_column(_CTX_utf8(L_CONTEXT("Size", "OfFile"), "OfFile"), widths[4]);
|
||||
append_text_column(_CTX(L_CONTEXT("Size", "OfFile"), "OfFile"), widths[4]);
|
||||
append_text_column(_L("Filename"), widths[5]);
|
||||
append_text_column(_L("Error Message"), -1, wxALIGN_CENTER, wxDATAVIEW_COL_HIDDEN);
|
||||
append_text_column(_L("Message"), widths[6]);
|
||||
//append_text_column(_L("Error Message"), -1, wxALIGN_CENTER, wxDATAVIEW_COL_HIDDEN);
|
||||
|
||||
auto *btnsizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
btn_cancel = new wxButton(this, wxID_DELETE, _L("Cancel selected"));
|
||||
|
@ -325,7 +378,7 @@ void PrintHostQueueDialog::append_job(const PrintHostJob &job)
|
|||
} else
|
||||
stream << std::fixed << std::setprecision(2) << ((float)size_i / 1024 / 1024) << "MB";
|
||||
fields.push_back(wxVariant(stream.str()));
|
||||
fields.push_back(wxVariant(job.upload_data.upload_path.string()));
|
||||
fields.push_back(wxVariant(from_path(job.upload_data.upload_path)));
|
||||
fields.push_back(wxVariant(""));
|
||||
job_list->AppendItem(fields, static_cast<wxUIntPtr>(ST_NEW));
|
||||
// Both strings are UTF-8 encoded.
|
||||
|
@ -421,7 +474,7 @@ void PrintHostQueueDialog::on_error(Event &evt)
|
|||
|
||||
set_state(evt.job_id, ST_ERROR);
|
||||
|
||||
auto errormsg = from_u8((boost::format("%1%\n%2%") % _utf8(L("Error uploading to print host:")) % std::string(evt.error.ToUTF8())).str());
|
||||
auto errormsg = from_u8((boost::format("%1%\n%2%") % _utf8(L("Error uploading to print host:")) % std::string(evt.status.ToUTF8())).str());
|
||||
job_list->SetValue(wxVariant(0), evt.job_id, COL_PROGRESS);
|
||||
job_list->SetValue(wxVariant(errormsg), evt.job_id, COL_ERRORMSG); // Stashes the error message into a hidden column for later
|
||||
|
||||
|
@ -450,6 +503,29 @@ void PrintHostQueueDialog::on_cancel(Event &evt)
|
|||
wxGetApp().notification_manager()->upload_job_notification_show_canceled(evt.job_id + 1, boost::nowide::narrow(nm.GetString()), boost::nowide::narrow(hst.GetString()));
|
||||
}
|
||||
|
||||
void PrintHostQueueDialog::on_info(Event& evt)
|
||||
{
|
||||
wxCHECK_RET(evt.job_id < (size_t)job_list->GetItemCount(), "Out of bounds access to job list");
|
||||
|
||||
if (evt.tag == L"resolve") {
|
||||
wxVariant hst(evt.status);
|
||||
job_list->SetValue(hst, evt.job_id, COL_HOST);
|
||||
wxGetApp().notification_manager()->set_upload_job_notification_host(evt.job_id + 1, boost::nowide::narrow(evt.status));
|
||||
} else if (evt.tag == L"complete") {
|
||||
wxVariant hst(evt.status);
|
||||
job_list->SetValue(hst, evt.job_id, COL_ERRORMSG);
|
||||
wxGetApp().notification_manager()->set_upload_job_notification_completed(evt.job_id + 1);
|
||||
wxGetApp().notification_manager()->set_upload_job_notification_status(evt.job_id + 1, boost::nowide::narrow(evt.status));
|
||||
} else if(evt.tag == L"complete_with_warning"){
|
||||
wxVariant hst(evt.status);
|
||||
job_list->SetValue(hst, evt.job_id, COL_ERRORMSG);
|
||||
wxGetApp().notification_manager()->set_upload_job_notification_completed_with_warning(evt.job_id + 1);
|
||||
wxGetApp().notification_manager()->set_upload_job_notification_status(evt.job_id + 1, boost::nowide::narrow(evt.status));
|
||||
} else if (evt.tag == L"set_complete_off") {
|
||||
wxGetApp().notification_manager()->set_upload_job_notification_comp_on_100(evt.job_id + 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintHostQueueDialog::get_active_jobs(std::vector<std::pair<std::string, std::string>>& ret)
|
||||
{
|
||||
int ic = job_list->GetItemCount();
|
||||
|
@ -461,7 +537,6 @@ void PrintHostQueueDialog::get_active_jobs(std::vector<std::pair<std::string, st
|
|||
if(st == JobState::ST_NEW || st == JobState::ST_PROGRESS)
|
||||
ret.emplace_back(upload_names[i]);
|
||||
}
|
||||
//job_list->data
|
||||
}
|
||||
void PrintHostQueueDialog::save_user_data(int udt)
|
||||
{
|
||||
|
@ -510,7 +585,7 @@ bool PrintHostQueueDialog::load_user_data(int udt, std::vector<int>& vector)
|
|||
}
|
||||
if (udt & UserDataType::UDT_COLS)
|
||||
{
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
for (size_t i = 0; i < 7; i++)
|
||||
{
|
||||
if (!hasget("print_host_queue_dialog_column_" + std::to_string(i), vector))
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue