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.

109 lines
3.7KB

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