changeset 543:282bede45eef trunk

[svn] Support for writing downloaded data to a file (no UI provided yet).
author iabervon
date Tue, 23 Jan 2007 20:19:01 -0800
parents d58404ba9af9
children e045af8665c6
files ChangeLog src/curl/curl.c
diffstat 2 files changed, 37 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jan 23 16:44:29 2007 -0800
+++ b/ChangeLog	Tue Jan 23 20:19:01 2007 -0800
@@ -1,3 +1,10 @@
+2007-01-24 00:44:29 +0000  Giacomo Lozito <james@develia.org>
+  revision [1170]
+  - made popup window use audacious_fileinfopopup_show_from_title if track_name and song length is not available
+  trunk/src/statusicon/si_ui.c |   12 +++++++++++-
+  1 file changed, 11 insertions(+), 1 deletion(-)
+
+
 2007-01-23 17:21:15 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [1168]
   - portability fixes for solaris
--- a/src/curl/curl.c	Tue Jan 23 16:44:29 2007 -0800
+++ b/src/curl/curl.c	Tue Jan 23 20:19:01 2007 -0800
@@ -66,6 +66,8 @@
   gboolean failed; // true if we've tried and failed already
   GThread *thread; // the thread that's reading from the connection
 
+  VFSFile *download; // file to write to as we download
+
   gchar *name;
   gchar *title;
 };
@@ -280,8 +282,8 @@
     {
       while (!(trans = buf_space(handle)) && !handle->cancel)
 	{
+	  //g_print("Wait for free space on %p\n", handle);
 	  g_usleep(10000);
-	  g_print("Wait for free space\n");
 	}
       if (handle->cancel)
 	break;
@@ -296,7 +298,10 @@
 	  if (!handle->in_icy_meta)
 	    {
 	      handle->wr_abs += trans;
-	      // write download here
+	      if (handle->download)
+		{
+		  vfs_fwrite(ptr + ret, trans, 1, handle->download);
+		}
 	      if (handle->icy_interval && !handle->icy_left)
 		{
 		  if (DEBUG_ICY)
@@ -378,6 +383,7 @@
 		  got_header(handle, size);
 		  if (i == handle->hdr_index)
 		    {
+		      size_t leftover;
 		      // Empty header means the end of the headers
 		      handle->header = 0;
 		      handle->hdr_index = (i + 2) % handle->buffer_length;
@@ -385,10 +391,16 @@
 		      handle->rd_index = handle->hdr_index;
 		      // We've already written the amount that's after
 		      // the header.
-		      handle->wr_abs +=
-			(handle->wr_index - handle->hdr_index + handle->buffer_length) % handle->buffer_length;
-		      // write download here...
-		      //handle->icy_interval = 0;
+		      leftover = (handle->wr_index - handle->hdr_index + handle->buffer_length) % handle->buffer_length;
+		      handle->wr_abs += leftover;
+		      if (handle->download)
+			{
+			  // the data which has to go into the
+			  // beginning of the file must be at the end
+			  // of the input that we've dealt with.
+			  vfs_fwrite(ptr + ret - leftover, leftover, 1, 
+				     handle->download);
+			}
 		      handle->icy_left = handle->icy_interval;
 		      if (handle->icy_interval)
 			{
@@ -529,13 +541,14 @@
   curl_easy_setopt(handle->curl, CURLOPT_SSL_VERIFYPEER, 0);
   curl_easy_setopt(handle->curl, CURLOPT_SSL_VERIFYHOST, 0);
 
-  //add header icy-metadata:1 (when we're ready for it)
   {
     struct curl_slist *hdr = NULL;
     hdr = curl_slist_append(hdr, "icy-metadata:1");
     curl_easy_setopt(handle->curl, CURLOPT_HTTPHEADER, hdr);
   }
 
+  //handle->download = vfs_fopen(FILENAME, "wb");
+
   file->handle = handle;
   file->base = &curl_const;
 
@@ -568,6 +581,12 @@
       if (handle->stream_stack != NULL)
         g_slist_free(handle->stream_stack);
       curl_easy_cleanup(handle->curl);
+
+      if (handle->download)
+	{
+	  vfs_fclose(handle->download);
+	}
+
       g_free(handle);
     }
   return ret;
@@ -613,7 +632,10 @@
     {
       size_t available;
       while (!(available = buf_available(handle)) && !handle->cancel)
-	g_usleep(10000);
+	{
+	  //g_print("Wait for data on %p\n", handle);
+	  g_usleep(10000);
+	}
       if (available > sz - ret)
 	available = sz - ret;
       memcpy(ptr + ret, handle->buffer + handle->rd_index, available);