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.

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