/** Loads a playlist. */ public void importM3U(Playlist playlist) { File parentFile = FileChooserHandler.getLastInputDirectory(); if (parentFile == null) parentFile = CommonUtils.getCurrentDirectory(); final File selFile = FileChooserHandler.getInputFile( GUIMediator.getAppFrame(), I18nMarker.marktr("Open Playlist (.m3u)"), parentFile, new PlaylistListFileFilter()); // nothing selected? exit. if (selFile == null || !selFile.isFile()) return; String path = selFile.getPath(); try { path = FileUtils.getCanonicalPath(selFile); } catch (IOException ignored) { // LOG.warn("unable to get canonical path for file: " + selFile, ignored); } // create a new thread off of the event queue to process reading the files from // disk loadM3U(playlist, selFile, path); }
/** Saves a playlist. */ public void exportM3U(Playlist playlist) { if (playlist == null) { return; } String suggestedName = CommonUtils.convertFileName(playlist.getName()); // get the user to select a new one.... avoid FrostWire installation folder. File suggested; File suggestedDirectory = FileChooserHandler.getLastInputDirectory(); if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) { suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop"); } suggested = new File(suggestedDirectory, suggestedName + ".m3u"); File selFile = FileChooserHandler.getSaveAsFile( GUIMediator.getAppFrame(), I18nMarker.marktr("Save Playlist As"), suggested, new PlaylistListFileFilter()); // didn't select a file? nothing we can do. if (selFile == null) { return; } // if the file already exists and not the one just opened, ask if it should be // overwritten. // TODO: this should be handled in the jfilechooser if (selFile.exists()) { DialogOption choice = GUIMediator.showYesNoMessage( I18n.tr( "Warning: a file with the name {0} already exists in the folder. Overwrite this file?", selFile.getName()), QuestionsHandler.PLAYLIST_OVERWRITE_OK, DialogOption.NO); if (choice != DialogOption.YES) return; } String path = selFile.getPath(); try { path = FileUtils.getCanonicalPath(selFile); } catch (IOException ignored) { // LOG.warn("unable to get canonical path for file: " + selFile, ignored); } // force m3u on the end. if (!path.toLowerCase().endsWith(".m3u")) path += ".m3u"; // create a new thread to handle saving the playlist to disk saveM3U(playlist, path); }