changeset 2:d4c65ef43e0f

Added signal callbacks, labels and entry
author unexist
date Sun, 13 Dec 2009 04:29:49 +0100
parents 60b9314c5115
children c86049015094
files subtly/browser.rb
diffstat 1 files changed, 63 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/subtly/browser.rb	Sun Dec 13 04:29:19 2009 +0100
+++ b/subtly/browser.rb	Sun Dec 13 04:29:49 2009 +0100
@@ -11,45 +11,89 @@
 require "subtly/glib"
 require "subtly/gtk"
 require "subtly/gdk"
-require "subtly/webkit"
 
 module Subtly
-  class Browser < Subtly::Gtk::Runner
-    attr_accessor :win, :scrolled, :label, :box, :view
+  class Browser < Subtly::Runner
+    attr_accessor :win, :scrolled, :l_uri, :l_load, :vbox, :hbox, :view
 
     def initialize
       super
 
       # Create widgets
-      @win      = Subtly::Gtk::Window.new
-      @scrolled = Subtly::Gtk::Scrolled.new
-      @label    = Subtly::Gtk::Label.new("subtly")
-      @box      = Subtly::Gtk::VBox.new(true, 0)
-      @view     = Subtly::Webkit::View.new
+      @win      = Subtly::Window.new
+      @scrolled = Subtly::Scrolled.new
+      @l_uri    = Subtly::Label.new(true, true)
+      @l_load   = Subtly::Label.new(true, false)
+      @e_input  = Subtly::Entry.new(false)
+      @vbox     = Subtly::Box.new(:vbox, false, 0)
+      @hbox     = Subtly::Box.new(:hbox, false, 5)
+      @view     = Subtly::Webkit.new
+
+      # Options
+      @win.size  = [ 800, 600 ]
+      @win.title = "Subtly"
+      @win.klass = [ "Browser", "Subtly" ]
+
+      @win.background     = "#000000"
+      @l_uri.foreground   = "#ffffff"
+      @l_load.foreground  = "#ffffff"
+      @e_input.foreground = "#000000"
+      @e_input.background = "#ffffff"
+      @l_uri.alignment(0, 0)
+      @l_load.alignment(1, 0)
 
       # Containers
-      @win.add(@box)
+      @win.add(@vbox)
       @scrolled.add(@view)
 
       # Boxes
-      @box.add(@scrolled, true, true, 0)
-      @box.add(@label,    true, true, 0)
+      @vbox.add(@scrolled, true,  true, 0)
+      @vbox.add(@hbox,     false, true, 0)
+      @hbox.add(@l_uri,    true,  true, 5)
+      @hbox.add(@l_load,   true,  true, 5)
+      @vbox.add(@e_input,  false, true, 0)
 
-      # Options
-      @win.default_size = [ 800, 600 ]
-      @win.title        = "Subtly"
+      # Signals
+      @win.connect("destroy",                method(:destroy).to_proc,       nil)
+      @view.connect("load-started",          method(:load_started).to_proc,  nil)
+      @view.connect("load-finished",         method(:load_finished).to_proc, nil)
+      @view.connect("load-progress-changed", method(:load_progress).to_proc, nil)
+      #@view.connect("hovering-over-link",    method(:hover).to_proc,         nil)
+      
       @win.show_all
-
-      # Colors
-      #set_colors(@bar, "white", "black")
     end
 
     def load(uri)
-      @view.uri  = uri
-      @label.text = uri
+      @view.uri    = uri
+      @l_uri.text = uri
     end
 
     def add_key(hash)
     end
+
+    private
+    
+    # Callbacks
+    def destroy(widget, event)
+      Subtly::Runner.ffi_quit 
+    end
+
+    def load_started(widget, event)
+      @l_load.text = "[>%s]" % [ " " * 10 ]
+    end
+
+    def load_finished(widget, event)
+      @l_load.text = ""
+    end
+
+    def load_progress(widget, progress, data)
+      times = (progress * 10) / 100
+
+      @l_load.markup = "[%s>%s]" % [ "=" * times, " " * (10 - times) ]
+    end
+
+    def hover(widget, title, uri, data)
+      puts uri unless(uri.nil?)
+    end
   end
 end