aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormutantturkey <crazycal00@gmail.com>2011-05-18 23:26:37 -0400
committermutantturkey <crazycal00@gmail.com>2011-05-18 23:26:37 -0400
commit9028c807cfd507c57a17c33fd144678db25edea0 (patch)
treea0795dcbe96d569fc668e67fc27e2f16f338f292
parent8c189045d953c4dc42076776d6f853a692421a42 (diff)
reworked load_status into cb_load status. now uses the WebKitLoadStatus enumerator instead of the deprecated way, allows for handling of other options also
-rw-r--r--callbacks.c44
-rw-r--r--callbacks.h3
-rw-r--r--sb.c42
-rw-r--r--sb.h1
4 files changed, 54 insertions, 36 deletions
diff --git a/callbacks.c b/callbacks.c
index 23c745b..b4cbd17 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -38,7 +38,7 @@ if ( (event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK ) {
}
if (gtk_widget_has_focus(w.bar) && g == GDK_Escape) { gtk_widget_grab_focus(GTK_WIDGET(w.notebook)); return TRUE; }
-if (gtk_widget_has_focus(w.search)) {
+if (gtk_widget_has_focus(w.searchbar)) {
if (g == GDK_Escape) { show_search(FALSE); focus_view(); return TRUE; }
if ((g == GDK_Return) && (event->state & GDK_MOD1_MASK) == GDK_MOD1_MASK) { search(NULL, FALSE); }
}
@@ -67,6 +67,11 @@ w.hide = FALSE;
}
+/* link hovering callback */
+void cb_link_hover (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) {
+if(link != NULL) { gtk_statusbar_push(GTK_STATUSBAR(w.status), 0, link); }
+else { gtk_statusbar_push(GTK_STATUSBAR(w.status), 0, ""); }
+}
/* go forward or backwards, simple enough */
void cb_go(gboolean b) {
@@ -77,16 +82,32 @@ else { webkit_web_view_go_back(t->view); }
/* when the page load is commited, call this function */
-void cb_commit_load (WebKitWebView* page, WebKitWebFrame* frame, tab *t) {
-
-const gchar* uri = webkit_web_frame_get_uri(frame);
-
-if (gtk_notebook_get_current_page(w.notebook) == gtk_notebook_page_num(w.notebook, t->scroll)) {
-gtk_entry_set_text (GTK_ENTRY (w.bar), uri);
-}
-FILE *history = fopen(g_build_filename(g_get_home_dir(), DEFAULT_HISTORY_FILE, NULL), "a+");
-fprintf(history, "%s \n", uri);
-fclose(history);
+void cb_load_status (GObject* object, GParamSpec* pspec, tab *t) {
+
+ const gchar* uri = webkit_web_view_get_uri(t->view);
+ WebKitLoadStatus status = webkit_web_view_get_load_status(t->view);
+ switch(status) {
+ case WEBKIT_LOAD_PROVISIONAL:
+ break;
+ case WEBKIT_LOAD_COMMITTED:
+
+ if (gtk_notebook_get_current_page(w.notebook) == gtk_notebook_page_num(w.notebook, t->scroll)) {
+ gtk_entry_set_text (GTK_ENTRY (w.bar), uri);
+ }
+
+ FILE *history = fopen(g_build_filename(g_get_home_dir(), DEFAULT_HISTORY_FILE, NULL), "a+");
+ fprintf(history, "%s \n", uri);
+ fclose(history);
+
+ break;
+ case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
+ break;
+ case WEBKIT_LOAD_FINISHED:
+ break;
+ default:
+ case WEBKIT_LOAD_FAILED:
+ break;
+ }
}
@@ -94,7 +115,6 @@ fclose(history);
/* title change callback */
void cb_title_changed(WebKitWebView *v, WebKitWebFrame *f, const char *title, tab *t) {
gchar *tabtitle;
-
if (gtk_notebook_get_current_page(w.notebook) == gtk_notebook_page_num(w.notebook, t->scroll)) {
gtk_window_set_title(GTK_WINDOW(w.win), g_strconcat(title, NULL));
}
diff --git a/callbacks.h b/callbacks.h
index b085616..62f2e87 100644
--- a/callbacks.h
+++ b/callbacks.h
@@ -1,7 +1,8 @@
gboolean cb_keypress(GtkWidget *widget, GdkEventKey *event);
void cb_entry(GtkWidget* entry, gpointer data);
+void cb_link_hover(WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
void cb_go(gboolean b);
void cb_download(WebKitWebView *web_view, GObject *download, gpointer user_data);
void cb_title_changed(WebKitWebView *v, WebKitWebFrame *f, const char *title, tab *t);
-void cb_commit_load(WebKitWebView* page, WebKitWebFrame* frame, tab *t);
+void cb_load_status(GObject* object, GParamSpec* pspec, tab *t);
diff --git a/sb.c b/sb.c
index 0c30802..0fe7252 100644
--- a/sb.c
+++ b/sb.c
@@ -26,17 +26,17 @@ gchar* tab_get_tab_postition() {
void search(GtkEntry *entry, gboolean b) {
struct tab *t = get_tab(NULL, gtk_notebook_get_current_page(w.notebook));
- webkit_web_view_search_text(t->view, gtk_entry_get_text(GTK_ENTRY(w.search)), FALSE, b, TRUE);
+ webkit_web_view_search_text(t->view, gtk_entry_get_text(GTK_ENTRY(w.searchbar)), FALSE, b, TRUE);
}
void show_search(gboolean b) {
if(b) {
- gtk_widget_show(w.search);
- gtk_widget_grab_focus(w.search);
+ gtk_widget_show(w.searchbar);
+ gtk_widget_grab_focus(w.searchbar);
}
else {
- gtk_widget_hide(w.search);
+ gtk_widget_hide(w.searchbar);
}
}
@@ -63,15 +63,7 @@ if (gtk_notebook_get_n_pages(w.notebook) == 0) { gtk_main_quit(); }
}
-/* link hovering callback */
-void link_hover (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) {
-if(link != NULL) { gtk_statusbar_push(GTK_STATUSBAR(w.status), 0, link); }
-else { gtk_statusbar_push(GTK_STATUSBAR(w.status), 0, ""); }
-}
-
-
/* an alternative to the regular tab command, combines tabbing and history command into one */
-
void tab_and_go() {
gchar *returned;
g_spawn_command_line_sync(g_strconcat("sh -c 'sort ", g_build_filename(g_get_home_dir(), ".sb_history", NULL), " | dmenu -l 15 -xs -c'", NULL), &returned, NULL, NULL, NULL);
@@ -120,7 +112,7 @@ void toggle() {
}
else {
gtk_widget_show_all(w.vbox);
- gtk_widget_hide(w.search);
+ gtk_widget_hide(w.searchbar);
if (gtk_notebook_get_n_pages(w.notebook) == 1) { } else { gtk_notebook_set_show_tabs(w.notebook, TRUE);}
}
}
@@ -202,8 +194,8 @@ webkit_web_view_set_zoom_level(t->view, DEFAULT_ZOOM_LEVEL);
/*callbacks*/
g_signal_connect (G_OBJECT (t->view), "title-changed", G_CALLBACK (cb_title_changed), t);
-g_signal_connect (G_OBJECT (t->view), "load-committed", G_CALLBACK (cb_commit_load), t);
-g_signal_connect (G_OBJECT (t->view), "hovering-over-link", G_CALLBACK (link_hover), t->view);
+g_signal_connect (G_OBJECT (t->view), "notify::load-status", G_CALLBACK (cb_load_status), t);
+g_signal_connect (G_OBJECT (t->view), "hovering-over-link", G_CALLBACK (cb_link_hover), t->view);
g_signal_connect (G_OBJECT (t->view), "download-requested", G_CALLBACK (cb_download), t->view);
g_signal_connect (G_OBJECT (t->view), "create-web-view", G_CALLBACK (tab_new_requested), NULL);
/*settings*/
@@ -211,7 +203,7 @@ g_signal_connect (G_OBJECT (t->view), "create-web-view", G_CALLBACK (tab_new_req
g_object_set_qdata_full(G_OBJECT(gtk_notebook_get_nth_page((GtkNotebook*)w.notebook, index)), term_data_id, t, NULL);
gtk_widget_show_all(w.win);
-gtk_widget_hide(w.search);
+gtk_widget_hide(w.searchbar);
if (!b) { gtk_notebook_set_current_page(w.notebook, index); }
gtk_widget_grab_focus(w.bar);
}
@@ -257,22 +249,28 @@ void window_setup() {
term_data_id = g_quark_from_static_string("s");
w.vbox = gtk_vbox_new(FALSE, 0);
+w.hbox = gtk_hbox_new(FALSE, 0);
+
w.notebook = gtk_notebook_new();
w.bar = gtk_entry_new ();
-w.search = gtk_entry_new();
+w.searchbar = gtk_entry_new();
w.status = gtk_statusbar_new();
gtk_entry_set_has_frame(GTK_ENTRY(w.bar), FALSE);
-gtk_notebook_set_scrollable(w.notebook, TRUE) ;
-gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(w.status), FALSE);
+//gtk_entry_set_icon_from_stock(GTK_ENTRY(w.bar), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_YES);
+
+gtk_notebook_set_scrollable(w.notebook, TRUE);
gtk_notebook_set_show_border(w.notebook, FALSE);
gtk_notebook_set_tab_border(w.notebook, 0);
+gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(w.status), FALSE);
+
gtk_box_pack_start(GTK_BOX (w.vbox), w.bar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(w.vbox), GTK_WIDGET(w.notebook), TRUE, TRUE, 0);
-gtk_box_pack_start(GTK_BOX(w.vbox), w.search, FALSE, FALSE, 0);
+gtk_box_pack_start(GTK_BOX(w.vbox), w.searchbar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(w.vbox), w.status, FALSE, FALSE, 0);
+//gtk_box_pack_start(GTK_BOX(w.hbox), w.status, TRUE, FALSE, 0);
w.win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(w.win), DEFAULT_HEIGHT, DEFAULT_WIDTH);
@@ -286,7 +284,7 @@ soup_session_add_feature(w.session, SOUP_SESSION_FEATURE(w.jar));
tab_new(FALSE);
-g_signal_connect (G_OBJECT (w.search), "activate", G_CALLBACK (search), GINT_TO_POINTER(1));
+g_signal_connect (G_OBJECT (w.searchbar), "activate", G_CALLBACK (search), GINT_TO_POINTER(1));
g_signal_connect (G_OBJECT (w.bar), "activate", G_CALLBACK (cb_entry), NULL);
g_signal_connect (G_OBJECT(w.notebook), "switch-page", G_CALLBACK(tab_focus), NULL);
g_signal_connect (G_OBJECT (w.win), "destroy", G_CALLBACK (gtk_main_quit), NULL);
@@ -294,7 +292,7 @@ g_signal_connect(w.win, "key-press-event", G_CALLBACK(cb_keypress), NULL);
gtk_container_add (GTK_CONTAINER (w.win), w.vbox);
gtk_widget_show_all (w.win);
-gtk_widget_hide(w.search);
+gtk_widget_hide(w.searchbar);
gtk_widget_grab_focus(w.bar);
}
diff --git a/sb.h b/sb.h
index f69bd59..c45fbab 100644
--- a/sb.h
+++ b/sb.h
@@ -1,6 +1,5 @@
void history_command();
void grab_bar();
-void link_hover(WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
void load_uri(gchar *uri);
void tab_new(gboolean b);
void tab_zoom(gboolean b);