1 /* 2 * This program source code file is part of KiCad, a free EDA CAD application. 3 * 4 * Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com 5 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. 6 * 7 * This program is free software: you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the 9 * Free Software Foundation, either version 3 of the License, or (at your 10 * option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef DIALOG_PCM_PROGRESS_H_ 22 #define DIALOG_PCM_PROGRESS_H_ 23 24 25 #include "dialog_pcm_progress_base.h" 26 #include "reporter.h" 27 #include <atomic> 28 #include <widgets/progress_reporter_base.h> 29 #if wxCHECK_VERSION( 3, 1, 0 ) 30 #include <wx/appprogress.h> 31 #endif 32 33 34 /** 35 * @brief Progress dialog for PCM system 36 * 37 * This dialog is designed to work with PCM_TASK_MANAGER's threading system. 38 * Some of it's methods are safe to call from a non-UI thread. 39 */ 40 class DIALOG_PCM_PROGRESS : public DIALOG_PCM_PROGRESS_BASE, public PROGRESS_REPORTER_BASE 41 { 42 protected: 43 // Handlers for DIALOG_PCM_PROGRESS_BASE events. 44 void OnCancelClicked( wxCommandEvent& event ) override; 45 void OnCloseClicked( wxCommandEvent& event ) override; 46 47 public: 48 /** Constructor */ 49 DIALOG_PCM_PROGRESS( wxWindow* parent, bool aShowDownloadSection = true ); 50 51 ///< Safe to call from non-UI thread. Adds a message to detailed report window. 52 void Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ); 53 54 ///< Safe to call from non-UI thread. Sets the download progress of the current zip entry. 55 void SetDownloadProgress( uint64_t aDownloaded, uint64_t aTotal ); 56 57 ///< Safe to call from non-UI thread. Sets the download prgress of the current package. 58 void SetPackageProgress( uint64_t aProgress, uint64_t aTotal ); 59 60 ///< Safe to call from non-UI thread. Advances to the next package. 61 void AdvancePhase() override; 62 63 ///< Safe to call from non-UI thread. Disables cancel button, enables close button. 64 void SetFinished(); 65 66 private: 67 bool updateUI() override; 68 69 static uint64_t toKb( uint64_t aValue ); 70 71 private: 72 std::atomic_int64_t m_downloaded; 73 std::atomic_int64_t m_downloadTotal; 74 75 std::atomic_int64_t m_currentProgress; 76 std::atomic_int64_t m_currentProgressTotal; 77 78 std::atomic_bool m_finished; 79 80 std::vector< std::pair<wxString, SEVERITY> > m_reports; 81 82 #if wxCHECK_VERSION( 3, 1, 0 ) 83 wxAppProgressIndicator m_appProgressIndicator; 84 #endif 85 }; 86 87 #endif // DIALOG_PCM_PROGRESS_H_ 88