Sha256: 221c312cbe76c9d6a4b8f1a035ded54afc9e29aab692db7449e0786cd88a12af

Contents?: true

Size: 1.89 KB

Versions: 38

Compression:

Stored size: 1.89 KB

Contents

#!/usr/bin/env ruby

$VERBOSE = true

$: << '../lib'

require 'Qt'
system('rbuic -o zipdialogui.rb zipdialogui.ui')
require 'zipdialogui.rb'
require '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::File.open(@zip_filename, &proc)
  end

  def each(&proc)
    Zip::File.foreach(@zip_filename, &proc)
  end

  def refresh
    lv = child('entry_list_view')
    lv.clear
    each do |e|
      lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
    end
  end

  def load(zipfile)
    @zip_filename = zipfile
    refresh
  end

  def add_files
    l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
    zipfile do |zf|
      l.each do |path|
        zf.add(File.basename(path), path)
      end
    end
    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

unless 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

38 entries across 32 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.9 vendor/bundle/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.8 vendor/bundle/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.7 vendor/bundle/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/qtzip.rb
tdiary-5.0.6 vendor/bundle/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/qtzip.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/qtzip.rb