Skip to content
Browse files

Added a page load spinner.

  • Loading branch information...
1 parent 6f46cab commit b8ca8cefb789f4409df1f45580207190bbacd93b @thomaslee committed May 26, 2012
Showing with 57 additions and 10 deletions.
  1. +55 −10 browserwindow.c
  2. +2 −0 browserwindow.h
View
65 browserwindow.c
@@ -8,6 +8,10 @@
static gboolean
browser_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer p)
{
+ /* TODO destroy lingering spinner/placeholder? */
+ /*
+ BrowserWindow *w = (BrowserWindow *)p;
+ */
gtk_main_quit ();
return FALSE;
}
@@ -123,6 +127,30 @@ browser_window_refresh_button_clicked (
webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW (w->view));
}
+static void
+browser_window_load_status_changed (
+ GObject *obj, GParamSpec *p, gpointer user_data)
+{
+ BrowserWindow *w = (BrowserWindow *) user_data;
+ switch (webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (w->view))) {
+ case WEBKIT_LOAD_PROVISIONAL:
+ {
+ gtk_spinner_start (GTK_SPINNER (w->spinner));
+ gtk_widget_set_sensitive (w->spinner, TRUE);
+ break;
+ }
+ case WEBKIT_LOAD_FINISHED:
+ case WEBKIT_LOAD_FAILED:
+ {
+ gtk_spinner_stop (GTK_SPINNER (w->spinner));
+ gtk_widget_set_sensitive (w->spinner, FALSE);
+ break;
+ }
+ default:
+ return;
+ };
+}
+
static GtkWidget *
browser_window_new_nav_button (const gchar *stock_id)
{
@@ -137,7 +165,7 @@ browser_window_new_nav_button (const gchar *stock_id)
gboolean
browser_window_init(BrowserWindow *bw)
{
- GtkWidget *vbox, *hbox;
+ GtkWidget *vbox;
bw->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
bw->view = browser_view_new ();
@@ -146,6 +174,10 @@ browser_window_init(BrowserWindow *bw)
bw->back_button = browser_window_new_nav_button (GTK_STOCK_GO_BACK);
bw->forward_button = browser_window_new_nav_button (GTK_STOCK_GO_FORWARD);
bw->refresh_button = browser_window_new_nav_button (GTK_STOCK_REFRESH);
+ bw->spinner = gtk_spinner_new ();
+ bw->hbox = gtk_hbox_new (FALSE, 0);
+
+ gtk_widget_set_sensitive (bw->spinner, FALSE);
gtk_container_add (GTK_CONTAINER (bw->scrolled), bw->view);
gtk_scrolled_window_set_policy (
@@ -154,15 +186,20 @@ browser_window_init(BrowserWindow *bw)
GTK_POLICY_AUTOMATIC
);
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), bw->back_button, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), bw->forward_button, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), bw->refresh_button, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), bw->entry, TRUE, TRUE, 0);
-
+ bw->hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (
+ GTK_BOX (bw->hbox), bw->back_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (
+ GTK_BOX (bw->hbox), bw->forward_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (
+ GTK_BOX (bw->hbox), bw->refresh_button, FALSE, FALSE, 0);
+ gtk_box_pack_start (
+ GTK_BOX (bw->hbox), bw->entry, TRUE, TRUE, 0);
+ gtk_box_pack_start (
+ GTK_BOX (bw->hbox), bw->spinner, FALSE, FALSE, 10);
vbox = gtk_vbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (vbox), bw->hbox, FALSE, FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), bw->scrolled, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (bw->window), vbox);
@@ -193,14 +230,12 @@ browser_window_init(BrowserWindow *bw)
G_CALLBACK (browser_window_back_button_clicked),
bw
);
-
g_signal_connect (
bw->forward_button,
"clicked",
G_CALLBACK (browser_window_forward_button_clicked),
bw
);
-
g_signal_connect (
bw->refresh_button,
"clicked",
@@ -210,6 +245,13 @@ browser_window_init(BrowserWindow *bw)
g_signal_connect (
bw->view,
+ "notify::load-status",
+ G_CALLBACK (browser_window_load_status_changed),
+ bw
+ );
+
+ g_signal_connect (
+ bw->view,
"title-changed",
G_CALLBACK (browser_window_title_changed),
bw
@@ -225,6 +267,9 @@ browser_window_init(BrowserWindow *bw)
gtk_window_set_default_size (GTK_WINDOW (bw->window), 800, 600);
gtk_window_set_position (GTK_WINDOW (bw->window), GTK_WIN_POS_CENTER);
+ gtk_widget_grab_focus (bw->entry);
+ gtk_editable_select_region (GTK_EDITABLE (bw->entry), 0, -1);
+
return TRUE;
}
View
2 browserwindow.h
@@ -11,6 +11,8 @@ typedef struct _BrowserWindow {
GtkWidget *back_button;
GtkWidget *forward_button;
GtkWidget *refresh_button;
+ GtkWidget *spinner;
+ GtkWidget *hbox;
} BrowserWindow;
gboolean

0 comments on commit b8ca8ce

Please sign in to comment.
Something went wrong with that request. Please try again.