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.

164 lines
6.4KB

  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/privacy-policy"));
  46. addAndMakeVisible (okButton);
  47. if (showCheckbox)
  48. {
  49. addAndMakeVisible (shareApplicationUsageDataToggle);
  50. auto* controller = ProjucerApplication::getApp().licenseController.get();
  51. if (controller != nullptr && controller->getState().applicationUsageDataState == LicenseState::ApplicationUsageData::disabled)
  52. shareApplicationUsageDataToggle.setToggleState (false, dontSendNotification);
  53. else
  54. shareApplicationUsageDataToggle.setToggleState (true, dontSendNotification);
  55. addAndMakeVisible (shareApplicationUsageDataLabel);
  56. shareApplicationUsageDataLabel.setFont (Font (14.0f));
  57. shareApplicationUsageDataLabel.setMinimumHorizontalScale (1.0f);
  58. }
  59. else
  60. {
  61. addAndMakeVisible (upgradeLicenseButton);
  62. upgradeLicenseButton.setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  63. upgradeLicenseButton.onClick = []
  64. {
  65. if (auto* controller = ProjucerApplication::getApp().licenseController.get())
  66. controller->chooseNewLicense();
  67. };
  68. }
  69. }
  70. ~ApplicationUsageDataWindowComponent()
  71. {
  72. if (auto* controller = ProjucerApplication::getApp().licenseController.get())
  73. {
  74. auto newApplicationUsageDataState = LicenseState::ApplicationUsageData::enabled;
  75. if (shareApplicationUsageDataToggle.isShowing() && ! shareApplicationUsageDataToggle.getToggleState())
  76. newApplicationUsageDataState = LicenseState::ApplicationUsageData::disabled;
  77. controller->setApplicationUsageDataState (newApplicationUsageDataState);
  78. }
  79. }
  80. void resized() override
  81. {
  82. auto bounds = getLocalBounds().reduced (20);
  83. headerLabel.setBounds (bounds.removeFromTop (40));
  84. bodyLabel.setBounds (bounds.removeFromTop (75));
  85. bounds.removeFromTop (10);
  86. auto linkBounds = bounds.removeFromTop (20);
  87. juceEULALink.setBounds (linkBounds.removeFromLeft (linkBounds.getWidth() / 2).reduced (2));
  88. privacyPolicyLink.setBounds (linkBounds.reduced (2));
  89. if (shareApplicationUsageDataToggle.isShowing())
  90. {
  91. bounds.removeFromTop (10);
  92. auto toggleBounds = bounds.removeFromTop (40);
  93. shareApplicationUsageDataToggle.setBounds (toggleBounds.removeFromLeft (40).reduced (5));
  94. shareApplicationUsageDataLabel.setBounds (toggleBounds);
  95. }
  96. bounds.removeFromTop (10);
  97. auto buttonW = 125;
  98. auto buttonH = 40;
  99. if (upgradeLicenseButton.isShowing())
  100. {
  101. auto left = bounds.removeFromLeft (bounds.getWidth() / 2);
  102. upgradeLicenseButton.setSize (buttonW, buttonH);
  103. upgradeLicenseButton.setCentrePosition (left.getCentreX(), left.getCentreY());
  104. }
  105. okButton.setSize (buttonW, buttonH);
  106. okButton.setCentrePosition (bounds.getCentreX(), bounds.getCentreY());
  107. okButton.onClick = [] { ProjucerApplication::getApp().dismissApplicationUsageDataAgreementPopup(); };
  108. }
  109. void paint (Graphics& g) override
  110. {
  111. g.fillAll (findColour (backgroundColourId));
  112. }
  113. private:
  114. Label headerLabel, bodyLabel;
  115. HyperlinkButton juceEULALink, privacyPolicyLink;
  116. Label shareApplicationUsageDataLabel { {}, "Help JUCE to improve its software and services by sharing my application usage data" };
  117. ToggleButton shareApplicationUsageDataToggle;
  118. TextButton okButton { "OK" }, upgradeLicenseButton { "Upgrade License" };
  119. void lookAndFeelChanged() override
  120. {
  121. upgradeLicenseButton.setColour (TextButton::buttonColourId, findColour (secondaryButtonBackgroundColourId));
  122. }
  123. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationUsageDataWindowComponent)
  124. };