Several fixes and improvements in SendSystemInfoDialog:

- do not show memory in MB, show it in GiB rounded to one decimal place
- when sending fails, the HTTP error code is not presented to the user (it is logged though)
- when the user cancels the sending, no extra "sending cancelled" message is shown
- in case there is no internet connection, the dialog is not shown at all
- a 6 second timeout for a case that connection is lost during sending
- the dialog is only shown when the wizard does not show on startup
This commit is contained in:
Lukas Matena 2021-10-08 12:23:02 +02:00
parent 8d115def76
commit 13ff92335b
4 changed files with 58 additions and 14 deletions

View file

@ -104,6 +104,7 @@ struct Http::priv
{
enum {
DEFAULT_TIMEOUT_CONNECT = 10,
DEFAULT_TIMEOUT_MAX = 0,
DEFAULT_SIZE_LIMIT = 5 * 1024 * 1024,
};
@ -137,6 +138,7 @@ struct Http::priv
static size_t form_file_read_cb(char *buffer, size_t size, size_t nitems, void *userp);
void set_timeout_connect(long timeout);
void set_timeout_max(long timeout);
void form_add_file(const char *name, const fs::path &path, const char* filename);
void set_post_body(const fs::path &path);
void set_post_body(const std::string &body);
@ -163,6 +165,7 @@ Http::priv::priv(const std::string &url)
}
set_timeout_connect(DEFAULT_TIMEOUT_CONNECT);
set_timeout_max(DEFAULT_TIMEOUT_MAX);
::curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); // curl makes a copy internally
::curl_easy_setopt(curl, CURLOPT_USERAGENT, SLIC3R_APP_NAME "/" SLIC3R_VERSION);
::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer.front());
@ -253,6 +256,11 @@ void Http::priv::set_timeout_connect(long timeout)
::curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);
}
void Http::priv::set_timeout_max(long timeout)
{
::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
}
void Http::priv::form_add_file(const char *name, const fs::path &path, const char* filename)
{
// We can't use CURLFORM_FILECONTENT, because curl doesn't support Unicode filenames on Windows
@ -409,6 +417,13 @@ Http& Http::timeout_connect(long timeout)
return *this;
}
Http& Http::timeout_max(long timeout)
{
if (timeout < 1) { timeout = priv::DEFAULT_TIMEOUT_MAX; }
if (p) { p->set_timeout_max(timeout); }
return *this;
}
Http& Http::size_limit(size_t sizeLimit)
{
if (p) { p->limit = sizeLimit; }