From f77f6793ceb76f3172e63a7472c678ef9d841594 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Wed, 25 Jan 2017 16:26:58 +0200 Subject: [PATCH] MGR: Version check. Remove code duplicates. --- clientgui/AdvancedFrame.cpp | 20 +------------------- clientgui/MainDocument.cpp | 26 ++++++++++++++++++++++++-- clientgui/MainDocument.h | 2 +- clientgui/sg_BoincSimpleFrame.cpp | 20 +------------------- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/clientgui/AdvancedFrame.cpp b/clientgui/AdvancedFrame.cpp index 10933147d7..15445ec3bc 100644 --- a/clientgui/AdvancedFrame.cpp +++ b/clientgui/AdvancedFrame.cpp @@ -1685,25 +1685,7 @@ void CAdvancedFrame::OnHelpAbout(wxCommandEvent& WXUNUSED(event)) { void CAdvancedFrame::OnCheckVersion(wxCommandEvent& WXUNUSED(event)) { wxLogTrace(wxT("Function Start/End"), wxT("CAdvancedFrame::OnCheckVersion - Function Begin")); - std::string version, url; - wxString message, title; - title.Printf(_("Version Update")); - CMainDocument* pDoc = wxGetApp().GetDocument(); - CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced(); - if (pDoc->IsConnected()) { - pDoc->rpc.get_newer_version(version, url); - - if (!version.empty() && !url.empty()) { - message.Printf("%s: %s", _("A new version of BOINC is available for downloading here"), url); - } - else { - message.Printf("%s", _("No new version available for downloading"), url); - } - } - else { - message.Printf("%s is not connected to the client", pSkinAdvanced->GetApplicationName().c_str()); - } - wxGetApp().SafeMessageBox(message, title); + wxGetApp().GetDocument()->CheckForVersionUpdate(true); wxLogTrace(wxT("Function Start/End"), wxT("CAdvancedFrame::OnCheckVersion - Function End")); } diff --git a/clientgui/MainDocument.cpp b/clientgui/MainDocument.cpp index 4b86a4c27c..b2169f10cd 100644 --- a/clientgui/MainDocument.cpp +++ b/clientgui/MainDocument.cpp @@ -37,6 +37,7 @@ #include "BOINCTaskBar.h" #include "DlgEventLog.h" #include "Events.h" +#include "SkinManager.h" #ifndef _WIN32 #include @@ -1279,9 +1280,30 @@ bool CMainDocument::IsUserAuthorized() { return true; } -void CMainDocument::CheckForVersionUpdate() { +void CMainDocument::CheckForVersionUpdate(bool showMessage) { std::string version, url; - rpc.get_newer_version(version, url); + wxString message, title; + title.Printf(_("Version Update")); + std::string applicationName = wxGetApp().GetSkinManager()->GetAdvanced()->GetApplicationName(); + if (IsConnected()) { + rpc.get_newer_version(version, url); + + if (!showMessage) + return; + + if (!version.empty() && !url.empty()) { + message.Printf("%s: %s", _("A new version of BOINC is available for downloading here"), url); + } + else { + message.Printf("%s", _("No new version available for downloading"), url); + } + } + else { + message.Printf("%s is not connected to the client", applicationName.c_str()); + } + if (showMessage) { + wxGetApp().SafeMessageBox(message, title); + } } int CMainDocument::CachedProjectStatusUpdate(bool bForce) { diff --git a/clientgui/MainDocument.h b/clientgui/MainDocument.h index de5fb71592..92f96c01f2 100644 --- a/clientgui/MainDocument.h +++ b/clientgui/MainDocument.h @@ -167,7 +167,7 @@ public: bool IsUserAuthorized(); - void CheckForVersionUpdate(); + void CheckForVersionUpdate(bool showMessage = false); CNetworkConnection* m_pNetworkConnection; CBOINCClientManager* m_pClientManager; diff --git a/clientgui/sg_BoincSimpleFrame.cpp b/clientgui/sg_BoincSimpleFrame.cpp index 910ff63eaf..75fdf43bb9 100644 --- a/clientgui/sg_BoincSimpleFrame.cpp +++ b/clientgui/sg_BoincSimpleFrame.cpp @@ -630,25 +630,7 @@ void CSimpleFrame::OnHelpAbout(wxCommandEvent& /*event*/) { void CSimpleFrame::OnCheckVersion(wxCommandEvent& WXUNUSED(event)) { wxLogTrace(wxT("Function Start/End"), wxT("CSimpleFrame::OnCheckVersion - Function Begin")); - std::string version, url; - wxString message, title; - title.Printf(_("Version Update")); - CMainDocument* pDoc = wxGetApp().GetDocument(); - CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced(); - if (pDoc->IsConnected()) { - pDoc->rpc.get_newer_version(version, url); - - if (!version.empty() && !url.empty()) { - message.Printf("%s: %s", _("A new version of BOINC is available for downloading here"), url); - } - else { - message.Printf("%s", _("No new version available for downloading"), url); - } - } - else { - message.Printf("%s is not connected to the client", pSkinAdvanced->GetApplicationName().c_str()); - } - wxGetApp().SafeMessageBox(message, title); + wxGetApp().GetDocument()->CheckForVersionUpdate(true); wxLogTrace(wxT("Function Start/End"), wxT("CSimpleFrame::OnCheckVersion - Function End")); }