From f1f63561f944cdedac79bebaa72ca8afa8419a24 Mon Sep 17 00:00:00 2001 From: Alexander Kojevnikov Date: Wed, 23 Feb 2011 13:00:34 +0800 Subject: [PATCH] Add Platform.read_line --- src/spek-platform.c | 20 ++++++++++++++++++++ src/spek-platform.h | 3 +++ src/spek-window.vala | 11 ++--------- vapi/spek-platform.vapi | 1 + 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/spek-platform.c b/src/spek-platform.c index aca0de9..a9b62fa 100644 --- 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 index 5a91a14..2f6c314 100644 --- 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 index 3d2fd97..92be7e9 100644 --- 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 index ed7d264..2cd1780 100644 --- 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); }