gboolean cb_wv_download_requested(WebKitWebView *view, WebKitDownload *download, Browser *b) { const char *suggested_filename = webkit_download_get_suggested_filename(download); char *download_path = NULL; char *filename; /* build download dir if necessary */ if (download_dir[0] == '~') { download_path = g_build_filename(g_get_home_dir(), download_dir + 1, NULL); } else { download_path = g_strdup(download_dir); } g_mkdir_with_parents(download_path, 0771); /* download file */ filename = g_build_filename("file://", download_path, suggested_filename, NULL); webkit_download_set_destination_uri(download, filename); g_signal_connect(G_OBJECT(download), "notify::status", G_CALLBACK(cb_download_notify_status), b); g_free(download_path); g_free(filename); return TRUE; }
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; }
static void test_webkit_download_create(void) { WebKitNetworkRequest* request; WebKitDownload* download; const gchar* uri = "http://example.com"; gchar* tmpDir; request = webkit_network_request_new(uri); download = webkit_download_new(request); g_object_unref(request); g_assert_cmpstr(webkit_download_get_uri(download), ==, uri); g_assert(webkit_download_get_network_request(download) == request); g_assert(g_strrstr(uri, webkit_download_get_suggested_filename(download))); g_assert(webkit_download_get_status(download) == WEBKIT_DOWNLOAD_STATUS_CREATED); g_assert(!webkit_download_get_total_size(download)); g_assert(!webkit_download_get_current_size(download)); g_assert(!webkit_download_get_progress(download)); g_assert(!webkit_download_get_elapsed_time(download)); tmpDir = g_filename_to_uri(g_get_tmp_dir(), NULL, NULL); webkit_download_set_destination_uri(download, tmpDir); g_assert_cmpstr(tmpDir, ==, webkit_download_get_destination_uri(download));; g_free(tmpDir); g_object_unref(download); }
/** * Returns the suggested filename for the download. * This is provided by \c WebKit and inferred from the URI and response headers. * * \param L The Lua VM state. * \param download The \ref download_t of the download. * * \luastack * \lparam A \c download object. * \lreturn The filename that WebKit suggests for the download as a string. */ static gint luaH_download_get_suggested_filename(lua_State *L, download_t *download) { const gchar *suggested_filename = webkit_download_get_suggested_filename( download->webkit_download); lua_pushstring(L, suggested_filename); return 1; }
JNIEXPORT jintLong JNICALL WebKitGTK_NATIVE(_1webkit_1download_1get_1suggested_1filename) (JNIEnv *env, jclass that, jintLong arg0) { jintLong rc = 0; WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1download_1get_1suggested_1filename_FUNC); rc = (jintLong)webkit_download_get_suggested_filename((WebKitDownload *)arg0); WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1download_1get_1suggested_1filename_FUNC); return rc; }
static VALUE Download_suggested_filename(VALUE self) { VALUE __p_retval = Qnil; WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); #line 245 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" do { __p_retval = rb_str_new2(webkit_download_get_suggested_filename(_self)); goto out; } while(0); out: return __p_retval; }
/* on_download_requested */ static gboolean _on_download_requested(WebKitWebView * view, WebKitDownload * download, gpointer data) { GHtml * ghtml; char const * url; char const * suggested; ghtml = g_object_get_data(G_OBJECT(data), "ghtml"); url = webkit_download_get_uri(download); suggested = webkit_download_get_suggested_filename(download); surfer_download(ghtml->surfer, url, suggested); webkit_download_cancel(download); return FALSE; }
static gboolean download_request_cb(WebKitWebView *v, GObject *dl, widget_t *w) { (void) v; const gchar *uri = webkit_download_get_uri((WebKitDownload *) dl); const gchar *filename = webkit_download_get_suggested_filename((WebKitDownload *) dl); lua_State *L = globalconf.L; luaH_object_push(L, w->ref); lua_pushstring(L, uri); lua_pushstring(L, filename); luaH_object_emit_signal(L, -3, "download-request", 2, 0); lua_pop(L, 1); return FALSE; }
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; }
/** * ephy_download_set_auto_destination: * @download: an #EphyDownload * * Tells @download to automatically determine a destination for itself. **/ void ephy_download_set_auto_destination (EphyDownload *download) { #ifdef HAVE_WEBKIT2 /* In WebKit2 priv->destination == NULL means auto_destination */ #else char *dest; g_return_if_fail (EPHY_IS_DOWNLOAD (download)); dest = define_destination_uri (download, webkit_download_get_suggested_filename (download->priv->download)); ephy_download_set_destination_uri (download, dest); g_free (dest); #endif }