Simplify status bar updates in the webrequest sample

Use wxLogStatus() to update the status bar, this is shorter and simpler
than using GetStatusBar()->SetStatusText(wxString::Format(...)).

Also use wxFrame::SetStatusText() which forwards to wxStatusBar method
with the same name when we want to just clear the status bar.

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-01-04 02:13:53 +01:00
parent 6e546a3d4b
commit f89781bfdd

View File

@@ -165,7 +165,7 @@ public:
CreateStatusBar(); CreateStatusBar();
GetStatusBar()->SetStatusText(wxWebSession::GetDefault().GetLibraryVersionInfo().ToString()); wxLogStatus(this, "%s", wxWebSession::GetDefault().GetLibraryVersionInfo().ToString());
m_downloadProgressTimer.Bind(wxEVT_TIMER, m_downloadProgressTimer.Bind(wxEVT_TIMER,
&WebRequestFrame::OnProgressTimer, this); &WebRequestFrame::OnProgressTimer, this);
@@ -173,7 +173,7 @@ public:
void OnStartButton(wxCommandEvent& WXUNUSED(evt)) void OnStartButton(wxCommandEvent& WXUNUSED(evt))
{ {
GetStatusBar()->SetStatusText("Started request..."); wxLogStatus(this, "Started request...");
// Create request for the specified URL from the default session // Create request for the specified URL from the default session
m_currentRequest = wxWebSession::GetDefault().CreateRequest(this, m_currentRequest = wxWebSession::GetDefault().CreateRequest(this,
@@ -206,13 +206,13 @@ public:
m_downloadGauge->Pulse(); m_downloadGauge->Pulse();
m_downloadStaticText->SetLabel(""); m_downloadStaticText->SetLabel("");
m_downloadProgressTimer.Start(500); m_downloadProgressTimer.Start(500);
GetStatusBar()->SetStatusText(""); SetStatusText("");
break; break;
case Page_Advanced: case Page_Advanced:
m_currentRequest.SetStorage(wxWebRequest::Storage_None); m_currentRequest.SetStorage(wxWebRequest::Storage_None);
Bind(wxEVT_WEBREQUEST_DATA, &WebRequestFrame::OnRequestData, this); Bind(wxEVT_WEBREQUEST_DATA, &WebRequestFrame::OnRequestData, this);
GetStatusBar()->SetStatusText("Counting..."); wxLogStatus(this, "Counting...");
m_advCount = 0; m_advCount = 0;
m_advCountStaticText->SetLabel("0"); m_advCountStaticText->SetLabel("0");
break; break;
@@ -251,22 +251,22 @@ public:
wxImage img(*evt.GetResponse().GetStream()); wxImage img(*evt.GetResponse().GetStream());
m_imageStaticBitmap->SetBitmap(img); m_imageStaticBitmap->SetBitmap(img);
m_notebook->GetPage(Page_Image)->Layout(); m_notebook->GetPage(Page_Image)->Layout();
GetStatusBar()->SetStatusText(wxString::Format("Loaded %lld bytes image data", evt.GetResponse().GetContentLength())); wxLogStatus(this, "Loaded %lld bytes image data", evt.GetResponse().GetContentLength());
break; break;
} }
case Page_Text: case Page_Text:
m_textResponseTextCtrl->SetValue(evt.GetResponse().AsString()); m_textResponseTextCtrl->SetValue(evt.GetResponse().AsString());
GetStatusBar()->SetStatusText(wxString::Format("Loaded %lld bytes text data (Status: %d %s)", wxLogStatus(this, "Loaded %lld bytes text data (Status: %d %s)",
evt.GetResponse().GetContentLength(), evt.GetResponse().GetContentLength(),
evt.GetResponse().GetStatus(), evt.GetResponse().GetStatus(),
evt.GetResponse().GetStatusText())); evt.GetResponse().GetStatusText());
break; break;
case Page_Download: case Page_Download:
{ {
m_downloadGauge->SetValue(100); m_downloadGauge->SetValue(100);
m_downloadStaticText->SetLabel(""); m_downloadStaticText->SetLabel("");
GetStatusBar()->SetStatusText("Download completed"); wxLogStatus(this, "Download completed");
// Ask the user where to save the file // Ask the user where to save the file
wxFileDialog fileDlg(this, "Save download", "", wxFileDialog fileDlg(this, "Save download", "",
@@ -282,20 +282,20 @@ public:
} }
case Page_Advanced: case Page_Advanced:
UpdateAdvCount(); UpdateAdvCount();
GetStatusBar()->SetStatusText(""); SetStatusText("");
break; break;
} }
break; break;
case wxWebRequest::State_Failed: case wxWebRequest::State_Failed:
wxLogError("Web Request failed: %s", evt.GetErrorDescription()); wxLogError("Web Request failed: %s", evt.GetErrorDescription());
GetStatusBar()->SetStatusText(""); SetStatusText("");
break; break;
case wxWebRequest::State_Cancelled: case wxWebRequest::State_Cancelled:
m_downloadGauge->SetValue(0); m_downloadGauge->SetValue(0);
m_downloadStaticText->SetLabel(""); m_downloadStaticText->SetLabel("");
GetStatusBar()->SetStatusText("Cancelled"); wxLogStatus(this, "Cancelled");
break; break;
default: default: