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.

162 lines
5.6KB

  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. //==============================================================================
  21. class UserSettingsPopup : public Component
  22. #if ! JUCER_ENABLE_GPL_MODE
  23. , private Button::Listener,
  24. private LicenseController::StateChangedCallback
  25. #endif
  26. {
  27. public:
  28. UserSettingsPopup (bool isShownInsideWebview)
  29. #if ! JUCER_ENABLE_GPL_MODE
  30. : isInsideWebview (isShownInsideWebview)
  31. #endif
  32. {
  33. #if JUCER_ENABLE_GPL_MODE
  34. ignoreUnused (isShownInsideWebview);
  35. #endif
  36. auto standardFont = Font (16.0f);
  37. addAndMakeVisible (loggedInUsernameLabel = new Label ("Username Label"));
  38. loggedInUsernameLabel->setFont (standardFont);
  39. loggedInUsernameLabel->setJustificationType (Justification::centred);
  40. loggedInUsernameLabel->setMinimumHorizontalScale (0.75f);
  41. #if JUCER_ENABLE_GPL_MODE
  42. loggedInUsernameLabel->setText ("GPL Mode: Re-compile with JUCER_ENABLE_GPL_MODE=0 to enable login!",
  43. NotificationType::dontSendNotification);
  44. #else
  45. addAndMakeVisible (licenseTypeLabel = new Label ("License Type Label"));
  46. licenseTypeLabel->setFont (standardFont);
  47. licenseTypeLabel->setJustificationType (Justification::centred);
  48. licenseTypeLabel->setMinimumHorizontalScale (1.0f);
  49. addAndMakeVisible (logoutButton = new TextButton (isInsideWebview ? "Select different account..." : "Logout"));
  50. logoutButton->addListener (this);
  51. logoutButton->setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  52. if (! isInsideWebview)
  53. {
  54. addAndMakeVisible (switchLicenseButton = new TextButton ("Switch License"));
  55. switchLicenseButton->addListener (this);
  56. }
  57. if (auto* controller = ProjucerApplication::getApp().licenseController.get())
  58. licenseStateChanged (controller->getState());
  59. #endif
  60. }
  61. void paint (Graphics& g) override
  62. {
  63. g.fillAll (findColour (secondaryBackgroundColourId));
  64. }
  65. void resized() override
  66. {
  67. auto bounds = getLocalBounds().reduced (10);
  68. #if JUCER_ENABLE_GPL_MODE
  69. loggedInUsernameLabel->setBounds (bounds);
  70. #else
  71. loggedInUsernameLabel->setBounds (bounds.removeFromTop (hasLicenseType ? 25 : 75));
  72. if (hasLicenseType)
  73. {
  74. bounds.removeFromTop (10);
  75. licenseTypeLabel->setBounds (bounds.removeFromTop (25));
  76. }
  77. bounds.removeFromBottom (5);
  78. auto buttonArea = bounds.removeFromBottom (40);
  79. if (! isInsideWebview)
  80. switchLicenseButton->setBounds (buttonArea.removeFromRight (buttonArea.getWidth() / 2).reduced (2));
  81. logoutButton->setBounds (buttonArea.reduced (2));
  82. #endif
  83. }
  84. private:
  85. //==============================================================================
  86. #if ! JUCER_ENABLE_GPL_MODE
  87. void buttonClicked (Button* b) override
  88. {
  89. if (b == logoutButton)
  90. {
  91. dismissCalloutBox();
  92. ProjucerApplication::getApp().doLogout();
  93. }
  94. else if (b == switchLicenseButton)
  95. {
  96. dismissCalloutBox();
  97. if (auto* controller = ProjucerApplication::getApp().licenseController.get())
  98. controller->chooseNewLicense();
  99. }
  100. }
  101. void licenseStateChanged (const LicenseState& state) override
  102. {
  103. hasLicenseType = (state.type != LicenseState::Type::noLicenseChosenYet);
  104. licenseTypeLabel->setVisible (hasLicenseType);
  105. loggedInUsernameLabel->setText (state.username, NotificationType::dontSendNotification);
  106. licenseTypeLabel->setText (LicenseState::licenseTypeToString (state.type), NotificationType::dontSendNotification);
  107. }
  108. void dismissCalloutBox()
  109. {
  110. if (auto* parent = findParentComponentOfClass<CallOutBox>())
  111. parent->dismiss();
  112. }
  113. void lookAndFeelChanged() override
  114. {
  115. if (logoutButton != nullptr)
  116. logoutButton->setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  117. }
  118. #endif
  119. //==============================================================================
  120. ScopedPointer<Label> loggedInUsernameLabel;
  121. #if ! JUCER_ENABLE_GPL_MODE
  122. ScopedPointer<Label> licenseTypeLabel;
  123. ScopedPointer<TextButton> logoutButton, switchLicenseButton;
  124. bool hasLicenseType = false;
  125. bool isInsideWebview;
  126. #endif
  127. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UserSettingsPopup)
  128. };