Ruby/GTK2 file push GUI example

A basic GUI where you select a file and BT device, then transfer it using OBEX PUSH.

A simple demo of a graphical application written in Ruby with GTK2.
It’s basicly the ObexFTP Ruby example sprinkled with some of the Ruby/GTK2 example code.

#!ruby
#!/usr/bin/env ruby

require 'gtk2'
require 'obexftp'

dialog =  Gtk::FileChooserDialog.new("Send file via bluetooth", nil, 
                                     Gtk::FileChooser::ACTION_OPEN,
                                     "gnome-vfs",
                                     [Gtk::Stock::COPY, Gtk::Dialog::RESPONSE_ACCEPT],
                                     [Gtk::Stock::CLOSE, Gtk::Dialog::RESPONSE_CANCEL]
                                     )
label = Gtk::Label.new("Select target device:")
combo = Gtk::ComboBox.new
hbox = Gtk::HBox.new
hbox.add(label).add(combo).show_all

dialog.extra_widget = hbox

dialog.signal_connect("response") do |widget, response|
  case response
  when Gtk::Dialog::RESPONSE_ACCEPT
    filename = dialog.filename
    dev = combo.active_text
    channel = Obexftp.browsebt(dev, Obexftp::PUSH)

    cli = Obexftp::Client.new(Obexftp::BLUETOOTH)
    puts cli.connectpush(dev, channel)
    puts cli.put_file(filename)
    puts cli.disconnect

  else
    dialog.destroy
    Gtk.main_quit
  end
end

puts "Scanning USB..."
intfs = Obexftp.discover(Obexftp::USB)
intfs.each { |i| combo.append_text(i) }
puts "Scanning BT..."
intfs = Obexftp.discover(Obexftp::BLUETOOTH)
intfs.each { |i| combo.append_text(i) }
combo.active = 0

dialog.show_all
Gtk.main

This is just a small example to give you a start with this.
Of course you should process error codes, use gtk.timeout_add and/or Thread.new for the scanning and many other things.