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.

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