Skip to content

Commit db803a2

Browse files
authored
Merge pull request #30 from DrRename/feature/missing-nfo-warning
Make missing NFO warning configurable
2 parents 60cfbf6 + a3e7e68 commit db803a2

File tree

6 files changed

+66
-24
lines changed

6 files changed

+66
-24
lines changed

src/main/java/drrename/kodi/KodiToolsController.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import javafx.collections.ListChangeListener;
99
import javafx.concurrent.WorkerStateEvent;
1010
import javafx.event.ActionEvent;
11+
import javafx.event.EventHandler;
1112
import javafx.fxml.Initializable;
1213
import javafx.scene.Scene;
1314
import javafx.scene.control.*;
1415
import javafx.scene.image.Image;
1516
import javafx.scene.image.ImageView;
17+
import javafx.scene.input.KeyEvent;
1618
import javafx.scene.layout.BorderPane;
19+
import javafx.scene.layout.HBox;
1720
import javafx.scene.layout.VBox;
1821
import javafx.stage.Stage;
1922
import lombok.RequiredArgsConstructor;
@@ -53,6 +56,10 @@ public class KodiToolsController implements Initializable {
5356

5457
public CheckBox checkBoxHideEmpty;
5558

59+
public HBox goCancelButtonsComponent;
60+
61+
public CheckBox checkBoxMissingNfoFileIsAWarning;
62+
5663
private Stage mainStage;
5764

5865
Stage imageStage;
@@ -89,7 +96,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
8996
buttonExpandAll.setDisable(e.getList().isEmpty());
9097
buttonCollapseAll.setDisable(e.getList().isEmpty());
9198
});
92-
checkBoxHideEmpty.selectedProperty().addListener((observable, oldValue, newValue) -> updateTreeRootPredicate(newValue));
99+
checkBoxHideEmpty.selectedProperty().addListener((observable, oldValue, newValue) -> updateTreeRootPredicate());
100+
checkBoxMissingNfoFileIsAWarning.selectedProperty().addListener((observable, oldValue, newValue) -> updateTreeRootPredicate());
93101
startDirectoryComponentController.inputPathProperty().addListener((observable, oldValue, newValue) -> {
94102
if (newValue != null) {
95103
onButtonGoEvent(null);
@@ -131,18 +139,11 @@ protected void updateItem(KodiTreeItemContent item, boolean empty) {
131139
continue;
132140
}
133141
var hans = treeView.getTreeItem(c.getAddedSubList().get(0)).getValue();
134-
log.debug("Selection changed: {}", hans);
135-
if (hans instanceof KodiLevel3TreeItemContent peter) {
136-
log.debug("Handling {}", hans);
137-
if (peter.getCheckResult() instanceof NfoFileContentCheckResult) {
138-
Path nfoFile = ((NfoFileContentCheckResult) peter.getCheckResult()).getNfoFile();
142+
log.debug("Selection changed: {} ({})", hans, hans.getClass());
143+
if (hans instanceof NfoCheckResultTreeItemContent<?> peter) {
144+
log.debug("Handling {}", peter);
145+
Path nfoFile = peter.getCheckResult().getNfoFile();
139146
executor.execute(() -> showImage(nfoFile));
140-
} else if (peter.getCheckResult() instanceof NfoFileNameCheckResult) {
141-
if (!((NfoFileNameCheckResult) peter.getCheckResult()).getNfoFiles().isEmpty()) {
142-
Path nfoFile = ((NfoFileNameCheckResult) peter.getCheckResult()).getNfoFiles().get(0);
143-
executor.execute(() -> showImage(nfoFile));
144-
}
145-
}
146147
}
147148
}
148149
});
@@ -182,13 +183,15 @@ private void showImageStage(ImageView imageView, String title) {
182183
imageStage.show();
183184
}
184185

185-
private void updateTreeRootPredicate(boolean onlyWarnings) {
186-
treeRoot.setPredicate(buildHideEmptyPredicate(onlyWarnings));
186+
private void updateTreeRootPredicate() {
187+
Platform.runLater(() -> treeRoot.setPredicate(buildHideEmptyPredicate()));
187188
}
188189

189-
private static Predicate<KodiTreeItemContent> buildHideEmptyPredicate(boolean onlyWarnings) {
190+
private Predicate<KodiTreeItemContent> buildHideEmptyPredicate() {
190191
return item -> {
191-
if (onlyWarnings)
192+
if(item instanceof NfoCheckResultTreeItemContent<?> anotherItem)
193+
anotherItem.setMissingNfoIsAWarning(checkBoxMissingNfoFileIsAWarning.isSelected());
194+
if (checkBoxHideEmpty.isSelected())
192195
return item.hasWarning();
193196
return true;
194197
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Dr.Rename - A Minimalistic Batch Renamer
3+
*
4+
* Copyright (C) 2022
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
package drrename.kodi;
21+
22+
public class NfoCheckResultTreeItemContent<T extends NfoCheckResult> extends CheckResultTreeItemContent<T>{
23+
24+
private boolean missingNfoIsAWarning;
25+
26+
public NfoCheckResultTreeItemContent(T checkResult) {
27+
super(checkResult);
28+
}
29+
30+
public boolean isMissingNfoIsAWarning() {
31+
return missingNfoIsAWarning;
32+
}
33+
34+
public void setMissingNfoIsAWarning(boolean missingNfoIsAWarning) {
35+
this.missingNfoIsAWarning = missingNfoIsAWarning;
36+
}
37+
}

src/main/java/drrename/kodi/NfoFileContentCheckService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public NfoFileContentCheckResult checkPath(Path path) throws IOException {
6464
}
6565
return new NfoFileContentCheckResult("XML NFO", child, false);
6666
} catch (JsonParseException e) {
67+
log.debug("{} for {}", e.getLocalizedMessage(), child);
6768
try {
6869
String content = Files.readString(child);
6970
if (content == null) {
@@ -75,6 +76,7 @@ public NfoFileContentCheckResult checkPath(Path path) throws IOException {
7576
return new NfoFileContentCheckResult("Unknown NFO content", child, true);
7677
}
7778
} catch (MalformedInputException ee) {
79+
log.debug("{} for {}", ee.getLocalizedMessage(), child);
7880
log.debug("{} for path {}", ee.getLocalizedMessage(), path);
7981
return new NfoFileContentCheckResult("Invalid NFO content", child, true);
8082
}

src/main/java/drrename/kodi/NfoFileContentTreeItemContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package drrename.kodi;
2121

22-
public class NfoFileContentTreeItemContent extends CheckResultTreeItemContent<NfoFileContentCheckResult> {
22+
public class NfoFileContentTreeItemContent extends NfoCheckResultTreeItemContent<NfoFileContentCheckResult> {
2323

2424
public NfoFileContentTreeItemContent(NfoFileContentCheckResult value) {
2525
super(value);

src/main/java/drrename/kodi/NfoFileNameTreeItemContent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121

2222
import java.util.stream.Collectors;
2323

24-
public class NfoFileNameTreeItemContent extends CheckResultTreeItemContent<NfoFileNameCheckResult> {
24+
public class NfoFileNameTreeItemContent extends NfoCheckResultTreeItemContent<NfoFileNameCheckResult> {
2525

2626
public NfoFileNameTreeItemContent(NfoFileNameCheckResult checkResult) {
2727
super(checkResult);
2828
}
2929

3030
@Override
3131
protected boolean hasWarning() {
32+
if(NfoFileNameType.NO_FILE.equals(getCheckResult().getType()) && !isMissingNfoIsAWarning()){
33+
return false;
34+
}
3235
return !NfoFileNameType.MOVIE_NAME.equals(getCheckResult().getType()) && !NfoFileNameType.DEFAULT_NAME.equals(getCheckResult().getType());
3336
}
3437

src/main/resources/fxml/KodiTools.fxml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import java.lang.*?>
4-
<?import java.util.*?>
5-
<?import javafx.scene.*?>
3+
<?import javafx.geometry.Insets?>
64
<?import javafx.scene.control.*?>
75
<?import javafx.scene.layout.*?>
8-
9-
<?import javafx.geometry.Insets?>
106
<BorderPane xmlns="http://javafx.com/javafx"
117
xmlns:fx="http://javafx.com/fxml"
128
fx:controller="drrename.kodi.KodiToolsController" fx:id="root"
@@ -25,7 +21,7 @@
2521
<Insets top="4" right="4" bottom="4" left="4"/>
2622
</padding>
2723
<center>
28-
<TreeView fx:id="treeView"></TreeView>
24+
<TreeView fx:id="treeView"/>
2925
</center>
3026
<bottom>
3127
<BorderPane >
@@ -47,6 +43,7 @@
4743
</tooltip>
4844
</Button>
4945
<CheckBox fx:id="checkBoxHideEmpty" text="Show only warnings"/>
46+
<CheckBox fx:id="checkBoxMissingNfoFileIsAWarning" text="Missing NFO file is a warning"/>
5047
</HBox>
5148
</center>
5249
</BorderPane>

0 commit comments

Comments
 (0)