예제 #1
0
파일: browser.c 프로젝트: kublaj/lariza
void
changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
{
    WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
    WebKitURIResponse *resp;
    GtkToolItem *tb = GTK_TOOL_ITEM(data);
    gdouble p, size_mb;
    const gchar *uri;
    gchar *t, *filename, *base;

    p = webkit_download_get_estimated_progress(download) * 100;
    resp = webkit_download_get_response(download);
    size_mb = webkit_uri_response_get_content_length(resp) / 1e6;

    uri = webkit_download_get_destination(download);
    filename = g_filename_from_uri(uri, NULL, NULL);
    if (filename == NULL)
    {
        /* This really should not happen because WebKit uses that URI to
         * write to a file... */
        fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
        t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
                            webkit_uri_response_get_uri(resp), p, size_mb);
    }
    else
    {
        base = g_path_get_basename(filename);
        t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
        g_free(filename);
        g_free(base);
    }
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
    g_free(t);
}
예제 #2
0
/**
 * ephy_download_get_content_type:
 * @download: an #EphyDownload
 *
 * Gets content-type information for @download. If the file is already
 * present on the filesystem and readable, uses GIO to get the
 * content-type. Otherwise it uses WebKit and Soup.
 *
 * Returns: content-type for @download, must be freed with g_free()
 **/
char *
ephy_download_get_content_type (EphyDownload *download)
{
#ifdef HAVE_WEBKIT2
  WebKitURIResponse *response;
#else
  WebKitNetworkResponse *response;
  SoupMessage *message;
#endif
  char *content_type = NULL;
  GError *error = NULL;

  if (download->priv->destination) {
    GFile *destination;
    GFileInfo *info;

    destination = g_file_new_for_uri (download->priv->destination);
    info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                              G_FILE_QUERY_INFO_NONE, NULL, &error);
    if (info) {
      content_type = g_strdup (g_file_info_get_content_type (info));
      LOG ("ephy_download_get_content_type: GIO: %s", content_type);
      g_object_unref (info);
    } else {
      LOG ("ephy_download_get_content_type: error getting file "
           "content-type: %s", error->message);
      g_error_free (error);
    }

    g_object_unref (destination);
  }

  if (content_type)
    return content_type;

  /* Fallback to Soup */
#ifdef HAVE_WEBKIT2
  response = webkit_download_get_response (download->priv->download);
  if (response)
    content_type = g_strdup (webkit_uri_response_get_mime_type (response));
#else
  response = webkit_download_get_network_response (download->priv->download);
  message = webkit_network_response_get_message (response);

  if (message != NULL)
    content_type = g_strdup (soup_message_headers_get_content_type (message->response_headers, NULL));
#endif

  LOG ("ephy_download_get_content_type: Soup: %s", content_type);

  LOG ("ephy_download_get_content_type: %s", content_type);

  return content_type;
}
예제 #3
0
 static void receivedResponseCallback(WebKitDownload* download, GParamSpec*, DownloadTest* test)
 {
     g_assert(webkit_download_get_response(download));
     test->receivedResponse(download);
 }