Skip to content

Commit

Permalink
Add option to disable keeping download url
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr authored and koppor committed Sep 9, 2024
1 parent 3df3b4f commit 4a52c01
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ private void onSuccess(Path targetDirectory, Path downloadedFile) {
}
if (linkedFile.getSourceUrl().isEmpty() && LinkedFile.isOnlineLink(linkedFile.getLink())) {
newLinkedFile.setSourceURL(linkedFile.getLink());
} else {
} else if (filePreferences.shouldKeepDownloadUrl()) {
// Add pref check to not store source URL
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 @@ -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
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 @@ -105,6 +105,7 @@
import org.jabref.logic.protectedterms.ProtectedTermsPreferences;
import org.jabref.logic.push.CitationCommandString;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.search.SearchPreferences;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.shared.security.Password;
import org.jabref.logic.util.OS;
Expand Down Expand Up @@ -453,6 +454,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 @@ -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

0 comments on commit 4a52c01

Please sign in to comment.