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.

117 lines
3.9KB

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