Sha256: 9226adbc3fc5113f638a4eeb55d64e155ee76b2496b8cd8d8420ba3322bba660

Contents?: true

Size: 1.93 KB

Versions: 31

Compression:

Stored size: 1.93 KB

Contents

#!/usr/bin/env ruby

$VERBOSE=true

$: << "../lib"

require 'Qt'
system('rbuic -o zipdialogui.rb zipdialogui.ui')
require 'zipdialogui.rb'
require 'zip/zip'



a = Qt::Application.new(ARGV)

class ZipDialog < ZipDialogUI


  def initialize()
    super()
    connect(child('add_button'), SIGNAL('clicked()'),
            self, SLOT('add_files()'))
    connect(child('extract_button'), SIGNAL('clicked()'),
            self, SLOT('extract_files()'))
  end

  def zipfile(&proc)
    Zip::ZipFile.open(@zip_filename, &proc)
  end

  def each(&proc)
    Zip::ZipFile.foreach(@zip_filename, &proc)
  end
  
  def refresh()
    lv = child("entry_list_view")
    lv.clear
    each { 
      |e|
      lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
    }
  end

    
  def load(zipfile)
    @zip_filename = zipfile
    refresh
  end

  def add_files
    l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
    zipfile { 
      |zf| 
      l.each { 
        |path|
        zf.add(File.basename(path), path)
      }
    }
    refresh
  end

  def extract_files
    selected_items = []
    unselected_items = []
    lv_item = entry_list_view.first_child
    while (lv_item)
      if entry_list_view.is_selected(lv_item)
        selected_items << lv_item.text(0)
      else
        unselected_items << lv_item.text(0)
      end
      lv_item = lv_item.next_sibling
    end
    puts "selected_items.size = #{selected_items.size}"
    puts "unselected_items.size = #{unselected_items.size}"
    items = selected_items.size > 0 ? selected_items : unselected_items
    puts "items.size = #{items.size}"

    d = Qt::FileDialog.get_existing_directory(nil, self)
    if (!d)
      puts "No directory chosen"
    else
      zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
    end
    
  end

  slots 'add_files()', 'extract_files()'
end

if !ARGV[0]
  puts "usage: #{$0} zipname"
  exit
end

zd = ZipDialog.new
zd.load(ARGV[0])

a.mainWidget = zd
zd.show()
a.exec()

Version data entries

31 entries across 31 versions & 11 rubygems

Version Path
IronDigital-rubyzip-0.9.2 samples/qtzip.rb
agraham-rubyzip-0.9.1 samples/qtzip.rb
erawk-rubyzip-0.9.1 samples/qtzip.rb
erawk-rubyzip-0.9.2 samples/qtzip.rb
expectedbehavior-rubyzip-0.9.1.2 samples/qtzip.rb
febeling-rubyzip-0.9.2 samples/qtzip.rb
mksm-rubyzip-0.9.3 samples/qtzip.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.9/samples/qtzip.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/qtzip.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/qtzip.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/qtzip.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/qtzip.rb
rubyzip-0.9.9 samples/qtzip.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/qtzip.rb
rubyzip-0.9.8 samples/qtzip.rb
rubyzip-0.9.7 samples/qtzip.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/qtzip.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/qtzip.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/qtzip.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/qtzip.rb