Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
void update_progress(void)
{
    if (0 && cur_download) {
	gdouble prog = webkit_download_get_progress(cur_download);
	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), prog);
    }
}
Ejemplo n.º 3
0
/**
 * Returns the current progress in percent of the given download.
 *
 * \param L The Lua VM state.
 * \param download The \ref download_t of the download.
 *
 * \luastack
 * \lparam A \c download object.
 * \lreturn The progress of the download as a number between 0.0 and 1.0
 */
static gint
luaH_download_get_progress(lua_State *L, download_t *download)
{
    gdouble progress = webkit_download_get_progress(download->webkit_download);
    if (progress == 1)
        luaH_download_unref(L, download);
    lua_pushnumber(L, progress);
    return 1;
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
static VALUE
Download_progress(VALUE self)
{
  VALUE __p_retval = Qnil;
  WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self));

#line 233 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr"
  do { __p_retval =  rb_float_new(webkit_download_get_progress(_self)); goto out; } while(0);
out:
  return __p_retval;
}
Ejemplo 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;
    }