Changeset 158
- Timestamp:
- 04/13/07 16:28:10 (2 years ago)
- Files:
-
- trunk/src/org/thestaticvoid/iriverter/AddDirectoryDialog.java (added)
- trunk/src/org/thestaticvoid/iriverter/Converter.java (modified) (2 diffs)
- trunk/src/org/thestaticvoid/iriverter/ConverterUI.java (modified) (6 diffs)
- trunk/src/org/thestaticvoid/iriverter/DirectoryProgressDialog.java (added)
- trunk/src/org/thestaticvoid/iriverter/DirectoryScanner.java (added)
- trunk/src/org/thestaticvoid/iriverter/DoSomeShit.java (added)
- trunk/src/org/thestaticvoid/iriverter/FailedToDoSomeShit.java (added)
- trunk/src/org/thestaticvoid/iriverter/Job.java (modified) (1 diff)
- trunk/src/org/thestaticvoid/iriverter/ListOfFiles.java (deleted)
- trunk/src/org/thestaticvoid/iriverter/MPlayerPathDialog.java (modified) (1 diff)
- trunk/src/org/thestaticvoid/iriverter/MencoderCommand.java (modified) (4 diffs)
- trunk/src/org/thestaticvoid/iriverter/MencoderStreamParser.java (modified) (3 diffs)
- trunk/src/org/thestaticvoid/iriverter/ProgressDialog.java (modified) (10 diffs)
- trunk/src/org/thestaticvoid/iriverter/ProgressDialogInfo.java (modified) (1 diff)
- trunk/src/org/thestaticvoid/iriverter/SingleVideo.java (modified) (2 diffs)
- trunk/src/org/thestaticvoid/iriverter/VideoFileFilter.java (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/org/thestaticvoid/iriverter/Converter.java
r157 r158 1 /* 2 * Converter.java 3 * Copyright (C) 2005-2007 James Lee 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 * 02110-1301, USA. 19 * 20 * $Id$ 21 */ 1 22 package org.thestaticvoid.iriverter; 23 24 import java.util.*; 2 25 3 26 public class Converter extends Thread { 4 27 private Job[] jobs; 5 28 private ProgressDialogInfo progressDialogInfo; 6 private MencoderCommand currentCommand; 29 private DoSomeShit currentCommand; 30 private List failures; 7 31 8 32 public Converter(Job[] jobs, ProgressDialogInfo progressDialogInfo) { 9 33 this.jobs = jobs; 10 34 this.progressDialogInfo = progressDialogInfo; 35 failures = new ArrayList(); 11 36 } 12 37 13 38 public void run() { 14 39 for (int i = 0; i < jobs.length; i++) { 15 MencoderCommand[] mencoderCommands = jobs[i].getMencoderCommands(); 16 for (int j = 0; j < mencoderCommands.length; j++) { 17 currentCommand = mencoderCommands[j]; 18 currentCommand.run(progressDialogInfo); 40 progressDialogInfo.setCurrentJob(i + 1); 41 progressDialogInfo.setJobDescription(jobs[i].getDescription()); 42 43 try { 44 DoSomeShit[] shitToDo = jobs[i].getShitToDo(); 45 for (int j = 0; j < shitToDo.length; j++) { 46 currentCommand = shitToDo[j]; 47 currentCommand.run(progressDialogInfo); 48 } 49 } catch (FailedToDoSomeShit failed) { 50 failures.add(failed.getMessage()); 19 51 } 20 52 } … … 24 56 currentCommand.cancel(); 25 57 } 58 59 public String[] getFailures() { 60 return (String[]) failures.toArray(new String[]{}); 61 } 26 62 } trunk/src/org/thestaticvoid/iriverter/ConverterUI.java
r157 r158 43 43 private Menu videoSizeMenu; 44 44 private DropTarget target; 45 private String fileName;46 private Process proc;47 45 private ProgressDialog progressDialog; 48 46 … … 397 395 398 396 progressDialog = new ProgressDialog(shell, SWT.NONE); 397 progressDialog.setTotalJobs(jobs.length); 399 398 400 399 Converter converter = new Converter(jobs, progressDialog); … … 415 414 while (!canceled) 416 415 try { 417 proc =Runtime.getRuntime().exec(new String[]{MPlayerInfo.getMPlayerPath() + MPlayerInfo.MPLAYER_BIN, file});416 Runtime.getRuntime().exec(new String[]{MPlayerInfo.getMPlayerPath() + MPlayerInfo.MPLAYER_BIN, file}); 418 417 canceled = true; 419 418 } catch (IOException io) { 420 io.printStackTrace();419 Logger.logException(io); 421 420 canceled = true; 422 421 } catch (MPlayerNotFoundException mpe) { … … 436 435 } 437 436 438 /*if (e.getSource() == newDirectory || e.getSource() == newDirectoryTool)439 newDirectory(); */437 if (e.getSource() == newDirectory || e.getSource() == newDirectoryTool) 438 newDirectory(); 440 439 441 440 if (e.getSource() == newDVD || e.getSource() == newDVDTool) … … 661 660 File file = new File(files[i]); 662 661 663 if (file.isFile() && new VideoFileFilter().accept(file))662 /* if (file.isFile() && new VideoFileFilter().accept(file)) 664 663 newSingleVideo(files[i].toString()); 665 664 else if (file.isDirectory()) 666 665 if (new File(files[i] + File.separator + "VIDEO_TS").exists()) 667 666 newDVD().setDrive(files[i]); 668 /*else669 newDirectory().setInputDirectory(files[i]); */667 else 668 newDirectory().setInputDirectory(files[i]); */ 670 669 } 671 670 } … … 676 675 } 677 676 678 private SingleVideo newSingleVideo(String video) { 679 CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE); 680 SingleVideo singleVideo = null; 681 682 boolean canceled = false; 683 while (!canceled) 684 try { 685 singleVideo = new SingleVideo(tabFolder, SWT.NONE, tabItem, video, MPlayerInfo.getMPlayerPath()); 686 tabItem.setControl(singleVideo); 687 tabFolder.setSelection(tabItem); 688 tabChanged(false); 689 canceled = true; 690 } catch (MPlayerNotFoundException mpe) { 691 canceled = new MPlayerPathDialog(shell).open(); 692 } catch (Exception e) { 693 tabItem.dispose(); 694 canceled = true; 677 private void newSingleVideo(final String video) { 678 display.syncExec(new Runnable() { 679 public void run() { 680 CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE); 681 SingleVideo singleVideo = null; 682 683 boolean canceled = false; 684 while (!canceled) 685 try { 686 singleVideo = new SingleVideo(tabFolder, SWT.NONE, tabItem, video, MPlayerInfo.getMPlayerPath()); 687 tabItem.setControl(singleVideo); 688 tabFolder.setSelection(tabItem); 689 tabChanged(false); 690 canceled = true; 691 } catch (MPlayerNotFoundException mpe) { 692 canceled = new MPlayerPathDialog(shell).open(); 693 } catch (Exception e) { 694 tabItem.dispose(); 695 canceled = true; 696 } 695 697 } 696 697 return singleVideo; 698 } 699 700 /* private Directory newDirectory() { 701 CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE); 702 Directory directory = new Directory(tabFolder, SWT.NONE, tabItem); 703 tabItem.setControl(directory); 704 tabFolder.setSelection(tabItem); 705 tabChanged(false); 706 707 return directory; 708 } */ 698 }); 699 } 700 701 private void newDirectory() { 702 final DirectoryScanner directoryScanner = new AddDirectoryDialog(shell, SWT.NONE).open(); 703 if (directoryScanner != null) { 704 final DirectoryProgressDialog directoryProgressDialog = new DirectoryProgressDialog(shell, SWT.NONE); 705 new Thread() { 706 public void run() { 707 String[] videos = directoryScanner.getVideos(); 708 directoryProgressDialog.setMaximum(videos.length); 709 for (int i = 0; i < videos.length; i++) { 710 directoryProgressDialog.setCurrent(i + 1); 711 newSingleVideo(videos[i]); 712 } 713 directoryProgressDialog.close(); 714 } 715 }.start(); 716 directoryProgressDialog.open(); 717 } 718 } 709 719 710 720 private DVD newDVD() { trunk/src/org/thestaticvoid/iriverter/Job.java
r157 r158 24 24 public interface Job { 25 25 public String getDescription(); 26 public MencoderCommand[] getMencoderCommands();26 public DoSomeShit[] getShitToDo(); 27 27 } trunk/src/org/thestaticvoid/iriverter/MPlayerPathDialog.java
r152 r158 35 35 dialog.setFilterPath(ConverterOptions.getMPlayerPath()); 36 36 dialog.setText("MPlayer Path"); 37 dialog.setMessage("Select the path to MPlayer");37 dialog.setMessage("Select the path to 'mplayer'"); 38 38 String directory = dialog.open(); 39 39 if (directory != null) trunk/src/org/thestaticvoid/iriverter/MencoderCommand.java
r157 r158 25 25 import java.io.*; 26 26 27 public class MencoderCommand {27 public class MencoderCommand implements DoSomeShit { 28 28 private String description; 29 29 private String[] command; … … 35 35 } 36 36 37 public int run(ProgressDialogInfo progressDialogInfo){37 public void run(ProgressDialogInfo progressDialogInfo) throws FailedToDoSomeShit { 38 38 int exitCode = 1; 39 39 … … 45 45 commandStr += command[i] + " "; 46 46 Logger.logMessage(description + " " + commandStr, Logger.INFO); 47 48 progressDialogInfo.setSubdescription(description); 47 49 48 50 try { … … 59 61 } 60 62 61 return exitCode; 63 if (exitCode > 0) 64 throw new FailedToDoSomeShit(description); 62 65 } 63 66 trunk/src/org/thestaticvoid/iriverter/MencoderStreamParser.java
r157 r158 27 27 public class MencoderStreamParser extends Thread { 28 28 private ProgressDialogInfo progressDialogInfo; 29 private String status;30 29 private BufferedReader input; 31 30 private String inputLine = "", lengthLine = ""; … … 34 33 public MencoderStreamParser(ProgressDialogInfo progressDialogInfo) { 35 34 this.progressDialogInfo = progressDialogInfo; 36 status = progressDialogInfo.getStatus();37 35 } 38 36 … … 83 81 String timeRemaining = inputLine.substring(inputLine.indexOf("Trem:") + 6, inputLine.indexOf("min")).trim(); 84 82 if (timeRemaining.equals("0")) 85 timeRemaining = " less than a minute remaining";83 timeRemaining = "Less than a minute remaining."; 86 84 else if (timeRemaining.equals("1")) 87 timeRemaining = " about " + timeRemaining + " minute remaining";85 timeRemaining = "About " + timeRemaining + " minute remaining."; 88 86 else 89 timeRemaining = " about " + timeRemaining + " minutes remaining";87 timeRemaining = "About " + timeRemaining + " minutes remaining."; 90 88 91 progressDialogInfo.setStatus(status + " at " + inputLine.substring(inputLine.indexOf(")") + 1, inputLine.indexOf("fps")).trim() + " FPS with " + timeRemaining); 89 progressDialogInfo.setMiscellaneous1(timeRemaining); 90 progressDialogInfo.setMiscellaneous2(inputLine.substring(inputLine.indexOf(")") + 1, inputLine.indexOf("fps")).trim() + " frames per second"); 92 91 } 93 92 trunk/src/org/thestaticvoid/iriverter/ProgressDialog.java
r157 r158 30 30 public class ProgressDialog extends Dialog implements SelectionListener, ProgressDialogInfo { 31 31 private Shell shell; 32 private Label header, inputVideoLabel, inputVideo, outputVideoLabel, outputVideo, status;32 private Label header, jobDescription, subdescription, miscellaneous1, miscellaneous2; 33 33 private ProgressBar progressBar; 34 private String syncInputVideo, syncOutputVideo, syncStatus;35 34 private Button dismiss; 36 private int currentJob, totalJobs , syncPercentComplete;35 private int currentJob, totalJobs; 37 36 38 37 public ProgressDialog(Shell parent, int style) { … … 51 50 52 51 header = new Label(shell, SWT.NONE); 53 header.setText(" Converting");52 header.setText("Job"); 54 53 FontData[] fontData = header.getFont().getFontData(); 55 54 fontData[0].setStyle(SWT.BOLD); … … 59 58 header.setLayoutData(gridData); 60 59 61 Composite infoComp = new Composite(shell, SWT.NONE); 60 jobDescription = new Label(shell, SWT.NONE); 61 fontData = jobDescription.getFont().getFontData(); 62 fontData[0].setStyle(SWT.BOLD); 63 jobDescription.setFont(new Font(getParent().getDisplay(), fontData)); 64 65 progressBar = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH); 66 progressBar.setMaximum(100); 67 progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 68 69 subdescription = new Label(shell, SWT.NONE); 70 fontData = subdescription.getFont().getFontData(); 71 fontData[0].setStyle(SWT.ITALIC); 72 subdescription.setFont(new Font(getParent().getDisplay(), fontData)); 73 74 Composite details = new Composite(shell, SWT.NONE); 62 75 gridLayout = new GridLayout(); 63 76 gridLayout.horizontalSpacing = 6; … … 65 78 gridLayout.marginHeight = 0; 66 79 gridLayout.marginWidth = 0; 67 gridLayout.numColumns = 2; 68 infoComp.setLayout(gridLayout); 69 infoComp.setLayoutData(new GridData(GridData.FILL_BOTH)); 80 details.setLayout(gridLayout); 81 details.setLayoutData(new GridData(GridData.FILL_BOTH)); 70 82 71 inputVideoLabel = new Label(infoComp, SWT.NONE); 72 inputVideoLabel.setText("Input:"); 73 fontData = inputVideoLabel.getFont().getFontData(); 74 fontData[0].setStyle(SWT.BOLD); 75 inputVideoLabel.setFont(new Font(getParent().getDisplay(), fontData)); 76 77 inputVideo = new Label(infoComp, SWT.NONE); 78 79 outputVideoLabel = new Label(infoComp, SWT.NONE); 80 outputVideoLabel.setText("Output:"); 81 outputVideoLabel.setFont(new Font(getParent().getDisplay(), fontData)); 82 83 outputVideo = new Label(infoComp, SWT.NONE); 84 85 progressBar = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH); 86 progressBar.setMaximum(100); 87 progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 88 89 status = new Label(shell, SWT.NONE); 90 fontData = status.getFont().getFontData(); 91 fontData[0].setStyle(SWT.ITALIC); 92 status.setFont(new Font(getParent().getDisplay(), fontData)); 83 miscellaneous1 = new Label(details, SWT.NONE); 84 miscellaneous2 = new Label(details, SWT.NONE); 93 85 94 86 dismiss = new Button(shell, SWT.PUSH); … … 122 114 } 123 115 124 public synchronized void complete(final boolean success) { 125 Display.getDefault().syncExec(new Runnable() { 126 public void run() { 127 if (!success) { 128 MessageBox dialog = new MessageBox(getParent().getShell(), SWT.ICON_ERROR); 129 dialog.setText("There Was an Error While Converting"); 130 dialog.setMessage("An error occurred while converting " + inputVideo.getText()); 131 dialog.open(); 132 } 133 134 shell.setText("Complete"); 135 header.setText("Complete"); 136 inputVideoLabel.setText(""); 137 inputVideo.setText(""); 138 outputVideoLabel.setText(""); 139 outputVideo.setText(""); 140 progressBar.setSelection(100); 141 status.setText(""); 142 dismiss.setText("Close"); 143 } 144 }); 145 } 146 147 public synchronized void setCurrentJob(int currentJob) { 116 public void setCurrentJob(int currentJob) { 148 117 this.currentJob = currentJob; 149 118 … … 151 120 public void run() { 152 121 if (!shell.isDisposed() && !header.isDisposed()) { 153 shell.setText(" Converting" + ProgressDialog.this.currentJob + " of " + totalJobs);154 header.setText(" Converting" + ProgressDialog.this.currentJob + " of " + totalJobs);122 shell.setText("Job " + ProgressDialog.this.currentJob + " of " + totalJobs); 123 header.setText("Job " + ProgressDialog.this.currentJob + " of " + totalJobs); 155 124 header.pack(); 156 125 } … … 159 128 } 160 129 161 public synchronizedvoid setTotalJobs(int totalJobs) {130 public void setTotalJobs(int totalJobs) { 162 131 this.totalJobs = totalJobs; 163 132 } 164 133 165 public synchronized void setInputVideo(String inputVideo) { 166 syncInputVideo = inputVideo; 167 134 public synchronized void setJobDescription(final String jobDescription) { 168 135 Display.getDefault().syncExec(new Runnable() { 169 136 public void run() { 170 if (!ProgressDialog.this. inputVideo.isDisposed()) {171 ProgressDialog.this. inputVideo.setText(syncInputVideo);172 ProgressDialog.this. inputVideo.pack();137 if (!ProgressDialog.this.jobDescription.isDisposed()) { 138 ProgressDialog.this.jobDescription.setText(jobDescription); 139 ProgressDialog.this.jobDescription.pack(); 173 140 } 174 141 } … … 176 143 } 177 144 178 public synchronized void setOutputVideo(String outputVideo) { 179 syncOutputVideo = outputVideo; 180 145 public void setPercentComplete(final int percentComplete) { 181 146 Display.getDefault().syncExec(new Runnable() { 182 147 public void run() { 183 if (!ProgressDialog.this.outputVideo.isDisposed()) { 184 ProgressDialog.this.outputVideo.setText(syncOutputVideo); 185 ProgressDialog.this.outputVideo.pack(); 148 if (!progressBar.isDisposed()) 149 progressBar.setSelection(percentComplete); 150 } 151 }); 152 } 153 154 public void setSubdescription(final String subdescription) { 155 Display.getDefault().syncExec(new Runnable() { 156 public void run() { 157 if (!ProgressDialog.this.subdescription.isDisposed()) { 158 ProgressDialog.this.subdescription.setText(subdescription); 159 ProgressDialog.this.subdescription.pack(); 186 160 } 187 161 } … … 189 163 } 190 164 191 public synchronized void setPercentComplete(int percentComplete) { 192 syncPercentComplete = percentComplete; 193 165 public void setMiscellaneous1(final String miscellaneous1) { 194 166 Display.getDefault().syncExec(new Runnable() { 195 167 public void run() { 196 if (!progressBar.isDisposed()) 197 progressBar.setSelection(syncPercentComplete); 198 } 199 }); 200 } 201 202 public synchronized void setStatus(String status) { 203 syncStatus = status; 204 205 Display.getDefault().syncExec(new Runnable() { 206 public void run() { 207 if (!ProgressDialog.this.status.isDisposed()) { 208 ProgressDialog.this.status.setText(syncStatus); 209 ProgressDialog.this.status.pack(); 168 if (!ProgressDialog.this.miscellaneous1.isDisposed()) { 169 ProgressDialog.this.miscellaneous1.setText(miscellaneous1); 170 ProgressDialog.this.miscellaneous1.pack(); 210 171 } 211 172 } … … 213 174 } 214 175 215 public synchronized String getStatus() {176 public void setMiscellaneous2(final String miscellaneous2) { 216 177 Display.getDefault().syncExec(new Runnable() { 217 178 public void run() { 218 if (!status.isDisposed()) 219 syncStatus = status.getText(); 179 if (!ProgressDialog.this.miscellaneous2.isDisposed()) { 180 ProgressDialog.this.miscellaneous2.setText(miscellaneous2); 181 ProgressDialog.this.miscellaneous2.pack(); 182 } 220 183 } 221 184 }); 222 223 return syncStatus;224 185 } 225 186 } trunk/src/org/thestaticvoid/iriverter/ProgressDialogInfo.java
r157 r158 23 23 24 24 public interface ProgressDialogInfo { 25 public void complete(boolean success);26 25 public void setCurrentJob(int currentJob); 27 26 public void setTotalJobs(int totalJobs); 28 public void setInputVideo(String inputVideo); 29 public void setOutputVideo(String outputVideo); 27 public void setJobDescription(String jobDescription); 30 28 public void setPercentComplete(int percentComplete); 31 public void setStatus(String status); 32 public String getStatus(); 29 public void setSubdescription(String subdescription); 30 public void setMiscellaneous1(String miscellaneous1); 31 public void setMiscellaneous2(String miscellaneous2); 33 32 } trunk/src/org/thestaticvoid/iriverter/SingleVideo.java
r157 r158 132 132 } 133 133 134 public MencoderCommand[] getMencoderCommands() {135 java.util.List mencoderCommandsList= new ArrayList();134 public DoSomeShit[] getShitToDo() { 135 java.util.List shitToDo = new ArrayList(); 136 136 137 137 138 138 java.util.List commandList = MencoderCommand.prepareBaseCommandList(inputVideo, getOutputVideo(), mplayerPath, inputVideoInfo, 0); 139 139 String[] command = (String[]) commandList.toArray(new String[]{}); 140 mencoderCommandsList.add(new MencoderCommand("Encoding...", command));140 shitToDo.add(new MencoderCommand("Encoding...", command)); 141 141 142 142 int length = inputVideoInfo.getLength(); … … 154 154 command = new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + (length / pieces) * i, "-endpos", "" + (length / pieces)}; 155 155 156 mencoderCommandsList.add(new MencoderCommand("Splitting Part " + (i + 1) + " of " + pieces, command));156 shitToDo.add(new MencoderCommand("Splitting Part " + (i + 1) + " of " + pieces, command)); 157 157 } 158 158 } 159 159 160 return ( MencoderCommand[]) mencoderCommandsList.toArray(new MencoderCommand[]{});160 return (DoSomeShit[]) shitToDo.toArray(new DoSomeShit[]{}); 161 161 } 162 162 }
