From 5a235a59ddeb7123924acd94854edc5ac12789cb Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 12:55:29 +0200 Subject: [PATCH 1/4] Reset send slice info and show privacy dialog CURA-5095 Because the data Cura collects has been changed. --- .../VersionUpgrade34to35/VersionUpgrade34to35.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py b/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py index 9e3ea03c55..40add072c9 100644 --- a/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py +++ b/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py @@ -92,6 +92,11 @@ class VersionUpgrade34to35(VersionUpgrade): parser["metadata"] = {} parser["metadata"]["setting_version"] = "5" + # Need to show the data collection agreement again because the data Cura collects has been changed. + if parser.has_option("info", "asked_send_slice_info"): + parser.remove_option("info", "asked_send_slice_info") + parser.remove_option("info", "send_slice_info") + result = io.StringIO() parser.write(result) return [filename], [result.getvalue()] From 5fc8b95425ea5d7417a5c022a8301f83bfa24e84 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 20 Sep 2018 12:59:25 +0200 Subject: [PATCH 2/4] Better data handling CURA-5095 Avoid missing sections/options --- .../VersionUpgrade34to35/VersionUpgrade34to35.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py b/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py index 40add072c9..7acea7ab5e 100644 --- a/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py +++ b/plugins/VersionUpgrade/VersionUpgrade34to35/VersionUpgrade34to35.py @@ -86,17 +86,18 @@ class VersionUpgrade34to35(VersionUpgrade): parser = configparser.ConfigParser(interpolation = None) parser.read_string(serialized) + # Need to show the data collection agreement again because the data Cura collects has been changed. + if parser.has_option("info", "asked_send_slice_info"): + parser.remove_option("info", "asked_send_slice_info") + if parser.has_option("info", "send_slice_info"): + parser.remove_option("info", "send_slice_info") + # Update version number. parser["general"]["version"] = "6" if "metadata" not in parser: parser["metadata"] = {} parser["metadata"]["setting_version"] = "5" - # Need to show the data collection agreement again because the data Cura collects has been changed. - if parser.has_option("info", "asked_send_slice_info"): - parser.remove_option("info", "asked_send_slice_info") - parser.remove_option("info", "send_slice_info") - result = io.StringIO() parser.write(result) return [filename], [result.getvalue()] From 7d537f2c6f7e68e2f099a741c61edd76852e4917 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 1 Oct 2018 16:27:27 +0200 Subject: [PATCH 3/4] Fix data collection message at app start --- plugins/SliceInfoPlugin/SliceInfo.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/SliceInfoPlugin/SliceInfo.py b/plugins/SliceInfoPlugin/SliceInfo.py index fd58e68938..5149b6a6a6 100755 --- a/plugins/SliceInfoPlugin/SliceInfo.py +++ b/plugins/SliceInfoPlugin/SliceInfo.py @@ -33,30 +33,35 @@ class SliceInfo(QObject, Extension): def __init__(self, parent = None): QObject.__init__(self, parent) Extension.__init__(self) - Application.getInstance().getOutputDeviceManager().writeStarted.connect(self._onWriteStarted) - Application.getInstance().getPreferences().addPreference("info/send_slice_info", True) - Application.getInstance().getPreferences().addPreference("info/asked_send_slice_info", False) + + self._application = Application.getInstance() + + self._application.getOutputDeviceManager().writeStarted.connect(self._onWriteStarted) + self._application.getPreferences().addPreference("info/send_slice_info", True) + self._application.getPreferences().addPreference("info/asked_send_slice_info", False) self._more_info_dialog = None self._example_data_content = None - if not Application.getInstance().getPreferences().getValue("info/asked_send_slice_info"): + self._application.initializationFinished.connect(self._onAppInitialized) + + def _onAppInitialized(self): + # DO NOT read any preferences values in the constructor because at the time plugins are created, no version + # upgrade has been performed yet because version upgrades are plugins too! + if not self._application.getPreferences().getValue("info/asked_send_slice_info"): self.send_slice_info_message = Message(catalog.i18nc("@info", "Cura collects anonymized usage statistics."), lifetime = 0, dismissable = False, title = catalog.i18nc("@info:title", "Collecting Data")) self.send_slice_info_message.addAction("MoreInfo", name = catalog.i18nc("@action:button", "More info"), icon = None, - description = catalog.i18nc("@action:tooltip", "See more information on what data Cura sends."), button_style = Message.ActionButtonStyle.LINK) + description = catalog.i18nc("@action:tooltip", "See more information on what data Cura sends."), button_style = Message.ActionButtonStyle.LINK) self.send_slice_info_message.addAction("Dismiss", name = catalog.i18nc("@action:button", "Allow"), icon = None, - description = catalog.i18nc("@action:tooltip", "Allow Cura to send anonymized usage statistics to help prioritize future improvements to Cura. Some of your preferences and settings are sent, the Cura version and a hash of the models you're slicing.")) + description = catalog.i18nc("@action:tooltip", "Allow Cura to send anonymized usage statistics to help prioritize future improvements to Cura. Some of your preferences and settings are sent, the Cura version and a hash of the models you're slicing.")) self.send_slice_info_message.actionTriggered.connect(self.messageActionTriggered) self.send_slice_info_message.show() - Application.getInstance().initializationFinished.connect(self._onAppInitialized) - - def _onAppInitialized(self): if self._more_info_dialog is None: self._more_info_dialog = self._createDialog("MoreInfoWindow.qml") From d1fce50f60bd8c80c4f3c7591ffe32053da01448 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 1 Oct 2018 16:30:27 +0200 Subject: [PATCH 4/4] Add Preferences upgrade 34 to 35 unit test --- .../tests/TestVersionUpgrade34to35.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade34to35/tests/TestVersionUpgrade34to35.py b/plugins/VersionUpgrade/VersionUpgrade34to35/tests/TestVersionUpgrade34to35.py index 90b2cb5dea..a109d97dd7 100644 --- a/plugins/VersionUpgrade/VersionUpgrade34to35/tests/TestVersionUpgrade34to35.py +++ b/plugins/VersionUpgrade/VersionUpgrade34to35/tests/TestVersionUpgrade34to35.py @@ -17,6 +17,10 @@ test_upgrade_version_nr_data = [ version = 5 [metadata] setting_version = 4 + + [info] + asked_send_slice_info = True + send_slice_info = True """ ) ] @@ -32,4 +36,8 @@ def test_upgradeVersionNr(test_name, file_data, upgrader): #Check the new version. assert parser["general"]["version"] == "6" - assert parser["metadata"]["setting_version"] == "5" \ No newline at end of file + assert parser["metadata"]["setting_version"] == "5" + + # Check if the data collection values have been removed + assert not parser.has_option("info", "asked_send_slice_info") + assert not parser.has_option("info", "send_slice_info")