Esempio n. 1
0
/**
 * Returns the status of the given download.
 *
 * The status will be one of the following:
 * - \c finished
 * - \c created
 * - \c started
 * - \c cancelled
 * - \c error
 *
 * Returns nothing if an error occurs.
 *
 * \param L The Lua VM state.
 * \param download The \ref download_t of the download.
 *
 * \luastack
 * \lparam A \c download object.
 * \lreturn The status of the download as a string or \c nil.
 */
static gint
luaH_download_get_status(lua_State *L, download_t *download)
{
    WebKitDownloadStatus status = webkit_download_get_status(
            download->webkit_download);

    switch (status) {
      case WEBKIT_DOWNLOAD_STATUS_FINISHED:
        luaH_download_unref(L, download);
        lua_pushstring(L, "finished");
        break;
      case WEBKIT_DOWNLOAD_STATUS_CREATED:
        lua_pushstring(L, "created");
        break;
      case WEBKIT_DOWNLOAD_STATUS_STARTED:
        lua_pushstring(L, "started");
        break;
      case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
        luaH_download_unref(L, download);
        lua_pushstring(L, "cancelled");
        break;
      case WEBKIT_DOWNLOAD_STATUS_ERROR:
        luaH_download_unref(L, download);
        lua_pushstring(L, "error");
        break;
      default:
        luaH_warn(L, "unknown download status");
        return 0;
    }

    return 1;
}
Esempio n. 2
0
/**
 * Returns true if the download is currently in progress.
 *
 * \param download The \ref download_t whose progress to check.
 */
static gboolean
download_is_started(download_t *download)
{
    WebKitDownloadStatus status = webkit_download_get_status(
            download->webkit_download);
    return status == WEBKIT_DOWNLOAD_STATUS_STARTED;
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
static void
download_status_changed_cb (GObject *object,
                            GParamSpec *pspec,
                            EphyDownload *download)
{
  WebKitDownloadStatus status;
  EphyDownloadPrivate *priv;

  priv = download->priv;

  status = webkit_download_get_status (priv->download);

  if (status == WEBKIT_DOWNLOAD_STATUS_FINISHED) {
    g_signal_emit_by_name (download, "completed");

    if (g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_AUTO_DOWNLOADS) &&
        priv->action == EPHY_DOWNLOAD_ACTION_NONE) {
      ephy_download_do_download_action (download, EPHY_DOWNLOAD_ACTION_AUTO);
    } else {
      ephy_download_do_download_action (download, priv->action);
    }

    ephy_embed_shell_remove_download (embed_shell, download);
  } else if (status == WEBKIT_DOWNLOAD_STATUS_CANCELLED ||
             status == WEBKIT_DOWNLOAD_STATUS_ERROR) {
  } else if (status == WEBKIT_DOWNLOAD_STATUS_STARTED) {
    ephy_embed_shell_add_download (embed_shell, download);
  }
}
Esempio n. 5
0
/* download_on_timeout */
static gboolean _download_on_timeout(gpointer data)
{
    gboolean ret = TRUE;
    Download * d = data;
#ifdef WITH_WEBKIT
    WebKitDownloadStatus status;
    guint64 received = d->data_received;

    /* FIXME not very efficient */
    status = webkit_download_get_status(d->conn);
    switch(status)
    {
    case WEBKIT_DOWNLOAD_STATUS_ERROR:
        ret = FALSE;
        gtk_label_set_text(GTK_LABEL(d->status), _("Error"));
        break;
    case WEBKIT_DOWNLOAD_STATUS_FINISHED:
        /* XXX pasted from _http_data_complete */
        ret = FALSE;
        gtk_label_set_text(GTK_LABEL(d->status), _("Complete"));
        gtk_widget_set_sensitive(d->check, FALSE);
        gtk_button_set_label(GTK_BUTTON(d->cancel),
                             GTK_STOCK_CLOSE);
        gtk_widget_show(d->browse);
        d->data_received = webkit_download_get_current_size(
                               d->conn);
        g_object_unref(d->conn);
        d->conn = NULL;
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
                                            d->check)))
        {
            g_idle_add(_download_on_closex, d);
            break;
        }
        break;
    case WEBKIT_DOWNLOAD_STATUS_STARTED:
        gtk_label_set_text(GTK_LABEL(d->status),
                           _("Downloading"));
        d->data_received = webkit_download_get_current_size(
                               d->conn);
        d->content_length = webkit_download_get_total_size(
                                d->conn);
        if(d->content_length == d->data_received)
        {
            d->pulse = (d->data_received > received)
                       ? 1 : 0;
            d->content_length = 0;
        }
        break;
    default: /* XXX anything else to handle here? */
        break;
    }
#endif
    _download_refresh(d);
    if(ret != TRUE)
        d->timeout = 0;
    return ret;
}
Esempio n. 6
0
JNIEXPORT jint JNICALL WebKitGTK_NATIVE(_1webkit_1download_1get_1status)
	(JNIEnv *env, jclass that, jintLong arg0)
{
	jint rc = 0;
	WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1download_1get_1status_FUNC);
	rc = (jint)webkit_download_get_status((WebKitDownload *)arg0);
	WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1download_1get_1status_FUNC);
	return rc;
}
Esempio n. 7
0
void
download(WebKitDownload *o, GParamSpec *pspec, Client *c) {
	WebKitDownloadStatus status;

	status = webkit_download_get_status(c->download);
	if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
		c->progress = (gint)(webkit_download_get_progress(c->download)*100);
	}
	update(c);
}
Esempio n. 8
0
static void
notify_status_cb(GObject* object, GParamSpec* pspec, gpointer data)
{
    WebKitDownload* download = WEBKIT_DOWNLOAD(object);
    switch (webkit_download_get_status(download)) {
    case WEBKIT_DOWNLOAD_STATUS_FINISHED:
    case WEBKIT_DOWNLOAD_STATUS_ERROR:
        g_main_loop_quit(loop);
        break;
    case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
        g_assert_not_reached();
        break;
    default:
        break;
    }
}
Esempio n. 9
0
void cb_download_notify_status(WebKitDownload *download, GParamSpec *pspec, Browser *b)
{
	const char *filename = webkit_download_get_destination_uri(download);;

	switch (webkit_download_get_status(download)) {
	case WEBKIT_DOWNLOAD_STATUS_STARTED:
		printf("download started: \"%s\"\n", filename);
		break;
	case WEBKIT_DOWNLOAD_STATUS_FINISHED:
		printf("download finished: \"%s\"\n", filename);
		break;
	case WEBKIT_DOWNLOAD_STATUS_ERROR:
		printf("download error: \"%s\"\n", filename);
		break;
	default:
		break;
	}
}