Change of wifi config dialog showing rules

do not show automatically after decline
This commit is contained in:
David Kocik 2023-10-31 09:08:54 +01:00
parent 9974e4e33f
commit 0e889eae09
5 changed files with 64 additions and 34 deletions

View File

@ -2611,7 +2611,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
break;
case ConfigMenuWifiConfigFile:
{
open_wifi_config_dialog();
open_wifi_config_dialog(true);
/*
std::string file_path;
WifiConfigDialog dialog(mainframe, file_path, removable_drive_manager());
@ -3574,17 +3574,35 @@ void GUI_App::start_download(std::string url)
m_downloader->start_download(url);
}
void GUI_App::open_wifi_config_dialog(const wxString& drive_path/* = {}*/)
void GUI_App::open_wifi_config_dialog(bool forced, const wxString& drive_path/* = {}*/)
{
if(m_wifi_config_dialog_shown)
return;
if (!forced && m_wifi_config_dialog_was_declined) {
// dialog was already declined this run, show only notification
notification_manager()->push_notification(NotificationType::WifiConfigFileDetected
, NotificationManager::NotificationLevel::ImportantNotificationLevel
// TRN Text of notification when Slicer starts and usb stick with printer settings ini file is present
, _u8L("Printer configuration file detected on removable media.")
// TRN Text of hypertext of notification when Slicer starts and usb stick with printer settings ini file is present
, _u8L("Write Wi-Fi credetials."), [drive_path](wxEvtHandler* evt_hndlr) {
wxGetApp().open_wifi_config_dialog(true, drive_path);
return true; });
return;
}
m_wifi_config_dialog_shown = true;
std::string file_path;
WifiConfigDialog dialog(mainframe, file_path, removable_drive_manager(), drive_path);
if (dialog.ShowModal() == wxID_OK)
{
if (dialog.ShowModal() == wxID_OK) {
//wxString used_path = dialog.get_used_path();
//if(std::find(m_wifi_config_dialog_used_paths.begin(), m_wifi_config_dialog_used_paths.end(), used_path) == m_wifi_config_dialog_used_paths.end())
// m_wifi_config_dialog_used_paths.emplace_back(std::move(used_path));
plater_->get_notification_manager()->push_exporting_finished_notification(file_path, boost::filesystem::path(file_path).parent_path().string(), true);
}
} else
m_wifi_config_dialog_was_declined = true;
m_wifi_config_dialog_shown = false;
}

View File

@ -379,7 +379,7 @@ public:
// URL download - PrusaSlicer gets system call to open prusaslicer:// URL which should contain address of download
void start_download(std::string url);
void open_wifi_config_dialog(const wxString& drive_path = {});
void open_wifi_config_dialog(bool forced, const wxString& drive_path = {});
bool get_wifi_config_dialog_shown() const { return m_wifi_config_dialog_shown; }
private:
bool on_init_inner();
@ -404,6 +404,7 @@ private:
bool m_datadir_redefined { false };
bool m_wifi_config_dialog_shown { false };
bool m_wifi_config_dialog_was_declined { false };
};
DECLARE_APP(GUI_App)

View File

@ -2289,7 +2289,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
const std::string CONFIG_FILE_NAME = "prusa_printer_settings.ini";
if (evt.GetInt() == 0) { // not at startup, show dialog
if (fs::exists(fs::path(evt.GetString().utf8_string()) / CONFIG_FILE_NAME))
wxGetApp().open_wifi_config_dialog(evt.GetString());
wxGetApp().open_wifi_config_dialog(false, evt.GetString());
} else { // at startup, show only notification
notification_manager->push_notification(NotificationType::WifiConfigFileDetected
, NotificationManager::NotificationLevel::ImportantNotificationLevel
@ -2297,8 +2297,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
, _u8L("Printer configuration file detected on removable media.")
// TRN Text of hypertext of notification when Slicer starts and usb stick with printer settings ini file is present
, _u8L("Write Wi-Fi credetials."), [evt, CONFIG_FILE_NAME](wxEvtHandler* evt_hndlr){
if (fs::exists(fs::path(evt.GetString().utf8_string()) / CONFIG_FILE_NAME))
wxGetApp().open_wifi_config_dialog(evt.GetString());
//if (fs::exists(fs::path(evt.GetString().utf8_string()) / CONFIG_FILE_NAME))
wxGetApp().open_wifi_config_dialog(true, evt.GetString());
return true;});
}

View File

@ -50,8 +50,9 @@ WifiConfigDialog::WifiConfigDialog(wxWindow* parent, std::string& file_path, Rem
m_ssid_combo->SetToolTip(_L("On some versions of MacOS, this only loads SSID of connected network."));
#endif // __APPLE__
rescan_networks(false);
m_ssid_button_id = NewControlId();
// TRN Text of button to rescan visible networks in Wifi Config dialog.
wxButton* ssid_button = new wxButton(panel, wxID_ANY, _(L("Rescan")));
wxButton* ssid_button = new wxButton(panel, m_ssid_button_id, _(L("Rescan")));
ssid_sizer->Add(m_ssid_combo, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
ssid_sizer->Add(ssid_button, 0);
@ -61,8 +62,9 @@ WifiConfigDialog::WifiConfigDialog(wxWindow* parent, std::string& file_path, Rem
m_pass_textctrl = new ::TextInput(panel, "", "", "", wxDefaultPosition, wxDefaultSize);
pass_sizer->Add(m_pass_textctrl, 1, wxALIGN_CENTER_VERTICAL, 10);
#if __APPLE__
m_pass_button_id = NewControlId();
// TRN Text of button to retrieve password from keychain in Wifi Config dialog. Only on Mac.
wxButton* pass_button = new wxButton(panel, wxID_ANY, _(L("Retrieve")));
wxButton* pass_button = new wxButton(panel, m_pass_button_id, _(L("Retrieve")));
pass_sizer->Add(pass_button, 0);
pass_button->Bind(wxEVT_BUTTON, &WifiConfigDialog::on_retrieve_password, this);
#endif // __APPLE__
@ -74,8 +76,9 @@ WifiConfigDialog::WifiConfigDialog(wxWindow* parent, std::string& file_path, Rem
wxStaticText* drive_label = new wxStaticText(panel, wxID_ANY, GUI::format_wxstr("%1%:", _L("Drive")));
m_drive_combo = new ::ComboBox(panel, wxID_ANY);
rescan_drives(preffered_drive);
m_drive_button_id = NewControlId();
// TRN Text of button to rescan connect usb drives in Wifi Config dialog.
wxButton* drive_button = new wxButton(panel, wxID_ANY, _(L("Rescan")));
wxButton* drive_button = new wxButton(panel, m_drive_button_id, _(L("Rescan")));
drive_sizer->Add(m_drive_combo, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
drive_sizer->Add(drive_button, 0);
@ -274,6 +277,7 @@ void WifiConfigDialog::on_ok(wxCommandEvent& e)
data += "\n";
}
m_used_path = boost::nowide::widen(file_path.string());
FILE* file;
file = fopen(file_path.string().c_str(), "w");
if (file == NULL) {
@ -292,8 +296,8 @@ void WifiConfigDialog::on_dpi_changed(const wxRect& suggested_rect)
{
SetFont(wxGetApp().normal_font());
//const int em = em_unit();
//msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL });
const int em = em_unit();
msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL, m_ssid_button_id, m_pass_button_id, m_drive_button_id });
Fit();
Refresh();

View File

@ -22,10 +22,20 @@ class WifiConfigDialog : public DPIDialog
public:
WifiConfigDialog(wxWindow* parent, std::string& file_path, RemovableDriveManager* removable_manager, const wxString& preffered_drive );
~WifiConfigDialog();
wxString get_used_path() const { return m_used_path; }
private:
::ComboBox* m_ssid_combo {nullptr};
::TextInput* m_pass_textctrl {nullptr};
::ComboBox* m_drive_combo {nullptr};
// reference to string that is filled after ShowModal is called from owner
std::string& out_file_path;
WifiScanner* m_wifi_scanner;
RemovableDriveManager* m_removable_manager;
wxString m_used_path;
int m_ssid_button_id {wxID_ANY};
int m_pass_button_id {wxID_ANY};
int m_drive_button_id {wxID_ANY};
void on_ok(wxCommandEvent& e);
void on_combo(wxCommandEvent& e);
@ -35,10 +45,7 @@ private:
void rescan_drives(const wxString& preffered_drive);
void rescan_networks(bool select);
void fill_password();
// reference to string that is filled after ShowModal is called from owner
std::string& out_file_path;
WifiScanner* m_wifi_scanner;
RemovableDriveManager* m_removable_manager;
protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
void on_sys_color_changed() override {}