source: eviacam/trunk/fuentes/src/checkupdates_manager.cpp @ 567

Last change on this file since 567 was 567, checked in by mabarracus, 4 years ago

updated sources to version 2.0.3

File size: 3.2 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// Name:        checkupdates_listener.cpp
3// Purpose:     
4// Author:      Cesar Mauri Loba (cesar at crea-si dot com)
5// Copyright:   (C) 2012-14 Cesar Mauri Loba - CREA Software Systems
6//
7//  This program is free software: you can redistribute it and/or modify
8//  it under the terms of the GNU General Public License as published by
9//  the Free Software Foundation, either version 3 of the License, or
10//  (at your option) any later version.
11//
12//  This program is distributed in the hope that it will be useful,
13//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//  GNU General Public License for more details.
16//
17//  You should have received a copy of the GNU General Public License
18//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19/////////////////////////////////////////////////////////////////////////////
20#include "checkupdates_manager.h"
21#include "checkupdates_ui.h"
22#include "config.h"
23#include <wx/window.h>
24
25namespace eviacam {
26
27CheckUpdatesManager::CheckUpdatesManager(wxWindow* parent)
28: m_parent(parent)
29, m_pCheckUpdatesUI(NULL)
30{
31        m_checker.Connect(
32                CHECKUPDATE_FINISHED_EVENT, 
33                wxCommandEventHandler(CheckUpdatesManager::OnCheckUpdatesFinished), 
34                NULL, this);
35}
36
37CheckUpdatesManager::~CheckUpdatesManager()
38{
39        m_checker.Disconnect(
40                CHECKUPDATE_FINISHED_EVENT,
41                wxCommandEventHandler(CheckUpdatesManager::OnCheckUpdatesFinished),
42                NULL, this);
43}
44
45static 
46void SetResults(CheckUpdatesUI* dlg, CheckUpdates::ResultStatus status, wxString str)
47{
48        wxString txt1;
49        wxString txt2;
50
51        switch (status) {
52        case CheckUpdates::NEW_VERSION_AVAILABLE:
53                txt1 = _("New version available: ");
54                txt1 += str;
55                txt2 = _("Installed version: ");
56                txt2 += _T(VERSION);
57                dlg->SetResults(txt1, txt2, true);
58                break;
59        case CheckUpdates::NO_NEW_VERSION_AVAILABLE:
60                txt1 = _("No updates available");
61                dlg->SetResults(txt1, txt2, false);
62                break;
63        case CheckUpdates::ERROR_CHECKING_NEW_VERSION:
64                txt1 = _("Error checking for updates");
65                dlg->SetResults(txt1, str, false);
66                break;
67        default:
68                assert(false);
69        }
70}
71
72void CheckUpdatesManager::OnCheckUpdatesFinished(wxCommandEvent& event)
73{
74        event.Skip(false); // Finish processing the event
75
76        CheckUpdates::ResultStatus status = static_cast<CheckUpdates::ResultStatus>(event.GetInt());
77
78        if (m_pCheckUpdatesUI) {
79                // Checking in foreground
80                m_pCheckUpdatesUI->StopProgress();
81                SetResults(m_pCheckUpdatesUI, status, event.GetString());
82                return;
83        }
84
85        // Checking in background
86        if (status != CheckUpdates::NEW_VERSION_AVAILABLE) return;
87
88#if defined(ENABLE_UPDATES_CHECK)               
89        m_pCheckUpdatesUI = new CheckUpdatesUI(m_parent);
90
91        SetResults(m_pCheckUpdatesUI, status, event.GetString());
92       
93        m_pCheckUpdatesUI->ShowModal();
94       
95        wxDELETE(m_pCheckUpdatesUI);
96#endif
97}
98
99void CheckUpdatesManager::LaunchBackground()
100{
101        assert(m_pCheckUpdatesUI == NULL);
102        m_checker.Start();
103}
104
105void CheckUpdatesManager::LaunchForeground()
106{
107        assert(m_pCheckUpdatesUI == NULL);
108        m_pCheckUpdatesUI = new CheckUpdatesUI(m_parent);
109        m_checker.Start();
110        m_pCheckUpdatesUI->StartProgress();
111        m_pCheckUpdatesUI->ShowModal();
112}
113
114}
Note: See TracBrowser for help on using the repository browser.