From 88498918937df5077c7d83f7f84d9903bb9104d6 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sat, 16 Dec 2023 06:47:28 -0500 Subject: [PATCH] Add a update notice modal dialog instead of the incomplete notifications --- kicad/CMakeLists.txt | 2 + kicad/dialogs/dialog_update_notice.cpp | 68 +++ kicad/dialogs/dialog_update_notice.h | 48 ++ kicad/dialogs/dialog_update_notice_base.cpp | 94 +++ kicad/dialogs/dialog_update_notice_base.fbp | 611 ++++++++++++++++++++ kicad/dialogs/dialog_update_notice_base.h | 61 ++ kicad/kicad_manager_frame.cpp | 2 +- kicad/update_manager.cpp | 29 +- kicad/update_manager.h | 4 +- 9 files changed, 906 insertions(+), 13 deletions(-) create mode 100644 kicad/dialogs/dialog_update_notice.cpp create mode 100644 kicad/dialogs/dialog_update_notice.h create mode 100644 kicad/dialogs/dialog_update_notice_base.cpp create mode 100644 kicad/dialogs/dialog_update_notice_base.fbp create mode 100644 kicad/dialogs/dialog_update_notice_base.h diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index 127969190e..777d6f07f4 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -18,6 +18,8 @@ include_directories( set( KICAD_SRCS dialogs/dialog_update_check_prompt_base.cpp dialogs/dialog_update_check_prompt.cpp + dialogs/dialog_update_notice_base.cpp + dialogs/dialog_update_notice.cpp dialogs/dialog_template_selector_base.cpp dialogs/dialog_template_selector.cpp dialogs/panel_kicad_launcher_base.cpp diff --git a/kicad/dialogs/dialog_update_notice.cpp b/kicad/dialogs/dialog_update_notice.cpp new file mode 100644 index 0000000000..03f2e982f6 --- /dev/null +++ b/kicad/dialogs/dialog_update_notice.cpp @@ -0,0 +1,68 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Mark Roszko + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include + +DIALOG_UPDATE_NOTICE::DIALOG_UPDATE_NOTICE( wxWindow* aWindow, const wxString& aNewVersion, + const wxString& aDetailsUrl, + const wxString& aDownloadsUrl ) : + DIALOG_UPDATE_NOTICE_BASE( aWindow ), + m_detailsUrl( aDetailsUrl ), + m_downloadsUrl( aDownloadsUrl ) +{ + wxString msg = wxString::Format( _( "KiCad %s is now available (you have %s). Would you like to download it now?" ), aNewVersion, GetMajorMinorVersion() ); + m_messageLine2->SetLabelText( msg ); + + Fit(); + Layout(); +} + + +void DIALOG_UPDATE_NOTICE::OnSkipThisVersionClicked( wxCommandEvent& aEvent ) +{ + EndModal( wxID_NO ); +} + + +void DIALOG_UPDATE_NOTICE::OnBtnRemindMeClicked( wxCommandEvent& aEvent ) +{ + EndModal( wxID_RETRY ); +} + + +void DIALOG_UPDATE_NOTICE::OnBtnDetailsPageClicked( wxCommandEvent& aEvent ) +{ + wxLaunchDefaultBrowser( m_detailsUrl, wxBROWSER_NEW_WINDOW ); +} + + +void DIALOG_UPDATE_NOTICE::OnBtnDownloadsPageClicked( wxCommandEvent& aEvent ) +{ + wxLaunchDefaultBrowser( m_downloadsUrl, wxBROWSER_NEW_WINDOW ); + EndModal( wxID_YES ); +} \ No newline at end of file diff --git a/kicad/dialogs/dialog_update_notice.h b/kicad/dialogs/dialog_update_notice.h new file mode 100644 index 0000000000..bd73290c4a --- /dev/null +++ b/kicad/dialogs/dialog_update_notice.h @@ -0,0 +1,48 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Mark Roszko + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef DIALOG_UPDATE_NOTICE_H +#define DIALOG_UPDATE_NOTICE_H + +#include + +class DIALOG_UPDATE_NOTICE : public DIALOG_UPDATE_NOTICE_BASE +{ +public: + DIALOG_UPDATE_NOTICE( wxWindow* aWindow, + const wxString& aNewVersion, + const wxString& aDetailsUrl, + const wxString& aDownloadsUrl ); + +private: + virtual void OnSkipThisVersionClicked( wxCommandEvent& aEvent ) override; + virtual void OnBtnRemindMeClicked( wxCommandEvent& aEvent ) override; + virtual void OnBtnDetailsPageClicked( wxCommandEvent& aEvent ) override; + virtual void OnBtnDownloadsPageClicked( wxCommandEvent& aEvent ) override; + + wxString m_detailsUrl; + wxString m_downloadsUrl; +}; + +#endif \ No newline at end of file diff --git a/kicad/dialogs/dialog_update_notice_base.cpp b/kicad/dialogs/dialog_update_notice_base.cpp new file mode 100644 index 0000000000..6c674ab822 --- /dev/null +++ b/kicad/dialogs/dialog_update_notice_base.cpp @@ -0,0 +1,94 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_update_notice_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_UPDATE_NOTICE_BASE::DIALOG_UPDATE_NOTICE_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + wxFlexGridSizer* fgSizer4; + fgSizer4 = new wxFlexGridSizer( 0, 2, 10, 0 ); + fgSizer4->SetFlexibleDirection( wxBOTH ); + fgSizer4->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + m_icon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer4->Add( m_icon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 10 ); + + wxBoxSizer* bSizer4; + bSizer4 = new wxBoxSizer( wxVERTICAL ); + + m_messageLine1 = new wxStaticText( this, wxID_ANY, _("A new version of KiCad is available!"), wxDefaultPosition, wxDefaultSize, 0 ); + m_messageLine1->Wrap( -1 ); + m_messageLine1->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) ); + + bSizer4->Add( m_messageLine1, 0, wxALL, 5 ); + + m_messageLine2 = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_messageLine2->Wrap( -1 ); + bSizer4->Add( m_messageLine2, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + + fgSizer4->Add( bSizer4, 1, wxEXPAND|wxRIGHT, 5 ); + + + fgSizer4->Add( 0, 0, 1, wxEXPAND, 5 ); + + + bSizerMain->Add( fgSizer4, 1, wxEXPAND|wxALL, 5 ); + + wxBoxSizer* bButtonSizer; + bButtonSizer = new wxBoxSizer( wxHORIZONTAL ); + + m_skipBtn = new wxButton( this, wxID_ANY, _("Skip this version"), wxDefaultPosition, wxDefaultSize, 0 ); + m_skipBtn->SetToolTip( _("Override locks and apply the operation on all the items selected.\nAny locked items will remain locked after the operation is complete.") ); + + bButtonSizer->Add( m_skipBtn, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 10 ); + + + bButtonSizer->Add( 0, 0, 1, wxEXPAND, 5 ); + + m_btnRemind = new wxButton( this, wxID_ANY, _("Remind me later"), wxDefaultPosition, wxDefaultSize, 0 ); + bButtonSizer->Add( m_btnRemind, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP, 5 ); + + m_btnDetailsPage = new wxButton( this, wxID_ANY, _("View Details"), wxDefaultPosition, wxDefaultSize, 0 ); + bButtonSizer->Add( m_btnDetailsPage, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP, 5 ); + + m_btnDownloadPage = new wxButton( this, wxID_ANY, _("Open Downloads Page"), wxDefaultPosition, wxDefaultSize, 0 ); + bButtonSizer->Add( m_btnDownloadPage, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP, 5 ); + + + bSizerMain->Add( bButtonSizer, 0, wxEXPAND, 5 ); + + + this->SetSizer( bSizerMain ); + this->Layout(); + bSizerMain->Fit( this ); + + this->Centre( wxBOTH ); + + // Connect Events + m_skipBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnSkipThisVersionClicked ), NULL, this ); + m_btnRemind->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnBtnRemindMeClicked ), NULL, this ); + m_btnDetailsPage->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnBtnDetailsPageClicked ), NULL, this ); + m_btnDownloadPage->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnBtnDownloadsPageClicked ), NULL, this ); +} + +DIALOG_UPDATE_NOTICE_BASE::~DIALOG_UPDATE_NOTICE_BASE() +{ + // Disconnect Events + m_skipBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnSkipThisVersionClicked ), NULL, this ); + m_btnRemind->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnBtnRemindMeClicked ), NULL, this ); + m_btnDetailsPage->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnBtnDetailsPageClicked ), NULL, this ); + m_btnDownloadPage->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_UPDATE_NOTICE_BASE::OnBtnDownloadsPageClicked ), NULL, this ); + +} diff --git a/kicad/dialogs/dialog_update_notice_base.fbp b/kicad/dialogs/dialog_update_notice_base.fbp new file mode 100644 index 0000000000..d8d92102cd --- /dev/null +++ b/kicad/dialogs/dialog_update_notice_base.fbp @@ -0,0 +1,611 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_update_notice_base + 1000 + none + + + 1 + dialog_update_notice + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 0 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_UPDATE_NOTICE_BASE + + -1,-1 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Update Available + + 0 + + + + + + bSizerMain + wxVERTICAL + none + + 5 + wxEXPAND|wxALL + 1 + + 2 + wxBOTH + + + 0 + + fgSizer4 + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 10 + + 10 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_icon + 1 + + + protected + 1 + + Resizable + 1 + + ; ; forward_declare + 0 + + + + + + + + 5 + wxEXPAND|wxRIGHT + 1 + + + bSizer4 + wxVERTICAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + ,90,700,-1,70,0 + 0 + 0 + wxID_ANY + A new version of KiCad is available! + 0 + + 0 + + + 0 + + 1 + m_messageLine1 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + + 0 + + 1 + m_messageLine2 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + + + 5 + wxEXPAND + 0 + + + bButtonSizer + wxHORIZONTAL + none + + 10 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 0 + 1 + + 1 + + + 0 + 0 + wxID_ANY + Skip this version + + 0 + + 0 + + + 0 + + 1 + m_skipBtn + 1 + + + protected + 1 + + + + Resizable + 1 + + + + 0 + Override locks and apply the operation on all the items selected. Any locked items will remain locked after the operation is complete. + + wxFILTER_NONE + wxDefaultValidator + + + + + OnSkipThisVersionClicked + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 0 + 1 + + 1 + + + 0 + 0 + wxID_ANY + Remind me later + + 0 + + 0 + + + 0 + + 1 + m_btnRemind + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnRemindMeClicked + + + + 5 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 0 + 1 + + 1 + + + 0 + 0 + wxID_ANY + View Details + + 0 + + 0 + + + 0 + + 1 + m_btnDetailsPage + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnDetailsPageClicked + + + + 5 + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 0 + 1 + + 1 + + + 0 + 0 + wxID_ANY + Open Downloads Page + + 0 + + 0 + + + 0 + + 1 + m_btnDownloadPage + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnBtnDownloadsPageClicked + + + + + + + + diff --git a/kicad/dialogs/dialog_update_notice_base.h b/kicad/dialogs/dialog_update_notice_base.h new file mode 100644 index 0000000000..3527ce8564 --- /dev/null +++ b/kicad/dialogs/dialog_update_notice_base.h @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_UPDATE_NOTICE_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_UPDATE_NOTICE_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticBitmap* m_icon; + wxStaticText* m_messageLine1; + wxStaticText* m_messageLine2; + wxButton* m_skipBtn; + wxButton* m_btnRemind; + wxButton* m_btnDetailsPage; + wxButton* m_btnDownloadPage; + + // Virtual event handlers, override them in your derived class + virtual void OnSkipThisVersionClicked( wxCommandEvent& event ) { event.Skip(); } + virtual void OnBtnRemindMeClicked( wxCommandEvent& event ) { event.Skip(); } + virtual void OnBtnDetailsPageClicked( wxCommandEvent& event ) { event.Skip(); } + virtual void OnBtnDownloadsPageClicked( wxCommandEvent& event ) { event.Skip(); } + + + public: + + DIALOG_UPDATE_NOTICE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Update Available"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + ~DIALOG_UPDATE_NOTICE_BASE(); + +}; + diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 2afdd75546..f5f005fd23 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -966,7 +966,7 @@ void KICAD_MANAGER_FRAME::OnIdle( wxIdleEvent& aEvent ) if( !m_updateManager && settings->m_KiCadUpdateCheck ) { m_updateManager = std::make_unique(); - m_updateManager->CheckForUpdate(); + m_updateManager->CheckForUpdate( this ); } } diff --git a/kicad/update_manager.cpp b/kicad/update_manager.cpp index 873b4b0ac0..e02011cde8 100644 --- a/kicad/update_manager.cpp +++ b/kicad/update_manager.cpp @@ -36,6 +36,8 @@ #include #include +#include + #include #include @@ -152,7 +154,7 @@ int UPDATE_MANAGER::PostRequest( const wxString& aUrl, std::string aRequestBody, } -void UPDATE_MANAGER::CheckForUpdate() +void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent ) { if( m_working ) return; @@ -161,7 +163,7 @@ void UPDATE_MANAGER::CheckForUpdate() m_updateBackgroundJob = Pgm().GetBackgroundJobMonitor().Create( _( "Update Check" ) ); - auto update_check = [&]() -> void + auto update_check = [aNoticeParent, this]() -> void { std::stringstream update_json_stream; std::stringstream request_json_stream; @@ -221,15 +223,20 @@ void UPDATE_MANAGER::CheckForUpdate() if( response.version != settings->m_lastReceivedUpdate ) { - wxString notificationDesc = - wxString::Format( _( "KiCad %s was released on %s" ), response.version, - response.release_date ); - - Pgm().GetNotificationsManager().CreateOrUpdate( - wxS( "kicad_update" ), _( "Update Available" ), notificationDesc, - response.details_url ); - - settings->m_lastReceivedUpdate = response.version; + aNoticeParent->CallAfter( + [=]() + { + auto notice = new DIALOG_UPDATE_NOTICE( + aNoticeParent, response.version, response.details_url, + response.downloads_url ); + + int retCode = notice->ShowModal(); + if( retCode != wxID_RETRY ) + { + // basically saving the last received update prevents us from prompting again + settings->m_lastReceivedUpdate = response.version; + } + } ); } } catch( const std::exception& e ) diff --git a/kicad/update_manager.h b/kicad/update_manager.h index e255d304cc..7e5e5f906f 100644 --- a/kicad/update_manager.h +++ b/kicad/update_manager.h @@ -29,12 +29,14 @@ class PROGRESS_REPORTER; struct BACKGROUND_JOB; +class wxWindow; + class UPDATE_MANAGER { public: UPDATE_MANAGER(); - void CheckForUpdate(); + void CheckForUpdate( wxWindow* aNoticeParent ); int PostRequest( const wxString& aUrl, std::string aRequestBody, std::ostream* aOutput, PROGRESS_REPORTER* aReporter, const size_t aSizeLimit );