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.

128 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. struct LicenseThread;
  21. class LicenseWebview;
  22. //==============================================================================
  23. struct LicenseState
  24. {
  25. enum class Type
  26. {
  27. notLoggedIn, // only used when the webview is open and the user has not logged in yet
  28. noLicenseChosenYet,
  29. GPL, // GPL is used when the user enables the GPL compile flag
  30. personal,
  31. edu,
  32. indie,
  33. pro
  34. };
  35. enum class ApplicationUsageData
  36. {
  37. notChosenYet,
  38. enabled,
  39. disabled
  40. };
  41. Type type = Type::notLoggedIn;
  42. ApplicationUsageData applicationUsageDataState = ApplicationUsageData::notChosenYet;
  43. String username;
  44. String email;
  45. String authToken;
  46. static const char* licenseTypeToString (Type licenseType);
  47. bool isPaidOrGPL() const noexcept { return (type == Type::GPL || type == Type::indie || type == Type::pro); }
  48. Image avatar;
  49. };
  50. //==============================================================================
  51. class LicenseController
  52. {
  53. public:
  54. //==============================================================================
  55. struct StateChangedCallback
  56. {
  57. virtual ~StateChangedCallback() {}
  58. virtual void licenseStateChanged (const LicenseState&) = 0;
  59. };
  60. //==============================================================================
  61. LicenseController();
  62. ~LicenseController();
  63. void startWebviewIfNeeded();
  64. //==============================================================================
  65. LicenseState getState() const noexcept;
  66. void logout();
  67. void chooseNewLicense();
  68. void setApplicationUsageDataState (LicenseState::ApplicationUsageData newState);
  69. //==============================================================================
  70. void addLicenseStatusChangedCallback (StateChangedCallback* callback) { listeners.add (callback); }
  71. void removeLicenseStatusChangedCallback (StateChangedCallback* callback) { listeners.remove (callback); }
  72. private:
  73. //==============================================================================
  74. void updateState (const LicenseState&);
  75. static LicenseState licenseStateFromOldSettings (XmlElement*);
  76. static LicenseState licenseStateFromSettings (PropertiesFile&);
  77. static void licenseStateToSettings (const LicenseState&, PropertiesFile&);
  78. #if ! JUCER_ENABLE_GPL_MODE
  79. //==============================================================================
  80. struct ModalCompletionCallback;
  81. friend struct ModalCompletionCallback;
  82. friend struct ContainerDeletePolicy<LicenseThread>;
  83. friend struct LicenseThread;
  84. //==============================================================================
  85. void closeWebview (int);
  86. void modalStateFinished (int);
  87. void ensureLicenseWebviewIsOpenWithPage (const String&);
  88. void queryWebview (const String&, const String&, HashMap<String, String>&);
  89. //==============================================================================
  90. std::unique_ptr<LicenseThread> thread;
  91. LicenseWebview* licenseWebview = nullptr;
  92. #endif
  93. LicenseState state;
  94. ListenerList<LicenseController::StateChangedCallback> listeners;
  95. bool guiNotInitialisedYet = true;
  96. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LicenseController)
  97. };