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.

176 lines
6.8KB

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