Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/main/java/drrename/kodi/KodiToolsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import javafx.collections.ListChangeListener;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -53,6 +56,10 @@ public class KodiToolsController implements Initializable {

public CheckBox checkBoxHideEmpty;

public HBox goCancelButtonsComponent;

public CheckBox checkBoxMissingNfoFileIsAWarning;

private Stage mainStage;

Stage imageStage;
Expand Down Expand Up @@ -89,7 +96,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
buttonExpandAll.setDisable(e.getList().isEmpty());
buttonCollapseAll.setDisable(e.getList().isEmpty());
});
checkBoxHideEmpty.selectedProperty().addListener((observable, oldValue, newValue) -> updateTreeRootPredicate(newValue));
checkBoxHideEmpty.selectedProperty().addListener((observable, oldValue, newValue) -> updateTreeRootPredicate());
checkBoxMissingNfoFileIsAWarning.selectedProperty().addListener((observable, oldValue, newValue) -> updateTreeRootPredicate());
startDirectoryComponentController.inputPathProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
onButtonGoEvent(null);
Expand Down Expand Up @@ -131,18 +139,11 @@ protected void updateItem(KodiTreeItemContent item, boolean empty) {
continue;
}
var hans = treeView.getTreeItem(c.getAddedSubList().get(0)).getValue();
log.debug("Selection changed: {}", hans);
if (hans instanceof KodiLevel3TreeItemContent peter) {
log.debug("Handling {}", hans);
if (peter.getCheckResult() instanceof NfoFileContentCheckResult) {
Path nfoFile = ((NfoFileContentCheckResult) peter.getCheckResult()).getNfoFile();
log.debug("Selection changed: {} ({})", hans, hans.getClass());
if (hans instanceof NfoCheckResultTreeItemContent<?> peter) {
log.debug("Handling {}", peter);
Path nfoFile = peter.getCheckResult().getNfoFile();
executor.execute(() -> showImage(nfoFile));
} else if (peter.getCheckResult() instanceof NfoFileNameCheckResult) {
if (!((NfoFileNameCheckResult) peter.getCheckResult()).getNfoFiles().isEmpty()) {
Path nfoFile = ((NfoFileNameCheckResult) peter.getCheckResult()).getNfoFiles().get(0);
executor.execute(() -> showImage(nfoFile));
}
}
}
}
});
Expand Down Expand Up @@ -182,13 +183,15 @@ private void showImageStage(ImageView imageView, String title) {
imageStage.show();
}

private void updateTreeRootPredicate(boolean onlyWarnings) {
treeRoot.setPredicate(buildHideEmptyPredicate(onlyWarnings));
private void updateTreeRootPredicate() {
Platform.runLater(() -> treeRoot.setPredicate(buildHideEmptyPredicate()));
}

private static Predicate<KodiTreeItemContent> buildHideEmptyPredicate(boolean onlyWarnings) {
private Predicate<KodiTreeItemContent> buildHideEmptyPredicate() {
return item -> {
if (onlyWarnings)
if(item instanceof NfoCheckResultTreeItemContent<?> anotherItem)
anotherItem.setMissingNfoIsAWarning(checkBoxMissingNfoFileIsAWarning.isSelected());
if (checkBoxHideEmpty.isSelected())
return item.hasWarning();
return true;
};
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/drrename/kodi/NfoCheckResultTreeItemContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Dr.Rename - A Minimalistic Batch Renamer
*
* Copyright (C) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package drrename.kodi;

public class NfoCheckResultTreeItemContent<T extends NfoCheckResult> extends CheckResultTreeItemContent<T>{

private boolean missingNfoIsAWarning;

public NfoCheckResultTreeItemContent(T checkResult) {
super(checkResult);
}

public boolean isMissingNfoIsAWarning() {
return missingNfoIsAWarning;
}

public void setMissingNfoIsAWarning(boolean missingNfoIsAWarning) {
this.missingNfoIsAWarning = missingNfoIsAWarning;
}
}
2 changes: 2 additions & 0 deletions src/main/java/drrename/kodi/NfoFileContentCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public NfoFileContentCheckResult checkPath(Path path) throws IOException {
}
return new NfoFileContentCheckResult("XML NFO", child, false);
} catch (JsonParseException e) {
log.debug("{} for {}", e.getLocalizedMessage(), child);
try {
String content = Files.readString(child);
if (content == null) {
Expand All @@ -75,6 +76,7 @@ public NfoFileContentCheckResult checkPath(Path path) throws IOException {
return new NfoFileContentCheckResult("Unknown NFO content", child, true);
}
} catch (MalformedInputException ee) {
log.debug("{} for {}", ee.getLocalizedMessage(), child);
log.debug("{} for path {}", ee.getLocalizedMessage(), path);
return new NfoFileContentCheckResult("Invalid NFO content", child, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package drrename.kodi;

public class NfoFileContentTreeItemContent extends CheckResultTreeItemContent<NfoFileContentCheckResult> {
public class NfoFileContentTreeItemContent extends NfoCheckResultTreeItemContent<NfoFileContentCheckResult> {

public NfoFileContentTreeItemContent(NfoFileContentCheckResult value) {
super(value);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/drrename/kodi/NfoFileNameTreeItemContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

import java.util.stream.Collectors;

public class NfoFileNameTreeItemContent extends CheckResultTreeItemContent<NfoFileNameCheckResult> {
public class NfoFileNameTreeItemContent extends NfoCheckResultTreeItemContent<NfoFileNameCheckResult> {

public NfoFileNameTreeItemContent(NfoFileNameCheckResult checkResult) {
super(checkResult);
}

@Override
protected boolean hasWarning() {
if(NfoFileNameType.NO_FILE.equals(getCheckResult().getType()) && !isMissingNfoIsAWarning()){
return false;
}
return !NfoFileNameType.MOVIE_NAME.equals(getCheckResult().getType()) && !NfoFileNameType.DEFAULT_NAME.equals(getCheckResult().getType());
}

Expand Down
9 changes: 3 additions & 6 deletions src/main/resources/fxml/KodiTools.fxml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<?import javafx.geometry.Insets?>
<BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="drrename.kodi.KodiToolsController" fx:id="root"
Expand All @@ -25,7 +21,7 @@
<Insets top="4" right="4" bottom="4" left="4"/>
</padding>
<center>
<TreeView fx:id="treeView"></TreeView>
<TreeView fx:id="treeView"/>
</center>
<bottom>
<BorderPane >
Expand All @@ -47,6 +43,7 @@
</tooltip>
</Button>
<CheckBox fx:id="checkBoxHideEmpty" text="Show only warnings"/>
<CheckBox fx:id="checkBoxMissingNfoFileIsAWarning" text="Missing NFO file is a warning"/>
</HBox>
</center>
</BorderPane>
Expand Down