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.

119 lines
3.6 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 (C) 2023 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 <functional>
  27. #include <vector>
  28. class wxString;
  29. class KISTATUSBAR;
  30. struct NOTIFICATION;
  31. class NOTIFICATIONS_LIST;
  32. class wxWindow;
  33. class wxCloseEvent;
  34. struct NOTIFICATION
  35. {
  36. public:
  37. wxString title; ///< Title of the notification
  38. wxString description; ///< Additional message displayed under title
  39. wxString href; ///< URL if any to link to for details
  40. wxString key; ///< Unique key to find a notification
  41. wxString date; ///< Date notification will display
  42. };
  43. class NOTIFICATIONS_MANAGER
  44. {
  45. friend class NOTIFICATION_LIST;
  46. public:
  47. NOTIFICATIONS_MANAGER();
  48. /**
  49. * Creates 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 notification
  52. * @param aTitle is the displayed title for the event
  53. * @param aDescription is the text that displays underneath the title and has slightly more info
  54. * them later programtically in case a notificaiton is no logner required
  55. * @param aHref is link to external or internal content
  56. */
  57. void CreateOrUpdate( const wxString& aKey, const wxString& aTitle, const wxString& aDescription,
  58. const wxString& aHref = wxEmptyString );
  59. /**
  60. * Remove a notification by key
  61. *
  62. * @param aKey is the unique key to locate
  63. */
  64. void Remove( const wxString& aKey );
  65. /**
  66. * Loads notifications stored from disk
  67. */
  68. void Load();
  69. /**
  70. * Saves notifications to disk
  71. */
  72. void Save();
  73. /**
  74. * Shows the notification list
  75. */
  76. void ShowList( wxWindow* aParent, wxPoint aPos );
  77. /**
  78. * Add a status bar for handling
  79. */
  80. void RegisterStatusBar( KISTATUSBAR* aStatusBar );
  81. /**
  82. * Removes status bar from handling
  83. */
  84. void UnregisterStatusBar( KISTATUSBAR* aStatusBar );
  85. private:
  86. /**
  87. * Handles removing the shown list window from our list of shown windows
  88. */
  89. void onListWindowClosed( wxCloseEvent& aEvent );
  90. ///< Current stack of notifications
  91. std::vector<NOTIFICATION> m_notifications;
  92. ///< Currently shown notification lists
  93. std::vector<NOTIFICATIONS_LIST*> m_shownDialogs;
  94. ///< Status bars registered for updates
  95. std::vector<KISTATUSBAR*> m_statusBars;
  96. ///< The cached file path to read/write notifications on disk
  97. wxFileName m_destFileName;
  98. };
  99. #endif