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>
66 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxSize( -1, 75 ), wxBORDER_SIMPLE ),
67 m_hlDetails( nullptr ),
68 m_notification( aNoti ),
71 SetSizeHints( wxDefaultSize, wxDefaultSize );
73 wxBoxSizer* mainSizer;
74 mainSizer =
new wxBoxSizer( wxVERTICAL );
78 SetBackgroundColour( bg );
79 SetForegroundColour( fg );
81 m_stTitle =
new wxStaticText(
this, wxID_ANY, aNoti->
title );
82 m_stTitle->Wrap( -1 );
84 mainSizer->Add( m_stTitle, 0, wxALL | wxEXPAND, 1 );
86 m_stDescription =
new wxStaticText(
this, wxID_ANY, aNoti->
description );
87 m_stDescription->Wrap( -1 );
88 mainSizer->Add( m_stDescription, 0, wxALL | wxEXPAND, 1 );
90 wxBoxSizer* tailSizer;
91 tailSizer =
new wxBoxSizer( wxHORIZONTAL );
93 if( !aNoti->
href.IsEmpty() )
95 m_hlDetails =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"View Details" ), aNoti->
href );
96 tailSizer->Add( m_hlDetails, 0, wxALL, 2 );
99 m_hlDismiss =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"Dismiss" ), aNoti->
href );
100 tailSizer->Add( m_hlDismiss, 0, wxALL, 2 );
102 mainSizer->Add( tailSizer, 1, wxEXPAND, 5 );
104 if( m_hlDetails !=
nullptr )
109 SetSizer( mainSizer );
116 wxString url = aEvent.GetURL();
118 if( url.StartsWith( wxS(
"kicad://" ) ) )
120 url.Replace( wxS(
"kicad://" ), wxS(
"" ) );
122 if( url == wxS(
"pcm" ) )
129 wxLaunchDefaultBrowser( aEvent.GetURL(), wxBROWSER_NEW_WINDOW );
139 m_manager->Remove( m_notification->key );
157 wxFrame( parent, wxID_ANY,
_(
"Notifications" ), pos, wxSize( 300, 150 ),
158 wxFRAME_NO_TASKBAR | wxBORDER_SIMPLE ),
161 SetSizeHints( wxDefaultSize, wxDefaultSize );
164 bSizer1 =
new wxBoxSizer( wxVERTICAL );
167 wxSize( -1, -1 ), wxVSCROLL | wxBORDER_SIMPLE );
182 _(
"There are no notifications available" ),
183 wxDefaultPosition, wxDefaultSize,
184 wxALIGN_CENTER_HORIZONTAL );
200 if( IsDescendant( aEvent.GetWindow() ) )
258 std::unordered_map<NOTIFICATION*, NOTIFICATION_PANEL*>
m_panelMap;
275 nlohmann::json saved_json;
277 std::ifstream saved_json_stream(
m_destFileName.GetFullPath().fn_str() );
281 saved_json_stream >> saved_json;
285 catch( std::exception& )
290 if( wxGetEnv( wxT(
"KICAD_TEST_NOTI" ),
nullptr ) )
292 CreateOrUpdate( wxS(
"test" ), wxS(
"Test Notification" ), wxS(
"Test please ignore" ),
293 wxS(
"https://kicad.org" ) );
300 std::ofstream jsonFileStream(
m_destFileName.GetFullPath().fn_str() );
303 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
304 jsonFileStream.flush();
305 jsonFileStream.close();
310 const wxString& aTitle,
311 const wxString& aDescription,
312 const wxString& aHref )
314 wxCHECK_RET( !aKey.IsEmpty(), wxS(
"Notification key must not be empty" ) );
319 return noti.key == aKey;
333 aKey, wxEmptyString } );
355 return noti.key == aKey;
366 list->Remove( &(*it) );
384 return dialog == evtWindow;
412 wxSize windowSize = list->GetSize();
413 list->SetPosition( aPos - windowSize );
433 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)
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