2018-05-02 05:21:44 +03:00
|
|
|
package mplayer4anime.Settings;
|
|
|
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
import javafx.scene.control.*;
|
|
|
|
import javafx.stage.FileChooser;
|
|
|
|
import javafx.stage.Stage;
|
|
|
|
import mplayer4anime.AppPreferences;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
|
|
import mplayer4anime.MediatorControl;
|
|
|
|
|
|
|
|
public class SettingsController implements Initializable {
|
|
|
|
|
|
|
|
private AppPreferences appPreferences;
|
|
|
|
@FXML
|
2018-11-28 07:10:35 +03:00
|
|
|
private ControllerListsSelector subExtensionListController;
|
2018-05-02 05:21:44 +03:00
|
|
|
@FXML
|
2018-11-28 07:10:35 +03:00
|
|
|
private ControllerListsSelector subEncodingListController;
|
2018-05-02 05:21:44 +03:00
|
|
|
@FXML
|
2018-11-28 07:10:35 +03:00
|
|
|
private ControllerListsSelector videoExtensionListController;
|
2018-05-02 05:21:44 +03:00
|
|
|
@FXML
|
2018-11-28 07:10:35 +03:00
|
|
|
private ControllerListsSelector audioExtensionListController;
|
2018-05-02 05:21:44 +03:00
|
|
|
@FXML
|
2018-11-28 07:10:35 +03:00
|
|
|
private Label pathToMplayerLbl;
|
2018-05-02 05:21:44 +03:00
|
|
|
@FXML
|
2018-11-28 07:10:35 +03:00
|
|
|
private CheckBox subtitlesFirstCheckBox;
|
2018-05-02 05:21:44 +03:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initialize(URL url, ResourceBundle resBundle) {
|
|
|
|
appPreferences = new AppPreferences();
|
|
|
|
pathToMplayerLbl.setText(appPreferences.getPath());
|
2018-05-05 23:07:52 +03:00
|
|
|
|
2018-05-02 05:21:44 +03:00
|
|
|
// Subtitles should be shown first? If TRUE, then set checkbox.
|
|
|
|
subtitlesFirstCheckBox.setSelected(appPreferences.getSubtilesFirst());
|
2018-11-28 07:10:35 +03:00
|
|
|
// Fill lists of extensions and encodings
|
|
|
|
subExtensionListController.setList(appPreferences.getSubsExtensionsList(), true);
|
|
|
|
subEncodingListController.setList(appPreferences.getSubsEncodingList(), false);
|
|
|
|
videoExtensionListController.setList(appPreferences.getVideoExtensionsList(), true);
|
|
|
|
audioExtensionListController.setList(appPreferences.getAudioExtensionsList(), true);
|
2018-05-02 05:21:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private void findPathToMplayer(){
|
|
|
|
FileChooser fileChooser = new FileChooser();
|
|
|
|
fileChooser.setTitle("mplayer");
|
|
|
|
|
|
|
|
// In case we use Windows, limit selectable file to .exe
|
|
|
|
if (System.getProperty("os.name").contains("Windows")) {
|
|
|
|
fileChooser.getExtensionFilters().setAll(
|
|
|
|
new FileChooser.ExtensionFilter("mplayer", "*.exe")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
File mplayerExecutableFile = fileChooser.showOpenDialog(null);
|
|
|
|
|
|
|
|
if (mplayerExecutableFile != null) {
|
|
|
|
pathToMplayerLbl.setText(mplayerExecutableFile.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private void clearPath(){
|
2018-05-05 23:07:52 +03:00
|
|
|
if (System.getProperty("os.name").contains("Windows"))
|
|
|
|
pathToMplayerLbl.setText("mplayer\\mplayer.exe");
|
|
|
|
else
|
|
|
|
pathToMplayerLbl.setText("mplayer");
|
2018-05-02 05:21:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private void Cancel(){
|
|
|
|
Stage thisStage = (Stage) pathToMplayerLbl.getScene().getWindow(); // TODO: consider refactoring. Non-urgent.
|
|
|
|
thisStage.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private void Save(){
|
|
|
|
Stage thisStage = (Stage) pathToMplayerLbl.getScene().getWindow(); // TODO: consider refactoring. Non-urgent.
|
|
|
|
appPreferences.setPath(pathToMplayerLbl.getText());
|
|
|
|
appPreferences.setSubtilesFirst(subtitlesFirstCheckBox.isSelected());
|
2018-11-28 07:10:35 +03:00
|
|
|
appPreferences.setSubsExtensionsList(subExtensionListController.getList());
|
|
|
|
appPreferences.setSubsEncodingList(subEncodingListController.getList());
|
|
|
|
appPreferences.setVideoExtensionsList(videoExtensionListController.getList());
|
|
|
|
appPreferences.setAudioExtensionsList(audioExtensionListController.getList());
|
2018-05-02 05:21:44 +03:00
|
|
|
|
|
|
|
MediatorControl.getInstance().sentUpdates(); // TODO: implement list to track what should be updated
|
|
|
|
|
|
|
|
thisStage.close();
|
|
|
|
}
|
|
|
|
}
|