Exemplo n.º 1
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;
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
/**
 * Returns the current size of the download, i.e. the bytes already downloaded.
 *
 * \param L The Lua VM state.
 * \param download The \ref download_t of the download.
 *
 * \luastack
 * \lparam A \c download object.
 * \lreturn The current size of the download in bytes as a number.
 */
static gint
luaH_download_get_current_size(lua_State *L, download_t *download)
{
    gdouble current_size = webkit_download_get_current_size(
            download->webkit_download);
    lua_pushnumber(L, current_size);
    return 1;
}
Exemplo n.º 4
0
JNIEXPORT jlong JNICALL WebKitGTK_NATIVE(_1webkit_1download_1get_1current_1size)
	(JNIEnv *env, jclass that, jintLong arg0)
{
	jlong rc = 0;
	WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1download_1get_1current_1size_FUNC);
	rc = (jlong)webkit_download_get_current_size((WebKitDownload *)arg0);
	WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1download_1get_1current_1size_FUNC);
	return rc;
}
Exemplo n.º 5
0
static VALUE
Download_current_size(VALUE self)
{
  VALUE __p_retval = Qnil;
  WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self));

#line 236 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr"
  do { __p_retval =  rb_ull2inum(webkit_download_get_current_size(_self)); goto out; } while(0);
out:
  return __p_retval;
}
Exemplo n.º 6
0
/* download_progress_cb(WebKitDownload *) {{{*/
static void
download_progress_cb(WebKitDownload *download, GParamSpec *p, DwbDownloadStatus *status)
{
    /* Update at most four times a second */
    gint64 time = g_get_monotonic_time();
    static double speed = 0;
    static guint remaining = 0;
    if (time - status->time > 250000)
    {
        GList *l = download_get_download_label(download);
        DwbDownload *label = l->data;
        double elapsed = webkit_download_get_elapsed_time(download);
        double progress = webkit_download_get_progress(download);
        double total_size = (double)webkit_download_get_total_size(download) / 0x100000;

        if (time - status->speedtime > 1000000)
        {
            speed = ((progress - status->progress)*total_size) * 1000000 / (time - status->speedtime);
            status->speedtime = time;
            status->progress = progress;
            remaining = (guint)(elapsed / progress - elapsed);
        }

        double current_size = (double)webkit_download_get_current_size(download) / 0x100000;
        char buffer[128] = {0};
        const char *format = speed > 1 ? "[%.1fM/s|%d:%02d|%2d%%|%.3f/%.3f]" : "[%3.1fK/s|%d:%02d|%2d%%|%.3f/%.3f]";
        snprintf(buffer, sizeof(buffer), format, speed > 1 ? speed : speed*1024, remaining/60, remaining%60,  (int)(progress*100), current_size,  total_size);
        gtk_label_set_text(GTK_LABEL(label->rlabel), buffer);

#if _HAS_GTK3
        gdouble red, green, blue, alpha;
#else
        guint red, green, blue;
#endif
        red = ((progress) * dwb.color.download_end.red + (1-progress) * dwb.color.download_start.red);
        green = ((progress) * dwb.color.download_end.green + (1-progress) * dwb.color.download_start.green);
        blue = ((progress) * dwb.color.download_end.blue + (1-progress) * dwb.color.download_start.blue);
#if _HAS_GTK3
        alpha = ((progress) * dwb.color.download_end.alpha + (1-progress) * dwb.color.download_start.alpha);

        if (blue != status->blue || red != status->red || green != status->green || alpha != status->alpha) {
#else
        if (blue != status->blue || red != status->red || green != status->green) {
#endif
            DwbColor gradient = {
                .red = red,
                .green = green,
                .blue = blue,
#if _HAS_GTK3
                .alpha = alpha
#endif
            };
            DWB_WIDGET_OVERRIDE_BACKGROUND(label->event, GTK_STATE_NORMAL, &gradient);
        }
        status->blue  = blue;
        status->red   = red;
        status->green = green;
#if _HAS_GTK3
        status->alpha = alpha;
#endif
        status->time = time;
    }