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.

154 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "../../Licenses/jucer_LicenseController.h"
  15. #include "../../Application/jucer_Application.h"
  16. //==============================================================================
  17. class UserSettingsPopup : public Component
  18. #if ! JUCER_ENABLE_GPL_MODE
  19. , private LicenseController::StateChangedCallback
  20. #endif
  21. {
  22. public:
  23. UserSettingsPopup (bool isShownInsideWebview)
  24. #if ! JUCER_ENABLE_GPL_MODE
  25. : isInsideWebview (isShownInsideWebview)
  26. #endif
  27. {
  28. #if JUCER_ENABLE_GPL_MODE
  29. ignoreUnused (isShownInsideWebview);
  30. #endif
  31. auto standardFont = Font (16.0f);
  32. loggedInUsernameLabel.reset (new Label ("Username Label"));
  33. addAndMakeVisible (loggedInUsernameLabel.get());
  34. loggedInUsernameLabel->setFont (standardFont);
  35. loggedInUsernameLabel->setJustificationType (Justification::centred);
  36. loggedInUsernameLabel->setMinimumHorizontalScale (0.75f);
  37. #if JUCER_ENABLE_GPL_MODE
  38. loggedInUsernameLabel->setText ("GPL Mode: Re-compile with JUCER_ENABLE_GPL_MODE=0 to enable login!",
  39. NotificationType::dontSendNotification);
  40. #else
  41. licenseTypeLabel.reset (new Label ("License Type Label"));
  42. addAndMakeVisible (licenseTypeLabel.get());
  43. licenseTypeLabel->setFont (standardFont);
  44. licenseTypeLabel->setJustificationType (Justification::centred);
  45. licenseTypeLabel->setMinimumHorizontalScale (1.0f);
  46. logoutButton.reset (new TextButton (isInsideWebview ? "Select different account..." : "Sign out"));
  47. addAndMakeVisible (logoutButton.get());
  48. logoutButton->setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  49. logoutButton->onClick = [this]
  50. {
  51. dismissCalloutBox();
  52. ProjucerApplication::getApp().doLogout();
  53. };
  54. if (! isInsideWebview)
  55. {
  56. switchLicenseButton.reset (new TextButton ("Switch License"));
  57. addAndMakeVisible (switchLicenseButton.get());
  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. std::unique_ptr<Label> loggedInUsernameLabel;
  115. #if ! JUCER_ENABLE_GPL_MODE
  116. std::unique_ptr<Label> licenseTypeLabel;
  117. std::unique_ptr<TextButton> logoutButton, switchLicenseButton;
  118. bool hasLicenseType = false;
  119. bool isInsideWebview;
  120. #endif
  121. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UserSettingsPopup)
  122. };