Пример #1
0
gboolean
initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
	const char *filename;
	char *uri, *html;

	stop(c, NULL);
	c->download = o;
	filename = webkit_download_get_suggested_filename(o);
	if(!strcmp("", filename))
		filename = "index.html";
	uri = g_strconcat("file://", dldir, "/", filename, NULL);
	webkit_download_set_destination_uri(c->download, uri);
	c->progress = 0;
	g_free(uri);
	html = g_strdup_printf("Download <b>%s</b>...", filename);
	webkit_web_view_load_html_string(c->view, html,
			webkit_download_get_uri(c->download));
	g_signal_connect(c->download, "notify::progress", G_CALLBACK(updatedownload), c);
	g_signal_connect(c->download, "notify::status", G_CALLBACK(updatedownload), c);
	webkit_download_start(c->download);
	
	c->title = copystr(&c->title, filename);
	update(c);
	g_free(html);
	return TRUE;
}
Пример #2
0
static VALUE
Download_start(VALUE self)
{
  WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self));

#line 227 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr"
  webkit_download_start(_self);
 
  return Qnil;
}
Пример #3
0
/* 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;
}
Пример #4
0
/**
 * ephy_download_start:
 * @download: an #EphyDownload
 *
 * Starts the wrapped #WebKitDownload.
 **/
void
ephy_download_start (EphyDownload *download)
{
  EphyDownloadPrivate *priv;

  g_return_if_fail (EPHY_IS_DOWNLOAD (download));

  priv = download->priv;
  priv->start_time = gtk_get_current_event_time ();

  if (priv->destination == NULL)
    ephy_download_set_auto_destination (download);
#ifndef HAVE_WEBKIT2
  webkit_download_start (priv->download);
#endif
}
Пример #5
0
Файл: surf.c Проект: sr/surf
gboolean
download(WebKitWebView *view, WebKitDownload *o, gpointer d) {
    /* TODO */
    const gchar *home;
    gchar *uri, *filename;

    home = g_get_home_dir();
    filename = g_build_filename(home, "Desktop",
                                webkit_download_get_suggested_filename(o), NULL);
    uri = g_strconcat("file://", filename, NULL);
    webkit_download_set_destination_uri(o, uri);
    g_free(filename);
    g_free(uri);
    webkit_download_start(o);
    return TRUE;
}
Пример #6
0
/**
 * Starts the download.
 *
 * Will produce a warning if the download is already running.
 * References the download to prevent its garbage collection.
 * Will raise a Lua error if the start failed.
 *
 * \param L The Lua VM state.
 *
 * \luastack
 * \lparam A \c download object to start.
 */
static gint
luaH_download_start(lua_State *L)
{
    download_t *download = luaH_checkdownload(L, 1);
    if (!download_is_started(download)) {
        /* prevent lua garbage collection while downloading */
        lua_pushvalue(L, 1);
        download->ref = luaH_object_ref(L, -1);

        /* check if we can download to destination */
        if (download_check_prerequesites(L, download))
            webkit_download_start(download->webkit_download);

        /* check for webkit/glib errors from download start */
        if (download->error) {
            lua_pushstring(L, download->error);
            lua_error(L);
        }

    } else
        luaH_warn(L, "download already stared");
    return 0;
}