#!/usr/bin/ruby # so my editor will like it... puts 'Loading Sensible Cinema...' require 'rubygems' require 'sane' # File.write require File.dirname(__FILE__) + '/../lib/swing_helpers' load File.dirname(__FILE__) + '/sensible-cinema-cli' require 'tmpdir' require 'ruby-wmi' module SensibleSwing class MainWindow < JFrame def initialize super "Sensible-Cinema" setDefaultCloseOperation JFrame::EXIT_ON_CLOSE panel = JPanel.new panel.set_layout nil setSize 350,400 add panel # why can't I just slap these down? jlabel = JLabel.new 'Welcome to Sensible Cinema' happy = Font.new("Tahoma", Font::PLAIN, 11) jlabel.setFont(happy) jlabel.set_bounds(44,44,136,14) panel.add jlabel b = JButton.new( "Play Hulu, Youtube, or a DVD (Tracking)" ).on_clicked { self.close go_sc } button_width = 230 b.set_bounds(44,120,button_width,23) panel.add b c=JButton.new( "Copy edited DVD to Hard Drive" ) c.on_clicked { do_copy_dvd_to_hard_drive true } c.set_bounds(44,220,button_width,23) panel.add c d=JButton.new( "Play edited DVD with VLC" ) d.on_clicked { do_copy_dvd_to_hard_drive false } d.set_bounds(44,180,button_width,23) panel.add d @exit = JButton.new("Exit").on_clicked { self.close } @exit.set_bounds(44,320,button_width,23) panel.add @exit reload = JButton.new( "reload code" ).on_clicked { eval File.read(__FILE__), nil, __FILE__ p 're-evaled it' } reload.set_bounds(44,280,200,23) panel.add reload if ARGV.find{|a| a == '--test'} @buttons = [b,c,d,@exit] end def do_copy_dvd_to_hard_drive should_save_file drive = choose_dvd_drive fc = JFileChooser.new fc.setFileSelectionMode(nil) fc.set_dialog_title "Please pick a DVD Edit List File" fc.set_current_directory(JFile.new( __dir__ + "/../zamples/scene_lists/dvds")) edit_list_path = fc.go descriptors = YAML.load_file edit_list_path if should_save_file fc = JFileChooser.new # LODO allow for spaces in save to file fc.set_dialog_title "Pick where to save the file to" save_to_file_name = ((descriptors["title"] || "my dvd") + ' edited').gsub(' ', '_').gsub( /\W/, '') # no punctuation for now... fc.setSelectedFile(JFile.new(get_drive_with_most_space_with_slash + save_to_file_name)) save_to = fc.go else save_to = nil end # LODO don't pop up those annoying windows dvd_title_track = descriptors["dvd_title_track"] bat_file_or_xspf = VLCProgrammer.convert_to_full_xspf(descriptors, save_to, drive, dvd_title_track) temp_dir = Dir.tmpdir if should_save_file temp_file = temp_dir + '/' + 'convert_it.bat' File.write(temp_file, bat_file_or_xspf) # allow our popups to still be serviced while it is running Thread.new { run_copy_commands temp_file, save_to } else temp_file = temp_dir + '/' + 'vlc.xspf' File.write(temp_file, bat_file_or_xspf) command = "vlc \"#{temp_file.to_filename}\" vlc://quit" p 'running', command system(c) # blocks the current window while running... end # TODO warn if they don't have VLC installed, with instructions... # LODO warn if they will overwrite a file in the end end def run_copy_commands temp_file, save_to popup = ModeLessDialog.new("Running the encoding in the background...\n" + "This could take quite awhile, and will prompt you when it is done.\n" + "It may also cause small popup ballon dialogs to appear.") p 'running', temp_file, 'to ' + save_to + '.ps' @buttons.each{|b| b.set_enabled false} success = system(temp_file) unless ARGV.find{|a| a == '--test'} @buttons.each{|b| b.set_enabled true} popup.dispose if success JOptionPane.showMessageDialog(nil, " Done--you may now watch file #{save_to}.ps in VLC player", "Done!", JOptionPane::INFORMATION_MESSAGE) show_file = "explorer /e,/select,\"#{File.expand_path(save_to).to_filename}.ps\"" system show_file File.delete temp_file self.close else JOptionPane.showMessageDialog(nil, " Failed--please examine #{temp_file} and screen output and report back!", "Failed", JOptionPane::ERROR_MESSAGE) end end def choose_dvd_drive opticals = get_dvd_drives opticals.map!{|d| d.Name + "\\" + " (" + (d.VolumeName || 'empty') + ")"} if opticals.length != 1 dialog = GetDisk.new(self, opticals) dialog.setSize 200,125 dialog.show selected = dialog.selected else selected = opticals[0] end if selected return selected[0..2] else puts 'did not select drive' java.lang.System.exit 1 end end def get_drive_with_most_space_with_slash disks = WMI::Win32_LogicalDisk.find(:all) out = disks.sort_by{|d| d.FreeSpace.to_i}[-1].Name + "\\" out end private def get_dvd_drives disks = WMI::Win32_LogicalDisk.find(:all) disks.select{|d| d.Description =~ /CD-ROM/} # hope this works... end end class GetDisk < JDialog attr_reader :selected def initialize parent, options_array super parent, true box = JComboBox.new box.add_action_listener do |e| idx = box.get_selected_index if idx != 0 @selected = box.get_selected_item dispose end end box.add_item "Click to select DVD drive" # put something in index 0 options_array.each{|drive| box.add_item drive } add box pack end end end require 'os' class String def to_filename if OS.windows? self.gsub('/', "\\") else self end end end SensibleSwing::MainWindow.new.set_visible true puts 'Please use the Sensible Cinema GUI window popup'