Changeset 158

Show
Ignore:
Timestamp:
04/13/07 16:28:10 (2 years ago)
Author:
jlee
Message:

New ProgressDialog?; new directory handling; DnD still needs to be fixed now; other job types still need work

Files:

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 */ 
    122package org.thestaticvoid.iriverter; 
     23 
     24import java.util.*; 
    225 
    326public class Converter extends Thread { 
    427        private Job[] jobs; 
    528        private ProgressDialogInfo progressDialogInfo; 
    6         private MencoderCommand currentCommand; 
     29        private DoSomeShit currentCommand; 
     30        private List failures; 
    731         
    832        public Converter(Job[] jobs, ProgressDialogInfo progressDialogInfo) { 
    933                this.jobs = jobs; 
    1034                this.progressDialogInfo = progressDialogInfo; 
     35                failures = new ArrayList(); 
    1136        } 
    1237         
    1338        public void run() { 
    1439                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()); 
    1951                        } 
    2052                } 
     
    2456                currentCommand.cancel(); 
    2557        } 
     58         
     59        public String[] getFailures() { 
     60                return (String[]) failures.toArray(new String[]{}); 
     61        } 
    2662} 
  • trunk/src/org/thestaticvoid/iriverter/ConverterUI.java

    r157 r158  
    4343        private Menu videoSizeMenu; 
    4444        private DropTarget target; 
    45         private String fileName; 
    46         private Process proc; 
    4745        private ProgressDialog progressDialog; 
    4846         
     
    397395                         
    398396                        progressDialog = new ProgressDialog(shell, SWT.NONE); 
     397                        progressDialog.setTotalJobs(jobs.length); 
    399398                         
    400399                        Converter converter = new Converter(jobs, progressDialog); 
     
    415414                                while (!canceled) 
    416415                                        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}); 
    418417                                                canceled = true; 
    419418                                        } catch (IOException io) { 
    420                                                 io.printStackTrace(); 
     419                                                Logger.logException(io); 
    421420                                                canceled = true; 
    422421                                        } catch (MPlayerNotFoundException mpe) { 
     
    436435                } 
    437436                 
    438                 /*if (e.getSource() == newDirectory || e.getSource() == newDirectoryTool) 
    439                         newDirectory();*/ 
     437                if (e.getSource() == newDirectory || e.getSource() == newDirectoryTool) 
     438                        newDirectory(); 
    440439                 
    441440                if (e.getSource() == newDVD || e.getSource() == newDVDTool) 
     
    661660                                File file = new File(files[i]); 
    662661                                 
    663                                 if (file.isFile() && new VideoFileFilter().accept(file)) 
     662                                /* if (file.isFile() && new VideoFileFilter().accept(file)) 
    664663                                        newSingleVideo(files[i].toString()); 
    665664                                else if (file.isDirectory()) 
    666665                                        if (new File(files[i] + File.separator + "VIDEO_TS").exists()) 
    667666                                                newDVD().setDrive(files[i]); 
    668                                         /* else 
    669                                                 newDirectory().setInputDirectory(files[i]);*/ 
     667                                        else 
     668                                                newDirectory().setInputDirectory(files[i]); */ 
    670669                        } 
    671670                }                
     
    676675        } 
    677676         
    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                                        } 
    695697                        } 
    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        } 
    709719         
    710720        private DVD newDVD() { 
  • trunk/src/org/thestaticvoid/iriverter/Job.java

    r157 r158  
    2424public interface Job { 
    2525        public String getDescription(); 
    26         public MencoderCommand[] getMencoderCommands(); 
     26        public DoSomeShit[] getShitToDo(); 
    2727} 
  • trunk/src/org/thestaticvoid/iriverter/MPlayerPathDialog.java

    r152 r158  
    3535                dialog.setFilterPath(ConverterOptions.getMPlayerPath()); 
    3636                dialog.setText("MPlayer Path"); 
    37                 dialog.setMessage("Select the path to MPlayer"); 
     37                dialog.setMessage("Select the path to 'mplayer'"); 
    3838                String directory = dialog.open(); 
    3939                if (directory != null) 
  • trunk/src/org/thestaticvoid/iriverter/MencoderCommand.java

    r157 r158  
    2525import java.io.*; 
    2626 
    27 public class MencoderCommand
     27public class MencoderCommand implements DoSomeShit
    2828        private String description; 
    2929        private String[] command; 
     
    3535        } 
    3636         
    37         public int run(ProgressDialogInfo progressDialogInfo)
     37        public void run(ProgressDialogInfo progressDialogInfo) throws FailedToDoSomeShit
    3838                int exitCode = 1; 
    3939                 
     
    4545                        commandStr += command[i] + " "; 
    4646                Logger.logMessage(description + " " + commandStr, Logger.INFO); 
     47                 
     48                progressDialogInfo.setSubdescription(description); 
    4749                 
    4850                try { 
     
    5961                } 
    6062                 
    61                 return exitCode; 
     63                if (exitCode > 0) 
     64                        throw new FailedToDoSomeShit(description); 
    6265        } 
    6366         
  • trunk/src/org/thestaticvoid/iriverter/MencoderStreamParser.java

    r157 r158  
    2727public class MencoderStreamParser extends Thread { 
    2828        private ProgressDialogInfo progressDialogInfo; 
    29         private String status; 
    3029        private BufferedReader input; 
    3130        private String inputLine = "", lengthLine = ""; 
     
    3433        public MencoderStreamParser(ProgressDialogInfo progressDialogInfo) { 
    3534                this.progressDialogInfo = progressDialogInfo; 
    36                 status = progressDialogInfo.getStatus(); 
    3735        } 
    3836         
     
    8381                                        String timeRemaining = inputLine.substring(inputLine.indexOf("Trem:") + 6, inputLine.indexOf("min")).trim(); 
    8482                                        if (timeRemaining.equals("0")) 
    85                                                 timeRemaining = "less than a minute remaining"; 
     83                                                timeRemaining = "Less than a minute remaining."; 
    8684                                        else if (timeRemaining.equals("1")) 
    87                                                 timeRemaining = "about " + timeRemaining + " minute remaining"; 
     85                                                timeRemaining = "About " + timeRemaining + " minute remaining."; 
    8886                                        else 
    89                                                 timeRemaining = "about " + timeRemaining + " minutes remaining"; 
     87                                                timeRemaining = "About " + timeRemaining + " minutes remaining."; 
    9088                                         
    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"); 
    9291                                } 
    9392                                 
  • trunk/src/org/thestaticvoid/iriverter/ProgressDialog.java

    r157 r158  
    3030public class ProgressDialog extends Dialog implements SelectionListener, ProgressDialogInfo { 
    3131        private Shell shell; 
    32         private Label header, inputVideoLabel, inputVideo, outputVideoLabel, outputVideo, status
     32        private Label header, jobDescription, subdescription, miscellaneous1, miscellaneous2
    3333        private ProgressBar progressBar; 
    34         private String syncInputVideo, syncOutputVideo, syncStatus; 
    3534        private Button dismiss; 
    36         private int currentJob, totalJobs, syncPercentComplete
     35        private int currentJob, totalJobs
    3736         
    3837        public ProgressDialog(Shell parent, int style) { 
     
    5150                 
    5251                header = new Label(shell, SWT.NONE); 
    53                 header.setText("Converting"); 
     52                header.setText("Job"); 
    5453                FontData[] fontData = header.getFont().getFontData(); 
    5554                fontData[0].setStyle(SWT.BOLD); 
     
    5958                header.setLayoutData(gridData); 
    6059                 
    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); 
    6275                gridLayout = new GridLayout(); 
    6376                gridLayout.horizontalSpacing = 6; 
     
    6578                gridLayout.marginHeight = 0; 
    6679                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)); 
    7082                 
    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); 
    9385                 
    9486                dismiss = new Button(shell, SWT.PUSH); 
     
    122114        } 
    123115         
    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) { 
    148117                this.currentJob = currentJob; 
    149118                 
     
    151120                        public void run() { 
    152121                                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); 
    155124                                        header.pack(); 
    156125                                } 
     
    159128        } 
    160129         
    161         public synchronized void setTotalJobs(int totalJobs) { 
     130        public void setTotalJobs(int totalJobs) { 
    162131                this.totalJobs = totalJobs; 
    163132        } 
    164133         
    165         public synchronized void setInputVideo(String inputVideo) { 
    166                 syncInputVideo = inputVideo; 
    167  
     134        public synchronized void setJobDescription(final String jobDescription) { 
    168135                Display.getDefault().syncExec(new Runnable() { 
    169136                        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(); 
    173140                                } 
    174141                        } 
     
    176143        } 
    177144         
    178         public synchronized void setOutputVideo(String outputVideo) { 
    179                 syncOutputVideo = outputVideo; 
    180                  
     145        public void setPercentComplete(final int percentComplete) { 
    181146                Display.getDefault().syncExec(new Runnable() { 
    182147                        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(); 
    186160                                } 
    187161                        } 
     
    189163        } 
    190164         
    191         public synchronized void setPercentComplete(int percentComplete) { 
    192                 syncPercentComplete = percentComplete; 
    193                  
     165        public void setMiscellaneous1(final String miscellaneous1) { 
    194166                Display.getDefault().syncExec(new Runnable() { 
    195167                        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(); 
    210171                                } 
    211172                        } 
     
    213174        } 
    214175         
    215         public synchronized String getStatus() {                
     176        public void setMiscellaneous2(final String miscellaneous2) { 
    216177                Display.getDefault().syncExec(new Runnable() { 
    217178                        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                                } 
    220183                        } 
    221184                }); 
    222                  
    223                 return syncStatus; 
    224185        } 
    225186} 
  • trunk/src/org/thestaticvoid/iriverter/ProgressDialogInfo.java

    r157 r158  
    2323 
    2424public interface ProgressDialogInfo { 
    25         public void complete(boolean success); 
    2625        public void setCurrentJob(int currentJob); 
    2726        public void setTotalJobs(int totalJobs); 
    28         public void setInputVideo(String inputVideo); 
    29         public void setOutputVideo(String outputVideo); 
     27        public void setJobDescription(String jobDescription); 
    3028        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); 
    3332} 
  • trunk/src/org/thestaticvoid/iriverter/SingleVideo.java

    r157 r158  
    132132        } 
    133133         
    134         public MencoderCommand[] getMencoderCommands() { 
    135                 java.util.List mencoderCommandsList = new ArrayList(); 
     134        public DoSomeShit[] getShitToDo() { 
     135                java.util.List shitToDo = new ArrayList(); 
    136136                 
    137137                 
    138138                java.util.List commandList = MencoderCommand.prepareBaseCommandList(inputVideo, getOutputVideo(), mplayerPath, inputVideoInfo, 0); 
    139139                String[] command = (String[]) commandList.toArray(new String[]{}); 
    140                 mencoderCommandsList.add(new MencoderCommand("Encoding...", command)); 
     140                shitToDo.add(new MencoderCommand("Encoding...", command)); 
    141141                 
    142142                int length = inputVideoInfo.getLength(); 
     
    154154                                        command = new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + (length / pieces) * i, "-endpos", "" + (length / pieces)}; 
    155155                                 
    156                                 mencoderCommandsList.add(new MencoderCommand("Splitting Part " + (i + 1) + " of " + pieces, command)); 
     156                                shitToDo.add(new MencoderCommand("Splitting Part " + (i + 1) + " of " + pieces, command)); 
    157157                        } 
    158158                } 
    159159                 
    160                 return (MencoderCommand[]) mencoderCommandsList.toArray(new MencoderCommand[]{}); 
     160                return (DoSomeShit[]) shitToDo.toArray(new DoSomeShit[]{}); 
    161161        } 
    162162}