aboutsummaryrefslogtreecommitdiff
path: root/callbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'callbacks.c')
-rw-r--r--callbacks.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/callbacks.c b/callbacks.c
new file mode 100644
index 0000000..27bdaf1
--- /dev/null
+++ b/callbacks.c
@@ -0,0 +1,69 @@
+#include <gdk/gdkkeysyms.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <webkit/webkit.h>
+#include <glib/gstdio.h>
+#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);
+}