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.

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