| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  | #!/usr/bin/env ruby | 
					
						
							| 
									
										
										
										
											2021-05-24 01:24:22 +08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  |     @button_panel = ButtonPanel.new | 
					
						
							|  |  |  |     @button_panel.open_button.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 | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  |     @button_panel.extract_button.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 | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  |     box.pack_start(@button_panel, 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 | 
					
						
							| 
									
										
										
										
											2021-05-24 04:43:11 +08:00
										 |  |  |     attr_reader :extract_button, :open_button | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  |     def initialize | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |       set_layout(Gtk::BUTTONBOX_START) | 
					
						
							|  |  |  |       set_spacing(0) | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  |       @open_button = Gtk::Button.new('Open archive') | 
					
						
							|  |  |  |       @extract_button = Gtk::Button.new('Extract entry') | 
					
						
							|  |  |  |       pack_start(@open_button) | 
					
						
							|  |  |  |       pack_start(@extract_button) | 
					
						
							| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-13 22:29:53 +08:00
										 |  |  |   def show_file_selector | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  |     @file_selector = Gtk::FileSelection.new('Open zip file') | 
					
						
							|  |  |  |     @file_selector.show | 
					
						
							|  |  |  |     @file_selector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do | 
					
						
							|  |  |  |       open_zip(@file_selector.filename) | 
					
						
							|  |  |  |       @file_selector.destroy | 
					
						
							| 
									
										
										
										
											2015-03-21 16:10:37 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  |     @file_selector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do | 
					
						
							|  |  |  |       @file_selector.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, | 
					
						
							| 
									
										
										
										
											2021-06-18 23:10:57 +08:00
										 |  |  |                      "#{100.0 * entry.compressedSize / entry.size}%"]) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:10:37 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  | main_app = MainApp.new | 
					
						
							| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 15:37:32 +08:00
										 |  |  | main_app.show_all | 
					
						
							| 
									
										
										
										
											2002-03-30 06:26:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | Gtk.main |