bin/gui/properties.rb in origami-2.0.0 vs bin/gui/properties.rb in origami-2.0.1
- old
+ new
@@ -43,85 +43,83 @@
}
def initialize(parent, pdf)
super("Document properties", parent, Dialog::MODAL, [Stock::CLOSE, Dialog::RESPONSE_NONE])
- docframe = Frame.new(" File properties ")
- stat = File.stat(parent.filename)
+ file_frame = create_file_frame(parent)
+ pdf_frame = create_document_frame(pdf)
- creation_date = stat.ctime.to_s.encode("utf-8", :invalid => :replace, :undef => :replace)
- last_modified = stat.mtime.to_s.encode("utf-8", :invalid => :replace, :undef => :replace)
- md5sum = Digest::MD5.hexdigest(File.binread(parent.filename))
+ vbox.add(file_frame)
+ vbox.add(pdf_frame)
+ signal_connect('response') { destroy }
+
+ show_all
+ end
+
+ private
+
+ def create_file_frame(parent)
+ file_frame = Frame.new(" File properties ")
+ stat = File.stat(parent.filename)
+
labels =
[
[ "Filename:", parent.filename ],
[ "File size:", "#{File.size(parent.filename)} bytes" ],
- [ "MD5:", md5sum ],
+ [ "MD5:", Digest::MD5.file(parent.filename).hexdigest ],
[ "Read-only:", "#{not stat.writable?}" ],
- [ "Creation date:", creation_date ],
- [ "Last modified:", last_modified ]
+ [ "Creation date:", stat.ctime.to_s ],
+ [ "Last modified:", stat.mtime.to_s ]
]
- doctable = Table.new(labels.size + 1, 3)
+ create_table(file_frame, labels)
+ end
- row = 0
- labels.each do |name, value|
- doctable.attach(Label.new(name).set_alignment(1,0), 0, 1, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
- doctable.attach(Label.new(value).set_alignment(0,0), 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
+ def create_document_frame(pdf)
+ pdf_frame = Frame.new(" PDF properties ")
- row = row.succ
- end
-
- docframe.border_width = 5
- docframe.shadow_type = Gtk::SHADOW_IN
- docframe.add(doctable)
-
- pdfframe = Frame.new(" PDF properties ")
-
pdf_version = pdf.header.to_f
if pdf_version >= 1.0 and pdf_version <= 1.7
acrobat_version = @@acrobat_versions[pdf_version]
else
acrobat_version = "unknown version"
end
labels =
[
- [ "Version:", "#{pdf_version} (Acrobat #{acrobat_version})" ],
- [ "Number of revisions:", "#{pdf.revisions.size}" ],
+ [ "Version:", "#{pdf_version} (Acrobat #{acrobat_version})" ],
+ [ "Number of revisions:", "#{pdf.revisions.size}" ],
[ "Number of indirect objects:", "#{pdf.indirect_objects.size}" ],
- [ "Number of pages:", "#{pdf.pages.count}" ],
- [ "Linearized:", pdf.linearized? ? 'yes' : 'no' ],
- [ "Encrypted:", pdf.encrypted? ? 'yes' : 'no' ],
- [ "Signed:", pdf.signed? ? 'yes' : 'no' ],
- [ "Has usage rights:", pdf.usage_rights? ? 'yes' : 'no' ],
- [ "Form:", pdf.form? ? 'yes' : 'no' ],
- [ "XFA form:", pdf.xfa_form? ? 'yes' : 'no' ],
- [ "Document information:", pdf.document_info? ? 'yes' : 'no' ],
- [ "Metadata:", pdf.metadata? ? 'yes' : 'no' ]
+ [ "Number of pages:", "#{pdf.pages.count}" ],
+ [ "Linearized:", boolean_text(pdf.linearized?) ],
+ [ "Encrypted:", boolean_text(pdf.encrypted?) ],
+ [ "Signed:", boolean_text(pdf.signed?) ],
+ [ "Has usage rights:", boolean_text(pdf.usage_rights?) ],
+ [ "Form:", boolean_text(pdf.form?) ],
+ [ "XFA form:", boolean_text(pdf.xfa_form?) ],
+ [ "Document information:", boolean_text(pdf.document_info?) ],
+ [ "Metadata:", boolean_text(pdf.metadata?) ]
]
- pdftable = Table.new(labels.size + 1, 3)
+ create_table(pdf_frame, labels)
+ end
- row = 0
- labels.each do |name, value|
- pdftable.attach(Label.new(name).set_alignment(1,0), 0, 1, row, row + 1, Gtk::FILL, Gtk::SHRINK, 4, 4)
- pdftable.attach(Label.new(value).set_alignment(0,0), 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
+ def create_table(frame, labels)
+ table = Table.new(labels.size + 1, 3)
- row = row.succ
+ labels.each_with_index do |label, row|
+ table.attach(Label.new(label[0]).set_alignment(1,0), 0, 1, row, row + 1, Gtk::FILL, Gtk::SHRINK, 4, 4)
+ table.attach(Label.new(label[1]).set_alignment(0,0), 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
end
- pdfframe.border_width = 5
- pdfframe.shadow_type = Gtk::SHADOW_IN
- pdfframe.add(pdftable)
+ frame.border_width = 5
+ frame.shadow_type = Gtk::SHADOW_IN
+ frame.add(table)
+ end
- vbox.add(docframe)
- vbox.add(pdfframe)
-
- signal_connect('response') { destroy }
-
- show_all
+ def boolean_text(value)
+ value ? 'yes' : 'no'
end
end
end
end