You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 Mark Roszko <mark.roszko@gmail.com>
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef NOTIFICATIONS_MANAGER_H
  25. #define NOTIFICATIONS_MANAGER_H
  26. #include <kicommon.h>
  27. #include <functional>
  28. #include <vector>
  29. class wxString;
  30. class KISTATUSBAR;
  31. struct NOTIFICATION;
  32. class NOTIFICATIONS_LIST;
  33. class wxWindow;
  34. class wxCloseEvent;
  35. struct KICOMMON_API NOTIFICATION
  36. {
  37. public:
  38. wxString title; ///< Title of the notification.
  39. wxString description; ///< Additional message displayed under title.
  40. wxString href; ///< URL if any to link to for details.
  41. wxString key; ///< Unique key to find a notification.
  42. wxString date; ///< Date notification will display.
  43. };
  44. class KICOMMON_API NOTIFICATIONS_MANAGER
  45. {
  46. public:
  47. NOTIFICATIONS_MANAGER();
  48. /**
  49. * Create a notification with the given parameters or updates an existing one with the same key.
  50. *
  51. * @param aKey is a unique key for the notification, this allows removing or updating the same
  52. * notification.
  53. * @param aTitle is the displayed title for the event.
  54. * @param aDescription is the text that displays underneath the title and has slightly more info
  55. * them later programatically in case a notification is no longer required.
  56. * @param aHref is link to external or internal content.
  57. */
  58. void CreateOrUpdate( const wxString& aKey, const wxString& aTitle, const wxString& aDescription,
  59. const wxString& aHref = wxEmptyString );
  60. /**
  61. * Remove a notification by key.
  62. *
  63. * @param aKey is the unique key to locate.
  64. */
  65. void Remove( const wxString& aKey );
  66. /**
  67. * Load notifications stored from disk.
  68. */
  69. void Load();
  70. /**
  71. * Save notifications to disk.
  72. */
  73. void Save();
  74. /**
  75. * Show the notification list.
  76. */
  77. void ShowList( wxWindow* aParent, wxPoint aPos );
  78. /**
  79. * Add a status bar for handling.
  80. */
  81. void RegisterStatusBar( KISTATUSBAR* aStatusBar );
  82. /**
  83. * Remove status bar from handling.
  84. */
  85. void UnregisterStatusBar( KISTATUSBAR* aStatusBar );
  86. private:
  87. /**
  88. * Handle removing the shown list window from our list of shown windows.
  89. */
  90. void onListWindowClosed( wxCloseEvent& aEvent );
  91. private:
  92. /// Current stack of notifications.
  93. std::vector<NOTIFICATION> m_notifications;
  94. /// Currently shown notification lists.
  95. std::vector<NOTIFICATIONS_LIST*> m_shownDialogs;
  96. /// Status bars registered for updates.
  97. std::vector<KISTATUSBAR*> m_statusBars;
  98. /// The cached file path to read/write notifications on disk.
  99. wxFileName m_destFileName;
  100. };
  101. #endif