2012-07-06 93 views

回答

2
  1. 連接信號:

    gboolean ret = FALSE; 
    g_signal_connect(webView, "download-requested", G_CALLBACK(downloadRequested), &ret); 
    
  2. 編寫信號處理程序:如果你想自己處理下載過程

    static gboolean downloadRequested(WebKitWebView* webView, WebKitDownload *download,  gboolean *handled) 
    { 
        const gchar* dest = g_strdup_printf("%s", "file://xxx"); // The 'dest' path should be customized path using 'webkit_download_get_uri' 
        webkit_download_set_destination_uri(download, dest); 
        return TRUE; 
    } 
    

    ,你應該return FALSE;在這裏。

+0

它沒有工作。我使用的靜態gboolean downloadRequested(WebKitWebView * web_view,WebKitDownload *下載,gboolean處理) { \t \t 常量\t * gchar DEST = g_strdup_printf( 「%S」, 「/home/malteuser/Downloads/test.mp3」); \t \t //'dest'p ath應該使用'webkit_download_get_uri'定製路徑 \t \t webkit_download_set_destination_uri(download,dest); \t \t return TRUE; } – user1464420 2012-07-07 12:43:56

+1

該文件未創建。我得到這個錯誤:(program:3947):GLib-GIO-CRITICAL **:g_output_stream_write_all:聲明'G_IS_OUTPUT_STREAM(流)'失敗 – user1464420 2012-07-07 12:45:25

+0

你應該使用「file:///home/malteuser/Downloads/test.mp3」。請嘗試。 – 2012-07-07 23:13:00

-2

他忘了開始下載!

static gboolean downloadRequested(WebKitWebView* webView, WebKitDownload *download, gboolean *handled) 
{ 
    const gchar* dest = g_strdup_printf("%s", "file:///home/administrator/Downloads/test.jpg"); 
    webkit_download_set_destination_uri(download, dest); 
    webkit_download_start(download); //start the download 
    return TRUE; 
}