From 90441d8c5213d4566e1aabd918d530fb765acaf7 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 3 Jul 2023 18:58:18 +0200 Subject: [PATCH 01/27] Introduced gdpr dialog --- src/main/java/org/jabref/gui/JabRefGUI.java | 18 ++++-- .../entryeditor/EntryEditorPreferences.java | 15 ----- .../gui/entryeditor/RelatedArticlesTab.java | 5 +- .../java/org/jabref/gui/gdpr/GdprDialog.css | 8 +++ .../java/org/jabref/gui/gdpr/GdprDialog.fxml | 38 +++++++++++ .../org/jabref/gui/gdpr/GdprDialogView.java | 63 +++++++++++++++++++ .../jabref/gui/gdpr/GdprDialogViewModel.java | 58 +++++++++++++++++ .../gui/help/SearchForUpdateAction.java | 2 + .../org/jabref/gui/help/VersionWorker.java | 8 +++ .../java/org/jabref/gui/icon/IconTheme.java | 3 +- .../fetcher/WebSearchPaneViewModel.java | 10 +++ .../entryeditor/EntryEditorTabViewModel.java | 7 ++- .../preferences/websearch/WebSearchTab.fxml | 1 + .../preferences/websearch/WebSearchTab.java | 2 + .../websearch/WebSearchTabViewModel.java | 7 +++ .../logic/importer/ImporterPreferences.java | 17 ++++- .../preferences/InternalPreferences.java | 15 +++++ .../jabref/preferences/JabRefPreferences.java | 14 ++++- 18 files changed, 261 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/jabref/gui/gdpr/GdprDialog.css create mode 100644 src/main/java/org/jabref/gui/gdpr/GdprDialog.fxml create mode 100644 src/main/java/org/jabref/gui/gdpr/GdprDialogView.java create mode 100644 src/main/java/org/jabref/gui/gdpr/GdprDialogViewModel.java diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 133df390b3f..f87665f0247 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -13,6 +13,7 @@ import javafx.stage.Screen; import javafx.stage.Stage; +import org.jabref.gui.gdpr.GdprDialogView; import org.jabref.gui.help.VersionWorker; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.importer.ParserResultWarningDialog; @@ -32,6 +33,7 @@ import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.injection.Injector; +import com.tobiasdiez.easybind.EasyBind; import impl.org.controlsfx.skin.DecorationPane; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,11 +69,17 @@ public JabRefGUI(Stage mainStage, openWindow(mainStage); - new VersionWorker(Globals.BUILD_INFO.version, - mainFrame.getDialogService(), - Globals.TASK_EXECUTOR, - preferencesService.getInternalPreferences()) - .checkForNewVersionDelayed(); + mainFrame.getDialogService().showCustomDialogAndWait(new GdprDialogView()); + + EasyBind.subscribe(preferencesService.getInternalPreferences().versionCheckEnabledProperty(), enabled -> { + if (enabled) { + new VersionWorker(Globals.BUILD_INFO.version, + mainFrame.getDialogService(), + Globals.TASK_EXECUTOR, + preferencesService.getInternalPreferences()) + .checkForNewVersionDelayed(); + } + }); setupProxy(); } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java index 763d0e633d9..ceb82f12b6a 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java @@ -20,7 +20,6 @@ public class EntryEditorPreferences { private final MapProperty> defaultEntryEditorTabList; private final BooleanProperty shouldOpenOnNewEntry; private final BooleanProperty shouldShowRecommendationsTab; - private final BooleanProperty isMrdlibAccepted; private final BooleanProperty shouldShowLatexCitationsTab; private final BooleanProperty showSourceTabByDefault; private final BooleanProperty enableValidation; @@ -32,7 +31,6 @@ public EntryEditorPreferences(Map> entryEditorTabList, Map> defaultEntryEditorTabList, boolean shouldOpenOnNewEntry, boolean shouldShowRecommendationsTab, - boolean isMrdlibAccepted, boolean shouldShowLatexCitationsTab, boolean showSourceTabByDefault, boolean enableValidation, @@ -44,7 +42,6 @@ public EntryEditorPreferences(Map> entryEditorTabList, this.defaultEntryEditorTabList = new SimpleMapProperty<>(FXCollections.observableMap(defaultEntryEditorTabList)); this.shouldOpenOnNewEntry = new SimpleBooleanProperty(shouldOpenOnNewEntry); this.shouldShowRecommendationsTab = new SimpleBooleanProperty(shouldShowRecommendationsTab); - this.isMrdlibAccepted = new SimpleBooleanProperty(isMrdlibAccepted); this.shouldShowLatexCitationsTab = new SimpleBooleanProperty(shouldShowLatexCitationsTab); this.showSourceTabByDefault = new SimpleBooleanProperty(showSourceTabByDefault); this.enableValidation = new SimpleBooleanProperty(enableValidation); @@ -93,18 +90,6 @@ public void setShouldShowRecommendationsTab(boolean shouldShowRecommendationsTab this.shouldShowRecommendationsTab.set(shouldShowRecommendationsTab); } - public boolean isMrdlibAccepted() { - return isMrdlibAccepted.get(); - } - - public BooleanProperty isMrdlibAcceptedProperty() { - return isMrdlibAccepted; - } - - public void setIsMrdlibAccepted(boolean isMrdlibAccepted) { - this.isMrdlibAccepted.set(isMrdlibAccepted); - } - public boolean shouldShowLatexCitationsTab() { return shouldShowLatexCitationsTab.get(); } diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index ec1faf68ca2..c0e22a5b66a 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -212,9 +212,8 @@ private ScrollPane getPrivacyDialog(BibEntry entry) { vb.setSpacing(10); button.setOnAction(event -> { - preferences.setIsMrdlibAccepted(true); - MrDlibPreferences mrDlibPreferences = preferencesService.getMrDlibPreferences(); + mrDlibPreferences.setAcceptRecommendations(true); mrDlibPreferences.setSendLanguage(cbLanguage.isSelected()); mrDlibPreferences.setSendOs(cbOS.isSelected()); mrDlibPreferences.setSendTimezone(cbTimezone.isSelected()); @@ -237,7 +236,7 @@ public boolean shouldShow(BibEntry entry) { @Override protected void bindToEntry(BibEntry entry) { // Ask for consent to send data to Mr. DLib on first time to tab - if (preferences.isMrdlibAccepted()) { + if (preferencesService.getMrDlibPreferences().shouldAcceptRecommendations()) { setContent(getRelatedArticlesPane(entry)); } else { setContent(getPrivacyDialog(entry)); diff --git a/src/main/java/org/jabref/gui/gdpr/GdprDialog.css b/src/main/java/org/jabref/gui/gdpr/GdprDialog.css new file mode 100644 index 00000000000..373ab8b3ea4 --- /dev/null +++ b/src/main/java/org/jabref/gui/gdpr/GdprDialog.css @@ -0,0 +1,8 @@ +.info-section { + -fx-padding: 10px; + -fx-background-color: -fx-background; +} + +.info-section .ikonli-font-icon { + -fx-font-size: 36.0; +} diff --git a/src/main/java/org/jabref/gui/gdpr/GdprDialog.fxml b/src/main/java/org/jabref/gui/gdpr/GdprDialog.fxml new file mode 100644 index 00000000000..e02fa02c352 --- /dev/null +++ b/src/main/java/org/jabref/gui/gdpr/GdprDialog.fxml @@ -0,0 +1,38 @@ + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + +
diff --git a/src/main/java/org/jabref/gui/gdpr/GdprDialogView.java b/src/main/java/org/jabref/gui/gdpr/GdprDialogView.java new file mode 100644 index 00000000000..4f46a69700f --- /dev/null +++ b/src/main/java/org/jabref/gui/gdpr/GdprDialogView.java @@ -0,0 +1,63 @@ +package org.jabref.gui.gdpr; + +import javafx.fxml.FXML; +import javafx.scene.control.ButtonType; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Hyperlink; +import javafx.stage.Modality; + +import org.jabref.gui.DialogService; +import org.jabref.gui.desktop.JabRefDesktop; +import org.jabref.gui.util.BaseDialog; +import org.jabref.logic.l10n.Localization; +import org.jabref.preferences.PreferencesService; + +import com.airhacks.afterburner.views.ViewLoader; +import jakarta.inject.Inject; + +public class GdprDialogView extends BaseDialog { + @FXML private Hyperlink moreInformation; + @FXML private CheckBox version; + @FXML private CheckBox webSearch; + @FXML private CheckBox pdfMetaDataParser; + @FXML private CheckBox relatedArticles; + @FXML private ButtonType btnApply; + @FXML private ButtonType btnApplyAll; + + @Inject private PreferencesService preferencesService; + @Inject private DialogService dialogService; + + private GdprDialogViewModel viewModel; + + public GdprDialogView() { + this.setTitle(Localization.lang("Privacy setup")); + this.initModality(Modality.APPLICATION_MODAL); + this.setResizable(false); + + ViewLoader.view(this) + .load() + .setAsDialogPane(this); + } + + @FXML + private void initialize() { + viewModel = new GdprDialogViewModel(preferencesService); + + moreInformation.setOnAction(event -> JabRefDesktop.openBrowserShowPopup("https://jabref.org", dialogService)); + + version.selectedProperty().bindBidirectional(viewModel.versionEnabledProperty()); + webSearch.selectedProperty().bindBidirectional(viewModel.webSearchEnabledProperty()); + pdfMetaDataParser.selectedProperty().bindBidirectional(viewModel.pdfMetaDataParserEnabledProperty()); + relatedArticles.selectedProperty().bindBidirectional(viewModel.relatedArticlesEnabledProperty()); + + setResultConverter(button -> { + if (button == btnApply) { + viewModel.storeSettings(); + } else if (button == btnApplyAll) { + viewModel.selectAll(); + viewModel.storeSettings(); + } + return true; + }); + } +} diff --git a/src/main/java/org/jabref/gui/gdpr/GdprDialogViewModel.java b/src/main/java/org/jabref/gui/gdpr/GdprDialogViewModel.java new file mode 100644 index 00000000000..e0f7c1fe51c --- /dev/null +++ b/src/main/java/org/jabref/gui/gdpr/GdprDialogViewModel.java @@ -0,0 +1,58 @@ +package org.jabref.gui.gdpr; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; + +import org.jabref.preferences.PreferencesService; + +public class GdprDialogViewModel { + private final BooleanProperty versionEnabledProperty = new SimpleBooleanProperty(); + private final BooleanProperty webSearchEnabledProperty = new SimpleBooleanProperty(); + private final BooleanProperty pdfMetaDataParserEnabledProperty = new SimpleBooleanProperty(); + private final BooleanProperty relatedArticlesEnabledProperty = new SimpleBooleanProperty(); + + private final PreferencesService preferencesService; + + GdprDialogViewModel(PreferencesService preferencesService) { + this.preferencesService = preferencesService; + + setValues(); + } + + public void setValues() { + versionEnabledProperty.set(preferencesService.getInternalPreferences().isVersionCheckEnabled()); + webSearchEnabledProperty.set(preferencesService.getImporterPreferences().areImporterEnabled()); + pdfMetaDataParserEnabledProperty.set(preferencesService.getGrobidPreferences().isGrobidEnabled()); + relatedArticlesEnabledProperty.set(preferencesService.getMrDlibPreferences().shouldAcceptRecommendations()); + } + + public void storeSettings() { + preferencesService.getInternalPreferences().setVersionCheckEnabled(versionEnabledProperty.get()); + preferencesService.getImporterPreferences().setImporterEnabled(webSearchEnabledProperty.get()); + preferencesService.getGrobidPreferences().setGrobidEnabled(pdfMetaDataParserEnabledProperty.get()); + preferencesService.getMrDlibPreferences().setAcceptRecommendations(relatedArticlesEnabledProperty.get()); + } + + public void selectAll() { + versionEnabledProperty.set(true); + webSearchEnabledProperty.set(true); + pdfMetaDataParserEnabledProperty.set(true); + relatedArticlesEnabledProperty.set(true); + } + + public BooleanProperty versionEnabledProperty() { + return versionEnabledProperty; + } + + public BooleanProperty webSearchEnabledProperty() { + return webSearchEnabledProperty; + } + + public BooleanProperty pdfMetaDataParserEnabledProperty() { + return pdfMetaDataParserEnabledProperty; + } + + public BooleanProperty relatedArticlesEnabledProperty() { + return relatedArticlesEnabledProperty; + } +} diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index f2e0fff9bbc..3b39dbb473f 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -18,6 +18,8 @@ public SearchForUpdateAction(BuildInfo buildInfo, InternalPreferences internalPr this.internalPreferences = internalPreferences; this.dialogService = dialogService; this.taskExecutor = taskExecutor; + + this.executable.bind(internalPreferences.versionCheckEnabledProperty()); } @Override diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index b4760f58c9b..73963da0386 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -58,6 +58,10 @@ private Optional getNewVersion() throws IOException { } public void checkForNewVersionAsync() { + if (!internalPreferences.isVersionCheckEnabled()) { + return; + } + BackgroundTask.wrap(this::getNewVersion) .onSuccess(version -> showUpdateInfo(version, true)) .onFailure(exception -> showConnectionError(exception, true)) @@ -65,6 +69,10 @@ public void checkForNewVersionAsync() { } public void checkForNewVersionDelayed() { + if (!internalPreferences.isVersionCheckEnabled()) { + return; + } + BackgroundTask.wrap(this::getNewVersion) .onSuccess(version -> showUpdateInfo(version, false)) .onFailure(exception -> showConnectionError(exception, false)) diff --git a/src/main/java/org/jabref/gui/icon/IconTheme.java b/src/main/java/org/jabref/gui/icon/IconTheme.java index c92fea5ac8e..3633f49ac3b 100644 --- a/src/main/java/org/jabref/gui/icon/IconTheme.java +++ b/src/main/java/org/jabref/gui/icon/IconTheme.java @@ -348,7 +348,8 @@ public enum JabRefIcons implements JabRefIcon { REMOVE_TAGS(MaterialDesignC.CLOSE), ACCEPT_LEFT(MaterialDesignS.SUBDIRECTORY_ARROW_LEFT), ACCEPT_RIGHT(MaterialDesignS.SUBDIRECTORY_ARROW_RIGHT), - MERGE_GROUPS(MaterialDesignS.SOURCE_MERGE); + MERGE_GROUPS(MaterialDesignS.SOURCE_MERGE), + PRIVACY(MaterialDesignS.SHIELD_SEARCH); private final JabRefIcon icon; diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index b038a406f5c..8dfacb8df6f 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -17,6 +17,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.StateManager; +import org.jabref.gui.gdpr.GdprDialogView; import org.jabref.gui.importer.ImportEntriesDialog; import org.jabref.gui.util.BackgroundTask; import org.jabref.logic.importer.ParserResult; @@ -133,6 +134,15 @@ public StringProperty queryProperty() { } public void search() { + if (!preferencesService.getImporterPreferences().areImporterEnabled()) { + dialogService.showCustomDialogAndWait(new GdprDialogView()); + + if (!preferencesService.getImporterPreferences().areImporterEnabled()) { + dialogService.notify(Localization.lang("Web search disabled")); + return; + } + } + String query = getQuery().trim(); if (StringUtil.isBlank(query)) { dialogService.notify(Localization.lang("Please enter a search string")); diff --git a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java index 1f53eeabd3e..81e3a3339a6 100644 --- a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java @@ -16,6 +16,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; +import org.jabref.preferences.MrDlibPreferences; import org.jabref.preferences.PreferencesService; public class EntryEditorTabViewModel implements PreferenceTabViewModel { @@ -34,11 +35,13 @@ public class EntryEditorTabViewModel implements PreferenceTabViewModel { private final DialogService dialogService; private final PreferencesService preferencesService; private final EntryEditorPreferences entryEditorPreferences; + private final MrDlibPreferences mrDlibPreferences; public EntryEditorTabViewModel(DialogService dialogService, PreferencesService preferencesService) { this.dialogService = dialogService; this.preferencesService = preferencesService; this.entryEditorPreferences = preferencesService.getEntryEditorPreferences(); + this.mrDlibPreferences = preferencesService.getMrDlibPreferences(); } @Override @@ -49,7 +52,7 @@ public void setValues() { openOnNewEntryProperty.setValue(entryEditorPreferences.shouldOpenOnNewEntry()); defaultSourceProperty.setValue(entryEditorPreferences.showSourceTabByDefault()); enableRelatedArticlesTabProperty.setValue(entryEditorPreferences.shouldShowRecommendationsTab()); - acceptRecommendationsProperty.setValue(entryEditorPreferences.isMrdlibAccepted()); + acceptRecommendationsProperty.setValue(mrDlibPreferences.shouldAcceptRecommendations()); enableLatexCitationsTabProperty.setValue(entryEditorPreferences.shouldShowLatexCitationsTab()); enableValidationProperty.setValue(entryEditorPreferences.shouldEnableValidation()); allowIntegerEditionProperty.setValue(entryEditorPreferences.shouldAllowIntegerEditionBibtex()); @@ -80,7 +83,7 @@ public void storeSettings() { // entryEditorPreferences.setEntryEditorTabList(); entryEditorPreferences.setShouldOpenOnNewEntry(openOnNewEntryProperty.getValue()); entryEditorPreferences.setShouldShowRecommendationsTab(enableRelatedArticlesTabProperty.getValue()); - entryEditorPreferences.setIsMrdlibAccepted(acceptRecommendationsProperty.getValue()); + mrDlibPreferences.setAcceptRecommendations(acceptRecommendationsProperty.getValue()); entryEditorPreferences.setShouldShowLatexCitationsTab(enableLatexCitationsTabProperty.getValue()); entryEditorPreferences.setShowSourceTabByDefault(defaultSourceProperty.getValue()); entryEditorPreferences.setEnableValidation(enableValidationProperty.getValue()); diff --git a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml index 53a3d9c31f1..628f070c9f0 100644 --- a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml @@ -14,6 +14,7 @@