The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

107 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. struct LicenseThread;
  19. class LicenseWebview;
  20. //==============================================================================
  21. struct LicenseState
  22. {
  23. enum class Type
  24. {
  25. notLoggedIn, // only used when the webview is open and the user has not logged in yet
  26. noLicenseChosenYet,
  27. GPL, // GPL is used when the user enables the GPL compile flag
  28. personal,
  29. edu,
  30. indie,
  31. pro
  32. };
  33. Type type = Type::notLoggedIn;
  34. String username;
  35. String email;
  36. String authToken;
  37. static const char* licenseTypeToString (Type licenseType);
  38. bool isPaidOrGPL() const noexcept { return (type == Type::GPL || type == Type::indie || type == Type::pro); }
  39. Image avatar;
  40. };
  41. //==============================================================================
  42. class LicenseController
  43. {
  44. public:
  45. //==============================================================================
  46. struct StateChangedCallback
  47. {
  48. virtual ~StateChangedCallback() {}
  49. virtual void licenseStateChanged (const LicenseState&) = 0;
  50. };
  51. //==============================================================================
  52. LicenseController();
  53. ~LicenseController();
  54. //==============================================================================
  55. const LicenseState& getState() const noexcept { return state; }
  56. void logout();
  57. void chooseNewLicense();
  58. //==============================================================================
  59. void addLicenseStatusChangedCallback (StateChangedCallback* callback) { listeners.add (callback); }
  60. void removeLicenseStatusChangedCallback (StateChangedCallback* callback) { listeners.remove (callback); }
  61. private:
  62. //==============================================================================
  63. struct ModalCompletionCallback;
  64. friend struct ModalCompletionCallback;
  65. friend class ScopedPointer<LicenseThread>;
  66. friend struct LicenseThread;
  67. //==============================================================================
  68. void closeWebview (int);
  69. void modalStateFinished (int);
  70. void ensureLicenseWebviewIsOpenWithPage (const String&);
  71. void queryWebview (const String&, const String&, HashMap<String, String>&);
  72. void updateState (const LicenseState&);
  73. static LicenseState licenseStateFromSettings (PropertiesFile&);
  74. static void licenseStateToSettings (const LicenseState&, PropertiesFile&);
  75. //==============================================================================
  76. LicenseState state;
  77. ScopedPointer<LicenseThread> thread;
  78. LicenseWebview* licenseWebview = nullptr;
  79. ListenerList<LicenseController::StateChangedCallback> listeners;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LicenseController)
  81. };