saving size and position of print host queue dialog, added size column, sorting

This commit is contained in:
David Kocik 2021-03-11 13:35:19 +01:00
parent 913152d609
commit b8adfbda66
2 changed files with 114 additions and 8 deletions

View File

@ -182,15 +182,24 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent)
auto *topsizer = new wxBoxSizer(wxVERTICAL);
std::vector<int> 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<int> 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<int> 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<wxUIntPtr>(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<std::pair<std::string, std::string>>& ret)
{
int ic = job_list->GetItemCount();
@ -343,4 +377,60 @@ void PrintHostQueueDialog::get_active_jobs(std::vector<std::pair<std::string, st
}
//job_list->data
}
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<int>& vector)
{
auto* app_config = wxGetApp().app_config;
auto hasget = [app_config](const std::string& name, std::vector<int>& 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;
}
}}

View File

@ -65,6 +65,13 @@ public:
void append_job(const PrintHostJob &job);
void get_active_jobs(std::vector<std::pair<std::string, std::string>>& 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<std::pair<std::string, std::string>> upload_names;
void save_user_data(int);
bool load_user_data(int, std::vector<int>&);
};
wxDECLARE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event);