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.

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