Skip to content

Commit

Permalink
Add option to delete JPEGs after processing
Browse files Browse the repository at this point in the history
  • Loading branch information
qligier committed Nov 11, 2023
1 parent 5546652 commit b6f7077
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
18 changes: 18 additions & 0 deletions src/main/java/ch/qligier/app/pixeldngfixer/gui/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class MainController implements Initializable {
@FXML
protected CheckBox createBackupsCheckbox;
@FXML
protected CheckBox deleteJpegCheckbox;
@FXML
protected Button processButton;

/**
Expand All @@ -59,6 +61,11 @@ public class MainController implements Initializable {
*/
protected boolean createBackupBeforeFixing = true;

/**
* Whether the JPEG files are deleted after processing or not.
*/
protected boolean deleteJpegsAfterFixing = false;

/**
* The parent JavaFX {@link Stage}. A bit hacky.
*/
Expand All @@ -77,6 +84,7 @@ public void initialize(final URL url, final ResourceBundle resourceBundle) {
this.appNameLabel.setText(Config.APP_NAME);
this.photoDirLabel.setText(this.selectedDir.getAbsolutePath());
this.createBackupsCheckbox.setSelected(this.createBackupBeforeFixing);
this.deleteJpegCheckbox.setSelected(this.deleteJpegsAfterFixing);
this.progressBar.setDisable(true);
}

Expand Down Expand Up @@ -107,6 +115,7 @@ protected void onProcessButtonClick() {
};

final var createBackupBeforeFixing = this.createBackupBeforeFixing;
final var deleteJpegsAfterFixing = this.deleteJpegsAfterFixing;
final var photoDir = this.selectedDir;
final Consumer<String> logProxy = this::addLog;
// Create a task to process the photos
Expand All @@ -130,6 +139,10 @@ protected Void call() throws Exception {
createBackupBeforeFixing);
updateMessage("Processed file " + pair.getRawFile().getName());
updateProgress(i, nbPairs);

if (deleteJpegsAfterFixing) {
pair.getJpegFile().delete();
}
}
return null;
}
Expand Down Expand Up @@ -209,6 +222,11 @@ protected void onCreateBackupsCheckboxClick() {
this.createBackupBeforeFixing = this.createBackupsCheckbox.isSelected();
}

@FXML
protected void onDeleteJpegCheckboxClick() {
this.deleteJpegsAfterFixing = this.deleteJpegCheckbox.isSelected();
}

/**
* Adds a message log to the dedicated textarea.
*
Expand Down
44 changes: 28 additions & 16 deletions src/main/resources/views/main-view.fxml
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?>

<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="480.0" prefWidth="640.0" style="-fx-background-color: #f5f6f6;" stylesheets="@css/main.css"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
<VBox xmlns:fx="http://javafx.com/fxml/1" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity"
minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" style="-fx-background-color: #f5f6f6;"
stylesheets="@css/main.css" xmlns="http://javafx.com/javafx/18"
fx:controller="ch.qligier.app.pixeldngfixer.gui.MainController">
<Pane id="headerPane" prefHeight="70.0" prefWidth="640.0"
style="-fx-background-color: #e2e3e3; -fx-border-color: #bababa; -fx-border-width: 0 0 1 0;">
Expand Down Expand Up @@ -56,10 +47,13 @@
<rowConstraints>
<RowConstraints minHeight="30.0" prefHeight="40.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="30.0" prefHeight="40.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="30.0" prefHeight="40.0" vgrow="SOMETIMES"/>
</rowConstraints>
<VBox.margin>
<Insets/>
</VBox.margin>

<!-- Line 1 -->
<Button onAction="#onChooseDirClick" text="Choose photo directory" GridPane.columnIndex="1"
GridPane.rowIndex="0">
<tooltip>
Expand All @@ -81,6 +75,8 @@
<Font size="11.0"/>
</font>
</Label>

<!-- Line 2 -->
<Label alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="168.0" text="Create backups:"
GridPane.rowIndex="1">
<padding>
Expand All @@ -96,6 +92,22 @@
<Tooltip text="Create a backup of the DNG files before fixing metadata"/>
</tooltip>
</CheckBox>

<!-- Line 3 -->
<Label alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="168.0" text="Delete JPEGs:" GridPane.rowIndex="2">
<padding>
<Insets right="10.0"/>
</padding>
<GridPane.margin>
<Insets/>
</GridPane.margin>
</Label>
<CheckBox fx:id="deleteJpegCheckbox" mnemonicParsing="false" onAction="#onDeleteJpegCheckboxClick"
GridPane.columnIndex="1" GridPane.rowIndex="2">
<tooltip>
<Tooltip text="Delete the JPEG pictures after fixing metadata"/>
</tooltip>
</CheckBox>
</GridPane>
<Button fx:id="processButton" defaultButton="true" onAction="#onProcessButtonClick" prefHeight="40.0"
prefWidth="138.0" styleClass="main" text="Process photos!" textAlignment="CENTER">
Expand Down

0 comments on commit b6f7077

Please sign in to comment.