spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit f1f63561f944cdedac79bebaa72ca8afa8419a24
parent 1426e66ea4df6173abad25c7e34ef4caa4074d58
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Wed, 23 Feb 2011 13:00:34 +0800

Add Platform.read_line

Diffstat:
Msrc/spek-platform.c | 20++++++++++++++++++++
Msrc/spek-platform.h | 3+++
Msrc/spek-window.vala | 11++---------
Mvapi/spek-platform.vapi | 1+
4 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/spek-platform.c b/src/spek-platform.c @@ -64,3 +64,23 @@ void spek_platform_show_uri (const gchar *uri) { } #endif } + +gchar *spek_platform_read_line (const gchar *uri) { + gchar *line = NULL; + GFile *file = NULL; + GFileInputStream *file_stream = NULL; + + file = g_file_new_for_uri (uri); + file_stream = g_file_read (file, NULL, NULL); + if (file_stream) { + GDataInputStream *data_stream = NULL; + + data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream)); + line = g_data_input_stream_read_line (data_stream, NULL, NULL, NULL); + + g_object_unref (data_stream); + g_object_unref (file_stream); + } + g_object_unref (file); + return line; +} diff --git a/src/spek-platform.h b/src/spek-platform.h @@ -27,4 +27,7 @@ void spek_platform_fix_args (gchar **argv, gint argc); /* Open a link in the browser */ void spek_platform_show_uri (const gchar *uri); +/* Read a line from a uri */ +gchar *spek_platform_read_line (const gchar *uri); + #endif diff --git a/src/spek-window.vala b/src/spek-window.vala @@ -306,15 +306,8 @@ namespace Spek { } // Get the version number. - var file = File.new_for_uri ("http://www.spek-project.org/version"); - if (!file.query_exists (null)) { - return null; - } - string version; - try { - var stream = new DataInputStream (file.read (null)); - version = stream.read_line (null, null); - } catch (Error e) { + var version = Platform.read_line ("http://www.spek-project.org/version"); + if (version == null) { return null; } diff --git a/vapi/spek-platform.vapi b/vapi/spek-platform.vapi @@ -2,4 +2,5 @@ namespace Spek.Platform { public static void fix_args (string[] args); public static void show_uri (string uri); + public static string read_line (string uri); }