UserAgreement.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os
  4. from PyQt5.QtCore import QObject, pyqtSlot
  5. from UM.Extension import Extension
  6. from UM.Logger import Logger
  7. class UserAgreement(QObject, Extension):
  8. def __init__(self, application):
  9. super(UserAgreement, self).__init__()
  10. self._application = application
  11. self._user_agreement_window = None
  12. self._user_agreement_context = None
  13. self._application.engineCreatedSignal.connect(self._onEngineCreated)
  14. self._application.getPreferences().addPreference("general/accepted_user_agreement", False)
  15. def _onEngineCreated(self):
  16. if not self._application.getPreferences().getValue("general/accepted_user_agreement"):
  17. self.showUserAgreement()
  18. def showUserAgreement(self):
  19. if not self._user_agreement_window:
  20. self.createUserAgreementWindow()
  21. self._user_agreement_window.show()
  22. @pyqtSlot(bool)
  23. def didAgree(self, user_choice):
  24. if user_choice:
  25. Logger.log("i", "User agreed to the user agreement")
  26. self._application.getPreferences().setValue("general/accepted_user_agreement", True)
  27. self._user_agreement_window.hide()
  28. else:
  29. Logger.log("i", "User did NOT agree to the user agreement")
  30. self._application.getPreferences().setValue("general/accepted_user_agreement", False)
  31. self._application.quit()
  32. self._application.setNeedToShowUserAgreement(False)
  33. def createUserAgreementWindow(self):
  34. path = os.path.join(self._application.getPluginRegistry().getPluginPath(self.getPluginId()), "UserAgreement.qml")
  35. self._user_agreement_window = self._application.createQmlComponent(path, {"manager": self})