vala-tests r12 - trunk/tests/examples



Author: malureau
Date: Fri Oct 17 23:28:47 2008
New Revision: 12
URL: http://svn.gnome.org/viewvc/vala-tests?rev=12&view=rev

Log:
Continue to add more examples from live.gnome.org/Vala

Added:
   trunk/tests/examples/gnio-sock.test
      - copied, changed from r11, /trunk/tests/examples/gtk-builder-sample.test
   trunk/tests/examples/gnio-sock.vala
   trunk/tests/examples/gtk-filechooser-subclass.test
      - copied, changed from r11, /trunk/tests/examples/gtk-sample.test
   trunk/tests/examples/gtk-filechooser-subclass.vala
   trunk/tests/examples/gtk-valawidget.test
      - copied, changed from r11, /trunk/tests/examples/cairo.test
   trunk/tests/examples/gtk-valawidget.vala
   trunk/tests/examples/panel-applet-advanced.test
      - copied, changed from r11, /trunk/tests/examples/advanced.test
   trunk/tests/examples/panel-applet-advanced.vala
   trunk/tests/examples/panel-applet-simple.test
      - copied, changed from r11, /trunk/tests/examples/advanced.test
   trunk/tests/examples/panel-applet-simple.vala
   trunk/tests/examples/panel-applet.server
   trunk/tests/examples/pango-cairo.test
      - copied, changed from r11, /trunk/tests/examples/advanced.test
   trunk/tests/examples/pango-cairo.vala
   trunk/tests/examples/poppler-sample.test
      - copied, changed from r11, /trunk/tests/examples/cairo.test
   trunk/tests/examples/poppler-sample.vala
   trunk/tests/examples/webkit-sample.test
      - copied, changed from r11, /trunk/tests/examples/cairo.test
   trunk/tests/examples/webkit-sample.vala
Modified:
   trunk/tests/examples/advanced.test
   trunk/tests/examples/async-gio.test
   trunk/tests/examples/basic.test
   trunk/tests/examples/bluez-dbus-sample.test
   trunk/tests/examples/cairo.test
   trunk/tests/examples/dbus-sample.test
   trunk/tests/examples/dbus-server-sample.test
   trunk/tests/examples/egg-clock.test
   trunk/tests/examples/gconf.test
   trunk/tests/examples/glade.test
   trunk/tests/examples/gnome-desktop-and-menu.test
   trunk/tests/examples/gstreamer-square-beep.test
   trunk/tests/examples/gstreamer-video.test
   trunk/tests/examples/gtk-builder-sample.test
   trunk/tests/examples/gtk-sample.test
   trunk/tests/examples/list.test
   trunk/tests/examples/properties-construction.test
   trunk/tests/examples/properties.test
   trunk/tests/examples/string.test
   trunk/tests/examples/update.sh

Modified: trunk/tests/examples/advanced.test
==============================================================================
--- trunk/tests/examples/advanced.test	(original)
+++ trunk/tests/examples/advanced.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/async-gio.test
==============================================================================
--- trunk/tests/examples/async-gio.test	(original)
+++ trunk/tests/examples/async-gio.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 --pkg gio-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/basic.test
==============================================================================
--- trunk/tests/examples/basic.test	(original)
+++ trunk/tests/examples/basic.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/bluez-dbus-sample.test
==============================================================================
--- trunk/tests/examples/bluez-dbus-sample.test	(original)
+++ trunk/tests/examples/bluez-dbus-sample.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg dbus-glib-1 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/cairo.test
==============================================================================
--- trunk/tests/examples/cairo.test	(original)
+++ trunk/tests/examples/cairo.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/dbus-sample.test
==============================================================================
--- trunk/tests/examples/dbus-sample.test	(original)
+++ trunk/tests/examples/dbus-sample.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg dbus-glib-1 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/dbus-server-sample.test
==============================================================================
--- trunk/tests/examples/dbus-server-sample.test	(original)
+++ trunk/tests/examples/dbus-server-sample.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg dbus-glib-1 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/egg-clock.test
==============================================================================
--- trunk/tests/examples/egg-clock.test	(original)
+++ trunk/tests/examples/egg-clock.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/gconf.test
==============================================================================
--- trunk/tests/examples/gconf.test	(original)
+++ trunk/tests/examples/gconf.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gconf-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/glade.test
==============================================================================
--- trunk/tests/examples/glade.test	(original)
+++ trunk/tests/examples/glade.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 --pkg libglade-2.0 --pkg gmodule-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala -X "-Wl,--export-dynamic" $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Copied: trunk/tests/examples/gnio-sock.test (from r11, /trunk/tests/examples/gtk-builder-sample.test)
==============================================================================
--- /trunk/tests/examples/gtk-builder-sample.test	(original)
+++ trunk/tests/examples/gnio-sock.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  --pkg gtk+-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg gnio -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/gnio-sock.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/gnio-sock.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,120 @@
+using GLib;
+
+namespace Test {
+    class TestSync : Object {
+        public void run() throws Error {
+            Resolver resolver = new Resolver();
+
+            InetAddress address = resolver.resolve("www.google.com", null);
+
+            debug("(sync)  resolved www.google.com to %s", address.to_string());
+
+            SocketConnection client = new SocketConnection(new InetSocketAddress(address, 80));
+
+            client.connect(null);
+
+            debug("(sync)  connected to www.google.com");
+
+            string message = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
+
+            client.output_stream.write(message, message.len(), null);
+
+            debug("(sync)  wrote request");
+
+            size_t length;
+
+            DataInputStream input = new DataInputStream(client.input_stream);
+
+            message = input.read_line(out length, null).strip();
+
+            debug("(sync)  received status line: %s", message);
+
+            client.close();
+        }
+    }
+
+    class TestAsync : Object {
+        MainLoop loop;
+        InetSocketAddress socket_address;
+        SocketConnection client;
+
+        public void run() {
+            loop = new MainLoop(null, false);
+
+            Resolver resolver = new Resolver();
+
+            resolver.resolve_async("www.google.com", null, (sender, result) => {
+					InetAddress address;
+
+					try {
+						address = ((Resolver) sender).resolve_finish(result);
+					} catch (Error ex) {
+						debug(ex.message);
+						loop.quit();
+						return;
+					}
+
+					debug("(async) resolved www.google.com to %s", address.to_string());
+
+					socket_address = new InetSocketAddress(address, 80);
+
+					client = new SocketConnection(socket_address);
+
+					client.connect_async(null, (sender, result) => {
+							try {
+								((SocketConnection) sender).connect_finish(result);
+							} catch (Error ex) {
+								debug(ex.message);
+								loop.quit();
+								return;
+							}
+
+							debug("(async) connected to www.google.com");
+
+							string message = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
+
+							client.output_stream.write_async(message, message.len(), 1, null, (sender, result) => {
+									try {
+										client.output_stream.write_finish(result);
+									} catch (Error ex) {
+										debug(ex.message);
+										loop.quit();
+										return;
+									}
+
+									debug("(async) wrote request");
+
+									size_t length;
+
+									/* we set the socket back to blocking here for the convenience of DataInputStream */
+									client.socket.set_blocking(true);
+
+									DataInputStream input = new DataInputStream(client.input_stream);
+
+									string message = input.read_line(out length, null).strip();
+
+									debug("(async) received status line: %s", message);
+
+									client.close();
+
+									loop.quit();
+								});
+						});
+				});
+
+            loop.run();
+        }
+    }
+
+    class Test : Object {
+        public static void main(string[] args) {
+            try {
+                new TestSync().run();
+                new TestAsync().run();
+            } catch (Error ex) {
+                debug(ex.message);
+            }
+        }
+    }
+}
+

Modified: trunk/tests/examples/gnome-desktop-and-menu.test
==============================================================================
--- trunk/tests/examples/gnome-desktop-and-menu.test	(original)
+++ trunk/tests/examples/gnome-desktop-and-menu.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gnome-desktop-2.0 --pkg libgnome-menu -o $TESTNAME $SRCDIR/$TESTNAME.vala -X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE" $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/gstreamer-square-beep.test
==============================================================================
--- trunk/tests/examples/gstreamer-square-beep.test	(original)
+++ trunk/tests/examples/gstreamer-square-beep.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gstreamer-0.10 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/gstreamer-video.test
==============================================================================
--- trunk/tests/examples/gstreamer-video.test	(original)
+++ trunk/tests/examples/gstreamer-video.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 --pkg gstreamer-0.10 --pkg gdk-x11-2.0 --pkg gstreamer-interfaces-0.10 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/gtk-builder-sample.test
==============================================================================
--- trunk/tests/examples/gtk-builder-sample.test	(original)
+++ trunk/tests/examples/gtk-builder-sample.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Copied: trunk/tests/examples/gtk-filechooser-subclass.test (from r11, /trunk/tests/examples/gtk-sample.test)
==============================================================================
--- /trunk/tests/examples/gtk-sample.test	(original)
+++ trunk/tests/examples/gtk-filechooser-subclass.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/gtk-filechooser-subclass.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/gtk-filechooser-subclass.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,42 @@
+/* Custom FileChooserDialog in Vala sample code */
+
+using GLib;
+using Gtk;
+
+class OpenFileDialog : Gtk.FileChooserDialog {
+
+    public static string? CWD = null;
+
+    construct {
+        this.set_title ("Open file");
+        this.set_action (FileChooserAction.OPEN);
+        this.add_button (STOCK_CANCEL, ResponseType.CANCEL);
+        this.add_button (STOCK_OPEN, ResponseType.OK);
+
+        this.set_default_response (ResponseType.OK);
+
+        if (CWD != null) {
+            this.set_current_folder (CWD);
+        }
+    }
+
+    public override void response (int resp) {
+        if ((ResponseType) resp == ResponseType.OK) {
+            CWD = this.get_current_folder ();
+        }
+    }
+
+    public static void main (string[] args) {
+        Gtk.init (ref args);
+
+        for (int i = 0; i < 2; i++) {
+            var ofd = new OpenFileDialog ();
+
+            if (ofd.run () == ResponseType.OK) {
+                stdout.printf ("filename = %s\n".printf (ofd.get_filename ()));
+            }
+
+            ofd.destroy ();
+        }
+    }
+}

Modified: trunk/tests/examples/gtk-sample.test
==============================================================================
--- trunk/tests/examples/gtk-sample.test	(original)
+++ trunk/tests/examples/gtk-sample.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  --pkg gtk+-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Copied: trunk/tests/examples/gtk-valawidget.test (from r11, /trunk/tests/examples/cairo.test)
==============================================================================
--- /trunk/tests/examples/cairo.test	(original)
+++ trunk/tests/examples/gtk-valawidget.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg gtk+-2.0 --pkg cairo --pkg pangocairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/gtk-valawidget.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/gtk-valawidget.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,140 @@
+//
+// Johan Dahlin 2008
+//
+// A quite simple Gtk.Widget subclass which demonstrates how to subclass
+// and do realizing, sizing and drawing. Based on widget.py in PyGTK
+//
+
+using GLib;
+using Gtk;
+using Cairo;
+
+public class ValaWidget : Gtk.Widget {
+	private static const string text = "Hello World!\n";
+	private static const int _BORDER_WIDTH = 10;
+	private Pango.Layout _layout;
+
+	construct {
+		this._layout = this.create_pango_layout (ValaWidget.text);
+	}
+
+	// The realize method is responsible for creating GDK (windowing system)
+	// resources. In this example we will create a new gdk.Window which we
+	// then draw on
+
+	public override void realize ()
+	{
+        // First set an internal flag telling that we're realized
+        this.set_flags (Gtk.WidgetFlags.REALIZED);
+
+        // Create a new gdk.Window which we can draw on.
+        // Also say that we want to receive exposure events by setting
+        // the event_mask
+        var attrs = Gdk.WindowAttr ();
+        attrs.window_type = Gdk.WindowType.CHILD;
+        attrs.width = this.allocation.width;
+        attrs.wclass = Gdk.WindowClass.INPUT_OUTPUT;
+        attrs.event_mask = this.get_events() | Gdk.EventMask.EXPOSURE_MASK;
+        this.window = new Gdk.Window (this.get_parent_window (), attrs, 0);
+
+        // Associate the gdk.Window with ourselves, Gtk+ needs a reference
+        // between the widget and the gdk window
+        this.window.set_user_data (this);
+
+        // Attach the style to the gdk.Window, a style contains colors and
+        // GC contextes used for drawing
+        this.style = this.style.attach (this.window);
+
+        // The default color of the background should be what
+        // the style (theme engine) tells us.
+        this.style.set_background (this.window, Gtk.StateType.NORMAL);
+        this.window.move_resize (this.allocation.x, this.allocation.y,
+                                 this.allocation.width, this.allocation.height);
+	}
+
+	// The unrealized method is responsible for freeing the GDK resources
+	public override void unrealize ()
+	{
+        // De-associate the window we created in realize with ourselves
+        this.window.set_user_data (null);
+	}
+
+	// The size_request method Gtk+ is calling on a widget to ask
+	// it the widget how large it wishes to be. It's not guaranteed
+	// that gtk+ will actually give this size to the widget
+	public override void size_request (Gtk.Requisition requisition)
+	{
+        int width, height;
+
+        // In this case, we say that we want to be as big as the
+        // text is, plus a little border around it.
+        this._layout.get_size (out width, out height);
+        requisition.width = width / Pango.SCALE + this._BORDER_WIDTH*4;
+        requisition.height = height / Pango.SCALE + this._BORDER_WIDTH*4;
+
+	}
+
+	// The size_allocate is called by when the actual size is known
+	// and the widget is told how much space could actually be allocated
+	public override void size_allocate (Gdk.Rectangle allocation)
+	{
+
+        // Save the allocated space
+        this.allocation = (Gtk.Allocation)allocation;
+
+        // If we're realized, move and resize the window to the
+        // requested coordinates/positions
+        if ((this.get_flags () & Gtk.WidgetFlags.REALIZED) == 0)
+			return;
+        this.window.move_resize (this.allocation.x, this.allocation.y,
+                                 this.allocation.width, this.allocation.height);
+	}
+
+	// The do_expose_event is called when the widget is asked to draw itself
+	// Remember that this will be called a lot of times, so it's usually
+	// a good idea to write this code as optimized as it can be, don't
+	// Create any resources in here.
+	public override bool expose_event (Gdk.EventExpose event)
+	{
+        // In this example, draw a rectangle in the foreground color
+        var cr = Gdk.cairo_create (this.window);
+        Gdk.cairo_set_source_color (cr, this.style.fg[this.state]);
+        cr.rectangle (this._BORDER_WIDTH,
+                      this._BORDER_WIDTH,
+                      this.allocation.width - 2*this._BORDER_WIDTH,
+                      this.allocation.height - 2*this._BORDER_WIDTH);
+        cr.set_line_width (5.0);
+        cr.set_line_join (Cairo.LineJoin.ROUND);
+        cr.stroke ();
+
+        // And draw the text in the middle of the allocated space
+        int fontw, fonth;
+        this._layout.get_pixel_size (out fontw, out fonth);
+        cr.move_to ((this.allocation.width - fontw)/2,
+                    (this.allocation.height - fonth)/2);
+        Pango.cairo_update_layout (cr, this._layout);
+        Pango.cairo_show_layout (cr, this._layout);
+        return true;
+	}
+
+	static int main (string[] args) {
+
+        Gtk.init (ref args);
+
+        Gtk.Window win = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
+        win.set_border_width (5);
+        win.set_title ("Widget test");
+        win.destroy += Gtk.main_quit;
+
+        Gtk.Frame frame = new Gtk.Frame ("Example Vala Widget");
+        win.add (frame);
+
+        ValaWidget w = new ValaWidget ();
+        frame.add (w);
+
+        win.show_all ();
+
+        Gtk.main ();
+        return 0;
+	}
+}
\ No newline at end of file

Modified: trunk/tests/examples/list.test
==============================================================================
--- trunk/tests/examples/list.test	(original)
+++ trunk/tests/examples/list.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Copied: trunk/tests/examples/panel-applet-advanced.test (from r11, /trunk/tests/examples/advanced.test)
==============================================================================
--- /trunk/tests/examples/advanced.test	(original)
+++ trunk/tests/examples/panel-applet-advanced.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg gtk+-2.0 --pkg libpanelapplet-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/panel-applet-advanced.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/panel-applet-advanced.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,69 @@
+using GLib;
+using Panel;
+
+public class MainApplet : Panel.Applet {
+
+    public static bool factory (MainApplet applet, string iid) {
+        applet.create ();
+        return true;
+    }
+
+    private void on_change_background (MainApplet applet, Panel.AppletBackgroundType type,
+                                       ref Gdk.Color color, Gdk.Pixmap pixmap) {
+        applet.set_style (null);
+
+        var rc_style = new Gtk.RcStyle ();
+        applet.modify_style (rc_style);
+
+        switch (type) {
+        case Panel.AppletBackgroundType.COLOR_BACKGROUND:
+            applet.modify_bg (Gtk.StateType.NORMAL, color);
+            break;
+        case Panel.AppletBackgroundType.PIXMAP_BACKGROUND:
+            applet.style.bg_pixmap[0] = pixmap;
+            set_style (style);
+            break;
+        }
+    }
+
+    private void create () {
+        change_background += on_change_background;
+
+        var label = new Gtk.Label ("Vala Panel");
+        add (label);
+
+        string menu_definition =
+            "<popup name=\"button3\">" +
+			"<menuitem debuname=\"About\" verb=\"About\" _label=\"_About...\" pixtype=\"stock\" pixname=\"gnome-stock-about\"/>" +
+            "</popup>";
+
+        var verb = BonoboUI.Verb ();
+        verb.cname = "About";
+        verb.cb = on_about_clicked;
+
+        var verbs = new BonoboUI.Verb[] { verb };
+        setup_menu (menu_definition, verbs, null);
+
+        show_all();
+    }
+
+    private static void on_about_clicked (BonoboUI.Component component,
+                                          void* user_data, string cname) {
+        var dialog = new Gtk.MessageDialog (
+            null,
+            Gtk.DialogFlags.DESTROY_WITH_PARENT,
+            Gtk.MessageType.ERROR,
+            Gtk.ButtonsType.CLOSE,
+            "About");
+        dialog.secondary_text = "About dialog";
+        dialog.run ();
+        dialog.destroy ();
+    }
+
+    public static int main (string[] args) {
+        var program = Gnome.Program.init ("Vala_Applet", "0", Gnome.libgnomeui_module,
+                                          args, "sm-connect", false);
+        return Applet.factory_main ("OAFIID:Vala_Applet_Factory",
+                                    typeof (MainApplet), factory);
+    }
+}
\ No newline at end of file

Copied: trunk/tests/examples/panel-applet-simple.test (from r11, /trunk/tests/examples/advanced.test)
==============================================================================
--- /trunk/tests/examples/advanced.test	(original)
+++ trunk/tests/examples/panel-applet-simple.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg gtk+-2.0 --pkg libpanelapplet-2.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/panel-applet-simple.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/panel-applet-simple.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,20 @@
+using GLib;
+using Panel;
+
+public class MainApplet : GLib.Object {
+
+    public static bool panel_factory (Applet applet, string iid) {
+        var button = new Gtk.Button.with_label ("Vala Panel");
+        applet.add (button);
+        applet.show_all ();
+        return false;
+    }
+
+    public static int main (string[] args) {
+        var program = Gnome.Program.init ("Vala_Applet", "0", Gnome.libgnomeui_module,
+                                          args, "sm-connect", false);
+        return Applet.factory_main ("OAFIID:Vala_Applet_Factory",
+                                    typeof (Panel.Applet),
+                                    MainApplet.panel_factory);
+    }
+}

Added: trunk/tests/examples/panel-applet.server
==============================================================================
--- (empty file)
+++ trunk/tests/examples/panel-applet.server	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,24 @@
+<oaf_info>
+
+    <oaf_server iid="OAFIID:Vala_Applet_Factory" type="exe" location="/path/to/panel">
+        <oaf_attribute name="repo_ids" type="stringv">
+            <item value="IDL:Bonobo/GenericFactory:1.0"/>
+            <item value="IDL:Bonobo/Unknown:1.0"/>
+        </oaf_attribute>
+        <oaf_attribute name="name" type="string" value="Vala Panel Example"/>
+        <oaf_attribute name="description" type="string" value="Vala Panel Example"/>
+    </oaf_server>
+
+    <oaf_server iid="OAFIID:Vala_Applet" type="factory" location="OAFIID:Vala_Applet_Factory">
+        <oaf_attribute name="repo_ids" type="stringv">
+            <item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
+            <item value="IDL:Bonobo/Control:1.0"/>
+            <item value="IDL:Bonobo/Unknown:1.0"/>
+        </oaf_attribute>
+        <oaf_attribute name="name" type="string" value="Vala Panel Example"/>
+        <oaf_attribute name="description" type="string" value="Vala Panel Example"/>
+        <oaf_attribute name="panel:category" type="string" value="Utility"/>
+        <oaf_attribute name="panel:icon" type="string" value="computer.png"/>
+    </oaf_server>
+
+</oaf_info>
\ No newline at end of file

Copied: trunk/tests/examples/pango-cairo.test (from r11, /trunk/tests/examples/advanced.test)
==============================================================================
--- /trunk/tests/examples/advanced.test	(original)
+++ trunk/tests/examples/pango-cairo.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg cairo --pkg pangocairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME ../Makefile $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/pango-cairo.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/pango-cairo.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,181 @@
+//======================================================================
+//  pags.vala - Converting text to rendered image files of the text.
+//              It may e.g. be used for rendering text files to put
+//              into a mp3 player/image viewer.
+//
+//  Dov Grobgeld <dov grobgeld gmail com>
+//  Sat Jun 28 22:50:57 2008
+//----------------------------------------------------------------------
+
+using GLib;
+using Cairo;
+
+void clear_page(Cairo.Context cr,
+                int width,
+                int height,
+                double margin,
+                double top_margin,
+                bool do_rotate)
+{
+    cr.identity_matrix();
+    cr.set_source_rgb (1., 1., 1.);
+    cr.rectangle(0,0,width,height);
+    cr.fill();
+    cr.set_source_rgb (0., 0., 0.);
+    if (do_rotate) {
+        cr.translate(width,0);
+        cr.rotate(Math.PI/2);
+    }
+    cr.move_to(margin, top_margin);
+}
+
+int main(string[] args)
+{
+    int argp = 1;
+    int width=320;
+    int height=240;
+    string font_family = "Sans";
+    double font_size = 14;
+    double margin = font_size;
+    double top_margin = margin*2;
+    double bottom_margin = margin;
+    bool do_justify = false;
+    bool do_rotate = false;
+
+    while(argp < args.length && args[argp][0]=='-') {
+        string S_=args[argp++];
+
+        if (S_=="--help") {
+            stdout.printf(
+                "pags - render text to files\n"
+                +"\n"
+                +"Syntax:\n"
+                +"    pags [--help] [--width w] [--height h] [--family]\n"
+                +"         [--font_size fs] [--margin m] [--justify]\n"
+                +"         [--rotate] file\n"
+                );
+            return 0;
+        }
+        if (S_=="--width") {
+            width = args[argp++].to_int();
+            continue;
+        }
+        if (S_=="--height") {
+            height = args[argp++].to_int();
+            continue;
+        }
+        if (S_=="--family") {
+            font_family = args[argp++];
+            continue;
+        }
+        if (S_=="--font_size") {
+            font_size = args[argp++].to_double();
+            continue;
+        }
+        if (S_=="--margin") {
+            margin = args[argp++].to_double();
+            continue;
+        }
+        if (S_=="--justify") {
+            do_justify = true;
+            continue;
+        }
+        if (S_=="--rotate") {
+            do_rotate = true;
+            continue;
+        }
+        stderr.printf("Unknown option %s!\n", S_);
+        return -1;
+    }
+
+    if (argp >= args.length) {
+        stdout.printf("Need name of text file!\n");
+        return -1;
+    }
+
+    string filename = args[argp++];
+    Pango.Rectangle ink_rect, logical_rect;
+
+    string text;
+    try { FileUtils.get_contents(filename, out text); }
+    catch (FileError err) {
+        stderr.printf("Failed reading file %s!\n", filename);
+        return -1;
+    }
+
+    var surface = new Cairo.ImageSurface(Cairo.Format.RGB24, width, height);
+    var cr = new Cairo.Context(surface);
+
+    var font_description = new Pango.FontDescription();
+    font_description.set_family(font_family);
+    font_description.set_size((int)(font_size * Pango.SCALE));
+
+    var rwidth = width;
+    var rheight = height;
+    if (do_rotate) {
+        rwidth = height;
+        rheight = width;
+    }
+    var layout = Pango.cairo_create_layout (cr);
+    layout.set_font_description(font_description);
+    layout.set_justify(do_justify);
+    layout.set_width((int)((rwidth-2*margin)*Pango.SCALE));
+    layout.set_text(text,-1);
+
+    var pagenum_font_description = new Pango.FontDescription();
+    pagenum_font_description.set_family("Sans");
+    pagenum_font_description.set_size((int)(9 * Pango.SCALE));
+    var pagenum_layout = Pango.cairo_create_layout(cr);
+    pagenum_layout.set_font_description(pagenum_font_description);
+
+    // tbd - move to the baseline pos of the first line
+    int page_num = 1;
+    bool quit = false;
+    double ybottom = rheight-top_margin-bottom_margin;
+    weak Pango.LayoutIter iter = layout.get_iter();
+
+    clear_page(cr, width, height, margin, top_margin, do_rotate);
+    while(!iter.at_last_line()) {
+        double y_pos;
+        y_pos = 0;
+        bool first_line = true;
+
+        while(!iter.at_last_line()) {
+            iter.get_line_extents(out ink_rect, out logical_rect);
+            var line = iter.get_line_readonly();
+            iter.next_line();
+
+            // Decrease paragraph spacing
+            if (ink_rect.width == 0) {
+                double dy = font_size/2;
+                y_pos += dy;
+                if (!first_line)
+                    cr.rel_move_to(0,dy);
+            }
+            else {
+                double xstart=1.0*logical_rect.x/Pango.SCALE;
+                cr.rel_move_to(xstart,0);
+                Pango.cairo_show_layout_line(cr, line);
+                cr.rel_move_to(-xstart,(int)(logical_rect.height/Pango.SCALE));
+                y_pos += logical_rect.height/Pango.SCALE;
+            }
+
+            if (y_pos > ybottom)
+                break;
+            first_line = false;
+        }
+
+        // draw page at bottom
+        pagenum_layout.set_text(page_num.to_string(),-1);
+        pagenum_layout.get_extents(out ink_rect, out logical_rect);
+        cr.move_to(rwidth-logical_rect.width/Pango.SCALE,rheight-margin);
+        Pango.cairo_show_layout(cr, pagenum_layout);
+
+        surface.write_to_png("page-" + page_num.to_string("%03d") + ".png");
+        page_num++;
+        cr.show_page();
+        clear_page(cr, width, height, margin, top_margin, do_rotate);
+    }
+
+    return 0;
+}

Copied: trunk/tests/examples/poppler-sample.test (from r11, /trunk/tests/examples/cairo.test)
==============================================================================
--- /trunk/tests/examples/cairo.test	(original)
+++ trunk/tests/examples/poppler-sample.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg gtk+-2.0 --pkg poppler-glib -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/poppler-sample.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/poppler-sample.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,81 @@
+/* Using Poppler for PDF rendering in Vala sample code */
+
+using GLib;
+
+public class PopplerSample : GLib.Object {
+
+    private Gtk.Window win;
+
+    // To store the document and the current page
+    private Poppler.Document document;
+    private int index = 0;
+
+    private string _file_uri;
+    public string file_uri {
+        construct {
+            // When constructing, turn the file name into a uri
+            this._file_uri = "file://%s".printf (value);
+        }
+        get {
+            return this._file_uri;
+        }
+    }
+
+    // To create an application object with the name of the file to display
+    public PopplerSample (string file_name) {
+        this.file_uri = file_name;
+    }
+
+    construct {
+        this.document = new Poppler.Document.from_file (this.file_uri, "");
+
+        // Render the first page
+        var page = this.document.get_page (this.index);
+        var pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, 800, 600);
+        page.render_to_pixbuf (0, 0, 800, 600, 1.0, 0, pixbuf);
+
+        // Create a window to show an image, and set that image to show the buffer just rendered
+        this.win = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
+        var image = new Gtk.Image.from_pixbuf (pixbuf);
+        this.win.add (image);
+
+        this.win.key_press_event += next_cb;
+        this.win.destroy += Gtk.main_quit;
+    }
+
+    private bool next_cb (Gtk.Window w, Gdk.EventKey e) {
+        // If the key pressed was q, quit, else show the next page
+        if (e.str == "q") {
+            Gtk.main_quit ();
+        }
+
+        var image = (Gtk.Image) this.win.get_child ();
+        var pixbuf = image.get_pixbuf ();
+
+        // Render the next page, or the first if we were at the last
+        this.index = (++this.index) % this.document.get_n_pages ();
+        var page = this.document.get_page (this.index);
+        page.render_to_pixbuf (0, 0, 800, 600, 1.0, 0, pixbuf);
+        image.set_from_pixbuf (pixbuf);
+
+        return false;
+    }
+
+    public void run () {
+        this.win.show_all ();
+
+        Gtk.main ();
+    }
+
+    public static void main (string[] args) {
+        if (args.length != 2) {
+            stderr.printf ("Usage: %s /full/path/to/some.pdf\n", args[0]);
+            return;
+        }
+
+        Gtk.init (ref args);
+
+        var app = new PopplerSample (args[1]);
+        app.run ();
+    }
+}
\ No newline at end of file

Modified: trunk/tests/examples/properties-construction.test
==============================================================================
--- trunk/tests/examples/properties-construction.test	(original)
+++ trunk/tests/examples/properties-construction.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/properties.test
==============================================================================
--- trunk/tests/examples/properties.test	(original)
+++ trunk/tests/examples/properties.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/string.test
==============================================================================
--- trunk/tests/examples/string.test	(original)
+++ trunk/tests/examples/string.test	Fri Oct 17 23:28:47 2008
@@ -22,7 +22,7 @@
 $VALAC  -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x1" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Modified: trunk/tests/examples/update.sh
==============================================================================
--- trunk/tests/examples/update.sh	(original)
+++ trunk/tests/examples/update.sh	Fri Oct 17 23:28:47 2008
@@ -8,10 +8,15 @@
 egg-clock
 gconf
 glade
+gnio-sock
 gstreamer-square-beep
 gstreamer-video
 gtk-sample
 gtk-builder-sample
+gtk-filechooser-subclass
+gtk-valawidget
+poppler-sample
+webkit-sample
 "
 
 deprecated="
@@ -47,11 +52,19 @@
 grep "Gst\." $file >/dev/null && PACKAGES="$PACKAGES --pkg gstreamer-0.10"
 grep "Gdk\.x11" $file >/dev/null && PACKAGES="$PACKAGES --pkg gdk-x11-2.0"
 grep "XOverlay" $file >/dev/null && PACKAGES="$PACKAGES --pkg gstreamer-interfaces-0.10"
+grep "using Panel" $file >/dev/null && PACKAGES="$PACKAGES --pkg libpanelapplet-2.0"
+grep -i "pango" $file >/dev/null && PACKAGES="$PACKAGES --pkg pangocairo"
+grep "Poppler\." $file >/dev/null && PACKAGES="$PACKAGES --pkg poppler-glib"
+grep "SocketConnection" $file >/dev/null && PACKAGES="$PACKAGES --pkg gnio"
+grep "WebKit" $file >/dev/null && PACKAGES="$PACKAGES --pkg webkit-1.0"
 
 VALAFLAGS=
 [ "$test" = "glade" ] && VALAFLAGS='-X "-Wl,--export-dynamic"'
 [ "$test" = "gnome-desktop-and-menu" ] && VALAFLAGS='-X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE"'
 
+TESTARGS=
+[ "$test" = "pango-cairo" ] && TESTARGS="../Makefile"
+
 RUN=1
 for nr in $interactive ; do
   [ $nr = $test ] && RUN=0
@@ -82,7 +95,7 @@
 \$VALAC $PACKAGES -o \$TESTNAME \$SRCDIR/\$TESTNAME.vala $VALAFLAGS \$VALAFLAGS
 
 if [ "x$RUN" = "x1" -o "x\$INTERACT" = "x1" ] ; then
-  ./\$TESTNAME $@
+  ./\$TESTNAME $TESTARGS \$@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Copied: trunk/tests/examples/webkit-sample.test (from r11, /trunk/tests/examples/cairo.test)
==============================================================================
--- /trunk/tests/examples/cairo.test	(original)
+++ trunk/tests/examples/webkit-sample.test	Fri Oct 17 23:28:47 2008
@@ -19,10 +19,10 @@
 
 TESTNAME=`basename $0 .test`
 
-$VALAC  --pkg gtk+-2.0 --pkg cairo -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
+$VALAC  --pkg gtk+-2.0 --pkg webkit-1.0 -o $TESTNAME $SRCDIR/$TESTNAME.vala  $VALAFLAGS
 
 if [ "x0" = "x1" -o "x$INTERACT" = "x1" ] ; then
-  ./$TESTNAME 
+  ./$TESTNAME  $@
 else
   echo ""
   echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"

Added: trunk/tests/examples/webkit-sample.vala
==============================================================================
--- (empty file)
+++ trunk/tests/examples/webkit-sample.vala	Fri Oct 17 23:28:47 2008
@@ -0,0 +1,95 @@
+using GLib;
+using Gtk;
+using WebKit;
+
+public class ValaBrowser : Window {
+
+    private const string TITLE = "Vala Browser";
+    private const string HOME_URL = "http://acid3.acidtests.org/";;
+    private const string DEFAULT_PROTOCOL = "http";
+
+    private Regex protocol_regex;
+
+    private Entry url_bar;
+    private WebView web_view;
+    private Label status_bar;
+    private ToolButton back_button;
+    private ToolButton forward_button;
+    private ToolButton reload_button;
+
+    construct {
+        this.title = ValaBrowser.TITLE;
+        set_default_size (800, 600);
+        this.protocol_regex = new Regex (".*://.*");
+        create_widgets ();
+        connect_signals ();
+        this.url_bar.grab_focus ();
+    }
+
+    private void create_widgets () {
+        var toolbar = new Toolbar ();
+        this.back_button = new ToolButton.from_stock (STOCK_GO_BACK);
+        this.forward_button = new ToolButton.from_stock (STOCK_GO_FORWARD);
+        this.reload_button = new ToolButton.from_stock (STOCK_REFRESH);
+        toolbar.add (this.back_button);
+        toolbar.add (this.forward_button);
+        toolbar.add (this.reload_button);
+        this.url_bar = new Entry ();
+        this.web_view = new WebView ();
+        var scrolled_window = new ScrolledWindow (null, null);
+        scrolled_window.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
+        scrolled_window.add (this.web_view);
+        this.status_bar = new Label ("Welcome");
+        this.status_bar.xalign = 0;
+        var vbox = new VBox (false, 0);
+        vbox.pack_start (toolbar, false, true, 0);
+        vbox.pack_start (this.url_bar, false, true, 0);
+        vbox.add (scrolled_window);
+        vbox.pack_start (this.status_bar, false, true, 0);
+        add (vbox);
+    }
+
+    private void connect_signals () {
+        this.destroy += Gtk.main_quit;
+        this.url_bar.activate += on_activate;
+        this.web_view.title_changed += (s, w, t) => {
+            this.title = "%s - %s".printf (t, ValaBrowser.TITLE);
+        };
+        this.web_view.load_committed += (s, f) => {
+            this.url_bar.text = f.get_uri ();
+            update_buttons ();
+        };
+        this.back_button.clicked += this.web_view.go_back;
+        this.forward_button.clicked += this.web_view.go_forward;
+        this.reload_button.clicked += this.web_view.reload;
+    }
+
+    private void update_buttons () {
+        this.back_button.sensitive = this.web_view.can_go_back ();
+        this.forward_button.sensitive = this.web_view.can_go_forward ();
+    }
+
+    private void on_activate () {
+        var url = this.url_bar.text;
+        if (!this.protocol_regex.match (url)) {
+            url = "%s://%s".printf (ValaBrowser.DEFAULT_PROTOCOL, url);
+        }
+        this.web_view.open (url);
+    }
+
+    public void start () {
+        show_all ();
+        this.web_view.open (ValaBrowser.HOME_URL);
+    }
+
+    public static int main (string[] args) {
+        Gtk.init (ref args);
+
+        var browser = new ValaBrowser ();
+        browser.start ();
+
+        Gtk.main ();
+
+        return 0;
+    }
+}
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]