Sha256: 24df465565ce84cd3f677d51688634e23b1e832f168c23bcccc3435f25f2fff6

Contents?: true

Size: 1.91 KB

Versions: 42

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby

$VERBOSE = true

$LOAD_PATH << '../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(&a_proc)
    Zip::File.open(@zip_filename, &a_proc)
  end

  def each(&a_proc)
    Zip::File.foreach(@zip_filename, &a_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.empty? ? 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: #{$PROGRAM_NAME} zipname"
  exit
end

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

a.mainWidget = zd
zd.show
a.exec

Version data entries

42 entries across 32 versions & 7 rubygems

Version Path
rubyzip-2.4.1 samples/qtzip.rb
rubyzip-2.4 samples/qtzip.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubyzip-2.3.2/samples/qtzip.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/samples/qtzip.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/samples/qtzip.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubyzip-2.3.2/samples/qtzip.rb
rubyzip-2.4.rc1 samples/qtzip.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/rubyzip-2.3.2/samples/qtzip.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/rubyzip-2.3.0/samples/qtzip.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/samples/qtzip.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/samples/qtzip.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/rubyzip-2.3.2/samples/qtzip.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/rubyzip-2.3.0/samples/qtzip.rb
rubyzip-2.3.2 samples/qtzip.rb