/* download_on_idle */ static gboolean _download_on_idle(gpointer data) { Download * download = data; DownloadPrefs * prefs = &download->prefs; #ifdef WITH_WEBKIT char * p = NULL; char * cwd = NULL; size_t len; WebKitNetworkRequest * request; download->timeout = 0; if(prefs->output[0] != '/' && (cwd = getcwd(NULL, 0)) == NULL) { _download_error(download, prefs->output, 0); download_cancel(download); return FALSE; } len = ((cwd != NULL) ? strlen(cwd) : 0) + strlen(prefs->output) + 7; if((p = malloc(len)) == NULL) { _download_error(download, prefs->output, 0); download_cancel(download); free(cwd); return FALSE; } snprintf(p, len, "%s%s%s%s", "file:", (cwd != NULL) ? cwd : "", (cwd != NULL) ? "/" : "", prefs->output); request = webkit_network_request_new(download->url); download->conn = webkit_download_new(request); webkit_download_set_destination_uri(download->conn, p); free(p); free(cwd); webkit_download_start(download->conn); #else download->timeout = 0; if((download->fp = fopen(prefs->output, "w")) == NULL) { _download_error(download, prefs->output, 0); download_cancel(download); return FALSE; } download->conn = gnet_conn_http_new(); if(gnet_conn_http_set_method(download->conn, GNET_CONN_HTTP_METHOD_GET, NULL, 0) != TRUE) return _download_error(download, _("Unknown error"), FALSE); gnet_conn_http_set_uri(download->conn, download->url); if(prefs->user_agent != NULL) gnet_conn_http_set_user_agent(download->conn, prefs->user_agent); gnet_conn_http_run_async(download->conn, _download_on_http, download); #endif download->timeout = g_timeout_add(250, _download_on_timeout, download); return FALSE; }
gint do_reboot(GtkWidget *widget, gpointer *data) { if (download_in_progress) { download_cancel(NULL); gtk_widget_set_sensitive(program_button, FALSE); gtk_widget_set_sensitive(reboot_button, FALSE); gtk_widget_set_sensitive(bootloader_button, FALSE); } gtk_widget_set_sensitive(program_button, FALSE); gtk_widget_set_sensitive(reboot_button, FALSE); gtk_widget_set_sensitive(bootloader_button, FALSE); hard_reset_to_user_code(); #if 0 download_in_progress = 1; soft_reboot_begin(); #endif if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) { gtk_widget_set_sensitive(program_button, TRUE); } else { gtk_widget_set_sensitive(program_button, FALSE); } gtk_widget_set_sensitive(bootloader_button, TRUE); return FALSE; }
/* download_on_cancel */ static void _download_on_cancel(gpointer data) { Download * download = data; gtk_widget_hide(download->window); download_cancel(download); }
/* download_on_closex */ static gboolean _download_on_closex(gpointer data) { Download * download = data; gtk_widget_hide(download->window); download_cancel(download); return FALSE; }
static int _download_write(Download * download) { gchar * buf; gsize size; gsize s; if(gnet_conn_http_steal_buffer(download->conn, &buf, &size) != TRUE) return 0; /* FIXME use a GIOChannel instead */ s = fwrite(buf, sizeof(*buf), size, download->fp); g_free(buf); if(s == size) { download->pulse = 1; return 0; } _download_error(download, download->prefs.output, 0); download_cancel(download); return 1; }