#include #include #include #include #include #include #include #include "defaults.h" #include "callbacks.h" #include "sb.h" /* download callback */ void cb_download(WebKitWebView *web_view, GObject *d, gpointer user_data) { const gchar *c = webkit_download_get_uri(WEBKIT_DOWNLOAD(d)); gchar *command = g_strconcat(DEFAULT_DOWNLOAD, g_get_home_dir(), "/ ", g_strdup(c), NULL); g_spawn_command_line_async(command, NULL); g_free(command); } /* entry callback */ void cb_entry (GtkWidget* entry, gpointer data) { struct tab *t = get_tab(NULL, gtk_notebook_get_current_page(w.notebook)); load_uri(g_strdup(gtk_entry_get_text (GTK_ENTRY (w.bar)))); gtk_widget_grab_focus(GTK_WIDGET(t->view)); if(w.hide) { gtk_widget_hide(w.bar); } w.hide = FALSE; } /* go forward or backwards, simple enough */ void cb_go(gboolean b) { struct tab *t = get_tab(NULL, gtk_notebook_get_current_page(w.notebook)); if (b) { webkit_web_view_go_forward(t->view); } 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); } /* 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)); } if(strlen(title) < DEFAULT_TAB_LENGTH ) { tabtitle = g_strdup(title); } else { tabtitle = g_strndup(title, DEFAULT_TAB_LENGTH); strcat(tabtitle, "..."); } gtk_label_set_label(GTK_LABEL(t->label), tabtitle); }