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.

156 lines
5.5KB

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