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

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

Inheritance diagram for Slic3r::GUI::UpgradeNetworkJob:
Collaboration diagram for Slic3r::GUI::UpgradeNetworkJob:

Public Types

enum  JobPrepareState { PREPARE_STATE_DEFAULT = 0 , PREPARE_STATE_MENU = 1 }

Public Member Functions

 UpgradeNetworkJob ()
int status_range () const
bool is_finished ()
void on_success (std::function< void()> success)
void update_status (Ctl &ctl, int st, const std::string &msg)
void process (Ctl &ctl) override
void finalize (bool canceled, std::exception_ptr &e) override
void set_event_handle (wxWindow *hanle)

Protected Attributes

std::string name
std::string package_name

Private Attributes

wxWindow * m_event_handle {nullptr}
std::function< void()> m_success_fun {nullptr}
bool m_job_finished { false }
InstallProgressFn pro_fn { nullptr }

Detailed Description

Member Enumeration Documentation

◆ JobPrepareState

Enumerator
PREPARE_STATE_DEFAULT 
PREPARE_STATE_MENU 
22 {
25 };
@ PREPARE_STATE_MENU
Definition Job.hpp:24
@ PREPARE_STATE_DEFAULT
Definition Job.hpp:23

Constructor & Destructor Documentation

◆ UpgradeNetworkJob()

Slic3r::GUI::UpgradeNetworkJob::UpgradeNetworkJob ( )
26{
27 name = "plugins";
28 package_name = "networking_plugins.zip";
29}
std::string name
Definition UpgradeNetworkJob.hpp:37
std::string package_name
Definition UpgradeNetworkJob.hpp:38

References name, and package_name.

Member Function Documentation

◆ finalize()

void Slic3r::GUI::UpgradeNetworkJob::finalize ( bool canceled,
std::exception_ptr & e )
overridevirtual

Reimplemented from Slic3r::GUI::Job.

131{
132 try {
133 if (eptr)
134 std::rethrow_exception(eptr);
135 eptr = nullptr;
136 } catch (...) {
137 eptr = std::current_exception();
138 }
139
140 if (canceled || eptr)
141 return;
142}

◆ is_finished()

bool Slic3r::GUI::UpgradeNetworkJob::is_finished ( )
inline
48{ return m_job_finished; }
bool m_job_finished
Definition UpgradeNetworkJob.hpp:32

References m_job_finished.

◆ on_success()

void Slic3r::GUI::UpgradeNetworkJob::on_success ( std::function< void()> success)
32{
33 m_success_fun = success;
34}
std::function< void()> m_success_fun
Definition UpgradeNetworkJob.hpp:31

References m_success_fun.

◆ process()

void Slic3r::GUI::UpgradeNetworkJob::process ( Ctl & ctl)
overridevirtual

Implements Slic3r::GUI::Job.

47{
48 // downloading
49 int result = 0;
50
51 AppConfig* app_config = wxGetApp().app_config;
52 if (!app_config)
53 return;
54
55 BOOST_LOG_TRIVIAL(info) << "[UpgradeNetworkJob process]: enter";
56
57 // get temp path
58 fs::path target_file_path = (fs::temp_directory_path() / package_name);
59 fs::path tmp_path = target_file_path;
60 auto path_str = tmp_path.string() + wxString::Format(".%d%s", get_current_pid(), ".tmp").ToStdString();
61 tmp_path = fs::path(path_str);
62
63 BOOST_LOG_TRIVIAL(info) << "UpgradeNetworkJob: save netowrk_plugin to " << tmp_path.string();
64
65 auto cancel_fn = [&ctl]() {
66 return ctl.was_canceled();
67 };
68 int curr_percent = 0;
69 result = wxGetApp().download_plugin(name, package_name,
70 [this, &ctl, &curr_percent](int state, int percent, bool &cancel) {
71 if (state == InstallStatusNormal) {
72 update_status(ctl, percent, _u8L("Downloading"));
73 } else if (state == InstallStatusDownloadFailed) {
74 update_status(ctl, percent, _u8L("Download failed"));
75 } else {
76 update_status(ctl, percent, _u8L("Downloading"));
77 }
78 curr_percent = percent;
79 }, cancel_fn);
80
81 if (ctl.was_canceled()) {
82 update_status(ctl, 0, _u8L("Canceled"));
83 wxCommandEvent event(wxEVT_CLOSE_WINDOW);
84 event.SetEventObject(m_event_handle);
85 wxPostEvent(m_event_handle, event);
86 return;
87 }
88
89 if (result < 0) {
90 update_status(ctl, 0, _u8L("Download failed"));
91 wxCommandEvent event(EVT_DOWNLOAD_NETWORK_FAILED);
92 event.SetEventObject(m_event_handle);
93 wxPostEvent(m_event_handle, event);
94 return;
95 }
96
97 result = wxGetApp().install_plugin(
99 [this, &ctl](int state, int percent, bool &cancel) {
100 if (state == InstallStatusInstallCompleted) {
101 update_status(ctl, percent, _u8L("Installed successfully"));
102 } else {
103 update_status(ctl, percent, _u8L("Installing"));
104 }
105 }, cancel_fn);
106
107 if (ctl.was_canceled()) {
108 update_status(ctl, 0, _u8L("Canceled"));
109 wxCommandEvent event(wxEVT_CLOSE_WINDOW);
110 event.SetEventObject(m_event_handle);
111 wxPostEvent(m_event_handle, event);
112 return;
113 }
114
115 if (result != 0) {
116 update_status(ctl, 0, _u8L("Install failed"));
117 wxCommandEvent event(EVT_INSTALL_NETWORK_FAILED);
118 event.SetEventObject(m_event_handle);
119 wxPostEvent(m_event_handle, event);
120 return;
121 }
122
123 wxCommandEvent event(EVT_UPGRADE_NETWORK_SUCCESS);
124 event.SetEventObject(m_event_handle);
125 wxPostEvent(m_event_handle, event);
126 BOOST_LOG_TRIVIAL(info) << "[UpgradeNetworkJob process]: exit";
127 return;
128}
wxWindow * m_event_handle
Definition UpgradeNetworkJob.hpp:30
void update_status(Ctl &ctl, int st, const std::string &msg)
Definition UpgradeNetworkJob.cpp:36
@ InstallStatusInstallCompleted
Definition UpgradeNetworkJob.hpp:23
@ InstallStatusDownloadFailed
Definition UpgradeNetworkJob.hpp:20
@ InstallStatusNormal
Definition UpgradeNetworkJob.hpp:19
unsigned get_current_pid()
Definition utils.cpp:1480
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::get_current_pid(), Slic3r::GUI::InstallStatusDownloadFailed, Slic3r::GUI::InstallStatusInstallCompleted, Slic3r::GUI::InstallStatusNormal, m_event_handle, name, package_name, update_status(), and Slic3r::GUI::Job::Ctl::was_canceled().

Here is the call graph for this function:

◆ set_event_handle()

void Slic3r::GUI::UpgradeNetworkJob::set_event_handle ( wxWindow * hanle)
145{
146 m_event_handle = hanle;
147}

References m_event_handle.

◆ status_range()

int Slic3r::GUI::UpgradeNetworkJob::status_range ( ) const
inline
44 {
45 return 100;
46 }

◆ update_status()

void Slic3r::GUI::UpgradeNetworkJob::update_status ( Ctl & ctl,
int st,
const std::string & msg )
37{
38 BOOST_LOG_TRIVIAL(info) << "UpgradeNetworkJob: percent = " << st << "msg = " << msg;
39 ctl.update_status(st, msg);
40 wxCommandEvent event(EVT_UPGRADE_UPDATE_MESSAGE);
41 event.SetString(msg);
42 event.SetEventObject(m_event_handle);
43 wxPostEvent(m_event_handle, event);
44}

References m_event_handle, and Slic3r::GUI::Job::Ctl::update_status().

Referenced by process().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_event_handle

wxWindow* Slic3r::GUI::UpgradeNetworkJob::m_event_handle {nullptr}
private
30{nullptr};

Referenced by process(), set_event_handle(), and update_status().

◆ m_job_finished

bool Slic3r::GUI::UpgradeNetworkJob::m_job_finished { false }
private
32{ false };

Referenced by is_finished().

◆ m_success_fun

std::function<void()> Slic3r::GUI::UpgradeNetworkJob::m_success_fun {nullptr}
private
31{nullptr};

Referenced by on_success().

◆ name

std::string Slic3r::GUI::UpgradeNetworkJob::name
protected

Referenced by UpgradeNetworkJob(), and process().

◆ package_name

std::string Slic3r::GUI::UpgradeNetworkJob::package_name
protected

Referenced by UpgradeNetworkJob(), and process().

◆ pro_fn

InstallProgressFn Slic3r::GUI::UpgradeNetworkJob::pro_fn { nullptr }
private
34{ nullptr };

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