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