diff --git a/src/main/java/mediathek/gui/dialog/DialogAddDownload.java b/src/main/java/mediathek/gui/dialog/DialogAddDownload.java index 7717325acc..ea66bcf470 100644 --- a/src/main/java/mediathek/gui/dialog/DialogAddDownload.java +++ b/src/main/java/mediathek/gui/dialog/DialogAddDownload.java @@ -45,25 +45,33 @@ import java.util.concurrent.Future; public class DialogAddDownload extends JDialog { + private static final Logger logger = LogManager.getLogger(); + private static final String NO_DATA_AVAILABLE = "Keine Daten verfügbar."; + private static final String KEY_LABEL_FOREGROUND = "Label.foreground"; + private static final String KEY_TEXTFIELD_BACKROUND = "TextField.background"; + private static final String TITLED_BORDER_STRING = "Download-Qualität"; + private final DatenFilm film; + private final Optional requestedResolution; + private final ListePset listeSpeichern = Daten.listePset.getListeSpeichern(); /** * The currently selected pSet or null when no selection. */ private DatenPset active_pSet; private DatenDownload datenDownload; - private final DatenFilm film; private String orgPfad = ""; - private final Optional requestedResolution; private String dateiGroesse_HQ = ""; private String dateiGroesse_Hoch = ""; private String dateiGroesse_Klein = ""; private boolean nameGeaendert; private boolean stopBeob; private JTextComponent cbPathTextComponent; - private static final Logger logger = LogManager.getLogger(); - private final ListePset listeSpeichern = Daten.listePset.getListeSpeichern(); - private static final String NO_DATA_AVAILABLE = "Keine Daten verfügbar."; - private static final String KEY_LABEL_FOREGROUND = "Label.foreground"; - + private Path ffprobePath; + private ListenableFuture resultListenableFuture; + private ListenableFuture hqFuture; + private ListenableFuture hochFuture; + private ListenableFuture kleinFuture; + private boolean restoreFetchSize; + private boolean highQualityMandated; public DialogAddDownload(@NotNull Frame parent, @NotNull DatenFilm film, @Nullable DatenPset pSet, @NotNull Optional requestedResolution) { super(parent, true); @@ -84,6 +92,58 @@ public DialogAddDownload(@NotNull Frame parent, @NotNull DatenFilm film, @Nullab setLocationRelativeTo(parent); } + public static void setModelPfad(String pfad, JComboBox jcb) { + ArrayList pfade = new ArrayList<>(); + final boolean showLastUsedPath = ApplicationConfiguration.getConfiguration().getBoolean(ApplicationConfiguration.DOWNLOAD_SHOW_LAST_USED_PATH, true); + + // wenn gewünscht, den letzten verwendeten Pfad an den Anfang setzen + if (!showLastUsedPath && !pfad.isEmpty()) { + // aktueller Pfad an Platz 1 + pfade.add(pfad); + + } + if (!MVConfig.get(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN).isEmpty()) { + String[] p = MVConfig.get(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN).split("<>"); + for (String s : p) { + if (!pfade.contains(s)) { + pfade.add(s); + } + } + } + if (showLastUsedPath && !pfad.isEmpty()) { + // aktueller Pfad zum Schluss + if (!pfade.contains(pfad)) { + pfade.add(pfad); + } + } + jcb.setModel(new DefaultComboBoxModel<>(pfade.toArray(new String[0]))); + } + + public static void saveComboPfad(JComboBox jcb, String orgPath) { + ArrayList pfade = new ArrayList<>(); + String s = Objects.requireNonNull(jcb.getSelectedItem()).toString(); + + if (!s.equals(orgPath) || ApplicationConfiguration.getConfiguration().getBoolean(ApplicationConfiguration.DOWNLOAD_SHOW_LAST_USED_PATH, true)) { + pfade.add(s); + } + for (int i = 0; i < jcb.getItemCount(); ++i) { + s = jcb.getItemAt(i); + if (!s.equals(orgPath) && !pfade.contains(s)) { + pfade.add(s); + } + } + if (!pfade.isEmpty()) { + s = pfade.getFirst(); + for (int i = 1; i < Math.min(Konstanten.MAX_PFADE_DIALOG_DOWNLOAD, pfade.size()); ++i) { + final var pfad = pfade.get(i); + if (!pfad.isEmpty()) { + s += "<>" + pfad; + } + } + } + MVConfig.add(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN, s); + } + private void setupFilmQualityRadioButtons() { var listener = new ActionListener() { @Override @@ -111,9 +171,6 @@ public void actionPerformed(ActionEvent e) { btnRequestLiveInfo.addActionListener(l -> handleRequestLiveFilmInfo()); } - private Path ffprobePath; - private ListenableFuture resultListenableFuture; - /** * Return only the first part of the long codec name. * @param stream The video stream from ffprobe. @@ -147,6 +204,9 @@ private void handleRequestLiveFilmInfo() { .executeAsync(); resultListenableFuture = JdkFutureAdapters.listenInPoolThread(resultFuture); Futures.addCallback(resultListenableFuture, new FutureCallback<>() { + private static final String ERR_MSG_PART = "Server returned "; + private static final String MSG_UNKNOWN_ERROR = "Unbekannter Fehler aufgetreten."; + @Override public void onSuccess(FFprobeResult result) { var audioStreamResult = result.getStreams().stream().filter(stream -> stream.getCodecType() == StreamType.AUDIO).findAny(); @@ -244,9 +304,6 @@ private void setupLabels(String text) { }); } - private static final String ERR_MSG_PART = "Server returned "; - private static final String MSG_UNKNOWN_ERROR = "Unbekannter Fehler aufgetreten."; - private @NotNull String getJaffreeErrorString(JaffreeAbnormalExitException e) { String final_str; try { @@ -330,12 +387,6 @@ private void setupUI() { nameGeaendert = false; } - private ListenableFuture hqFuture; - private ListenableFuture hochFuture; - private ListenableFuture kleinFuture; - - private boolean restoreFetchSize; - private void launchResolutionFutures() { // always fetch file size during dialog ops... restoreFetchSize = ApplicationConfiguration.getConfiguration().getBoolean(ApplicationConfiguration.DOWNLOAD_FETCH_FILE_SIZE, true); @@ -473,7 +524,7 @@ private void tus() { if (!jTextFieldName.getText().equals(FilenameUtils.checkDateiname(jTextFieldName.getText(), false /*pfad*/))) { jTextFieldName.setBackground(MVColor.DOWNLOAD_FEHLER.color); } else { - jTextFieldName.setBackground(UIManager.getDefaults().getColor("TextField.background")); + jTextFieldName.setBackground(UIManager.getDefaults().getColor(KEY_TEXTFIELD_BACKROUND)); } } @@ -511,7 +562,7 @@ private void tus() { if (!s.equals(FilenameUtils.checkDateiname(s, true))) { editor.setBackground(MVColor.DOWNLOAD_FEHLER.color); } else { - editor.setBackground(UIManager.getColor("TextField.background")); + editor.setBackground(UIManager.getColor(KEY_TEXTFIELD_BACKROUND)); } } calculateAndCheckDiskSpace(); @@ -626,8 +677,6 @@ private long getFreeDiskSpace(final String strPath) { return usableSpace; } - private static final String TITLED_BORDER_STRING = "Download-Qualität"; - /** * Calculate free disk space on volume and check if the movies can be safely downloaded. */ @@ -678,58 +727,6 @@ private void calculateAndCheckDiskSpace() { } } - public static void setModelPfad(String pfad, JComboBox jcb) { - ArrayList pfade = new ArrayList<>(); - final boolean showLastUsedPath = ApplicationConfiguration.getConfiguration().getBoolean(ApplicationConfiguration.DOWNLOAD_SHOW_LAST_USED_PATH, true); - - // wenn gewünscht, den letzten verwendeten Pfad an den Anfang setzen - if (!showLastUsedPath && !pfad.isEmpty()) { - // aktueller Pfad an Platz 1 - pfade.add(pfad); - - } - if (!MVConfig.get(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN).isEmpty()) { - String[] p = MVConfig.get(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN).split("<>"); - for (String s : p) { - if (!pfade.contains(s)) { - pfade.add(s); - } - } - } - if (showLastUsedPath && !pfad.isEmpty()) { - // aktueller Pfad zum Schluss - if (!pfade.contains(pfad)) { - pfade.add(pfad); - } - } - jcb.setModel(new DefaultComboBoxModel<>(pfade.toArray(new String[0]))); - } - - public static void saveComboPfad(JComboBox jcb, String orgPath) { - ArrayList pfade = new ArrayList<>(); - String s = Objects.requireNonNull(jcb.getSelectedItem()).toString(); - - if (!s.equals(orgPath) || ApplicationConfiguration.getConfiguration().getBoolean(ApplicationConfiguration.DOWNLOAD_SHOW_LAST_USED_PATH, true)) { - pfade.add(s); - } - for (int i = 0; i < jcb.getItemCount(); ++i) { - s = jcb.getItemAt(i); - if (!s.equals(orgPath) && !pfade.contains(s)) { - pfade.add(s); - } - } - if (!pfade.isEmpty()) { - s = pfade.get(0); - for (int i = 1; i < Math.min(Konstanten.MAX_PFADE_DIALOG_DOWNLOAD, pfade.size()); ++i) { - final var pfad = pfade.get(i); - if (!pfad.isEmpty()) { - s += "<>" + pfad; - } - } - } - MVConfig.add(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN, s); - } - private boolean isHighQualityRequested() { return active_pSet.arr[DatenPset.PROGRAMMSET_AUFLOESUNG].equals(FilmResolution.Enum.HIGH_QUALITY.toString()) && film.isHighQuality(); @@ -740,7 +737,6 @@ private boolean isLowQualityRequested() { !film.getLowQualityUrl().isEmpty(); } - private boolean highQualityMandated; /** * Setup the resolution radio buttons based on available download URLs. */