25#include <wx/filename.h>
27#include <wx/hyperlink.h>
29#include <wx/scrolwin.h>
31#include <wx/settings.h>
32#include <wx/stattext.h>
64 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ), wxBORDER_SIMPLE ),
65 m_hlDetails( nullptr ),
66 m_notification( aNoti ),
69 SetSizeHints( wxDefaultSize, wxDefaultSize );
71 wxBoxSizer* mainSizer;
72 mainSizer =
new wxBoxSizer( wxVERTICAL );
76 SetBackgroundColour( bg );
77 SetForegroundColour( fg );
79 m_stTitle =
new wxStaticText(
this, wxID_ANY, aNoti->
title );
80 m_stTitle->Wrap( -1 );
82 mainSizer->Add( m_stTitle, 0, wxALL | wxEXPAND, 1 );
84 m_stDescription =
new wxStaticText(
this, wxID_ANY, aNoti->
description );
85 m_stDescription->Wrap( -1 );
86 mainSizer->Add( m_stDescription, 0, wxALL | wxEXPAND, 1 );
88 wxBoxSizer* tailSizer;
89 tailSizer =
new wxBoxSizer( wxHORIZONTAL );
91 if( !aNoti->
href.IsEmpty() )
93 m_hlDetails =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"View Details" ), aNoti->
href );
94 tailSizer->Add( m_hlDetails, 0, wxALL, 2 );
97 m_hlDismiss =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"Dismiss" ), aNoti->
href );
98 tailSizer->Add( m_hlDismiss, 0, wxALL, 2 );
100 mainSizer->Add( tailSizer, 1, wxEXPAND, 5 );
102 if( m_hlDetails !=
nullptr )
107 SetSizer( mainSizer );
114 wxString url = aEvent.GetURL();
116 if( url.StartsWith( wxS(
"kicad://" ) ) )
118 url.Replace( wxS(
"kicad://" ), wxS(
"" ) );
120 if( url == wxS(
"pcm" ) )
127 wxLaunchDefaultBrowser( aEvent.GetURL(), wxBROWSER_NEW_WINDOW );
137 m_manager->Remove( m_notification->key );
155 wxFrame( parent, wxID_ANY,
_(
"Notifications" ), pos, wxSize( 300, 150 ),
156 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE ),
159 SetSizeHints( wxDefaultSize, wxDefaultSize );
162 bSizer1 =
new wxBoxSizer( wxVERTICAL );
165 wxSize( -1, -1 ), wxVSCROLL | wxBORDER_SIMPLE );
180 _(
"There are no notifications available" ),
181 wxDefaultPosition, wxDefaultSize,
182 wxALIGN_CENTER_HORIZONTAL );
198 if( IsDescendant( aEvent.GetWindow() ) )
256 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
273 nlohmann::json saved_json;
275 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
279 saved_json_stream >> saved_json;
283 catch( std::exception& )
288 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
290 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
291 wxS(
"https://kicad.org" ) );
298 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
301 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
302 jsonFileStream.flush();
303 jsonFileStream.close();
308 const wxString& aTitle,
309 const wxString& aDescription,
310 const wxString& aHref )
312 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
317 return noti.key == aKey;
331 aKey, wxEmptyString } );
353 return noti.key == aKey;
364 list->Remove( &(*it) );
382 return dialog == evtWindow;
410 wxSize windowSize = list->GetSize();
411 list->SetPosition( aPos - windowSize );
431 return statusBar == aStatusBar;
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
void SetNotificationCount(int aCount)
Set the notification count on the notifications button.
void onFocusLoss(wxFocusEvent &aEvent)
void Add(NOTIFICATION *aNoti)
NOTIFICATIONS_MANAGER * m_manager
wxBoxSizer * m_contentSizer
Inner content of the scrolled window, add panels here.
std::unordered_map< NOTIFICATION *, NOTIFICATION_PANEL * > m_panelMap
void Remove(NOTIFICATION *aNoti)
wxScrolledWindow * m_scrolledWindow
wxStaticText * m_noNotificationsText
Text to be displayed when no notifications are present, this gets a Show/Hide call as needed.
NOTIFICATIONS_LIST(NOTIFICATIONS_MANAGER *aManager, wxWindow *parent, const wxPoint &pos)
void Save()
Save notifications to disk.
void onListWindowClosed(wxCloseEvent &aEvent)
Handle removing the shown list window from our list of shown windows.
wxFileName m_destFileName
The cached file path to read/write notifications on disk.
void Load()
Load notifications stored from disk.
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
void CreateOrUpdate(const wxString &aKey, const wxString &aTitle, const wxString &aDescription, const wxString &aHref=wxEmptyString)
Create a notification with the given parameters or updates an existing one with the same key.
void Remove(const wxString &aKey)
Remove a notification by key.
std::vector< KISTATUSBAR * > m_statusBars
Status bars registered for updates.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Remove status bar from handling.
std::vector< NOTIFICATION > m_notifications
Current stack of notifications.
void ShowList(wxWindow *aParent, wxPoint aPos)
Show the notification list.
std::vector< NOTIFICATIONS_LIST * > m_shownDialogs
Currently shown notification lists.
wxHyperlinkCtrl * m_hlDetails
wxStaticText * m_stDescription
NOTIFICATION * m_notification
void onDismiss(wxHyperlinkEvent &aEvent)
NOTIFICATION_PANEL(wxWindow *aParent, NOTIFICATIONS_MANAGER *aManager, NOTIFICATION *aNoti)
void onDetails(wxHyperlinkEvent &aEvent)
NOTIFICATIONS_MANAGER * m_manager
wxHyperlinkCtrl * m_hlDismiss
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
void delete_if(_Container &__c, _Function &&__f)
Deletes all values from __c for which __f returns true.
static long long g_last_closed_timer
wxString description
Additional message displayed under title.
wxString title
Title of the notification.
wxString href
URL if any to link to for details.
Functions to provide common constants and other functions to assist in making a consistent UI.
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(UPDATE_REQUEST, platform, arch, current_version, lang, last_check) struct UPDATE_RESPONSE