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.

157 lines
6.2KB

  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. //==============================================================================
  15. class ApplicationUsageDataWindowComponent : public Component
  16. {
  17. public:
  18. ApplicationUsageDataWindowComponent (bool showCheckbox)
  19. {
  20. addAndMakeVisible (headerLabel);
  21. headerLabel.setText ("Application Usage Analytics", dontSendNotification);
  22. headerLabel.setFont (Font (20.0f, Font::FontStyleFlags::bold));
  23. headerLabel.setJustificationType (Justification::centred);
  24. auto textToShow = String ("We use analytics services to understand how developers use our software in order for JUCE to improve its software and services. ");
  25. if (! showCheckbox)
  26. textToShow += String (" Analytics can be disabled with an Indie or Pro license. ");
  27. textToShow += String ("For more information, please read the JUCE EULA and Privacy policy:");
  28. addAndMakeVisible (bodyLabel);
  29. bodyLabel.setText (textToShow, dontSendNotification);
  30. bodyLabel.setFont (Font (14.0f));
  31. bodyLabel.setJustificationType (Justification::centredLeft);
  32. addAndMakeVisible (juceEULALink);
  33. juceEULALink.setButtonText ("JUCE EULA");
  34. juceEULALink.setFont (Font (14.0f), false);
  35. juceEULALink.setURL (URL ("https://juce.com/juce-5-license"));
  36. addAndMakeVisible (privacyPolicyLink);
  37. privacyPolicyLink.setButtonText ("Privacy Policy");
  38. privacyPolicyLink.setFont (Font (14.0f), false);
  39. privacyPolicyLink.setURL (URL ("https://juce.com/juce-5-privacy-policy"));
  40. addAndMakeVisible (okButton);
  41. if (showCheckbox)
  42. {
  43. shareApplicationUsageDataToggle.reset (new ToggleButton());
  44. addAndMakeVisible (shareApplicationUsageDataToggle.get());
  45. auto* controller = ProjucerApplication::getApp().licenseController.get();
  46. if (controller != nullptr && controller->getState().applicationUsageDataState == LicenseState::ApplicationUsageData::disabled)
  47. shareApplicationUsageDataToggle->setToggleState (false, dontSendNotification);
  48. else
  49. shareApplicationUsageDataToggle->setToggleState (true, dontSendNotification);
  50. addAndMakeVisible (shareApplicationUsageDataLabel);
  51. shareApplicationUsageDataLabel.setFont (Font (14.0f));
  52. shareApplicationUsageDataLabel.setMinimumHorizontalScale (1.0f);
  53. }
  54. else
  55. {
  56. addAndMakeVisible (upgradeLicenseButton);
  57. upgradeLicenseButton.setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  58. upgradeLicenseButton.onClick = []
  59. {
  60. if (auto* controller = ProjucerApplication::getApp().licenseController.get())
  61. controller->chooseNewLicense();
  62. };
  63. }
  64. }
  65. ~ApplicationUsageDataWindowComponent() override
  66. {
  67. if (auto* controller = ProjucerApplication::getApp().licenseController.get())
  68. {
  69. auto newApplicationUsageDataState = LicenseState::ApplicationUsageData::enabled;
  70. if (shareApplicationUsageDataToggle != nullptr && ! shareApplicationUsageDataToggle->getToggleState())
  71. newApplicationUsageDataState = LicenseState::ApplicationUsageData::disabled;
  72. controller->setApplicationUsageDataState (newApplicationUsageDataState);
  73. }
  74. }
  75. void resized() override
  76. {
  77. auto bounds = getLocalBounds().reduced (20);
  78. headerLabel.setBounds (bounds.removeFromTop (40));
  79. bodyLabel.setBounds (bounds.removeFromTop (75));
  80. bounds.removeFromTop (10);
  81. auto linkBounds = bounds.removeFromTop (20);
  82. juceEULALink.setBounds (linkBounds.removeFromLeft (linkBounds.getWidth() / 2).reduced (2));
  83. privacyPolicyLink.setBounds (linkBounds.reduced (2));
  84. if (shareApplicationUsageDataToggle != nullptr)
  85. {
  86. bounds.removeFromTop (10);
  87. auto toggleBounds = bounds.removeFromTop (40);
  88. shareApplicationUsageDataToggle->setBounds (toggleBounds.removeFromLeft (40).reduced (5));
  89. shareApplicationUsageDataLabel.setBounds (toggleBounds);
  90. }
  91. bounds.removeFromTop (10);
  92. auto buttonW = 125;
  93. auto buttonH = 40;
  94. if (upgradeLicenseButton.isShowing())
  95. {
  96. auto left = bounds.removeFromLeft (bounds.getWidth() / 2);
  97. upgradeLicenseButton.setSize (buttonW, buttonH);
  98. upgradeLicenseButton.setCentrePosition (left.getCentreX(), left.getCentreY());
  99. }
  100. okButton.setSize (buttonW, buttonH);
  101. okButton.setCentrePosition (bounds.getCentreX(), bounds.getCentreY());
  102. okButton.onClick = [] { ProjucerApplication::getApp().dismissApplicationUsageDataAgreementPopup(); };
  103. }
  104. void paint (Graphics& g) override
  105. {
  106. g.fillAll (findColour (backgroundColourId));
  107. }
  108. private:
  109. Label headerLabel, bodyLabel;
  110. HyperlinkButton juceEULALink, privacyPolicyLink;
  111. Label shareApplicationUsageDataLabel { {}, "Help JUCE to improve its software and services by sharing my application usage data" };
  112. std::unique_ptr<ToggleButton> shareApplicationUsageDataToggle;
  113. TextButton okButton { "OK" }, upgradeLicenseButton { "Upgrade License" };
  114. void lookAndFeelChanged() override
  115. {
  116. upgradeLicenseButton.setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  117. }
  118. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationUsageDataWindowComponent)
  119. };