MGR: Version check. Remove code duplicates.

This commit is contained in:
Vitalii Koshura 2017-01-25 16:26:58 +02:00
parent 777ffdbb3f
commit f77f6793ce
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
4 changed files with 27 additions and 41 deletions

View File

@ -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"));
}

View File

@ -37,6 +37,7 @@
#include "BOINCTaskBar.h"
#include "DlgEventLog.h"
#include "Events.h"
#include "SkinManager.h"
#ifndef _WIN32
#include <sys/wait.h>
@ -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) {

View File

@ -167,7 +167,7 @@ public:
bool IsUserAuthorized();
void CheckForVersionUpdate();
void CheckForVersionUpdate(bool showMessage = false);
CNetworkConnection* m_pNetworkConnection;
CBOINCClientManager* m_pClientManager;

View File

@ -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"));
}