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.

120 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 <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. friend class NOTIFICATION_LIST;
  47. public:
  48. NOTIFICATIONS_MANAGER();
  49. /**
  50. * Creates a notification with the given parameters or updates an existing one with the same key
  51. *
  52. * @param aKey is a unique key for the notification, this allows removing or updating the same 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 programtically in case a notificaiton is no logner 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. * Loads notifications stored from disk
  68. */
  69. void Load();
  70. /**
  71. * Saves notifications to disk
  72. */
  73. void Save();
  74. /**
  75. * Shows 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. * Removes status bar from handling
  84. */
  85. void UnregisterStatusBar( KISTATUSBAR* aStatusBar );
  86. private:
  87. /**
  88. * Handles removing the shown list window from our list of shown windows
  89. */
  90. void onListWindowClosed( wxCloseEvent& aEvent );
  91. ///< Current stack of notifications
  92. std::vector<NOTIFICATION> m_notifications;
  93. ///< Currently shown notification lists
  94. std::vector<NOTIFICATIONS_LIST*> m_shownDialogs;
  95. ///< Status bars registered for updates
  96. std::vector<KISTATUSBAR*> m_statusBars;
  97. ///< The cached file path to read/write notifications on disk
  98. wxFileName m_destFileName;
  99. };
  100. #endif