Skip to content

Commit 9e37761

Browse files
committed
Add check for HEIC file attachments
1 parent 32806b7 commit 9e37761

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class Messages
4040
GroupingFailed,
4141
GroupSelectedEntries,
4242
JumpToLogEntry,
43+
HeicFilesNotSupported,
4344
Level,
4445
Logbook,
4546
LogbookNotSupported,

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/AttachmentsEditorController.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,18 @@ public void setTextArea(TextArea textArea) {
291291
this.textArea = textArea;
292292
}
293293

294+
/**
295+
* Add
296+
* @param files
297+
*/
294298
private void addFiles(List<File> files) {
295299
Platform.runLater(() -> sizesErrorMessage.set(null));
296300
if (!checkFileSizes(files)) {
297301
return;
298302
}
303+
if(!checkForHeicFiles(files)){
304+
return;
305+
}
299306
MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
300307
for (File file : files) {
301308
OlogAttachment ologAttachment = new OlogAttachment();
@@ -403,4 +410,31 @@ private void showTotalSizeExceedsLimit() {
403410
public void clearAttachments(){
404411
getAttachments().clear();
405412
}
413+
414+
/**
415+
* Checks if any of the attached files uses extension heic or heics, which are unsupported. If a heic file
416+
* is detected, an error dialog is shown.
417+
* @param files List of {@link File}s to check.
418+
* @return <code>true</code> if all is well, i.e. no heic files deyected, otherwise <code>false</code>.
419+
*/
420+
private boolean checkForHeicFiles(List<File> files){
421+
if(hasHeicFiles(files)){
422+
Alert alert = new Alert(AlertType.ERROR);
423+
alert.setHeaderText(Messages.HeicFilesNotSupported);
424+
DialogHelper.positionDialog(alert, textArea, -200, -100);
425+
alert.show();
426+
return false;
427+
}
428+
return true;
429+
}
430+
431+
/**
432+
* Checks for heic(s) file extension. Ideally Apache Tika should be used to detect heic content.
433+
* @param files List of {@link File}s to check.
434+
* @return <code>true</code> if all is well, i.e. no heic files deyected, otherwise <code>false</code>.
435+
*/
436+
private boolean hasHeicFiles(List<File> files){
437+
return files.stream().filter(f ->
438+
(f.getName().toLowerCase().endsWith(".heic") || f.getName().toLowerCase().endsWith(".heics"))).findFirst().isPresent();
439+
}
406440
}

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/EmbedImageDialogController.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.File;
4646
import java.io.IOException;
4747
import java.net.URL;
48+
import java.util.List;
4849
import java.util.ResourceBundle;
4950
import java.util.UUID;
5051
import java.util.logging.Level;
@@ -55,49 +56,60 @@
5556
*/
5657
public class EmbedImageDialogController implements Initializable{
5758

59+
@SuppressWarnings("unused")
5860
@FXML
5961
private DialogPane dialogPane;
62+
@SuppressWarnings("unused")
6063
@FXML
6164
private Label fileLabel;
65+
@SuppressWarnings("unused")
6266
@FXML
6367
private Label widthLabel;
68+
@SuppressWarnings("unused")
6469
@FXML
6570
private Label heightLabel;
71+
@SuppressWarnings("unused")
6672
@FXML
6773
private Button browseButton;
74+
@SuppressWarnings("unused")
6875
@FXML
6976
private Button clipboardButton;
77+
@SuppressWarnings("unused")
7078
@FXML
7179
private TextField fileName;
80+
@SuppressWarnings("unused")
7281
@FXML
7382
private TextField width;
83+
@SuppressWarnings("unused")
7484
@FXML
7585
private TextField height;
86+
@SuppressWarnings("unused")
7687
@FXML
7788
private Label scaleLabel;
89+
@SuppressWarnings("unused")
7890
@FXML
7991
private TextField scale;
8092

8193
/**
8294
* This is set when image is selected from file or clipboard. It is not bound to
8395
* a UI component.
8496
*/
85-
private IntegerProperty widthProperty = new SimpleIntegerProperty();
97+
private final IntegerProperty widthProperty = new SimpleIntegerProperty();
8698
/**
8799
* This is the computed width value rendered in the UI component.
88100
*/
89-
private IntegerProperty scaledWidthProperty = new SimpleIntegerProperty();
101+
private final IntegerProperty scaledWidthProperty = new SimpleIntegerProperty();
90102
/**
91103
* This is set when image is selected from file or clipboard. It is not bound to
92104
* a UI component.
93105
*/
94-
private IntegerProperty heightProperty = new SimpleIntegerProperty();
106+
private final IntegerProperty heightProperty = new SimpleIntegerProperty();
95107
/**
96108
* This is the computed width value rendered in the UI component.
97109
*/
98-
private IntegerProperty scaledHeightProperty = new SimpleIntegerProperty();
99-
private SimpleStringProperty filenameProperty = new SimpleStringProperty();
100-
private DoubleProperty scaleProperty = new SimpleDoubleProperty(1.0);
110+
private final IntegerProperty scaledHeightProperty = new SimpleIntegerProperty();
111+
private final SimpleStringProperty filenameProperty = new SimpleStringProperty();
112+
private final DoubleProperty scaleProperty = new SimpleDoubleProperty(1.0);
101113

102114
private String id;
103115

@@ -127,13 +139,14 @@ public void initialize(URL url, ResourceBundle resourceBundle){
127139
dialogPane.lookupButton(ButtonType.OK).disableProperty().bind(okButtonBinding);
128140
}
129141

142+
@SuppressWarnings("unused")
130143
@FXML
131144
public void browse(){
132145
FileChooser fileChooser = new FileChooser();
133146
fileChooser.setTitle(Messages.SelectFile);
134147
fileChooser.getExtensionFilters().addAll(
135-
new FileChooser.ExtensionFilter("Image files (jpg, png, gif)", "*.jpg", "*.png", "*.gif"),
136-
new FileChooser.ExtensionFilter("All files", "*.*")
148+
new FileChooser.ExtensionFilter("Image files (jpg, jpeg, png, gif)", "*.jpg", "*.jpeg", "*.png", "*.gif")
149+
137150
);
138151

139152
File file = fileChooser.showOpenDialog(dialogPane.getScene().getWindow());
@@ -152,6 +165,7 @@ public void browse(){
152165
}
153166
}
154167

168+
@SuppressWarnings("unused")
155169
@FXML
156170
public void pasteClipboard(){
157171
image = Clipboard.getSystemClipboard().getImage();

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ HitsPerPage=Hits per page:
5757
ImageWidth=Width
5858
ImageHeight=Height
5959
JumpToLogEntry=Jump to Log Entry:
60+
HeicFilesNotSupported=HEIC file attachments not supported
6061
Level=Level
6162
Logbook=Logbook
6263
Logbooks=Logbooks:

0 commit comments

Comments
 (0)