#!/usr/bin/ruby puts 'Welcome to Sensible Cinema...' require 'rubygems' require 'sane' require File.dirname(__FILE__) + '/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" ).on_clicked { self.close go_sc } b.set_bounds(44,120,200,23) panel.add b c=JButton.new( "Copy edited DVD to Hard Drive" ) c.on_clicked { drive = choose_dvd_drive fc = JFileChooser.new fc.setFileSelectionMode(nil) fc.set_dialog_title "Please pick a DVD descriptor file" fc.set_current_directory(JFile.new( __dir__ + "/../zamples/scene_lists/dvds")) descriptor_path = fc.go descriptors = YAML.load_file descriptor_path fc = JFileChooser.new # LODO allow for spaces in save to file fc.set_dialog_title "Pick a location to save 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 + save_to_file_name)) save_to = fc.go # LODO don't pop up those annoying windows dvd_title_track = descriptors["dvd_title_track"] bat_file = VLCProgrammer.convert_to_full_xspf(descriptors, save_to, drive) temp_dir = Dir.tmpdir temp_file = temp_dir + '/' + 'convert_it.bat' File.write(temp_file, bat_file) p 'running', temp_file # TODO change title to "running" or something, while it runs... if !ARGV.find{|a| a == '--test'} && system(temp_file) JOptionPane.showMessageDialog(nil, " Done--you may now watch file #{save_to}.ps in VLC player", "Done!", JOptionPane::ERROR_MESSAGE) command = "explorer /e,/select,\"#{File.expand_path(save_to).gsub('/', '\\')}.ps\"" system command 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 # TODO warn if they don't have VLC installed... # LODO warn if they will overwrite a file } c.set_bounds(44,180,200,23) panel.add c exit = JButton.new("Exit").on_clicked { self.close } exit.set_bounds(44,320,200,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'} end def exit_and_close JOptionPane.showMessageDialog(nil, "exiting", "exiting", JOptionPane::ERROR_MESSAGE) close exit end def choose_dvd_drive opticals = get_dvd_drives opticals.map!{|d| d.Name + "\\" + " (" + d.VolumeName + ")"} if opticals.length != 1 dialog = GetDisk.new(self, opticals) dialog.show selected = dialog.selected else selected = opticals[0] end return selected[0..2] end def get_drive_with_most_space 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 "Select DVD drive" # put something in index 0 options_array.each{|drive| box.add_item drive } add box pack end end end SensibleSwing::MainWindow.new.set_visible true puts 'Please use the Sensible Cinema GUI window'