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.

105 lines
3.6KB

  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. Type type = Type::notLoggedIn;
  30. String username, email, authToken;
  31. static const char* licenseTypeToString (Type licenseType);
  32. bool isPaidOrGPL() const noexcept { return (type == Type::GPL || type == Type::indie || type == Type::pro); }
  33. Image avatar;
  34. };
  35. //==============================================================================
  36. class LicenseController
  37. {
  38. public:
  39. //==============================================================================
  40. struct StateChangedCallback
  41. {
  42. virtual ~StateChangedCallback() {}
  43. virtual void licenseStateChanged (const LicenseState&) = 0;
  44. };
  45. //==============================================================================
  46. LicenseController();
  47. ~LicenseController();
  48. void startWebviewIfNeeded();
  49. //==============================================================================
  50. LicenseState getState() const noexcept;
  51. void logout();
  52. void chooseNewLicense();
  53. //==============================================================================
  54. void addLicenseStatusChangedCallback (StateChangedCallback* callback) { listeners.add (callback); }
  55. void removeLicenseStatusChangedCallback (StateChangedCallback* callback) { listeners.remove (callback); }
  56. private:
  57. //==============================================================================
  58. void updateState (const LicenseState&);
  59. static LicenseState licenseStateFromOldSettings (XmlElement*);
  60. static LicenseState licenseStateFromSettings (PropertiesFile&);
  61. static void licenseStateToSettings (const LicenseState&, PropertiesFile&);
  62. #if ! JUCER_ENABLE_GPL_MODE
  63. //==============================================================================
  64. struct ModalCompletionCallback;
  65. friend struct LicenseThread;
  66. //==============================================================================
  67. void closeWebview (int);
  68. void modalStateFinished (int);
  69. void ensureLicenseWebviewIsOpenWithPage (const String&);
  70. void queryWebview (const String&, const String&, HashMap<String, String>&);
  71. //==============================================================================
  72. std::unique_ptr<LicenseThread> thread;
  73. LicenseWebview* licenseWebview = nullptr;
  74. #endif
  75. LicenseState state;
  76. ListenerList<LicenseController::StateChangedCallback> listeners;
  77. bool guiNotInitialisedYet = true;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LicenseController)
  79. };