From b8adfbda662af5a225cbd9fd594e8c3314691d45 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 11 Mar 2021 13:35:19 +0100 Subject: [PATCH 1/2] saving size and position of print host queue dialog, added size column, sorting --- src/slic3r/GUI/PrintHostDialogs.cpp | 104 ++++++++++++++++++++++++++-- src/slic3r/GUI/PrintHostDialogs.hpp | 18 ++++- 2 files changed, 114 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index cb4c22299..af98f3279 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -182,15 +182,24 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent) auto *topsizer = new wxBoxSizer(wxVERTICAL); + std::vector widths; + widths.reserve(6); + if (!load_user_data(UDT_COLS, widths)) { + widths.clear(); + for (size_t i = 0; i < 6; i++) + widths.push_back(-1); + } + job_list = new wxDataViewListCtrl(this, wxID_ANY); // Note: Keep these in sync with Column - job_list->AppendTextColumn(_L("ID"), wxDATAVIEW_CELL_INERT); - job_list->AppendProgressColumn(_L("Progress"), wxDATAVIEW_CELL_INERT); - job_list->AppendTextColumn(_L("Status"), wxDATAVIEW_CELL_INERT); - job_list->AppendTextColumn(_L("Host"), wxDATAVIEW_CELL_INERT); - job_list->AppendTextColumn(_L("Filename"), wxDATAVIEW_CELL_INERT); + job_list->AppendTextColumn(_L("ID"), wxDATAVIEW_CELL_INERT, widths[0], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); + job_list->AppendProgressColumn(_L("Progress"), wxDATAVIEW_CELL_INERT, widths[1], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); + job_list->AppendTextColumn(_L("Status"), wxDATAVIEW_CELL_INERT, widths[2], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); + job_list->AppendTextColumn(_L("Host"), wxDATAVIEW_CELL_INERT, widths[3], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); + job_list->AppendTextColumn(_CTX_utf8(L_CONTEXT("Size", "OfFile"), "OfFile"), wxDATAVIEW_CELL_INERT, widths[4], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); + job_list->AppendTextColumn(_L("Filename"), wxDATAVIEW_CELL_INERT, widths[5], wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); job_list->AppendTextColumn(_L("Error Message"), wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, wxDATAVIEW_COL_HIDDEN); - + auto *btnsizer = new wxBoxSizer(wxHORIZONTAL); btn_cancel = new wxButton(this, wxID_DELETE, _L("Cancel selected")); btn_cancel->Disable(); @@ -207,7 +216,21 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent) topsizer->Add(btnsizer, 0, wxEXPAND); SetSizer(topsizer); - SetSize(wxSize(HEIGHT * em, WIDTH * em)); + std::vector size; + SetSize(load_user_data(UDT_SIZE, size) ? wxSize(size[0] * em, size[1] * em) : wxSize(HEIGHT * em, WIDTH * em)); + + Bind(wxEVT_SIZE, [this, em](wxSizeEvent& evt) { + OnSize(evt); + save_user_data(UDT_SIZE | UDT_POSITION | UDT_COLS); + }); + + std::vector pos; + if (load_user_data(UDT_POSITION, pos)) + SetPosition(wxPoint(pos[0], pos[1])); + + Bind(wxEVT_MOVE, [this, em](wxMoveEvent& evt) { + save_user_data(UDT_SIZE | UDT_POSITION | UDT_COLS); + }); job_list->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxDataViewEvent&) { on_list_select(); }); @@ -238,6 +261,12 @@ void PrintHostQueueDialog::append_job(const PrintHostJob &job) fields.push_back(wxVariant(0)); fields.push_back(wxVariant(_L("Enqueued"))); fields.push_back(wxVariant(job.printhost->get_host())); + boost::system::error_code ec; + boost::uintmax_t size_i = boost::filesystem::file_size(job.upload_data.source_path, ec); + std::string size = ec ? "unknown" : ((size_i >> 10) > 1024 ? std::to_string((float)(size_i >> 10)/1024) + "MB" : std::to_string(size_i >> 10) + "KB"); + if (ec) + BOOST_LOG_TRIVIAL(error) << ec.message(); + fields.push_back(wxVariant(size)); fields.push_back(wxVariant(job.upload_data.upload_path.string())); fields.push_back(wxVariant("")); job_list->AppendItem(fields, static_cast(ST_NEW)); @@ -255,6 +284,8 @@ void PrintHostQueueDialog::on_dpi_changed(const wxRect &suggested_rect) Fit(); Refresh(); + + save_user_data(UDT_SIZE | UDT_POSITION | UDT_COLS); } PrintHostQueueDialog::JobState PrintHostQueueDialog::get_state(int idx) @@ -276,6 +307,8 @@ void PrintHostQueueDialog::set_state(int idx, JobState state) case ST_CANCELLED: job_list->SetValue(_L("Cancelled"), idx, COL_STATUS); break; case ST_COMPLETED: job_list->SetValue(_L("Completed"), idx, COL_STATUS); break; } + // This might be ambigous call, but user data needs to be saved time to time + save_user_data(UDT_SIZE | UDT_POSITION | UDT_COLS); } void PrintHostQueueDialog::on_list_select() @@ -330,6 +363,7 @@ void PrintHostQueueDialog::on_cancel(Event &evt) on_list_select(); } + void PrintHostQueueDialog::get_active_jobs(std::vector>& ret) { int ic = job_list->GetItemCount(); @@ -343,4 +377,60 @@ void PrintHostQueueDialog::get_active_jobs(std::vectordata } +void PrintHostQueueDialog::save_user_data(int udt) +{ + const auto em = GetTextExtent("m").x; + BOOST_LOG_TRIVIAL(error) << "save" << this->GetSize().x / em << " " << this->GetSize().y / em << " " << this->GetPosition().x << " " << this->GetPosition().y; + auto *app_config = wxGetApp().app_config; + if (udt & UserDataType::UDT_SIZE) { + + app_config->set("print_host_queue_dialog_height", std::to_string(this->GetSize().x / em)); + app_config->set("print_host_queue_dialog_width", std::to_string(this->GetSize().y / em)); + } + if (udt & UserDataType::UDT_POSITION) + { + app_config->set("print_host_queue_dialog_x", std::to_string(this->GetPosition().x)); + app_config->set("print_host_queue_dialog_y", std::to_string(this->GetPosition().y)); + } + if (udt & UserDataType::UDT_COLS) + { + for (size_t i = 0; i < job_list->GetColumnCount() - 1; i++) + { + app_config->set("print_host_queue_dialog_column_" + std::to_string(i), std::to_string(job_list->GetColumn(i)->GetWidth())); + } + } +} +bool PrintHostQueueDialog::load_user_data(int udt, std::vector& vector) +{ + auto* app_config = wxGetApp().app_config; + auto hasget = [app_config](const std::string& name, std::vector& vector)->bool { + if (app_config->has(name)) { + vector.push_back(std::stoi(app_config->get(name))); + return true; + } + return false; + }; + if (udt & UserDataType::UDT_SIZE) { + if (!hasget("print_host_queue_dialog_height",vector)) + return false; + if (!hasget("print_host_queue_dialog_width", vector)) + return false; + } + if (udt & UserDataType::UDT_POSITION) + { + if (!hasget("print_host_queue_dialog_x", vector)) + return false; + if (!hasget("print_host_queue_dialog_y", vector)) + return false; + } + if (udt & UserDataType::UDT_COLS) + { + for (size_t i = 0; i < 6; i++) + { + if (!hasget("print_host_queue_dialog_column_" + std::to_string(i), vector)) + return false; + } + } + return true; +} }} diff --git a/src/slic3r/GUI/PrintHostDialogs.hpp b/src/slic3r/GUI/PrintHostDialogs.hpp index 1fda0db66..c185f57be 100644 --- a/src/slic3r/GUI/PrintHostDialogs.hpp +++ b/src/slic3r/GUI/PrintHostDialogs.hpp @@ -65,6 +65,13 @@ public: void append_job(const PrintHostJob &job); void get_active_jobs(std::vector>& ret); + + virtual bool Show(bool show = true) override + { + if(!show) + save_user_data(UDT_SIZE | UDT_POSITION | UDT_COLS); + return DPIDialog::Show(show); + } protected: void on_dpi_changed(const wxRect &suggested_rect) override; @@ -74,8 +81,9 @@ private: COL_PROGRESS, COL_STATUS, COL_HOST, + COL_SIZE, COL_FILENAME, - COL_ERRORMSG, + COL_ERRORMSG }; enum JobState { @@ -89,6 +97,12 @@ private: enum { HEIGHT = 60, WIDTH = 30, SPACING = 5 }; + enum UserDataType{ + UDT_SIZE = 1, + UDT_POSITION = 2, + UDT_COLS = 4 + }; + wxButton *btn_cancel; wxButton *btn_error; wxDataViewListCtrl *job_list; @@ -105,6 +119,8 @@ private: void on_cancel(Event&); // This vector keep adress and filename of uploads. It is used when checking for running uploads during exit. std::vector> upload_names; + void save_user_data(int); + bool load_user_data(int, std::vector&); }; wxDECLARE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event); From 58733e68075566062fe5623be5a847ede74d102d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 11 Mar 2021 16:32:20 +0100 Subject: [PATCH 2/2] print host upload queue dialog - precision in size column --- src/slic3r/GUI/PrintHostDialogs.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index af98f3279..605e14349 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -263,10 +263,14 @@ void PrintHostQueueDialog::append_job(const PrintHostJob &job) fields.push_back(wxVariant(job.printhost->get_host())); boost::system::error_code ec; boost::uintmax_t size_i = boost::filesystem::file_size(job.upload_data.source_path, ec); - std::string size = ec ? "unknown" : ((size_i >> 10) > 1024 ? std::to_string((float)(size_i >> 10)/1024) + "MB" : std::to_string(size_i >> 10) + "KB"); - if (ec) + std::stringstream stream; + if (ec) { + stream << "unknown"; + size_i = 0; BOOST_LOG_TRIVIAL(error) << ec.message(); - fields.push_back(wxVariant(size)); + } 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("")); job_list->AppendItem(fields, static_cast(ST_NEW));