I'm stuck with an issue that I'm gonna try and explain clearly. I'm using a gtkmm webkit browser in a sort of embedded application to access php/html files. The point is that I fail to code a way for this webkit to handle downloads.
Oh, and I'm coding in C++.
The file to download currently looks like below in my HTML code :
<a href='excel/template_users.php'><img src='imgs/excelbis.png'/>Download Excel File</a>
The "template_users.php" file is just a way of forcing the user to download the file (you can also access to the website via a "classic" web browser). It contains only :
<?php
header("Content-disposition: attachment; filename=template_users.xls");
header("Content-type: application/vnd.ms-excel:");
readfile("template_users.xls");
?>
I've been trying to handle downloads by adding to my IntegratedBrowser class constructor (which instantiate the webkit) a connector to the signal "download-requested" :
gboolean ret = FALSE;
g_signal_connect(webView, "download-requested", G_CALLBACK(&IntegratedBrowser::downloadRequested), &ret);
And the associated method :
gboolean IntegratedBrowser::downloadRequested(WebKitWebView* webView, WebKitDownload *download, gboolean *handled)
{
const gchar* dest = webkit_download_get_uri(download);
webkit_download_set_destination_uri(download, dest);
return FALSE;
}
I should precise that everything runs of course fine when I'm trying to download the file via a "classic web browser". The c++ code compile smoothly, however, nothing happens when I click on the link using the webkit. I would like the file to be downloaded in a location chosen by the user if possible (downloading the file into a specific location is viable as well) when clicking on the link.
Have you got any idea of what I am doing incorrectly ?
Thanks for your answers !
Edit : now my downloadRequested method looks like that :
gboolean IntegratedBrowser::downloadRequested(WebKitWebView* webView, WebKitDownload *download, gboolean *handled)
{
const gchar* dest = g_strdup_printf("%s", "file:///home/user/test.xls");
webkit_download_set_destination_uri(download, dest);
return TRUE;
}