예제 #1
0
static void
icon_loader_write_cb (EventObject *obj, EventArgs *ea, gpointer user_data)
{
	HttpRequestWriteEventArgs *args = (HttpRequestWriteEventArgs *) ea;
	IconLoader *icon = (IconLoader *) user_data;

	const guchar *buffer = (const guchar*)args->GetData ();
	gint32 offset = args->GetOffset ();
	gint32 n = args->GetCount ();

	if (icon->loader == NULL && offset == 0)
		CreateLoader (icon, buffer);

	if (icon->loader && icon->moon_error == NULL)
		icon->loader->Write (buffer, n, &icon->moon_error);
}
예제 #2
0
파일: bitmapimage.cpp 프로젝트: lewing/moon
void
BitmapImage::pixbuf_write (EventObject *sender, EventArgs *calldata, gpointer data)
{
	BitmapImage *source = (BitmapImage *) data;
	HttpRequestWriteEventArgs *ea = (HttpRequestWriteEventArgs *) calldata;

	source->PixbufWrite ((unsigned char *) ea->GetData (), ea->GetOffset (), ea->GetCount ());
	if (source->moon_error) {
		ImageErrorEventArgs *args = NULL;
		if (source->HasHandlers(ImageFailedEvent))
			args = new ImageErrorEventArgs (*source->moon_error);
		source->CleanupLoader ();
		if (args)
			source->Emit (ImageFailedEvent, args);
	}
}
예제 #3
0
bool
Application::GetResource (const Uri *resourceBase, const Uri *uri,
			  NotifyFunc notify_cb, EventHandler write_cb,
			  DownloaderAccessPolicy policy, HttpRequest::Options options,
			  Cancellable *cancellable, gpointer user_data)
{
	if (!uri) {
		g_warning ("Passing a null uri to Application::GetResource");
		if (notify_cb)
			notify_cb (NotifyFailed, GPOINTER_TO_INT(NULL), user_data);
		
		return false;
	}

	if (get_resource_cb && !uri->IsAbsolute ()) {
		ManagedStreamCallbacks stream;
		if (!Uri::IsNullOrEmpty (uri)) {
			stream = get_resource_cb (resourceBase, uri);
		} else {
			memset (&stream, 0, sizeof (stream));
		}
		
		if (stream.handle) {
			if (notify_cb)
				notify_cb (NotifyStarted, GPOINTER_TO_INT(NULL), user_data);
			
			if (write_cb) {
				char buf[4096];
				int offset = 0;
				int nread;
				
				if (stream.CanSeek (stream.handle))
					stream.Seek (stream.handle, 0, 0);
				
				HttpRequestWriteEventArgs *args = new HttpRequestWriteEventArgs (NULL, 0, 0);
				do {
					if ((nread = stream.Read (stream.handle, buf, 0, sizeof (buf))) <= 0)
						break;
					
					args->SetData (buf);
					args->SetOffset (offset);
					args->SetCount (nread);
					write_cb (this, args, user_data);
					offset += nread;
				} while (true);
				args->unref ();
			}
			
			if (notify_cb)
				notify_cb (NotifyCompleted, GPOINTER_TO_INT(NULL), user_data);
			
			stream.Close (stream.handle);
			
			return true;
		}
	}	
	
#if 0
	// FIXME: drt 171 and 173 expect this to fail simply because the uri
	// begins with a '/', but other drts (like 238) depend on this
	// working. I give up.
	if (!uri->isAbsolute && uri->path && uri->path[0] == '/') {
		if (notify_cb)
			notify_cb (NotifyFailed, NULL, user_data);
		
		return false;
	}
#endif
	
	//no get_resource_cb or empty stream
	HttpRequest *request;
	if (!(request = GetDeployment ()->CreateHttpRequest (options))) {
		if (notify_cb)
			notify_cb (NotifyFailed, GPOINTER_TO_INT(NULL), user_data);
		
		return false;
	}
	
	NotifyCtx *ctx = g_new (NotifyCtx, 1);
	ctx->user_data = user_data;
	ctx->notify_cb = notify_cb;
	ctx->write_cb = write_cb;
	ctx->request = request;

	if (notify_cb) {
		request->AddHandler (HttpRequest::ProgressChangedEvent, application_downloader_progress_changed, ctx);
		request->AddHandler (HttpRequest::StartedEvent, application_downloader_started, ctx);
	}

	if (cancellable) {
		cancellable->SetCancelFuncAndData (application_downloader_abort, request, ctx);
	}

	request->AddHandler (HttpRequest::WriteEvent, application_downloader_write, ctx);
	request->AddHandler (HttpRequest::StoppedEvent, application_downloader_stopped, ctx);
	request->Open ("GET", uri, resourceBase, policy);
	request->Send ();
	
	return true;
}