Browsing Category "Vala"
25 Jan
2012

Vala : Writing a simple singleton in vala

Here’s some more information on the Singleton design pattern from wikipedia

class Foo {
Foo () {}
static Foo instance;

public Foo get () {
if (instance == null) {
instance = new Foo ();
}
return instance;
}
}

1 Dec
2011

Vala : example for writing archives using libarchive

I only found one example of how to use libarchive in Vala. Example for reading archives using libarchive

I am trying to make the code to write an archives in Vala using libarchive. I have translated from C to Vala. http://code.google.com/p/libarchive/wiki/ManPageArchiveWrite3

/* write-archive.vala
 *
 * Copyright (C) 2011  Aji Kisworo Mukti <adzy@di.blankon.in>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */
using Archive;
using Posix;
using GLib;

private const int BUFFER_SIZE = 4096;

void main (string[] args) {
	var archive = new Write ();
	var buffer = new uint8[BUFFER_SIZE];

	archive.set_compression_compress ();
	archive.set_format_ar_bsd ();

	if (archive.open_filename ("archive.ar") != Result.OK) {
		GLib.stderr.printf ("%s\n", archive.error_string ());
	}

	var entry = new Entry ();
	entry.set_pathname ("METADATA");
	Posix.Stat st;
	Posix.stat ("METADATA", out st);
	entry.copy_stat (st);
	entry.set_size (st.st_size);

	if (archive.write_header (entry) != Result.OK) {
		GLib.stderr.printf ("%s\n", archive.error_string ());
	}

	// write the file
	var file = File.new_for_path ("METADATA");
	var reader = file.read ();
	var len = reader.read (buffer);
	while(len > 0)
	{
		archive.write_data(buffer, len);
		len = reader.read (buffer);
	}

	if (archive.finish_entry () != Result.OK) {
		GLib.stderr.printf ("%s\n", archive.error_string ());
	}

	// close the archive
	if (archive.close () != Result.OK) {
		GLib.stderr.printf ("%s\n", archive.error_string ());
	}
}

 


Tell me about the problems and questions about my code :)

Warung Aplikasi : Apakah ini upaya menggantikan Manager Paket? Atau Paket deb?

Saya tertarik dengan bahasan di sebuah Group Facebook, namun saya tidak akan membalas disana. (lebih suka bentuk milis).

Curhatan bapak samsul di atas merupakan salah satu tujuan di kembangkannya Warung Aplikasi, seperti yang pernah saya tulis di Warung Aplikasi BlankOn. Jelas pak samsul tidak memiliki koneksi pasti untuk setiap saat melakukan installasi melalui repository, dan akhirnya beliau sedikit “mengakali” dengan membuat repository lokal.

Read more >>

Vala : Glade to Vala UI Code

Glade user interface designer biasa di gunakan untuk membuat disain layout pada Gtk. Berkas ini di simpan dalam format XML dan akan di muat pada runtime program. Kelebihannya sang programmer tidak perlu menulis kode untuk membuat UI pada kode program. Cukup memuat berkas tadi, dan kemudian mengkoneksikan signal pada setiap widget. (GtkBuilder)

Tapi sebenarnya program akan lebih bagus jika menulis kode UI pada program, cuman ini membutuhkan ketelitian dan kesabaran. Bagaimana tidak, kita menggunakan Glade tinggal klik dan klik. Kode UI di kompilasi menjadi bagian dari program, akan sangat berbeda dengan program yang harus memuat berkas Glade terlebih dahulu.

Read more >>