Skip to content

Commit

Permalink
Add pref switch to not store url (JabRef#11735)
Browse files Browse the repository at this point in the history
* Add option to disable keeping download url

Refs https://discourse.jabref.org/t/import-adds-pdf-link-and-url-to-file-entry/4484/

* Fix checkstyle

* Compilefix

* add default

* Update CHANGELOG.md

* add addtional check

* fix ui

* fix test

* fix fcking test

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
Siedlerchr and koppor authored Sep 9, 2024
1 parent a67b056 commit 875dcd4
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We enabled creating a new file link manually. [#11017](https://github.com/JabRef/jabref/issues/11017)
- We added a toggle button to invert the selected groups. [#9073](https://github.com/JabRef/jabref/issues/9073)
- We reintroduced the floating search in the main table. [#4237](https://github.com/JabRef/jabref/issues/4237)
- We added a switch not to store the linked file URL, because it caused troubles at other apps. [#11735](https://github.com/JabRef/jabref/pull/11735)
- When starting a new SLR, the selected catalogs now persist within and across JabRef sessions. [koppor#614](https://github.com/koppor/jabref/issues/614)
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ private void onSuccess(Path targetDirectory, Path downloadedFile) {
if (newLinkedFile.getDescription().isEmpty() && !linkedFile.getDescription().isEmpty()) {
newLinkedFile.setDescription((linkedFile.getDescription()));
}
if (linkedFile.getSourceUrl().isEmpty() && LinkedFile.isOnlineLink(linkedFile.getLink())) {
if (linkedFile.getSourceUrl().isEmpty() && LinkedFile.isOnlineLink(linkedFile.getLink()) && filePreferences.shouldKeepDownloadUrl()) {
newLinkedFile.setSourceURL(linkedFile.getLink());
} else {
} else if (filePreferences.shouldKeepDownloadUrl()) {
newLinkedFile.setSourceURL(linkedFile.getSourceUrl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<CheckBox fx:id="generateNewKeyOnImport" text="%Generate a new key for imported entries (overwriting their default)"/>
<CheckBox fx:id="warnAboutDuplicatesOnImport" text="%Warn about duplicates on import"/>
<CheckBox fx:id="downloadLinkedOnlineFiles" text="%Download linked online files"/>
<CheckBox fx:id="keepDownloadUrl" text="%Store url for downloaded file" />

<Label styleClass="sectionHeader" text="%Custom DOI URI"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class WebSearchTab extends AbstractPreferenceTabView<WebSearchTabViewMode
@FXML private CheckBox generateNewKeyOnImport;
@FXML private CheckBox warnAboutDuplicatesOnImport;
@FXML private CheckBox downloadLinkedOnlineFiles;
@FXML private CheckBox keepDownloadUrl;

@FXML private CheckBox useCustomDOI;
@FXML private TextField useCustomDOIName;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void initialize() {
generateNewKeyOnImport.selectedProperty().bindBidirectional(viewModel.generateKeyOnImportProperty());
warnAboutDuplicatesOnImport.selectedProperty().bindBidirectional(viewModel.warnAboutDuplicatesOnImportProperty());
downloadLinkedOnlineFiles.selectedProperty().bindBidirectional(viewModel.shouldDownloadLinkedOnlineFiles());
keepDownloadUrl.selectedProperty().bindBidirectional(viewModel.shouldKeepDownloadUrl());

grobidEnabled.selectedProperty().bindBidirectional(viewModel.grobidEnabledProperty());
grobidURL.textProperty().bindBidirectional(viewModel.grobidURLProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty generateKeyOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty warnAboutDuplicatesOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty shouldDownloadLinkedOnlineFiles = new SimpleBooleanProperty();
private final BooleanProperty shouldkeepDownloadUrl = new SimpleBooleanProperty();

private final BooleanProperty useCustomDOIProperty = new SimpleBooleanProperty();
private final StringProperty useCustomDOINameProperty = new SimpleStringProperty("");
Expand Down Expand Up @@ -83,7 +84,7 @@ public void setValues() {
generateKeyOnImportProperty.setValue(importerPreferences.isGenerateNewKeyOnImport());
warnAboutDuplicatesOnImportProperty.setValue(importerPreferences.shouldWarnAboutDuplicatesOnImport());
shouldDownloadLinkedOnlineFiles.setValue(filePreferences.shouldDownloadLinkedFiles());

shouldkeepDownloadUrl.setValue(filePreferences.shouldKeepDownloadUrl());
useCustomDOIProperty.setValue(doiPreferences.isUseCustom());
useCustomDOINameProperty.setValue(doiPreferences.getDefaultBaseURI());

Expand All @@ -110,7 +111,7 @@ public void storeSettings() {
importerPreferences.setGenerateNewKeyOnImport(generateKeyOnImportProperty.getValue());
importerPreferences.setWarnAboutDuplicatesOnImport(warnAboutDuplicatesOnImportProperty.getValue());
filePreferences.setDownloadLinkedFiles(shouldDownloadLinkedOnlineFiles.getValue());

filePreferences.setKeepDownloadUrl(shouldkeepDownloadUrl.getValue());
grobidPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
grobidPreferences.setGrobidOptOut(grobidPreferences.isGrobidOptOut());
grobidPreferences.setGrobidURL(grobidURLProperty.getValue());
Expand Down Expand Up @@ -172,6 +173,10 @@ public BooleanProperty shouldDownloadLinkedOnlineFiles() {
return shouldDownloadLinkedOnlineFiles;
}

public BooleanProperty shouldKeepDownloadUrl() {
return shouldkeepDownloadUrl;
}

public ReadOnlyBooleanProperty apiKeyPersistAvailable() {
return apikeyPersistAvailableProperty;
}
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/jabref/preferences/FilePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class FilePreferences {
private final ObjectProperty<Path> backupDirectory = new SimpleObjectProperty<>();
private final BooleanProperty confirmDeleteLinkedFile = new SimpleBooleanProperty();
private final BooleanProperty moveToTrash = new SimpleBooleanProperty();
private final BooleanProperty shouldKeepDownloadUrl = new SimpleBooleanProperty();

public FilePreferences(String userAndHost,
String mainFileDirectory,
Expand All @@ -51,7 +52,8 @@ public FilePreferences(String userAndHost,
boolean createBackup,
Path backupDirectory,
boolean confirmDeleteLinkedFile,
boolean moveToTrash) {
boolean moveToTrash,
boolean shouldKeepDownloadUrl) {
this.userAndHost.setValue(userAndHost);
this.mainFileDirectory.setValue(mainFileDirectory);
this.storeFilesRelativeToBibFile.setValue(storeFilesRelativeToBibFile);
Expand All @@ -65,6 +67,7 @@ public FilePreferences(String userAndHost,
this.backupDirectory.setValue(backupDirectory);
this.confirmDeleteLinkedFile.setValue(confirmDeleteLinkedFile);
this.moveToTrash.setValue(moveToTrash);
this.shouldKeepDownloadUrl.setValue(shouldKeepDownloadUrl);
}

public String getUserAndHost() {
Expand Down Expand Up @@ -214,4 +217,16 @@ public BooleanProperty moveToTrashProperty() {
public void moveToTrash(boolean moveToTrash) {
this.moveToTrash.set(moveToTrash);
}

public boolean shouldKeepDownloadUrl() {
return shouldKeepDownloadUrl.get();
}

public BooleanProperty shouldKeepDownloadUrlProperty() {
return shouldKeepDownloadUrl;
}

public void setKeepDownloadUrl(boolean shouldKeepDownloadUrl) {
this.shouldKeepDownloadUrl.set(shouldKeepDownloadUrl);
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ public class JabRefPreferences implements PreferencesService {
private static final String PREFS_EXPORT_PATH = "prefsExportPath";
private static final String DOWNLOAD_LINKED_FILES = "downloadLinkedFiles";
private static final String FULLTEXT_INDEX_LINKED_FILES = "fulltextIndexLinkedFiles";
private static final String KEEP_DOWNLOAD_URL = "keepDownloadUrl";

// Helper string
private static final String USER_HOME = System.getProperty("user.home");
Expand Down Expand Up @@ -774,6 +775,7 @@ private JabRefPreferences() {
defaults.put(WARN_BEFORE_OVERWRITING_KEY, Boolean.TRUE);
defaults.put(CONFIRM_DELETE, Boolean.TRUE);
defaults.put(CONFIRM_LINKED_FILE_DELETE, Boolean.TRUE);
defaults.put(KEEP_DOWNLOAD_URL, Boolean.TRUE);
defaults.put(DEFAULT_CITATION_KEY_PATTERN, "[auth][year]");
defaults.put(UNWANTED_CITATION_KEY_CHARACTERS, "-`ʹ:!;?^");
defaults.put(RESOLVE_STRINGS_FOR_FIELDS, "author;booktitle;editor;editora;editorb;editorc;institution;issuetitle;journal;journalsubtitle;journaltitle;mainsubtitle;month;publisher;shortauthor;shorteditor;subtitle;titleaddon");
Expand Down Expand Up @@ -2257,7 +2259,8 @@ public FilePreferences getFilePreferences() {
getPath(BACKUP_DIRECTORY, OS.getNativeDesktop().getBackupDirectory()),
getBoolean(CONFIRM_LINKED_FILE_DELETE),
// We make use of the fallback, because we need AWT being initialized, which is not the case at the constructor JabRefPreferences()
getBoolean(TRASH_INSTEAD_OF_DELETE, OS.getNativeDesktop().moveToTrashSupported()));
getBoolean(TRASH_INSTEAD_OF_DELETE, OS.getNativeDesktop().moveToTrashSupported()),
getBoolean(KEEP_DOWNLOAD_URL));

EasyBind.listen(getInternalPreferences().getUserAndHostProperty(), (obs, oldValue, newValue) -> filePreferences.getUserAndHostProperty().setValue(newValue));
EasyBind.listen(filePreferences.mainFileDirectoryProperty(), (obs, oldValue, newValue) -> put(MAIN_FILE_DIRECTORY, newValue));
Expand All @@ -2273,6 +2276,7 @@ public FilePreferences getFilePreferences() {
EasyBind.listen(filePreferences.backupDirectoryProperty(), (obs, oldValue, newValue) -> put(BACKUP_DIRECTORY, newValue.toString()));
EasyBind.listen(filePreferences.confirmDeleteLinkedFileProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_LINKED_FILE_DELETE, newValue));
EasyBind.listen(filePreferences.moveToTrashProperty(), (obs, oldValue, newValue) -> putBoolean(TRASH_INSTEAD_OF_DELETE, newValue));
EasyBind.listen(filePreferences.shouldKeepDownloadUrlProperty(), (obs, oldValue, newValue) -> putBoolean(KEEP_DOWNLOAD_URL, newValue));

return filePreferences;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2780,3 +2780,4 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The
Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0'
Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0'
Store\ url\ for\ downloaded\ file=Store url for downloaded file
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void replacesLinkedFiles(@TempDir Path tempFolder) throws Exception {
when(databaseContext.getFirstExistingFileDir(any())).thenReturn(Optional.of(tempFolder));
when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]");
when(filePreferences.getFileDirectoryPattern()).thenReturn("");
when(filePreferences.shouldKeepDownloadUrl()).thenReturn(true);

DownloadLinkedFileAction downloadLinkedFileAction = new DownloadLinkedFileAction(
databaseContext,
Expand All @@ -100,6 +101,7 @@ void doesntReplaceSourceURL(boolean keepHtml) throws Exception {
when(databaseContext.getFirstExistingFileDir(any())).thenReturn(Optional.of(tempFolder));
when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]");
when(filePreferences.getFileDirectoryPattern()).thenReturn("");
when(filePreferences.shouldKeepDownloadUrl()).thenReturn(true);

DownloadLinkedFileAction downloadLinkedFileAction = new DownloadLinkedFileAction(
databaseContext,
Expand Down

0 comments on commit 875dcd4

Please sign in to comment.