Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FS#433 Update last checking time

  • Loading branch information...
commit 86366946842f96596ac614410995eed50176497e 1 parent ffa5706
Vlad Ershov vershov authored
31 src/SettingsDlg.cpp
View
@@ -19,7 +19,6 @@
#include <wx/spinctrl.h>
#include "EnvVarsPanel.h"
-
#include "UpdaterThread.h"
#include "eSettings.h"
#include "AppVersion.h"
@@ -79,7 +78,7 @@ END_EVENT_TABLE()
SettingsDlg::SettingsDlg(wxWindow *parent, CatalystWrapper cw, eSettings& settings):
wxDialog (parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
- m_settings(settings), m_catalyst(cw), m_ctUserPic(false)
+ m_settings(settings), m_catalyst(cw), m_ctUserPic(false), m_Updater(NULL)
{
SetTitle (_("Settings"));
@@ -140,8 +139,8 @@ wxPanel* SettingsDlg::CreateUpdatePage(wxWindow* parent) {
wxStaticText* labelLastUpdate = new wxStaticText(page, wxID_ANY, _("Last Update:"));
sizer->Add(labelLastUpdate , 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
- wxStaticText* labelWhen= new wxStaticText(page, wxID_ANY, when);
- sizer->Add(labelWhen, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
+ m_labelWhen = new wxStaticText(page, wxID_ANY, when);
+ sizer->Add(m_labelWhen, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
// Checkbox
sizer->AddStretchSpacer();
@@ -448,8 +447,19 @@ void SettingsDlg::OnButtonOk(wxCommandEvent& WXUNUSED(event)) {
EndModal(wxID_OK);
}
+void SettingsDlg::EndModal(int retCode) {
+ if (NULL != m_Updater) {
+ m_Updater->SetWatcher(NULL);
+ }
+ wxDialog::EndModal(retCode);
+}
+
void SettingsDlg::OnButtonCheckForUpdates(wxCommandEvent& WXUNUSED(event)) {
- CheckForUpdates(m_settings, GetAppVersion(), true);
+ m_Updater = CheckForUpdates(m_settings, GetAppVersion(), true);
+ if (NULL != m_Updater) { // lock button till the checking end
+ m_Updater->SetWatcher(this);
+ m_checkForUpdatesButton->Enable(false);
+ }
}
void SettingsDlg::OnButtonCygwinAction(wxCommandEvent& WXUNUSED(event)) {
@@ -573,3 +583,14 @@ void SettingsDlg::OnCheckAtomicSave(wxCommandEvent& event) {
void SettingsDlg::OnCheckLastTab(wxCommandEvent& event) {
m_settings.SetSettingBool(wxT("gotoLastTab"), event.IsChecked());
}
+
+void SettingsDlg::NotifyWatcher() {
+ if (NULL != m_labelWhen) {
+ wxString when = wxDateTime::Now().Format();
+ m_labelWhen->SetLabel(when);
+ }
+ if (NULL != m_checkForUpdatesButton) {
+ m_checkForUpdatesButton->Enable(true);
+ }
+ m_Updater = NULL;
+}
7 src/SettingsDlg.h
View
@@ -20,6 +20,7 @@
#endif
#include "Catalyst.h"
+#include "UpdaterThread.h"
// Pre-declarations
class eSettings;
@@ -30,6 +31,8 @@ class EnvVarsPanel;
class SettingsDlg : public wxDialog {
public:
SettingsDlg(wxWindow *parent, CatalystWrapper cw, eSettings& settings);
+ // Notify about end of update cheching
+ void NotifyWatcher();
private:
wxPanel* CreateSettingsPage(wxWindow* parent);
@@ -64,6 +67,8 @@ class SettingsDlg : public wxDialog {
void OnCheckBom(wxCommandEvent& event);
DECLARE_EVENT_TABLE();
+ virtual void EndModal(int retCode);
+
// Member variables
eSettings& m_settings;
CatalystWrapper m_catalyst;
@@ -102,6 +107,8 @@ class SettingsDlg : public wxDialog {
// Updates page
wxCheckBox* m_checkForUpdatesAtStartup;
wxButton* m_checkForUpdatesButton;
+ wxStaticText* m_labelWhen;
+ UpdaterThread* m_Updater;
};
#endif // __SETTINGSDLG_H__
42 src/UpdaterThread.cpp
View
@@ -11,20 +11,13 @@
#include "eSettings.h"
#include "AppVersion.h"
+#include "SettingsDlg.h"
-class UpdaterThread : public wxThread {
-public:
- UpdaterThread(wxHTTP* http, AppVersion* info):
- m_http(http), m_info(info) {};
- virtual void *Entry();
-
-private:
- wxHTTP* m_http;
- AppVersion* m_info;
+UpdaterThread::UpdaterThread(wxHTTP* http, AppVersion* info):
+ m_http(http), m_info(info), m_CritSectWatcher(), m_Watcher(NULL) {
};
-
-void CheckForUpdates(ISettings& settings, AppVersion* info, bool forceCheck) {
+UpdaterThread* CheckForUpdates(ISettings& settings, AppVersion* info, bool forceCheck) {
if (!forceCheck) {
// Check if it more than 7 days have gone since last update check
wxLongLong lastup;
@@ -32,7 +25,7 @@ void CheckForUpdates(ISettings& settings, AppVersion* info, bool forceCheck) {
wxDateTime sevendaysago = wxDateTime::Now() - wxDateSpan(0, 0, 1, 0);
wxDateTime lastupdated(lastup);
- if (lastupdated > sevendaysago) return;
+ if (lastupdated > sevendaysago) return NULL;
}
}
@@ -41,8 +34,20 @@ void CheckForUpdates(ISettings& settings, AppVersion* info, bool forceCheck) {
wxHTTP* http = new wxHTTP;
// Start the updater thread
+ wxThreadError res;
UpdaterThread *updater = new UpdaterThread(http, info);
- if (updater->Create() == wxTHREAD_NO_ERROR) updater->Run();
+ if (wxTHREAD_NO_ERROR == (res = updater->Create())) {
+ if (wxTHREAD_NO_ERROR != (res = updater->Run())) {
+ // need to release resources
+ updater->Delete(); delete updater; updater = NULL;
+ wxLogDebug(wxT("Can't run thread, err %i!"), res);
+ }
+ } else {
+ // need to release resources
+ updater->Delete(); delete updater; updater = NULL;
+ wxLogDebug(wxT("Can't create thread, err %i!"), res);
+ }
+ return updater;
}
@@ -114,5 +119,16 @@ void* UpdaterThread::Entry() {
wxTheApp->AddPendingEvent(event);
}
+ // Notify watcher
+ wxCriticalSectionLocker locker(m_CritSectWatcher);
+ if (NULL != m_Watcher) {
+ m_Watcher->NotifyWatcher();
+ m_Watcher = NULL;
+ }
return NULL;
}
+
+void UpdaterThread::SetWatcher(SettingsDlg* dlg) {
+ wxCriticalSectionLocker locker(m_CritSectWatcher);
+ m_Watcher = dlg;
+}
23 src/UpdaterThread.h
View
@@ -1,6 +1,8 @@
#ifndef __UPDATERTHREAD_H__
#define __UPDATERTHREAD_H__
+#include <wx/thread.h>
+
// Constants
enum {
ID_UPDATES_AVAILABLE=100,
@@ -9,6 +11,25 @@ enum {
class ISettings;
class AppVersion;
-void CheckForUpdates(ISettings& settings, AppVersion* info, bool forceCheck=false);
+class wxHTTP;
+class AppVersion;
+class SettingsDlg;
+
+class UpdaterThread : public wxThread {
+public:
+ UpdaterThread(wxHTTP* http, AppVersion* info);
+ virtual void *Entry();
+ // set dialog to be notified after checking or NULL
+ void SetWatcher(SettingsDlg *dlg);
+
+private:
+ wxHTTP* m_http;
+ AppVersion* m_info;
+
+ wxCriticalSection m_CritSectWatcher; // locker for m_Watcher ptr
+ SettingsDlg *m_Watcher;
+};
+
+UpdaterThread* CheckForUpdates(ISettings& settings, AppVersion* info, bool forceCheck=false);
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.