2002-03-30 06:26:20 +08:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2019-09-27 04:46:00 +08:00
|
|
|
$LOAD_PATH << '../lib'
|
2002-03-30 06:26:20 +08:00
|
|
|
|
|
|
|
$VERBOSE = true
|
|
|
|
|
|
|
|
require 'gtk'
|
2014-03-31 19:20:27 +08:00
|
|
|
require 'zip'
|
2002-03-30 06:26:20 +08:00
|
|
|
|
|
|
|
class MainApp < Gtk::Window
|
|
|
|
def initialize
|
|
|
|
super()
|
|
|
|
set_usize(400, 256)
|
2015-03-21 16:27:44 +08:00
|
|
|
set_title('rubyzip')
|
2002-03-30 06:26:20 +08:00
|
|
|
signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
|
|
|
|
|
|
|
|
box = Gtk::VBox.new(false, 0)
|
|
|
|
add(box)
|
|
|
|
|
|
|
|
@zipfile = nil
|
|
|
|
@buttonPanel = ButtonPanel.new
|
2015-03-21 16:10:37 +08:00
|
|
|
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
2003-08-13 22:29:53 +08:00
|
|
|
show_file_selector
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
|
|
|
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
2015-03-21 16:27:44 +08:00
|
|
|
puts 'Not implemented!'
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
2002-03-30 06:26:20 +08:00
|
|
|
box.pack_start(@buttonPanel, false, false, 0)
|
2014-03-31 19:20:27 +08:00
|
|
|
|
2002-03-30 06:26:20 +08:00
|
|
|
sw = Gtk::ScrolledWindow.new
|
|
|
|
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
|
|
|
|
box.pack_start(sw, true, true, 0)
|
|
|
|
|
2017-06-29 10:57:12 +08:00
|
|
|
@clist = Gtk::CList.new(%w[Name Size Compression])
|
2002-03-30 06:26:20 +08:00
|
|
|
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
|
|
|
@clist.set_column_width(0, 120)
|
|
|
|
@clist.set_column_width(1, 120)
|
2015-03-21 16:10:37 +08:00
|
|
|
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) do |_w, row, _column, _event|
|
2002-03-30 06:26:20 +08:00
|
|
|
@selected_row = row
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
2002-03-30 06:26:20 +08:00
|
|
|
sw.add(@clist)
|
|
|
|
end
|
|
|
|
|
|
|
|
class ButtonPanel < Gtk::HButtonBox
|
|
|
|
attr_reader :openButton, :extractButton
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
set_layout(Gtk::BUTTONBOX_START)
|
|
|
|
set_spacing(0)
|
2015-03-21 16:27:44 +08:00
|
|
|
@openButton = Gtk::Button.new('Open archive')
|
|
|
|
@extractButton = Gtk::Button.new('Extract entry')
|
2002-03-30 06:26:20 +08:00
|
|
|
pack_start(@openButton)
|
|
|
|
pack_start(@extractButton)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-08-13 22:29:53 +08:00
|
|
|
def show_file_selector
|
2015-03-21 16:27:44 +08:00
|
|
|
@fileSelector = Gtk::FileSelection.new('Open zip file')
|
2002-03-30 06:26:20 +08:00
|
|
|
@fileSelector.show
|
2015-03-21 16:10:37 +08:00
|
|
|
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
2003-08-13 22:29:53 +08:00
|
|
|
open_zip(@fileSelector.filename)
|
2002-03-30 06:26:20 +08:00
|
|
|
@fileSelector.destroy
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
|
|
|
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
2002-03-30 06:26:20 +08:00
|
|
|
@fileSelector.destroy
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
2002-03-30 06:26:20 +08:00
|
|
|
end
|
|
|
|
|
2003-08-13 22:29:53 +08:00
|
|
|
def open_zip(filename)
|
2013-06-03 15:56:24 +08:00
|
|
|
@zipfile = Zip::File.open(filename)
|
2002-03-30 06:26:20 +08:00
|
|
|
@clist.clear
|
2015-03-21 16:10:37 +08:00
|
|
|
@zipfile.each do |entry|
|
2015-03-23 00:58:07 +08:00
|
|
|
@clist.append([entry.name,
|
|
|
|
entry.size.to_s,
|
2015-03-23 01:03:50 +08:00
|
|
|
(100.0 * entry.compressedSize / entry.size).to_s + '%'])
|
2015-03-21 16:10:37 +08:00
|
|
|
end
|
2002-03-30 06:26:20 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-24 00:06:43 +08:00
|
|
|
mainApp = MainApp.new
|
2002-03-30 06:26:20 +08:00
|
|
|
|
|
|
|
mainApp.show_all
|
|
|
|
|
|
|
|
Gtk.main
|