OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::FileGet Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DownloaderFileGet.hpp>

Inheritance diagram for Slic3r::GUI::FileGet:
Collaboration diagram for Slic3r::GUI::FileGet:

Classes

struct  priv

Public Member Functions

 FileGet (int ID, std::string url, const std::string &filename, wxEvtHandler *evt_handler, const boost::filesystem::path &dest_folder)
 FileGet (FileGet &&other)
 ~FileGet ()
void get ()
void cancel ()
void pause ()
void resume ()

Static Public Member Functions

static std::string escape_url (const std::string &url)
static bool is_subdomain (const std::string &url, const std::string &domain)

Private Attributes

std::unique_ptr< priv > p

Detailed Description

Constructor & Destructor Documentation

◆ FileGet() [1/2]

Slic3r::GUI::FileGet::FileGet ( int ID,
std::string url,
const std::string & filename,
wxEvtHandler * evt_handler,
const boost::filesystem::path & dest_folder )
386 : p(new priv(ID, std::move(url), filename, evt_handler, dest_folder))
387{}
std::unique_ptr< priv > p
Definition DownloaderFileGet.hpp:29
Definition DownloaderFileGet.cpp:102

References p.

Referenced by FileGet().

Here is the caller graph for this function:

◆ FileGet() [2/2]

Slic3r::GUI::FileGet::FileGet ( FileGet && other)
389: p(std::move(other.p)) {}

References FileGet(), and p.

Here is the call graph for this function:

◆ ~FileGet()

Slic3r::GUI::FileGet::~FileGet ( )
392{
393 if (p && p->m_io_thread.joinable()) {
394 p->m_cancel = true;
395 p->m_io_thread.join();
396 }
397}

References p.

Member Function Documentation

◆ cancel()

void Slic3r::GUI::FileGet::cancel ( )
416{
417 if(p && p->m_stopped) {
418 if (p->m_io_thread.joinable()) {
419 p->m_cancel = true;
420 p->m_io_thread.join();
421 wxCommandEvent* evt = new wxCommandEvent(EVT_DWNLDR_FILE_CANCELED);
422 evt->SetInt(p->m_id);
423 p->m_evt_handler->QueueEvent(evt);
424 }
425 }
426
427 if (p)
428 p->m_cancel = true;
429
430}

References p.

Referenced by Slic3r::GUI::FileGet::priv::get_perform().

Here is the caller graph for this function:

◆ escape_url()

std::string Slic3r::GUI::FileGet::escape_url ( const std::string & url)
static
38{
39 std::string ret_val;
40 CURL* curl = curl_easy_init();
41 if (curl) {
42 int decodelen;
43 char* decoded = curl_easy_unescape(curl, unescaped.c_str(), unescaped.size(), &decodelen);
44 if (decoded) {
45 ret_val = std::string(decoded);
46 curl_free(decoded);
47 }
48 curl_easy_cleanup(curl);
49 }
50 return ret_val;
51}

Referenced by Slic3r::GUI::Downloader::start_download().

Here is the caller graph for this function:

◆ get()

void Slic3r::GUI::FileGet::get ( )
400{
401 assert(p);
402 if (p->m_io_thread.joinable()) {
403 // This will stop transfers being done by the thread, if any.
404 // Cancelling takes some time, but should complete soon enough.
405 p->m_cancel = true;
406 p->m_io_thread.join();
407 }
408 p->m_cancel = false;
409 p->m_pause = false;
410 p->m_io_thread = std::thread([this]() {
411 p->get_perform();
412 });
413}

References p.

◆ is_subdomain()

bool Slic3r::GUI::FileGet::is_subdomain ( const std::string & url,
const std::string & domain )
static
53{
54 // domain should be f.e. printables.com (.com including)
55 char* host;
56 std::string host_string;
57 CURLUcode rc;
58 CURLU* curl = curl_url();
59 if (!curl) {
60 BOOST_LOG_TRIVIAL(error) << "Failed to init Curl library in function is_domain.";
61 return false;
62 }
63 rc = curl_url_set(curl, CURLUPART_URL, url.c_str(), 0);
64 if (rc != CURLUE_OK) {
65 curl_url_cleanup(curl);
66 return false;
67 }
68 rc = curl_url_get(curl, CURLUPART_HOST, &host, 0);
69 if (rc != CURLUE_OK || !host) {
70 curl_url_cleanup(curl);
71 return false;
72 }
73 host_string = std::string(host);
74 curl_free(host);
75 // now host should be subdomain.domain or just domain
76 if (domain == host_string) {
77 curl_url_cleanup(curl);
78 return true;
79 }
80 if(boost::ends_with(host_string, "." + domain)) {
81 curl_url_cleanup(curl);
82 return true;
83 }
84 curl_url_cleanup(curl);
85 return false;
86}

◆ pause()

void Slic3r::GUI::FileGet::pause ( )
433{
434 if (p) {
435 p->m_pause = true;
436 }
437}

References p.

◆ resume()

void Slic3r::GUI::FileGet::resume ( )
439{
440 assert(p);
441 if (p->m_io_thread.joinable()) {
442 // This will stop transfers being done by the thread, if any.
443 // Cancelling takes some time, but should complete soon enough.
444 p->m_cancel = true;
445 p->m_io_thread.join();
446 }
447 p->m_cancel = false;
448 p->m_pause = false;
449 p->m_io_thread = std::thread([this]() {
450 p->get_perform();
451 });
452}

References p.

Member Data Documentation

◆ p

std::unique_ptr<priv> Slic3r::GUI::FileGet::p
private

The documentation for this class was generated from the following files: