21#include <wx/filename.h>
23#include <wx/hyperlink.h>
25#include <wx/scrolwin.h>
27#include <wx/settings.h>
28#include <wx/stattext.h>
62 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ), wxBORDER_SIMPLE ),
67 SetSizeHints( wxDefaultSize, wxDefaultSize );
69 wxBoxSizer* mainSizer;
70 mainSizer =
new wxBoxSizer( wxVERTICAL );
74 SetBackgroundColour( bg );
75 SetForegroundColour( fg );
80 mainSizer->Add(
m_stTitle, 0, wxALL | wxEXPAND, 1 );
86 wxBoxSizer* tailSizer;
87 tailSizer =
new wxBoxSizer( wxHORIZONTAL );
89 if( !aNoti->
href.IsEmpty() )
91 m_hlDetails =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"View Details" ), aNoti->
href );
95 m_hlDismiss =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"Dismiss" ), aNoti->
href );
98 mainSizer->Add( tailSizer, 1, wxEXPAND, 5 );
105 SetSizer( mainSizer );
112 wxString url = aEvent.GetURL();
114 if( url.StartsWith( wxS(
"kicad://" ) ) )
116 url.Replace( wxS(
"kicad://" ), wxS(
"" ) );
118 if( url == wxS(
"pcm" ) )
125 wxLaunchDefaultBrowser( aEvent.GetURL(), wxBROWSER_NEW_WINDOW );
153 wxFrame( parent, wxID_ANY,
_(
"Notifications" ), pos, wxSize( 300, 150 ),
154 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE ),
157 SetSizeHints( wxDefaultSize, wxDefaultSize );
160 bSizer1 =
new wxBoxSizer( wxVERTICAL );
163 wxSize( -1, -1 ), wxVSCROLL | wxBORDER_SIMPLE );
178 _(
"There are no notifications available" ),
179 wxDefaultPosition, wxDefaultSize,
180 wxALIGN_CENTER_HORIZONTAL );
206 if( IsDescendant( aEvent.GetWindow() ) )
264 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
281 nlohmann::json saved_json;
283 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
287 saved_json_stream >> saved_json;
291 catch( std::exception& )
296 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
298 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
299 wxS(
"https://kicad.org" ) );
306 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
309 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
310 jsonFileStream.flush();
311 jsonFileStream.close();
316 const wxString& aTitle,
317 const wxString& aDescription,
318 const wxString& aHref )
320 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
325 return noti.key == aKey;
339 aKey, wxEmptyString } );
361 return noti.key == aKey;
372 list->Remove( &(*it) );
390 return dialog == evtWindow;
418 wxSize windowSize = list->GetSize();
419 list->SetPosition( aPos - windowSize );
439 return statusBar == aStatusBar;
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)
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