Make the progressbar work properly again

The code was not updated along with other changes in the past.
It was cleaned up to work properly again, particularly the percentage
is displayed in text form again.
This commit is contained in:
Christian Dywan 2007-12-20 02:07:22 +01:00
parent 5928f8ad88
commit dcb8b2b8d1
3 changed files with 11 additions and 32 deletions

View file

@ -68,8 +68,6 @@ typedef struct _CBrowser
gboolean hasStatusbar;
gchar* elementUri; // the element the mouse is hovering on
gint loadedPercent; // -1 means "not loading"
gint loadedBytes;
gint loadedBytesMax;
//UNDEFINED favicon;
guint security;
gchar* statusMessage; // message from a webView

View file

@ -318,16 +318,10 @@ void update_statusbar_text(CBrowser* browser)
gtk_statusbar_push(GTK_STATUSBAR(browser->statusbar), 1
, browser->statusMessage);
}
else
sokoke_widget_set_visible(browser->progress, browser->loadedPercent > -1);
if(browser->loadedPercent > -1)
{
gchar* message;
if(browser->loadedPercent)
message = g_strdup_printf("%d%% loaded, %d/%d bytes"
, browser->loadedPercent, browser->loadedBytes, browser->loadedBytesMax);
else if(browser->loadedBytes)
message = g_strdup_printf("%d bytes", browser->loadedBytes);
else
message = g_strdup(" ");
gchar* message = g_strdup_printf("%d%% loaded", browser->loadedPercent);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(browser->progress), message);
g_free(message);
}
@ -388,23 +382,13 @@ void update_gui_state(CBrowser* browser)
gtk_image_set_from_stock(GTK_IMAGE(browser->location_icon), GTK_STOCK_FILE
, GTK_ICON_SIZE_MENU);
if(browser->loadedBytesMax < 1) // Skip null and negative values
{
if(browser->loadedPercent > -1)
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(browser->progress)
, browser->loadedPercent ? browser->loadedPercent / 100.0 : 0);
else
gtk_progress_bar_pulse(GTK_PROGRESS_BAR(browser->progress));
update_statusbar_text(browser);
}
else
{
if(browser->loadedBytes > browser->loadedBytesMax)
browser->loadedPercent = 100;
else
browser->loadedPercent
= (browser->loadedBytes * 100) / browser->loadedBytesMax;
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(browser->progress)
, browser->loadedPercent / 100.0);
update_statusbar_text(browser);
}
}
void update_feeds(CBrowser* browser)
{

View file

@ -77,8 +77,6 @@ void on_webView_load_started(GtkWidget* webView, WebKitWebFrame* widget
, CBrowser* browser)
{
browser->loadedPercent = 0;
browser->loadedBytes = 0;
browser->loadedBytesMax = 0;
update_favicon(browser);
if(webView == get_nth_webView(-1, browser))
update_gui_state(browser);
@ -104,8 +102,7 @@ void on_webView_load_committed(GtkWidget* webView, WebKitWebFrame* frame
void on_webView_load_changed(GtkWidget* webView, gint progress, CBrowser* browser)
{
browser->loadedBytes = progress;
browser->loadedBytes = 100;
browser->loadedPercent = progress;
if(webView == get_nth_webView(-1, browser))
update_gui_state(browser);
}