# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+require 'getoptlong'
require 'gtk2'
-class Gtk::Allocation
- def to_s; "x:#{x} y:#{y} width:#{width} height:#{height}"; end
-end
require 'booh/GtkAutoTable'
require 'gettext'
include Booh
+#- options
+$options = [
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
+
+ [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
+]
+
+def usage
+ puts __("Usage: %s [OPTION]...", File.basename($0))
+ $options.each { |ary|
+ printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
+ }
+end
+
+def handle_options
+ parser = GetoptLong.new
+ parser.set_options(*$options.collect { |ary| ary[0..2] })
+ begin
+ parser.each_option do |name, arg|
+ case name
+ when '--help'
+ usage
+ exit(0)
+
+ when '--verbose-level'
+ $verbose_level = arg.to_i
+
+ end
+ end
+ rescue
+ puts $!
+ usage
+ exit(1)
+ end
+end
+
def read_config
$config = {}
$config_file = File.expand_path('~/.booh-gui-rc')
w = Gtk::Window.new
default_size = $images_size.detect { |sizeobj| sizeobj['default'] }
- puts "filename: #{filename}"
+ msg 3, "filename: #{filename}"
dest_img = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '') + "-#{default_size['fullscreen']}.jpg"
#- typically this file won't exist in case of videos; try with the largest thumbnail around
if !File.exists?(dest_img)
xmldir.elements.each { |element|
if element.name == 'image' || element.name == 'video'
dest_img = build_full_dest_filename(element.attributes['filename']).sub(/\.[^\.]+$/, '') + "-#{default_size['thumbnails']}.jpg"
- puts "dest_img: #{dest_img}"
+ msg 3, "dest_img: #{dest_img}"
add_thumbnail($autotable, element.attributes['filename'], element.name, dest_img, from_utf8(element.attributes['caption']))
end
}
$filename = filename
select_theme('simple')
- puts "source: #{source}"
+ msg 3, "source: #{source}"
xmldir = $xmldoc.elements["//dir[@path='#{source}']"]
if !xmldir
child_iter = $albums_ts.append(parent_iter)
child_iter[0] = File.basename(location)
child_iter[1] = location
- puts "puttin location: #{location}"
+ msg 3, "puttin location: #{location}"
$xmldoc.elements.each("//dir[@path='#{location}']/dir") { |elem|
append_dir_elem.call(child_iter, elem.attributes['path'])
}
save_changes
iter = w.selected
if !iter
- puts "no selection"
+ msg 3, "no selection"
else
$current_path = $albums_ts.get_value(iter, 1)
show_thumbnails
else
$main_window.window_position = Gtk::Window::POS_CENTER
end
- puts "width: #{$config['width']}\n\n"
+ msg 3, "width: #{$config['width']}\n\n"
$main_window.set_default_size(($config['width'] || 600).to_i, ($config['height'] || 400).to_i)
$main_window.signal_connect('configure-event') {
- puts "configure: pos: #{$main_window.window.root_origin.inspect} size: #{$main_window.window.size.inspect}"
+ msg 3, "configure: pos: #{$main_window.window.root_origin.inspect} size: #{$main_window.window.size.inspect}"
x, y = $main_window.window.root_origin
width, height = $main_window.window.size
$config['pos-x'] = x
end
+handle_options
read_config
Gtk.init
require 'gtk2'
+require 'booh/booh-lib'
+include Booh
+
class Gtk::AutoTable < Gtk::VBox
def initialize(row_spacings)
super
recreate_table
signal_connect('size-allocate') { |w, allocation|
- puts "got self allocation: #{allocation}"
+ msg 3, "got self allocation: #{allocation}"
if @width != allocation.width
if !@old_widths.include?(allocation.width)
@width = allocation.width
@old_widths = @old_widths[0..2]
redistribute(false)
else
- puts "\tDISABLING: #{allocation.width} - #{@old_widths.join(',')}"
+ msg 3, "\tDISABLING: #{allocation.width} - #{@old_widths.join(',')}"
end
end
}
#- connect 'size-allocate' signal to be sure to update allocation when received
widget.signal_connect('size-allocate') { |w, allocation|
- puts "got allocation for #{w.hash}: #{allocation} (#{allocation.hash})"
+ msg 3, "got allocation for #{w.hash}: #{allocation} (#{allocation.hash})"
chld = @children.find { |e| e[:widget] == w }
if chld
old = chld[:allocation]
#- need to copy values because the object will be magically exploded when widget is removed
chld[:allocation] = { :width => allocation.width, :height => allocation.height }
if !old #|| old[:width] != allocation.width # || old[:height] != allocation.height
- puts "redistribute!"
- chld == @children[0] && old and puts "************ old was #{old[:width]} #{old[:height]}"
+ msg 3, "redistribute!"
+ chld == @children[0] && old and msg 3, "************ old was #{old[:width]} #{old[:height]}"
redistribute(true)
end
else
private
def put(element, x, y)
- puts "putting #{element[:widget].hash} at #{x},#{y}"
+ msg 3, "putting #{element[:widget].hash} at #{x},#{y}"
element[:x] = x
element[:y] = y
container = @containers.find { |e| e[:x] == x && e[:y] == y }
if !container
container = { :x => x, :y => y, :widget => Gtk::VBox.new, :fake => Gtk::Label.new('fake') }
- puts "attaching at #{x},#{y}"
+ msg 3, "attaching at #{x},#{y}"
@table.attach(container[:widget], x, x + 1, y, y + 1, Gtk::FILL, Gtk::FILL, 5, 0)
@containers << container
end
def recreate_table
@containers.each { |e|
if e[:contained_element]
- if e[:contained_element][:widget].focus?
- puts "I HAVE A FOCUS!"
- end
e[:widget].remove(e[:contained_element][:widget])
end
}
end
def redistribute(force)
- puts "redistribute: "
- @children.each { |e| print e[:allocation] ? 'O' : '.' }; puts
+ msg 3, "redistribute: "
+ @children.each { |e| msg_ 3, e[:allocation] ? 'O' : '.' }; msg 3, ''
if unallocated = @children.find { |e| !e[:allocation] }
#- waiting for allocations. replace last displayed widget with first unallocated.
last_container = @containers[-1]
xpix += 5 + e[:allocation][:width] + 5
}
if @children[1..-1].find { |e| e[:xnew] != e[:x] || e[:ynew] != e[:y] } || force
- puts "I can proceed with #{allocation}"
+ msg 3, "I can proceed with #{allocation}"
recreate_table
put(@children[0], 0, 0)
@children[1..-1].each { |e|