Languages

vala

GStreamer video example

0
Your rating: None
/* valac --pkg gtk+-2.0 --pkg gstreamer-interfaces-0.10 --pkg gdk-x11-2.0 videosample.vala */
 
using Gtk;
using Gst;
 
public class VideoSample : Window {
 
    private DrawingArea drawing_area;
    private Pipeline pipeline;
    private Element src;
    private Element sink;
 
    construct {
        create_widgets ();
        setup_gst_pipeline ();
    }
 
    private void create_widgets () {
        var vbox = new VBox (false, 0);
        this.drawing_area = new DrawingArea ();
        this.drawing_area.set_size_request (300, 150);
        vbox.pack_start (this.drawing_area

GStreamer audio example

0
Your rating: None
using Gst;
 
public void main (string[] args) {
    Element src;
    Element sink;
    Pipeline pipeline;
 
    // Initializing GStreamer
    Gst.init (ref args);
 
    // Creating pipeline and elements
    // NOTE: The return type of the pipeline construction method is Element,
    // not Pipeline, so we have to cast
    pipeline = (Pipeline) new Pipeline ("test");
    src = ElementFactory.make ("audiotestsrc", "my_src");
    sink = ElementFactory.make ("autoaudiosink", "my_sink");
 
    // Adding elements to pipeline
    pipeline.add_many (src, sink);
 
    // Linking source t

Gnome-Desktop and GMenu example

0
Your rating: None
/* GnomeDesktop and GMenu in Vala sample code */
 
 
public class GnomeDesktopAndGMenuExample : Object {
 
    private List<GMenu.TreeDirectory> getMainDirectories () {
        var tree = GMenu.Tree.lookup ("applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED);
        var root = tree.get_root_directory ();
 
        var mainDirectoryEntries = new List<GMenu.TreeDirectory> ();
 
        foreach (GMenu.TreeItem item in root.get_contents()) {
            if (item.get_type() == GMenu.TreeItemType.DIRECTORY) {
                mainDirectoryEntries.append((GMenu.TreeDirectory) item);
 

Sockets with GNIO

4
Your rating: None Average: 4 (1 vote)
public class SyncDemo : Object {
 
    public void run () throws Error {
 
        // Resolve hostname to IP address
        var resolver = new Resolver ();
        var address = resolver.lookup_name ("www.google.com", null);
        debug ("(sync)  resolved www.google.com to %s", address.to_string ());
 
        // Connect
        var client = new SocketConnection (new InetSocketAddress (address, 80));
        client.connect (null);
        debug ("(sync)  connected to www.google.com");
 
        // Send HTTP GET request
        string message = "GET / HTTP/1.1\r\nHost: www.google.

Glade example

5
Your rating: None Average: 5 (1 vote)
/* Glade in Vala sample code */
 
using Gtk;
 
public class GladeSample {
 
    public GladeSample () {
        var xml = new Glade.XML ("gladesample.glade", null, null);
        xml.signal_autoconnect_full (connect_signals);
    }
 
    // When generate C code, put the instance parameter (self) to the end of the
    // parameter list. See connect_signals() below.

Asynchronous GIO sample

0
Your rating: None
/* Asynchronous GIO in Vala sample code */
 
using Gtk;
 
/**
 * Loads the list of files in users home directory and displays them
 * in a GTK+ list view.
 */
public class ASyncGIOSample : Gtk.Window {
 
    private File dir;
    private Gtk.ListStore model;
 
    construct {
        this.setup ();
    }
 
    /* Set up the window and widget */
    private void setup () {
        var sc = new Gtk.ScrolledWindow (null, null);
        sc.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
 
        var tv = new Gtk.TreeView ();
        sc.add (tv);
 
        tv.

Reading binary data with GIO

0
Your rating: None
static int main (string[] args) {
    try {
 
        // Reference a BMP image file
        var file = File.new_for_uri ("http://wvnvaxa.wvnet.edu/vmswww/images/test8.bmp");
//      var file = File.new_for_path ("sample.bmp");
 
        // Open file for reading
        var file_stream = file.read (null);
        var data_stream = new DataInputStream (file_stream);
        data_stream.set_byte_order (DataStreamByteOrder.LITTLE_ENDIAN);
 
        // Read the signature
        uint16 signature = data_stream.read_uint16 (null);
        if (signature != 0x4d42) {
            stderr.prin

Simple file operations with GIO

0
Your rating: None
static int main (string[] args) {
    try {
 
        // Reference a local file name
        var file = File.new_for_path ("samplefile.txt");
 
        {
            // Create a new file with this name
            var file_stream = file.create (FileCreateFlags.NONE, null);
 
            // Test for the existence of file
            if (file.query_exists (null)) {
                stdout.printf ("File successfully created.\n");
            }
 
            // Write text data to file
            var data_stream = new DataOutputStream (file_stream);
            data_stream.put_string (

Reading text file line by line with GIO

0
Your rating: None
static int main (string[] args) {
    // A reference to our file
    var file = File.new_for_path ("data.txt");
 
    if (!file.query_exists (null)) {
        stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
        return 1;
    }
 
    try {
        // Open file for reading and wrap returned FileInputStream into a
        // DataInputStream, so we can read line by line
        var in_stream = new DataInputStream (file.read (null));
        string line;
        // Read lines until end of file (null) is reached
        while ((line = in_stream.read_line (null, null)

GConf sample

0
Your rating: None
/*
 * Various operations with GConf: Getting, Setting, Unsetting and Notifying
 */ 
 
using GConf;
 
public class GConfSample {
 
    public void run () throws GLib.Error {
 
        // You don't create a GConf.Client with "new GConf.Client ()" but
        // rather this way:
        var gc = GConf.Client.get_default ();
 
        // A root directory to work in
        string root = "/apps/myapp";
 
        /*
         * Set and retrieve a boolean key, see API for more information on how
         * to retrieve other types
         */
 
        // Sub directories are created auto
Syndicate content