[vala-tests] test/examples: update from live.gnome.org



commit 24dbe06a6e271ddef13cc94f916047fe865e897a
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Sun Aug 8 00:43:48 2010 +0200

    test/examples: update from live.gnome.org

 tests/examples/cairo-sample.vala            |  133 +++++++++++++++++
 tests/examples/cairo-shaped.vala            |  214 +++++++++++++++++++++++++++
 tests/examples/cairo-threaded.vala          |  168 +++++++++++++++++++++
 tests/examples/character.vala               |   14 +-
 tests/examples/clutter-demo.vala            |   16 +-
 tests/examples/conditional-compilation.vala |   26 ++++
 tests/examples/couchdb.vala                 |    9 +-
 tests/examples/dbus-bluez.vala              |   89 +++++------
 tests/examples/dbus-client-waiting.vala     |  171 +++++++++++++++++++++
 tests/examples/dbus-demo-client.vala        |   21 +++
 tests/examples/dbus-demo-server.vala        |   34 +++++
 tests/examples/dbus-purple.vala             |   81 +++-------
 tests/examples/dbus-skype.vala              |   65 ++++-----
 tests/examples/gdbus-demo-client.vala       |   20 +++
 tests/examples/gdbus-demo-server.vala       |   25 +++
 tests/examples/gee-iterable.vala            |    7 +-
 tests/examples/gee-list.vala                |    5 +-
 tests/examples/gee-map.vala                 |   35 ++++-
 tests/examples/gee-set.vala                 |    5 +-
 tests/examples/gio-compression.vala         |   46 ++++++
 tests/examples/gstreamer-audio-player.vala  |    6 +-
 tests/examples/gstreamer-square-beep.vala   |   17 +--
 tests/examples/gtk-cell-renderer.vala       |   97 ++++++++++++
 tests/examples/gtk-hello.vala               |    4 +-
 tests/examples/gtk-search-dialog.vala       |    2 +-
 tests/examples/gtk-sync-sample.vala         |    8 +-
 tests/examples/gtk-text-viewer.vala         |    1 +
 tests/examples/gtk-treeview-listsample.vala |   41 +++---
 tests/examples/mx-expander-demo.vala        |   36 +++++
 tests/examples/mx-widget-factory.vala       |  121 +++++++++++++++
 tests/examples/signals.vala                 |    9 +-
 tests/examples/soup-http-server.vala        |    1 +
 tests/examples/string.vala                  |    6 +-
 tests/examples/type-modules-myplugin.vala   |    2 +-
 34 files changed, 1306 insertions(+), 229 deletions(-)
---
diff --git a/tests/examples/cairo-sample.vala b/tests/examples/cairo-sample.vala
new file mode 100644
index 0000000..316345c
--- /dev/null
+++ b/tests/examples/cairo-sample.vala
@@ -0,0 +1,133 @@
+
+// http://live.gnome.org/Vala/CairoSample vala-test:examples/cairo-sample.vala
+
+using Gtk;
+using Cairo;
+
+public class CairoSample : Gtk.Window {
+
+    private const int SIZE = 30;
+
+    public CairoSample () {
+        this.title = "Cairo Vala Demo";
+        this.destroy.connect (Gtk.main_quit);
+        set_default_size (450, 550);
+        create_widgets ();
+    }
+
+    private void create_widgets () {
+        var drawing_area = new DrawingArea ();
+        drawing_area.expose_event.connect (on_expose);
+        add (drawing_area);
+    }
+
+    private bool on_expose (Widget da, Gdk.EventExpose event) {
+        var ctx = Gdk.cairo_create (da.window);
+
+        ctx.set_source_rgb (0, 0, 0);
+
+        ctx.set_line_width (SIZE / 4);
+        ctx.set_tolerance (0.1);
+
+        ctx.set_line_join (LineJoin.ROUND);
+        ctx.set_dash (new double[] {SIZE / 4.0, SIZE / 4.0}, 0);
+        stroke_shapes (ctx, 0, 0);
+
+        ctx.set_dash (null, 0);
+        stroke_shapes (ctx, 0, 3 * SIZE);
+
+        ctx.set_line_join (LineJoin.BEVEL);
+        stroke_shapes (ctx, 0, 6 * SIZE);
+
+        ctx.set_line_join (LineJoin.MITER);
+        stroke_shapes(ctx, 0, 9 * SIZE);
+
+        fill_shapes (ctx, 0, 12 * SIZE);
+
+        ctx.set_line_join (LineJoin.BEVEL);
+        fill_shapes (ctx, 0, 15 * SIZE);
+        ctx.set_source_rgb (1, 0, 0);
+        stroke_shapes (ctx, 0, 15 * SIZE);
+
+        return true;
+    }
+
+    private void stroke_shapes (Context ctx, int x, int y) {
+        this.draw_shapes (ctx, x, y, ctx.stroke);
+    }
+
+    private void fill_shapes (Context ctx, int x, int y) {
+        this.draw_shapes (ctx, x, y, ctx.fill);
+    }
+
+    private delegate void DrawMethod ();
+
+    private void draw_shapes (Context ctx, int x, int y, DrawMethod draw_method) {
+        ctx.save ();
+
+        ctx.new_path ();
+        ctx.translate (x + SIZE, y + SIZE);
+        bowtie (ctx);
+	draw_method ();
+
+        ctx.new_path ();
+        ctx.translate (3 * SIZE, 0);
+        square (ctx);
+	draw_method ();
+
+        ctx.new_path ();
+        ctx.translate (3 * SIZE, 0);
+        triangle (ctx);
+	draw_method ();
+
+        ctx.new_path ();
+        ctx.translate (3 * SIZE, 0);
+        inf (ctx);
+	draw_method ();
+
+        ctx.restore();
+    }
+
+    private void triangle (Context ctx) {
+        ctx.move_to (SIZE, 0);
+        ctx.rel_line_to (SIZE, 2 * SIZE);
+        ctx.rel_line_to (-2 * SIZE, 0);
+        ctx.close_path ();
+    }
+
+    private void square (Context ctx) {
+        ctx.move_to (0, 0);
+        ctx.rel_line_to (2 * SIZE, 0);
+        ctx.rel_line_to (0, 2 * SIZE);
+        ctx.rel_line_to (-2 * SIZE, 0);
+        ctx.close_path ();
+    }
+
+    private void bowtie (Context ctx) {
+        ctx.move_to (0, 0);
+        ctx.rel_line_to (2 * SIZE, 2 * SIZE);
+        ctx.rel_line_to (-2 * SIZE, 0);
+        ctx.rel_line_to (2 * SIZE, -2 * SIZE);
+        ctx.close_path ();
+    }
+
+    private void inf (Context ctx) {
+        ctx.move_to (0, SIZE);
+        ctx.rel_curve_to (0, SIZE, SIZE, SIZE, 2 * SIZE, 0);
+        ctx.rel_curve_to (SIZE, -SIZE, 2 * SIZE, -SIZE, 2 * SIZE, 0);
+        ctx.rel_curve_to (0, SIZE, -SIZE, SIZE, -2 * SIZE, 0);
+        ctx.rel_curve_to (-SIZE, -SIZE, -2 * SIZE, -SIZE, -2 * SIZE, 0);
+        ctx.close_path ();
+    }
+
+    static int main (string[] args) {
+        Gtk.init (ref args);
+
+        var cairo_sample = new CairoSample ();
+        cairo_sample.show_all ();
+
+        Gtk.main ();
+
+        return 0;
+    }
+}
diff --git a/tests/examples/cairo-shaped.vala b/tests/examples/cairo-shaped.vala
new file mode 100644
index 0000000..1531362
--- /dev/null
+++ b/tests/examples/cairo-shaped.vala
@@ -0,0 +1,214 @@
+
+// http://live.gnome.org/Vala/CairoSample vala-test:examples/cairo-shaped.vala
+
+using Gtk;
+using Cairo;
+
+/**
+ * This example creates a clock with the following features:
+ * Shaped window -- Window is unbordered and transparent outside the clock
+ * Events are only registered for the window on the hour dots or on the center
+ * dot. When the mouse is "in" the window (on one of the dots) it will turn
+ * green.
+ * This helps you understand where the events are actually being registered
+ * Clicking allows you to drag the clock.
+ * There is currently no code in place to close the window, you must kill the
+ * process manually. A Composited environment is required. The python code I
+ * copied this from includes checks for this. In my laziness I left them out.
+ */
+public class CairoShaped : Gtk.Window {
+
+    // Are we inside the window?
+    private bool inside = false;
+
+    /**
+     * Just creating the window, setting things up
+     */
+    public CairoShaped () {
+        this.title = "Cairo Vala Demo";
+        set_default_size (200, 200);
+
+        // 'skip_taskbar_hint' determines whether the window gets an icon in
+        // the taskbar / dock
+        this.skip_taskbar_hint = true;
+
+        // Turn off the border decoration
+        this.decorated = false;
+        this.app_paintable = true;
+
+        // Need to get the RGBA colormap or transparency doesn't work.
+        set_colormap (this.screen.get_rgba_colormap ());
+
+        // We need to register which events we are interested in
+        add_events (Gdk.EventMask.BUTTON_PRESS_MASK);
+        add_events (Gdk.EventMask.ENTER_NOTIFY_MASK);
+        add_events (Gdk.EventMask.LEAVE_NOTIFY_MASK);
+
+        // Connecting some events, 'queue_draw()' redraws the window.
+        // 'begin_move_drag()' sets up the window drag
+        this.enter_notify_event.connect (() => {
+            this.inside = true;
+            queue_draw ();
+            return true;
+        });
+        this.leave_notify_event.connect (() => {
+            this.inside = false;
+            queue_draw ();
+            return true;
+        });
+        this.button_press_event.connect ((e) => {
+            begin_move_drag ((int) e.button, (int) e.x_root, (int) e.y_root, e.time);
+            return true;
+        });
+
+        // The expose event is what is called when we need to draw the window
+        this.expose_event.connect (on_expose);
+
+        this.destroy.connect (Gtk.main_quit);
+    }
+
+    /**
+     * Actual drawing takes place within this method
+     */
+    private bool on_expose (Widget da, Gdk.EventExpose event) {
+        // Get a cairo context for our window
+        var ctx = Gdk.cairo_create (da.window);
+
+        // This makes the current color transparent (a = 0.0)
+        ctx.set_source_rgba (1.0, 1.0, 1.0, 0.0);
+
+        // Paint the entire window transparent to start with.
+        ctx.set_operator (Cairo.Operator.SOURCE);
+        ctx.paint ();
+
+        // If we wanted to allow scaling we could do some calculation here
+        float radius = 100;
+
+        // This creates a radial gradient. c() is just a helper method to
+        // convert from 0 - 255 scale to 0.0 - 1.0 scale.
+        var p = new Cairo.Pattern.radial (100, 100, 0, 100, 100, 100);
+        if (inside) {
+            p.add_color_stop_rgba (0.0, c (10), c (190), c (10), 1.0);
+            p.add_color_stop_rgba (0.8, c (10), c (190), c (10), 0.7);
+            p.add_color_stop_rgba (1.0, c (10), c (190), c (10), 0.5);
+        } else {
+            p.add_color_stop_rgba (0.0, c (10), c (10), c (190), 1.0);
+            p.add_color_stop_rgba (0.8, c (10), c (10), c (190), 0.7);
+            p.add_color_stop_rgba (1.0, c (10), c (10), c (190), 0.5);
+        }
+
+        // Set the gradient as our source and paint a circle.
+        ctx.set_source (p);
+        ctx.arc (100, 100, radius, 0, 2.0 * 3.14);
+        ctx.fill ();
+        ctx.stroke ();
+
+        // This chooses the color for the hour dots
+        if (inside) {
+            ctx.set_source_rgba (0.0, 0.2, 0.6, 0.8);
+        } else {
+            ctx.set_source_rgba (c (226), c (119), c (214), 0.8);
+        }
+
+        // Draw the 12 hour dots.
+        for (int i = 0; i < 12; i++) {
+            ctx.arc (100 + 90.0 * Math.cos (2.0 * 3.14 * (i / 12.0)),
+                     100 + 90.0 * Math.sin (2.0 * 3.14 * (i / 12.0)),
+                     5, 0, 2.0 * 3.14);
+            ctx.fill ();
+            ctx.stroke ();
+        }
+
+        // This is the math to draw the hands.
+        // Nothing overly useful in this section
+        ctx.move_to (100, 100);
+        ctx.set_source_rgba (0, 0, 0, 0.8);
+
+        var t = Time.local (time_t ());
+        int hour = t.hour;
+        int minutes = t.minute;
+        int seconds = t.second;
+        double per_hour = (2 * 3.14) / 12;
+        double dh = (hour * per_hour) + ((per_hour / 60) * minutes);
+        dh += 2 * 3.14 / 4;
+        ctx.set_line_width (0.05 * radius);
+        ctx.rel_line_to (-0.5 * radius * Math.cos (dh), -0.5 * radius * Math.sin (dh));
+        ctx.move_to (100, 100);
+        double per_minute = (2 * 3.14) / 60;
+        double dm = minutes * per_minute;
+        dm += 2 * 3.14 / 4;
+        ctx.rel_line_to (-0.9 * radius * Math.cos (dm), -0.9 * radius * Math.sin (dm));
+        ctx.move_to (100, 100);
+        double per_second = (2 * 3.14) / 60;
+        double ds = seconds * per_second;
+        ds += 2 * 3.14 / 4;
+        ctx.rel_line_to (-0.9 * radius * Math.cos (ds), -0.9 * radius * Math.sin (ds));
+        ctx.stroke ();
+
+        // Drawing the center dot
+        ctx.set_source_rgba (c (124), c (32), c (113), 0.7);
+
+        ctx.arc (100, 100, 0.1 * radius, 0, 2.0 * 3.14);
+        ctx.fill ();
+        ctx.stroke ();
+
+        // This is possibly the most important bit.
+        // Here is where we create the mask to shape the window
+        // And decide what areas will receive events and which areas
+        // Will let events pass through to the windows below.
+
+        // First create a pixmap the size of the window
+        var px = new Gdk.Pixmap (null, 200, 200, 1);
+        // Get a context for it
+        var pmcr = Gdk.cairo_create (px);
+
+        // Initially we want to blank out everything in transparent as we
+        // Did initially on the ctx context
+        pmcr.set_source_rgba (1.0, 1.0, 1.0, 0.0);
+        pmcr.set_operator (Cairo.Operator.SOURCE);
+        pmcr.paint ();
+
+        // Now the areas that should receive events need to be made opaque
+        pmcr.set_source_rgba (0, 0, 0, 1);
+
+        // Here we copy the motions to draw the middle dots and the hour dots.
+        // This is mostly to demonstrate that you can make this any shape you
+        // want.
+        pmcr.arc (100, 100, 10, 0, 2.0 * 3.14);
+        pmcr.fill ();
+        pmcr.stroke ();
+        for (int i = 0; i < 12; i++) {
+            pmcr.arc (100 + 90.0 * Math.cos (2.0 * 3.14 * (i / 12.0)),
+                      100 + 90.0 * Math.sin (2.0 * 3.14 * (i / 12.0)),
+                      5, 0, 2.0 * 3.14);
+            pmcr.fill ();
+            pmcr.stroke ();
+        }
+
+        // This sets the mask. Note that we have to cast to a Gdk.Bitmap*,
+        // it won't compile without that bit.
+        input_shape_combine_mask ((Gdk.Bitmap*) px, 0, 0);
+        return true;
+    }
+
+    private double c (int val) {
+        return val / 255.0;
+    }
+
+    static int main (string[] args) {
+        Gtk.init (ref args);
+
+        var cairo_sample = new CairoShaped ();
+        cairo_sample.show_all ();
+
+        // Just a timeout to update once a second.
+        Timeout.add_seconds (1, () => {
+            cairo_sample.queue_draw ();
+            return true;
+        });
+
+        Gtk.main ();
+
+        return 0;
+    }
+}
diff --git a/tests/examples/cairo-threaded.vala b/tests/examples/cairo-threaded.vala
new file mode 100644
index 0000000..103fbe0
--- /dev/null
+++ b/tests/examples/cairo-threaded.vala
@@ -0,0 +1,168 @@
+
+// http://live.gnome.org/Vala/CairoSample vala-test:examples/cairo-threaded.vala
+
+using Gtk;
+using Gdk;
+
+public class CairoThreadedExample : Gtk.Window {
+
+    // the global pixmap that will serve as our buffer
+    private Gdk.Pixmap pixmap;
+
+    private int oldw;
+    private int oldh;
+
+    private int currently_drawing;
+    private int i_draw;
+
+    private unowned Thread thread_info;
+    private bool first_execution = true;
+
+    public CairoThreadedExample () {
+        // constructor chain up
+        GLib.Object (type: Gtk.WindowType.TOPLEVEL);
+        // set_window size
+        set_size_request (500, 500);
+
+        // this must be done before we define our pixmap so that it can
+        // reference the colour depth and such
+        show_all ();
+
+        // set up our pixmap so it is ready for drawing
+        this.pixmap = new Gdk.Pixmap (this.window, 500, 500, -1);
+
+        // because we will be painting our pixmap manually during expose events
+        // we can turn off gtk's automatic painting and double buffering routines.
+        this.app_paintable = true;
+        this.double_buffered = false;
+
+        // Signals
+        this.destroy.connect (Gtk.main_quit);
+        this.expose_event.connect (on_window_expose_event);
+        this.configure_event.connect (on_window_configure_event);
+    }
+
+    public void run () {
+        // Timeout repeatedly calls closure every 100 ms after it returned true
+        Timeout.add (100, timer_exe);
+    }
+
+    private bool on_window_configure_event (Gtk.Widget sender, Gdk.EventConfigure event) {
+        // make our selves a properly sized pixmap if our window has been resized
+        if (oldw != event.width || oldh != event.height) {
+            // create our new pixmap with the correct size.
+            var tmppixmap = new Gdk.Pixmap (this.window, event.width, event.height, -1);
+            // copy the contents of the old pixmap to the new pixmap.
+            // This keeps ugly uninitialized pixmaps from being painted upon
+            // resize
+            int minw = oldw, minh = oldh;
+            if (event.width < minw) {
+                minw = event.width;
+            }
+            if (event.height < minh) {
+                minh = event.height;
+            }
+            Gdk.draw_drawable (tmppixmap, this.style.fg_gc[this.get_state ()],
+                               pixmap, 0, 0, 0, 0, minw, minh);
+            // we're done with our old pixmap, so we can get rid of it and
+            // replace it with our properly-sized one.
+            pixmap = tmppixmap;
+        }
+        oldw = event.width;
+        oldh = event.height;
+        return true;
+    }
+
+    private bool on_window_expose_event (Gtk.Widget da, Gdk.EventExpose event) {
+        da.window.draw_drawable (this.style.fg_gc[this.get_state ()], pixmap,
+                                 // Only copy the area that was exposed.
+                                 event.area.x, event.area.y,
+                                 event.area.x, event.area.y,
+                                 event.area.width, event.area.height);
+        return true;
+    }
+
+    // do_draw will be executed in a separate thread whenever we would like to
+    // update our animation
+    private void* do_draw () {
+        int width, height;
+        currently_drawing = 1;
+
+        Gdk.threads_enter ();
+        pixmap.get_size (out width, out height);
+        Gdk.threads_leave ();
+
+        //create a gtk-independant surface to draw on
+        var cst = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
+        var cr = new Cairo.Context (cst);
+
+        // do some time-consuming drawing
+        i_draw++;
+        i_draw = i_draw % 300;   // give a little movement to our animation
+        cr.set_source_rgb (0.9, 0.9, 0.9);
+        cr.paint ();
+        // let's just redraw lots of times to use a lot of proc power
+        for (int k = 0; k < 100; k++) {
+            for (int j = 0; j < 1000; j++) {
+                cr.set_source_rgb ((double) j / 1000.0, (double) j / 1000.0,
+                             1.0 - (double) j / 1000.0);
+                cr.move_to (i_draw, j / 2); 
+                cr.line_to (i_draw + 100, j / 2);
+                cr.stroke ();
+            }
+        }
+
+        // When dealing with gdkPixmap's, we need to make sure not to
+        // access them from outside Gtk.main().
+        Gdk.threads_enter ();
+
+        var cr_pixmap = Gdk.cairo_create (pixmap);
+        cr_pixmap.set_source_surface (cst, 0, 0);
+        cr_pixmap.paint ();
+
+        Gdk.threads_leave ();
+
+        currently_drawing = 0;
+        return null;
+    }
+
+    private bool timer_exe () {
+        // use a safe function to get the value of currently_drawing so
+        // we don't run into the usual multithreading issues
+        int drawing_status = AtomicInt.get (ref currently_drawing);
+
+        // if we are not currently drawing anything, launch a thread to 
+        // update our pixmap
+        if (drawing_status == 0) {
+            if (first_execution != true) {
+                thread_info.join ();
+            }
+            try {
+                thread_info = Thread.create (do_draw, true);
+            } catch (Error e) {
+                stderr.printf ("%s\n", e.message);
+            }
+        }
+
+        // tell our window it is time to draw our animation.
+        int width, height;
+        pixmap.get_size (out width, out height);
+        queue_draw_area (0, 0, width, height);
+        first_execution = false;
+        return true;
+    }
+
+    static int main (string[] args){
+        Gdk.threads_init ();
+        Gdk.threads_enter ();
+
+        Gtk.init (ref args);
+        var window = new CairoThreadedExample ();
+        window.run ();
+        Gtk.main ();
+
+        Gdk.threads_leave ();
+
+        return 0;
+    }
+}
diff --git a/tests/examples/character.vala b/tests/examples/character.vala
index 8c86f1a..c0105c5 100644
--- a/tests/examples/character.vala
+++ b/tests/examples/character.vala
@@ -3,16 +3,16 @@
 
 void main () {
 
-    string unicode_string = "1234567890 ١٢٣٤٥٦٧٨٩۰ ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz أبتةثجحخدذرزسشصضطظعغÙ?Ù?Ù?Ù?Ù?Ù?Ù?Ù?Ù?";
+    string s = "1234567890 ١٢٣٤٥٦٧٨٩۰ ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz أبتةثجحخدذرزسشصضطظعغÙ?Ù?Ù?Ù?Ù?Ù?Ù?Ù?Ù?";
 
-    for (unowned string s = unicode_string; s.get_char () != 0 ; s = s.next_char ()) {
+    for (unowned string it = s; it.get_char () != 0; it = it.next_char ()) {
 
-        unichar unicode_character = s.get_char ();
-        UnicodeType unicode_character_type = unicode_character.type ();
+        unichar c = it.get_char ();
+        UnicodeType type = c.type ();
 
-        stdout.printf("'%s' is ", new StringBuilder ().append_unichar (unicode_character).str);
+        stdout.printf ("'%s' is ", c.to_string ());
 
-        switch (unicode_character_type) {
+        switch (type) {
         case UnicodeType.UPPERCASE_LETTER:
             stdout.printf ("UPPERCASE_LETTER\n");
             break;
@@ -20,7 +20,7 @@ void main () {
             stdout.printf ("LOWERCASE_LETTER\n");
             break;
         case UnicodeType.OTHER_LETTER:
-            stdout.printf("OTHER_LETTER\n");
+            stdout.printf ("OTHER_LETTER\n");
             break;
         case UnicodeType.DECIMAL_NUMBER:
             stdout.printf ("OTHER_NUMBER\n");
diff --git a/tests/examples/clutter-demo.vala b/tests/examples/clutter-demo.vala
index a1ad9eb..a23f6f7 100644
--- a/tests/examples/clutter-demo.vala
+++ b/tests/examples/clutter-demo.vala
@@ -55,8 +55,8 @@ class ClutterDemo {
         for (int i = 0; i < rectangles.length; i++) {
             animations[i] = rectangles[i].animate (
                                       AnimationMode.LINEAR, 5000,
-                                      "x", stage.width / 2,
-                                      "rotation-angle-z", 500.0);
+                                      x: stage.width / 2,
+                                      rotation_angle_z: 500.0);
         }
         animations[animations.length - 1].completed.connect (() => {
             var text = new Text.full ("Bitstream Vera Sans 40",
@@ -68,16 +68,16 @@ class ClutterDemo {
             text.y = -text.height;    // Off-stage
             stage.add_actor (text);
             text.animate (AnimationMode.EASE_OUT_BOUNCE, 3000,
-                          "y", stage.height / 2);
+                          y: stage.height / 2);
 
             for (int i = 0; i < rectangles.length; i++) {
                 animations[i] = rectangles[i].animate (
                         AnimationMode.EASE_OUT_BOUNCE, 3000,
-                        "x", Random.next_double () * stage.width,
-                        "y", Random.next_double () * stage.height / 2
-                                                   + stage.height / 2,
-                        "rotation-angle-z", rectangles[i].rotation_angle_z,
-                        "opacity", 0);
+                        x: Random.next_double () * stage.width,
+                        y: Random.next_double () * stage.height / 2
+                                                 + stage.height / 2,
+                        rotation_angle_z: rectangles[i].rotation_angle_z,
+                        opacity: 0);
             }
         });
     }
diff --git a/tests/examples/conditional-compilation.vala b/tests/examples/conditional-compilation.vala
new file mode 100644
index 0000000..f18301d
--- /dev/null
+++ b/tests/examples/conditional-compilation.vala
@@ -0,0 +1,26 @@
+
+// http://live.gnome.org/Vala/PreprocessorSample vala-test:examples/conditional-compilation.vala
+
+void main () {
+
+#if ( FOOBAR || FOO || BAR ) && (FOOBAR == FOO && FOO == BAR)
+    message ("FOOBAR == FOO == BAR");
+#endif
+
+#if ! NOFOO && (FOOBAR || (FOO && BAR)) 
+    message ("FOOBAR");
+#elif FOO && ! NOFOO 
+    message ("FOO");
+#elif BAR && ! NOFOO
+    message ("BAR");
+#elif NOFOO
+#if FOOBAR || (FOO && BAR)
+    message ("NOFOO FOOBAR");
+#else
+    message ("NOFOO");
+#endif
+#else
+    message ("Nothing relevant defined");
+#endif
+
+}
diff --git a/tests/examples/couchdb.vala b/tests/examples/couchdb.vala
index 8ec67c6..a128db1 100644
--- a/tests/examples/couchdb.vala
+++ b/tests/examples/couchdb.vala
@@ -7,9 +7,9 @@ const string DB2 = "vala2";
 int main () {
 
     /* Connect to CouchDB */
-    var conn = new CouchDB.Connection ();
-//  var conn = new CouchDB.Connection ("http://localhost:5984";);
-    stdout.printf ("database hostname: %s\n", conn.get_hostname ());
+    var conn = new CouchDB.Session ();
+//  var conn = new CouchDB.Session ("http://localhost:5984";);
+    stdout.printf ("Connecting to CouchDB at %s\n", conn.get_uri ());
 
     try {
 
@@ -53,8 +53,7 @@ int main () {
             stdout.printf ("* update_sequence: %d\n", dbinfo.get_update_sequence ());
             stdout.printf ("* compact_running: %s\n", dbinfo.is_compact_running ().to_string ());
             stdout.printf ("* disk_size: %d\n", dbinfo.get_disk_size ());
-            var docinfos = conn.list_documents (dbase);
-            foreach (var docinfo in docinfos) {
+            foreach (var docinfo in conn.list_documents (dbase)) {
                 stdout.printf ("* document docid: %s revision: %s\n", docinfo.get_docid (),
                                                                       docinfo.get_revision ());
                 var doc = conn.get_document (dbase, docinfo.get_docid ());
diff --git a/tests/examples/dbus-bluez.vala b/tests/examples/dbus-bluez.vala
index 332f442..d40f7d3 100644
--- a/tests/examples/dbus-bluez.vala
+++ b/tests/examples/dbus-bluez.vala
@@ -1,64 +1,57 @@
 
 // http://live.gnome.org/Vala/DBusClientSamples vala-test:examples/dbus-bluez.vala
 
-using GLib;
-
-public class BlueZDiscoverySample : GLib.Object {
-
-    private DBus.Connection conn;
-    private dynamic DBus.Object bluez;
-    public MainLoop loop { set; get; }
-
-    public void run () throws DBus.Error, GLib.Error {
-        // remove the space before SYSTEM, it is just needed for this wiki
-        this.conn = DBus.Bus.get (DBus.BusType. SYSTEM);
-
-        this.bluez = conn.get_object ("org.bluez", "/org/bluez/hci0", "org.bluez.Adapter");
-
-        // dbus signals
-        this.bluez.RemoteDeviceFound += remote_device_found;
-        this.bluez.DiscoveryStarted += discovery_started;
-        this.bluez.DiscoveryCompleted += discovery_completed;
-        this.bluez.RemoteNameUpdated += remote_name_updated;
+[DBus (name = "org.bluez.Adapter")]
+interface Bluez : Object {
+    public signal void discovery_started ();
+    public signal void discovery_completed ();
+    public signal void remote_device_found (string address, uint klass, int rssi);
+    public signal void remote_name_updated (string address, string name);
+
+    public abstract void discover_devices () throws DBus.Error;
+}
 
-        // async dbus call
-        this.bluez.DiscoverDevices ();
-    }
+MainLoop loop;
 
-    private void remote_device_found (dynamic DBus.Object bluez,
-                                      string address_, uint class_, int rssi_) {
-        message ("Signal: RemoteDeviceFound(%s, %u, %d)", address_, class_, rssi_);
-    }
+void on_remote_device_found (string address, uint klass, int rssi) {
+    stdout.printf ("Remote device found (%s, %u, %d)\n",
+                   address, klass, rssi);
+}
 
-    private void discovery_started (dynamic DBus.Object bluez) {
-        message ("Signal: DiscoveryStarted()");
-    }
+void on_discovery_started () {
+    stdout.printf ("Discovery started\n");
+}
 
-    private void remote_name_updated (dynamic DBus.Object bluez, string address_, string name_) {
-        message ("Signal: RemoteNameUpdated(%s, %s)", address_, name_);
-    }
+void on_remote_name_updated (string address, string name) {
+    stdout.printf ("Remote name updated (%s, %s)\n", address, name);
+}
 
-    private void discovery_completed (dynamic DBus.Object bluez) {
-        message ("Signal: DiscoveryCompleted()");
-        this.loop.quit ();
-    }
+void on_discovery_completed () {
+    stdout.printf ("Discovery completed\n");
+    loop.quit ();
+}
 
-    static int main (string[] args) {
-        var loop = new MainLoop (null, false);
+int main () {
+    try {
+        var conn = DBus.Bus.get (DBus.BusType.SYSTEM);
+        var bluez = (Bluez) conn.get_object ("org.bluez", "/org/bluez/hci0");
 
-        var test = new BlueZDiscoverySample ();
-        test.loop = loop;
+        // Connect to D-Bus signals
+        bluez.remote_device_found.connect (on_remote_device_found);
+        bluez.discovery_started.connect (on_discovery_started);
+        bluez.discovery_completed.connect (on_discovery_completed);
+        bluez.remote_name_updated.connect (on_remote_name_updated);
 
-        try {
-            test.run ();
-        } catch (DBus.Error e) {
-            error ("Failed to initialise");
-        } catch (GLib.Error e) {
-            error ("Dynamic method failure");
-        }
+        // Async D-Bus call
+        bluez.discover_devices ();
 
+        loop = new MainLoop ();
         loop.run ();
 
-        return 0;
+    } catch (DBus.Error e) {
+        stderr.printf ("%s\n", e.message);
+        return 1;
     }
+
+    return 0;
 }
diff --git a/tests/examples/dbus-client-waiting.vala b/tests/examples/dbus-client-waiting.vala
new file mode 100644
index 0000000..5e52b21
--- /dev/null
+++ b/tests/examples/dbus-client-waiting.vala
@@ -0,0 +1,171 @@
+
+// http://live.gnome.org/Vala/DBusClientSamples/Waiting vala-test:examples/dbus-client-waiting.vala
+
+using DBus;
+
+// [DBus (name = "org.gnome.evolution.metadata.Manager")]
+// public interface Manager : GLib.Object {
+//    public abstract void Register (DBus.ObjectPath registrar_path, uint last_checkout);
+// }
+
+[DBus (name = "org.gnome.evolution.metadata.Registrar")]
+public class Registrar: GLib.Object {
+
+    public void Set (string subject, string[] predicates, string[] values) {
+	print ("set: %s\n", subject);
+    }
+
+    public void Cleanup () {
+	print ("cleanup\n");
+    }
+
+    public void SetMany (string[] subjects, string[][] predicates, string[][] values) {
+
+
+	uint len = subjects.length;
+	uint i;
+
+	print ("setmany: %d\n", subjects.length);
+
+
+	for (i = 0; i < len; i++) {
+		message ("setmany: " + subjects[i]);
+//
+//		There's a bug in Vala that makes lengths of inner arrays of a 
+//		stacked array being wrong (apparently the inner array is no 
+//		longer NULL terminated after demarshalign, which makes calcu-
+//		lating the length impossible)
+//
+//		uint plen = 7; // strv_length (predicates[i]); 
+//		uint y;
+//
+//		for (y = 0; y < plen; y++) {
+//			if (predicates[i][y] != null && values[i][y] != null) {
+//				print ("\t%s=%s\n", predicates[i][y], values[i][y]);
+//			}
+//		}
+	}
+ 
+   }
+
+    public void UnsetMany (string[] subjects) {
+	print ("unsetmany %d\n", subjects.length);
+
+    }
+
+    public void Unset (string subject) {
+	message ("unset: %s\n" + subject);
+    }
+}
+
+public class MyApplication : GLib.Object {
+
+    public uint stored_time;
+    private DBus.Connection conn;
+    private Registrar registrar;
+    private dynamic DBus.Object bus;
+
+    private void on_reply (GLib.Error e) {
+    }
+
+    private void deactivate () {
+	registrar = null;
+    }
+
+    private void activate () {
+	dynamic DBus.Object obj;
+
+	DBus.ObjectPath path;
+
+	registrar = new Registrar ();
+
+        conn = DBus.Bus.get (DBus.BusType .SESSION);
+
+	path = new DBus.ObjectPath ("/my/application/evolution_registrar");
+
+	obj = conn.get_object ("org.gnome.evolution",
+                               "/org/gnome/evolution/metadata/Manager",
+                               "org.gnome.evolution.metadata.Manager");
+
+	conn.register_object (path, registrar);
+
+	try {
+		obj.Register (path, stored_time, on_reply);
+	} catch (GLib.Error e) {
+		message ("Can't register: %s", e.message);
+	}
+    }
+
+    private void on_name_owner_changed (DBus.Object sender, string name, string old_owner, string new_owner) {
+	if (name == "org.gnome.evolution") {
+		if (new_owner != "" && old_owner == "")
+			activate ();
+		if (old_owner != "" && new_owner == "")
+			deactivate ();
+	}
+    }
+
+    private void list_names_reply_cb (string[] names, GLib.Error e) {
+	foreach (string name in names) {
+		if (name == "org.gnome.evolution") {
+			activate();
+			break;
+		}
+	}
+    }
+
+    private bool on_ready () {
+
+	try {
+		print ("...\n");
+		bus.list_names (list_names_reply_cb);
+	} catch (GLib.Error e) {
+		message ("Can't list: %s", e.message);
+	}
+
+	return false;
+    }
+
+    public void setup (uint stored_time) throws DBus.Error, GLib.Error {
+
+	this.stored_time = stored_time;
+
+        conn = DBus.Bus.get (DBus.BusType. SESSION);
+
+	bus = conn.get_object ("org.freedesktop.DBus",
+                               "/org/freedesktop/DBus",
+                               "org.freedesktop.DBus");
+
+        bus.NameOwnerChanged += on_name_owner_changed;
+
+	Idle.add (on_ready);
+    }
+
+    static int main (string[] args) {
+        var loop = new MainLoop (null, false);
+
+        var app = new MyApplication ();
+
+        try {
+	    uint a = 0;
+
+	    if (args.length > 1)
+	    	a = (uint) args[1].to_ulong();
+	    else
+		a = 0;
+
+            app.setup (a);
+
+        } catch (DBus.Error e) {
+            stderr.printf ("Failed to initialise");
+            return 1;
+        } catch {
+            stderr.printf ("Dynamic method failure");
+            return 1;
+        }
+
+        loop.run ();
+
+        return 0;
+    }
+}
diff --git a/tests/examples/dbus-demo-client.vala b/tests/examples/dbus-demo-client.vala
new file mode 100644
index 0000000..50a7eaa
--- /dev/null
+++ b/tests/examples/dbus-demo-client.vala
@@ -0,0 +1,21 @@
+
+// http://live.gnome.org/Vala/DBusServerSample vala-test:examples/dbus-demo-client.vala
+
+[DBus (name = "org.example.Demo")]
+interface Demo : Object {
+    public abstract int ping (string msg) throws DBus.Error;
+}
+
+void main () {
+    try {
+        var conn = DBus.Bus.get (DBus.BusType.SESSION);
+        var demo = (Demo) conn.get_object ("org.example.Demo",
+                                           "/org/example/demo");
+
+        int pong = demo.ping ("Hello from Vala");
+        stdout.printf ("%d\n", pong);
+
+    } catch (DBus.Error e) {
+        stderr.printf ("%s\n", e.message);
+    }
+}
diff --git a/tests/examples/dbus-demo-server.vala b/tests/examples/dbus-demo-server.vala
new file mode 100644
index 0000000..5df1de3
--- /dev/null
+++ b/tests/examples/dbus-demo-server.vala
@@ -0,0 +1,34 @@
+
+// http://live.gnome.org/Vala/DBusServerSample vala-test:examples/dbus-demo-server.vala
+
+[DBus (name = "org.example.Demo")]
+public class DemoServer : Object {
+    private int counter;
+
+    public int ping (string msg) {
+        stdout.printf ("%s\n", msg);
+        return counter++;
+    }
+}
+
+void main () {
+    try {
+        var conn = DBus.Bus.get (DBus.BusType.SESSION);
+        dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
+                                                   "/org/freedesktop/DBus",
+                                                   "org.freedesktop.DBus");
+
+        // try to register service in session bus
+        uint reply = bus.request_name ("org.example.Demo", (uint) 0);
+        assert (reply == DBus.RequestNameReply.PRIMARY_OWNER);
+
+        var demo = new DemoServer ();
+        conn.register_object ("/org/example/demo", demo);
+
+        var loop = new MainLoop ();
+        loop.run ();
+
+    } catch (DBus.Error e) {
+        stderr.printf ("%s\n", e.message);
+    }
+}
diff --git a/tests/examples/dbus-purple.vala b/tests/examples/dbus-purple.vala
index c3480c9..602e069 100644
--- a/tests/examples/dbus-purple.vala
+++ b/tests/examples/dbus-purple.vala
@@ -1,69 +1,38 @@
 
 // http://live.gnome.org/Vala/DBusClientSamples vala-test:examples/dbus-purple.vala
 
-using DBus;
+[DBus (name = "im.pidgin.purple.PurpleInterface")]
+interface Purple : Object {
+    public signal void received_im_msg (int account, string sender, string msg,
+                                        int conv, uint flags);
 
-public class DBusSample : GLib.Object {
-
-    private DBus.Connection conn;
-    private dynamic DBus.Object purple;
-
-    public void run () throws DBus.Error, GLib.Error {
-        // remove the space before SESSION, it is only required for this wiki
-        conn = DBus.Bus.get (DBus.BusType. SESSION);
-
-        purple = conn.get_object ("im.pidgin.purple.PurpleService",
-                                  "/im/pidgin/purple/PurpleObject",
-                                  "im.pidgin.purple.PurpleInterface");
-
-        // async dbus call
-        purple.PurpleAccountsGetAllActive (getall_reply);
-
-        // dbus signals
-        purple.ReceivedImMsg += msg_received;
-    }
-
-    private void msg_received (dynamic DBus.Object purple, int dummy1, string sender,
-                               string message_, int dummy2, uint dummy3)
-    {
-        // dbus signal handler
+    public abstract int[] purple_accounts_get_all_active () throws DBus.Error;
+    public abstract string purple_account_get_username (int account) throws DBus.Error;
+}
 
-        message ("Message received %s %s", sender, message_);
-    }
+int main () {
+    try {
+        var conn = DBus.Bus.get (DBus.BusType.SESSION);
+        var purple = (Purple) conn.get_object ("im.pidgin.purple.PurpleService",
+                                               "/im/pidgin/purple/PurpleObject");
 
-    private void getall_reply (int[] ids, GLib.Error e) {
-        // callback for async dbus call
-        if (e != null) {
-            critical ("%s", e.message);
-            return;
+        var accounts = purple.purple_accounts_get_all_active ();
+        foreach (int account in accounts) {
+            string username = purple.purple_account_get_username (account);
+            stdout.printf ("Account %s\n", username);
         }
-        try {
-            foreach (int id in ids) {
-                // sync dbus call
-                string s = purple.PurpleAccountGetUsername (id);
-                message ("Account %s", s);
-            }
-        } catch (GLib.Error err) {
-            critical ("%s", err.message);
-        }
-    }
 
-    static int main (string[] args) {
-        var loop = new MainLoop (null, false);
-
-        var test = new DBusSample ();
-        try {
-            test.run ();
-        } catch (DBus.Error e) {
-            stderr.printf ("Failed to initialise");
-            return 1;
-        } catch (GLib.Error e) {
-            stderr.printf ("Dynamic method failure");
-            return 1;
-        }
+        purple.received_im_msg.connect ((account, sender, msg) => {
+            stdout.printf (@"Message received $sender: $msg\n");
+        });
 
+        var loop = new MainLoop ();
         loop.run ();
 
-        return 0;
+    } catch (DBus.Error e) {
+        stderr.printf ("%s\n", e.message);
+        return 1;
     }
+
+    return 0;
 }
diff --git a/tests/examples/dbus-skype.vala b/tests/examples/dbus-skype.vala
index cdf6349..36fc224 100644
--- a/tests/examples/dbus-skype.vala
+++ b/tests/examples/dbus-skype.vala
@@ -1,51 +1,42 @@
 
 // http://live.gnome.org/Vala/DBusClientSamples vala-test:examples/dbus-skype.vala
 
-class SkypeStatusClient {
-
-    private DBus.Connection conn;
-    private dynamic DBus.Object skype;
-
-    public void init () throws DBus.Error {
-        this.conn = DBus.Bus.get (DBus.BusType.SESSION);
-        this.skype = conn.get_object ("com.Skype.API", "/com/Skype", "com.Skype.API");
-    }
+[DBus (name = "com.Skype.API")]
+interface Skype : Object {
+    public abstract string invoke (string cmd) throws DBus.Error;
+}
 
-    public string send (string cmd) {
-        try {
-            return this.skype.Invoke (cmd);
-        } catch (GLib.Error e) {
-            error (e.message);
-        }
-        return "";
-    }
+string send (Skype skype, string cmd) throws DBus.Error {
+    return skype.invoke (cmd);
+}
 
-    public void send_check (string cmd, string expected_result) {
-        string s = send (cmd);
-        if (s != expected_result) {
-            error ("Bad result '%s', expected '%s'\n", s, expected_result);
-        }
+void send_check (Skype skype, string cmd, string expected) throws DBus.Error {
+    string actual = send (skype, cmd);
+    if (actual != expected) {
+        stderr.printf ("Bad result '%s', expected '%s'\n", actual, expected);
     }
 }
 
 int main (string[] args) {
-    var client = new SkypeStatusClient ();
-
     try {
-        client.init ();
-    } catch (DBus.Error e) {
-        error ("Failed to initialise: %s", e.message);
-    }
-
-    client.send_check ("NAME skype-status-client", "OK");
-    client.send_check ("PROTOCOL 2", "PROTOCOL 2");
+        var conn = DBus.Bus.get (DBus.BusType.SESSION);
+        var skype = (Skype) conn.get_object ("com.Skype.API", "/com/Skype");
+
+        send_check (skype, "NAME skype-status-client", "OK");
+        send_check (skype, "PROTOCOL 2", "PROTOCOL 2");
+
+        // if no arguments given, show current status, otherwise update
+        // status to first argument
+        if (args.length < 2) {
+            stdout.printf ("%s\n", send (skype, "GET USERSTATUS"));
+        } else {
+            // possible statuses: ONLINE OFFLINE SKYPEME AWAY NA DND INVISIBLE
+            send_check (skype, "SET USERSTATUS " + args[1], "USERSTATUS " + args[1]);
+        }
 
-    // if no arguments given, show current status, otherwise update status to first argument
-    if (args.length < 2) {
-        stdout.printf ("%s\n", client.send ("GET USERSTATUS"));
-    } else {
-        // possible statuses: ONLINE OFFLINE SKYPEME AWAY NA DND INVISIBLE
-        client.send_check ("SET USERSTATUS " + args[1], "USERSTATUS " + args[1]);
+    } catch (DBus.Error e) {
+        stderr.printf ("%s\n", e.message);
+        return 1;
     }
 
     return 0;
diff --git a/tests/examples/gdbus-demo-client.vala b/tests/examples/gdbus-demo-client.vala
new file mode 100644
index 0000000..18ce832
--- /dev/null
+++ b/tests/examples/gdbus-demo-client.vala
@@ -0,0 +1,20 @@
+
+// http://live.gnome.org/Vala/DBusServerSample vala-test:examples/gdbus-demo-client.vala
+
+[DBus (name = "org.example.Demo")]
+interface Demo : Object {
+    public abstract int ping (string msg) throws IOError;
+}
+
+void main () {
+    try {
+        Demo demo = Bus.get_proxy_sync (BusType.SESSION, "org.example.Demo",
+                                                         "/org/example/demo");
+
+        int pong = demo.ping ("Hello from Vala");
+        stdout.printf ("%d\n", pong);
+
+    } catch (IOError e) {
+        stderr.printf ("%s\n", e.message);
+    }
+}
diff --git a/tests/examples/gdbus-demo-server.vala b/tests/examples/gdbus-demo-server.vala
new file mode 100644
index 0000000..04b9f43
--- /dev/null
+++ b/tests/examples/gdbus-demo-server.vala
@@ -0,0 +1,25 @@
+
+// http://live.gnome.org/Vala/DBusServerSample vala-test:examples/gdbus-demo-server.vala
+
+[DBus (name = "org.example.Demo")]
+public class DemoServer : Object {
+    private int counter;
+
+    public int ping (string msg) {
+        stdout.printf ("%s\n", msg);
+        return counter++;
+    }
+}
+
+void main () {
+    try {
+        var conn = Bus.get_sync (BusType.SESSION);
+        conn.register_object ("/org/example/demo", new DemoServer ());
+
+        var app = new Application ("org.example.Demo");
+        app.run ();
+
+    } catch (IOError e) {
+        stderr.printf ("%s\n", e.message);
+    }
+}
diff --git a/tests/examples/gee-iterable.vala b/tests/examples/gee-iterable.vala
index 0e1ee2a..672eaf8 100644
--- a/tests/examples/gee-iterable.vala
+++ b/tests/examples/gee-iterable.vala
@@ -3,7 +3,7 @@
 
 using Gee;
 
-private class RangeIterator : Object, Iterator<int> {
+class RangeIterator : Object, Iterator<int> {
 
     private Range range;
     private int current;
@@ -62,11 +62,8 @@ public class Range : Object, Iterable<int> {
     }
 }
 
-static int main (string[] args) {
-
+void main () {
     foreach (int i in new Range (10, 20)) {
         stdout.printf ("%d\n", i);
     }
-
-    return 0;
 }
diff --git a/tests/examples/gee-list.vala b/tests/examples/gee-list.vala
index 92847b7..e30146c 100644
--- a/tests/examples/gee-list.vala
+++ b/tests/examples/gee-list.vala
@@ -3,8 +3,7 @@
 
 using Gee;
 
-static int main (string[] args) {
-
+void main () {
     var list = new ArrayList<int> ();
     list.add (1);
     list.add (2);
@@ -17,6 +16,4 @@ static int main (string[] args) {
     }
     list[2] = 10;			// same as list.set (2, 10)
     stdout.printf ("%d\n", list[2]);	// same as list.get (2)
-
-    return 0;
 }
diff --git a/tests/examples/gee-map.vala b/tests/examples/gee-map.vala
index e218244..8e5ef7e 100644
--- a/tests/examples/gee-map.vala
+++ b/tests/examples/gee-map.vala
@@ -3,17 +3,44 @@
 
 using Gee;
 
-static int main (string[] args) {
+void main () {
 
     var map = new HashMap<string, int> ();
+
+    // Setting values
     map.set ("one", 1);
     map.set ("two", 2);
     map.set ("three", 3);
-    map["four"] = 4;		// same as map.set ("four", 4)
+    map["four"] = 4;            // same as map.set ("four", 4)
     map["five"] = 5;
+
+    // Getting values
+    int a = map.get ("four");
+    int b = map["four"];        // same as map.get ("four")
+    assert (a == b);
+
+    // Iteration
+
+    stdout.printf ("Iterating over entries\n");
+    foreach (var entry in map.entries) {
+        stdout.printf ("%s => %d\n", entry.key, entry.value);
+    }
+
+    stdout.printf ("Iterating over keys only\n");
     foreach (string key in map.keys) {
-        stdout.printf ("%d\n", map[key]);	// same as map.get (key)
+        stdout.printf ("%s\n", key);
+    }
+
+    stdout.printf ("Iterating over values only\n");
+    foreach (int value in map.values) {
+        stdout.printf ("%d\n", value);
     }
 
-    return 0;
+    stdout.printf ("Iterating via 'while' statement\n");
+    var iterator = map.map_iterator ();
+    var has_next = iterator.first ();
+    while (has_next == true) {
+        stdout.printf ("%d\n", iterator.get_value ());
+        has_next = iterator.next ();
+    }
 }
diff --git a/tests/examples/gee-set.vala b/tests/examples/gee-set.vala
index d3a51cc..1cc30e1 100644
--- a/tests/examples/gee-set.vala
+++ b/tests/examples/gee-set.vala
@@ -3,8 +3,7 @@
 
 using Gee;
 
-static int main (string[] args) {
-
+void main () {
     var my_set = new HashSet<string> ();
     my_set.add ("one");
     my_set.add ("two");
@@ -13,6 +12,4 @@ static int main (string[] args) {
     foreach (string s in my_set) {
         stdout.printf ("%s\n", s);
     }
-
-    return 0;
 }
diff --git a/tests/examples/gio-compression.vala b/tests/examples/gio-compression.vala
new file mode 100644
index 0000000..4be6295
--- /dev/null
+++ b/tests/examples/gio-compression.vala
@@ -0,0 +1,46 @@
+
+// http://live.gnome.org/Vala/GIOCompressionSample vala-test:examples/gio-compression.vala
+
+const ZlibCompressorFormat FORMAT = ZlibCompressorFormat.GZIP;
+
+void compress (File source, File dest) throws Error {
+    convert (source, dest, new ZlibCompressor (FORMAT));
+}
+
+void decompress (File source, File dest) throws Error {
+    convert (source, dest, new ZlibDecompressor (FORMAT));
+}
+
+void convert (File source, File dest, Converter converter) throws Error {
+    var src_stream = source.read ();
+    var dst_stream = dest.replace (null, false, 0);
+    var conv_stream = new ConverterOutputStream (dst_stream, converter);
+    // 'splice' pumps all data from an InputStream to an OutputStream
+    conv_stream.splice (src_stream, 0);
+}
+
+int main (string[] args) {
+    if (args.length < 2) {
+        stdout.printf ("Usage: %s FILE\n", args[0]);
+        return 0;
+    }
+
+    var infile = File.new_for_commandline_arg (args[1]);
+    if (!infile.query_exists ()) {
+        stderr.printf ("File '%s' does not exist.\n", args[1]);
+        return 1;
+    }
+
+    var zipfile = File.new_for_commandline_arg (args[1] + ".gz");
+    var outfile = File.new_for_commandline_arg (args[1] + "_out");
+
+    try {
+        compress (infile, zipfile);
+        decompress (zipfile, outfile);
+    } catch (Error e) {
+        stderr.printf ("%s\n", e.message);
+        return 1;
+    }
+
+    return 0;
+}
diff --git a/tests/examples/gstreamer-audio-player.vala b/tests/examples/gstreamer-audio-player.vala
index b639b69..62caf68 100644
--- a/tests/examples/gstreamer-audio-player.vala
+++ b/tests/examples/gstreamer-audio-player.vala
@@ -5,7 +5,7 @@ using Gst;
 
 public class StreamPlayer {
 
-    private MainLoop loop = new MainLoop (null, false);
+    private MainLoop loop = new MainLoop ();
 
     private void foreach_tag (Gst.TagList list, string tag) {
         switch (tag) {
@@ -45,7 +45,7 @@ public class StreamPlayer {
             Gst.TagList tag_list;
             stdout.printf ("taglist found\n");
             message.parse_tag (out tag_list);
-            tag_list.foreach (foreach_tag);
+            tag_list.foreach ((TagForeachFunc) foreach_tag);
             break;
         default:
             break;
@@ -67,7 +67,7 @@ public class StreamPlayer {
     }
 }
 
-const string DEFAULT_STREAM = "http://scfire-dtc-aa06.stream.aol.com:80/stream/1018";;
+const string DEFAULT_STREAM = "http://streamer-dtc-aa02.somafm.com:80/stream/1018";;
 
 int main (string[] args) {
 
diff --git a/tests/examples/gstreamer-square-beep.vala b/tests/examples/gstreamer-square-beep.vala
index dba3a29..7c3d92c 100644
--- a/tests/examples/gstreamer-square-beep.vala
+++ b/tests/examples/gstreamer-square-beep.vala
@@ -4,17 +4,13 @@
 using Gst;
 
 void main (string[] args) {
-    Pipeline pipeline;
-    Element src;
-    Element sink;
-
     // Initializing GStreamer
     Gst.init (ref args);
 
     // Creating pipeline and elements
-    pipeline = new Pipeline ("test");
-    src = ElementFactory.make ("audiotestsrc", "my_src");
-    sink = ElementFactory.make ("autoaudiosink", "my_sink");
+    var pipeline = new Pipeline ("test");
+    var src = ElementFactory.make ("audiotestsrc", "my_src");
+    var sink = ElementFactory.make ("autoaudiosink", "my_sink");
 
     // Adding elements to pipeline
     pipeline.add_many (src, sink);
@@ -28,9 +24,6 @@ void main (string[] args) {
     // Set pipeline state to PLAYING
     pipeline.set_state (State.PLAYING);
 
-    // Creating a GLib main loop with a default context
-    var loop = new MainLoop (null, false);
-
-    // Start GLib mainloop
-    loop.run ();
+    // Creating and starting a GLib main loop
+    new MainLoop ().run ();
 }
diff --git a/tests/examples/gtk-cell-renderer.vala b/tests/examples/gtk-cell-renderer.vala
new file mode 100644
index 0000000..41a1bb0
--- /dev/null
+++ b/tests/examples/gtk-cell-renderer.vala
@@ -0,0 +1,97 @@
+
+// http://live.gnome.org/Vala/GtkCellRendererSample vala-test:examples/gtk-cell-renderer.vala
+
+using Gtk;
+using Gdk;
+
+class MyCellRenderer : Gtk.CellRenderer {
+  /* icon property set by the tree column */
+  public Gdk.Pixbuf icon { get; set; }
+
+  /* dumb constructor */
+  construct {}
+  
+  /* get_size method, always request a 50x50 area */
+  public override void get_size (Gtk.Widget widget,
+                                 Gdk.Rectangle? cell_area,
+                                 out int x_offset,
+                                 out int y_offset,
+                                 out int width,
+                                 out int height) {
+    /* The bindings miss the nullable property, so we need to check if the
+     * values are null.
+     */
+    if (&x_offset != null) x_offset = 0;
+    if (&y_offset != null) y_offset = 0;
+    if (&width != null) width = 50;
+    if (&height != null) height = 50;
+    return;
+  }
+  
+  /* render method */
+  public override void render (Gdk.Window    window,
+                               Gtk.Widget    widget,
+                               Gdk.Rectangle background_area,
+                               Gdk.Rectangle cell_area,
+                               Gdk.Rectangle expose_area,
+                               Gtk.CellRendererState flags) {
+
+    var ctx = Gdk.cairo_create (window);
+    if (&expose_area != null) {
+      Gdk.cairo_rectangle (ctx, expose_area);
+      ctx.clip();
+    }
+    
+    Gdk.cairo_rectangle (ctx, background_area);
+    if (icon != null) {
+      Gdk.cairo_set_source_pixbuf (ctx, icon,
+                                   background_area.x, background_area.y); /* draws a pixbuf on a cairo context */
+      ctx.fill();
+    }
+  
+    return;
+  }
+
+}
+
+/* CLASS WITH TEST CODE */
+class TestCellRenderer {
+  public static Gdk.Pixbuf open_image () {
+    Gdk.Pixbuf pixbuf = null;
+    try {
+      pixbuf = new Gdk.Pixbuf.from_file ("/usr/share/pixmaps/firefox-3.0.png");
+    } catch (Error e) {
+      error ("%s", e.message);
+    }
+    return pixbuf;
+  }
+  
+  public static int main (string[] args) {    
+    Gtk.init (ref args);
+
+    var tv = new Gtk.TreeView();
+    var tm = new Gtk.ListStore(2, typeof(Gdk.Pixbuf), typeof(string));    
+    tv.set_model(tm);
+    
+    var renderer = new MyCellRenderer ();
+    var col = new Gtk.TreeViewColumn ();
+    col.pack_start (renderer, true);
+    col.set_title ("1st column");
+    col.add_attribute (renderer, "icon", 0);
+
+    Gtk.TreeIter ti;
+    tm.append (out ti);
+    tv.append_column (col);
+    
+    var pixbuf = open_image ();
+    tm.set (ti, 0, pixbuf, 1, "asd", -1); 
+    col.add_attribute (renderer, "icon", 0);
+
+    var win = new Gtk.Window(Gtk.WindowType.TOPLEVEL);
+    win.add(tv);    
+    win.show_all();    
+    Gtk.main();
+    
+    return 0;
+  }
+}
diff --git a/tests/examples/gtk-hello.vala b/tests/examples/gtk-hello.vala
index 2602e98..7195175 100644
--- a/tests/examples/gtk-hello.vala
+++ b/tests/examples/gtk-hello.vala
@@ -13,8 +13,8 @@ int main (string[] args) {
     window.destroy.connect (Gtk.main_quit);
 
     var button = new Button.with_label ("Click me!");
-    button.clicked.connect ((source) => {
-        source.label = "Thank you";
+    button.clicked.connect (() => {
+        button.label = "Thank you";
     });
 
     window.add (button);
diff --git a/tests/examples/gtk-search-dialog.vala b/tests/examples/gtk-search-dialog.vala
index 49d939e..98d6c9b 100644
--- a/tests/examples/gtk-search-dialog.vala
+++ b/tests/examples/gtk-search-dialog.vala
@@ -50,7 +50,7 @@ public class SearchDialog : Dialog {
     }
 
     private void connect_signals () {
-        this.search_entry.changed.connect ((source) => {
+        this.search_entry.changed.connect (() => {
             this.find_button.sensitive = (this.search_entry.text != "");
         });
         this.response.connect (on_response);
diff --git a/tests/examples/gtk-sync-sample.vala b/tests/examples/gtk-sync-sample.vala
index b161455..8eb2fab 100644
--- a/tests/examples/gtk-sync-sample.vala
+++ b/tests/examples/gtk-sync-sample.vala
@@ -16,11 +16,11 @@ public class SyncSample : Window {
 
         spin_box = new SpinButton.with_range (0, 130, 1);
         slider = new HScale.with_range (0, 130, 1);
-        spin_box.value_changed.connect ((s) => {
-            slider.set_value (s.get_value ());
+        spin_box.value_changed.connect (() => {
+            slider.set_value (spin_box.get_value ());
         });
-        slider.value_changed.connect ((s) => {
-            spin_box.set_value (s.get_value ());
+        slider.value_changed.connect (() => {
+            spin_box.set_value (slider.get_value ());
         });
         spin_box.value = 35;
 
diff --git a/tests/examples/gtk-text-viewer.vala b/tests/examples/gtk-text-viewer.vala
index f4f1fe7..81b7985 100644
--- a/tests/examples/gtk-text-viewer.vala
+++ b/tests/examples/gtk-text-viewer.vala
@@ -14,6 +14,7 @@ public class TextFileViewer : Window {
 
         var toolbar = new Toolbar ();
         var open_button = new ToolButton.from_stock (STOCK_OPEN);
+        open_button.is_important = true;
         toolbar.add (open_button);
         open_button.clicked.connect (on_open_clicked);
 
diff --git a/tests/examples/gtk-treeview-listsample.vala b/tests/examples/gtk-treeview-listsample.vala
index 5bbfb1f..274965e 100644
--- a/tests/examples/gtk-treeview-listsample.vala
+++ b/tests/examples/gtk-treeview-listsample.vala
@@ -5,8 +5,8 @@ using Gtk;
 
 public class ListSample : Gtk.Window {
 
-    private ListStore _list_store;
-    private TreeView _tree_view;
+    private ListStore list_store;
+    private TreeView tree_view;
 
     private enum Columns {
         TOGGLE,
@@ -19,44 +19,45 @@ public class ListSample : Gtk.Window {
         this.destroy.connect (Gtk.main_quit);
         set_size_request (200, 200);
 
-        _list_store = new ListStore (Columns.N_COLUMNS, typeof (bool), typeof (string));
-        _tree_view = new TreeView.with_model (_list_store);
+        list_store = new ListStore (Columns.N_COLUMNS, typeof (bool), typeof (string));
+        tree_view = new TreeView.with_model (list_store);
 
         var toggle = new CellRendererToggle ();
         toggle.toggled.connect ((toggle, path) => {
             var tree_path = new TreePath.from_string (path);
             TreeIter iter;
-            _list_store.get_iter (out iter, tree_path);
-            _list_store.set (iter, Columns.TOGGLE, !toggle.active);
+            list_store.get_iter (out iter, tree_path);
+            list_store.set (iter, Columns.TOGGLE, !toggle.active);
         });
 
         var column = new TreeViewColumn ();
         column.pack_start (toggle, false);
         column.add_attribute (toggle, "active", Columns.TOGGLE);
-        _tree_view.append_column (column);
+        tree_view.append_column (column);
 
         var text = new CellRendererText ();
 
         column = new TreeViewColumn ();
         column.pack_start (text, true);
         column.add_attribute (text, "text", Columns.TEXT);
-        _tree_view.append_column (column);
+        tree_view.append_column (column);
  
-        _tree_view.set_headers_visible (false);
+        tree_view.set_headers_visible (false);
  
         TreeIter iter;
-        _list_store.append (out iter);
-        _list_store.set (iter, Columns.TOGGLE, true, Columns.TEXT, "item 1");
-        _list_store.append (out iter);
-        _list_store.set (iter, Columns.TOGGLE, false, Columns.TEXT, "item 2");
+        list_store.append (out iter);
+        list_store.set (iter, Columns.TOGGLE, true, Columns.TEXT, "item 1");
+        list_store.append (out iter);
+        list_store.set (iter, Columns.TOGGLE, false, Columns.TEXT, "item 2");
  
-        add (_tree_view);
+        add (tree_view);
     }
+}
+
         
-    public static void main (string[] args) {
-        Gtk.init (ref args);
-        var list_sample = new ListSample ();
-        list_sample.show_all ();
-        Gtk.main ();
-    }
+void main (string[] args) {
+    Gtk.init (ref args);
+    var sample = new ListSample ();
+    sample.show_all ();
+    Gtk.main ();
 }
diff --git a/tests/examples/mx-expander-demo.vala b/tests/examples/mx-expander-demo.vala
new file mode 100644
index 0000000..1ad4889
--- /dev/null
+++ b/tests/examples/mx-expander-demo.vala
@@ -0,0 +1,36 @@
+
+// http://live.gnome.org/Vala/MxSample vala-test:examples/mx-expander-demo.vala
+
+int main (string[] args) {
+    Clutter.init (ref args);
+
+    var stage = Clutter.Stage.get_default ();
+    stage.set_size (640, 480);
+    stage.user_resizable = true;
+
+    var expander = new Mx.Expander ();
+    expander.label = "Expander";
+    stage.add_actor (expander);
+    expander.set_position (10, 10);
+
+    expander.expand_complete.connect (() => {
+        stdout.printf ("Expand complete (%s)\n",
+                       expander.expanded ? "open" : "closed");
+    });
+
+    var scroll = new Mx.ScrollView ();
+    expander.add_actor (scroll);
+    scroll.set_size (320, 240);
+
+    var grid = new Mx.Grid ();
+    scroll.add_actor (grid);
+
+    for (var i = 1; i <= 50; i++) {
+        grid.add_actor (new Mx.Button.with_label (@"Button $i"));
+    }
+
+    stage.show ();
+    Clutter.main ();
+
+    return 0;
+}
diff --git a/tests/examples/mx-widget-factory.vala b/tests/examples/mx-widget-factory.vala
new file mode 100644
index 0000000..31c1df6
--- /dev/null
+++ b/tests/examples/mx-widget-factory.vala
@@ -0,0 +1,121 @@
+
+// http://live.gnome.org/Vala/MxSample vala-test:examples/mx-widget-factory.vala
+
+using Mx;
+
+Clutter.Actor create_main_content () {
+    var table = new Table ();
+    table.column_spacing = 24;
+    table.row_spacing = 24;
+
+    /* button */
+    var button = new Button.with_label ("Button");
+    table.add_actor_with_properties (button, 0, 0, "y-fill", false);
+
+    /* entry */
+    var entry = new Entry.with_text ("Entry");
+    table.add_actor_with_properties (entry, 0, 1, "y-fill", false);
+
+    /* combo */
+    var combo = new ComboBox ();
+    combo.active_text = "Combo Box";
+    combo.append_text ("Hello");
+    combo.append_text ("Dave");
+    table.add_actor_with_properties (combo, 0, 2, "y-fill", false);
+
+    /* scrollbar */
+    var adjustment = new Adjustment.with_values (0, 0, 10, 1, 1, 1);
+    var scrollbar = new ScrollBar.with_adjustment (adjustment);
+    scrollbar.height = 22.0f;
+    table.add_actor_with_properties (scrollbar, 1, 0, "y-fill", false);
+
+    /* progress bar */
+    var progressbar = new ProgressBar ();
+    progressbar.progress = 0.7;
+    table.add_actor_with_properties (progressbar, 1, 1, "y-fill", false);
+
+    /* slider */
+    var slider = new Slider ();
+    table.add_actor_with_properties (slider, 1, 2, "y-fill", false);
+
+    slider.notify["value"].connect (() => {
+        progressbar.progress = slider.value;
+    });
+
+    /* path bar */
+    var pathbar = new PathBar ();
+    pathbar.push ("");
+    pathbar.push ("Path");
+    pathbar.push ("Bar");
+    table.add_actor_with_properties (pathbar, 2, 0, "y-fill", false);
+
+    /* expander */
+    var expander = new Expander ();
+    table.add_actor_with_properties (expander, 2, 1, "y-fill", false);
+    expander.label = "Expander";
+    expander.add_actor (new Label.with_text ("Hello"));
+
+    /* toggle */
+    var toggle = new Toggle ();
+    table.add_actor_with_properties (toggle, 2, 2, "y-fill", false);
+
+    /* toggle button */
+    var togglebutton = new Button.with_label ("Toggle");
+    togglebutton.is_toggle = true;
+    table.add_actor_with_properties (togglebutton, 3, 0, "y-fill", false);
+
+    /* check button */
+    var checkbutton = new Button ();
+    checkbutton.set_style_class ("check-box");
+    checkbutton.is_toggle = true;
+    table.add_actor_with_properties (checkbutton, 3, 1, "y-fill", false, "x-fill", false);
+
+    /* vertical scroll bar */
+    adjustment = new Adjustment.with_values (0, 0, 10, 1, 1, 1);
+    scrollbar = new ScrollBar.with_adjustment (adjustment);
+    scrollbar.orientation = Orientation.VERTICAL;
+    scrollbar.width = 22.0f;
+    table.add_actor_with_properties (scrollbar, 0, 3, "row-span", 3);
+
+    var frame = new Frame ();
+    frame.child = table;
+
+    return frame;
+}
+
+int main (string [] args) {
+    var app = new Application (ref args, "Widget Factory", 0);
+    var window = app.create_window ();
+    window.clutter_stage.set_size (500, 300);
+
+    var toolbar = window.get_toolbar ();
+    var hbox = new BoxLayout ();
+    toolbar.add_actor (hbox);
+
+    var button = new Button.with_label ("Click me");
+    button.tooltip_text = "Please click this button!";
+    button.clicked.connect (() => {
+        button.label = "Thank you!";
+    });
+
+    var combo = new ComboBox ();
+    combo.append_text ("Africa");
+    combo.append_text ("Antarctica");
+    combo.append_text ("Asia");
+    combo.append_text ("Australia");
+    combo.append_text ("Europe");
+    combo.append_text ("North America");
+    combo.append_text ("South America");
+    combo.index = 0;
+    combo.notify["index"].connect (() => {
+        stdout.printf ("Selected continent: %s\n", combo.active_text);
+    });
+
+    hbox.add (button, combo);
+    window.child = create_main_content ();
+
+    window.clutter_stage.show ();
+    app.run ();
+
+    return 0;
+}
diff --git a/tests/examples/signals.vala b/tests/examples/signals.vala
index 2032ab3..8693a2e 100644
--- a/tests/examples/signals.vala
+++ b/tests/examples/signals.vala
@@ -1,7 +1,7 @@
 
 // http://live.gnome.org/Vala/SignalsAndCallbacks vala-test:examples/signals.vala
 
-public class Foo : Object {
+class Foo : Object {
     public signal void some_event ();   // definition of the signal
 
     public void method () {
@@ -9,18 +9,17 @@ public class Foo : Object {
     }
 }
 
-static void callback_a () {
+void callback_a () {
     stdout.printf ("Callback A\n");
 }
 
-static void callback_b () {
+void callback_b () {
     stdout.printf ("Callback B\n");
 }
 
-static int main (string[] args) {
+void main () {
     var foo = new Foo ();
     foo.some_event.connect (callback_a);      // connecting the callback functions
     foo.some_event.connect (callback_b);
     foo.method ();
-    return 0;
 }
diff --git a/tests/examples/soup-http-server.vala b/tests/examples/soup-http-server.vala
index 5ae1838..1ee4ead 100644
--- a/tests/examples/soup-http-server.vala
+++ b/tests/examples/soup-http-server.vala
@@ -14,6 +14,7 @@ void default_handler (Soup.Server server, Soup.Message msg, string path,
 
     msg.set_response ("text/html", Soup.MemoryUse.COPY,
                       response_text, response_text.size ());
+    msg.set_status (Soup.KnownStatusCode.OK);
 }
 
 void xml_handler (Soup.Server server, Soup.Message msg, string path,
diff --git a/tests/examples/string.vala b/tests/examples/string.vala
index 252c850..b66bf60 100644
--- a/tests/examples/string.vala
+++ b/tests/examples/string.vala
@@ -107,8 +107,8 @@ They may contain quotes and may span multiple lines.""";
         // ...
     }
 
-    /* You can determine the length of a string in characters with the method
-     * len (). In order to obtain the size of a string in bytes you use the
+    /* You can determine the length of a string in characters with the .length
+     * property. In order to obtain the size of a string in bytes you use the
      * method size (). This value potentially differs from the length! The
      * reason is that a Unicode character may occupy more than one byte of
      * memory.
@@ -116,7 +116,7 @@ They may contain quotes and may span multiple lines.""";
 
     string dessert = "crème brûlée";
     stdout.printf ("The string '%s' is %ld characters long and is stored in %Zd bytes\n",
-                   dessert, dessert.len (), dessert.size ());
+                   dessert, dessert.length, dessert.size ());
 
     // Regular expressions
 
diff --git a/tests/examples/type-modules-myplugin.vala b/tests/examples/type-modules-myplugin.vala
index 623e781..8806f61 100644
--- a/tests/examples/type-modules-myplugin.vala
+++ b/tests/examples/type-modules-myplugin.vala
@@ -8,7 +8,7 @@ class MyPlugin : Object, TestPlugin {
 }
 
 [ModuleInit]
-public Type register_plugin () {
+public Type register_plugin (TypeModule module) {
     // types are registered automatically
     return typeof (MyPlugin);
 }



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