tazweb rev 2
Add main.c the web browser itself
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Apr 04 02:42:34 2011 +0200 (2011-04-04) |
parents | e5f8ff50f9fc |
children | 25fecd52f7d4 |
files | main.c |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/main.c Mon Apr 04 02:42:34 2011 +0200 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * TazWeb is a radicaly simple web browser providing a single window 1.6 + * with no toolbar, menu or tabs. 1.7 + * 1.8 + * 1.9 + * Copyright (C) 2011 SliTaz GNU/Linux <devel@slitaz.org> 1.10 + * 1.11 + * 1.12 + */ 1.13 + 1.14 +#include <gtk/gtk.h> 1.15 +#include <webkit/webkit.h> 1.16 + 1.17 +static GtkWidget* main_window; 1.18 +static GtkWidget* uri_entry; 1.19 +static WebKitWebView* web_view; 1.20 +static gchar* main_title; 1.21 +static gdouble load_progress; 1.22 +static guint status_context_id; 1.23 + 1.24 +/* Page title to window title */ 1.25 +static void 1.26 +update_title (GtkWindow* window) 1.27 +{ 1.28 + GString* string = g_string_new (main_title); 1.29 + g_string_append (string, " - TazWeb"); 1.30 + if (load_progress < 100) 1.31 + g_string_append_printf (string, " (%f%%)", load_progress); 1.32 + gchar* title = g_string_free (string, FALSE); 1.33 + gtk_window_set_title (window, title); 1.34 + g_free (title); 1.35 +} 1.36 + 1.37 +static void 1.38 +notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.39 +{ 1.40 + if (main_title) 1.41 + g_free (main_title); 1.42 + main_title = g_strdup (webkit_web_view_get_title(web_view)); 1.43 + update_title (GTK_WINDOW (main_window)); 1.44 +} 1.45 + 1.46 +/* Request progress in window title */ 1.47 +static void 1.48 +notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.49 +{ 1.50 + load_progress = webkit_web_view_get_progress (web_view) * 100; 1.51 + update_title (GTK_WINDOW (main_window)); 1.52 +} 1.53 + 1.54 +static void 1.55 +destroy_cb (GtkWidget* widget, gpointer data) 1.56 +{ 1.57 + gtk_main_quit (); 1.58 +} 1.59 + 1.60 +static GtkWidget* 1.61 +create_browser () 1.62 +{ 1.63 + GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); 1.64 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 1.65 + 1.66 + web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); 1.67 + gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view)); 1.68 + 1.69 + g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view); 1.70 + g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view); 1.71 + 1.72 + return scrolled_window; 1.73 +} 1.74 + 1.75 +static GtkWidget* 1.76 +create_window () 1.77 +{ 1.78 + GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 1.79 + /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/ 1.80 + gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); 1.81 + gtk_widget_set_name (window, "TazWeb"); 1.82 + g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL); 1.83 + 1.84 + return window; 1.85 +} 1.86 + 1.87 +int 1.88 +main (int argc, char* argv[]) 1.89 +{ 1.90 + gtk_init (&argc, &argv); 1.91 + if (!g_thread_supported ()) 1.92 + g_thread_init (NULL); 1.93 + 1.94 + GtkWidget* vbox = gtk_vbox_new (FALSE, 0); 1.95 + gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0); 1.96 + 1.97 + main_window = create_window (); 1.98 + gtk_container_add (GTK_CONTAINER (main_window), vbox); 1.99 + 1.100 + /* Home page url or file */ 1.101 + gchar* uri = (gchar*) (argc > 1 ? argv[1] : "file:///usr/share/webhome/index.html"); 1.102 + webkit_web_view_load_uri (web_view, uri); 1.103 + 1.104 + gtk_widget_grab_focus (GTK_WIDGET (web_view)); 1.105 + gtk_widget_show_all (main_window); 1.106 + gtk_main (); 1.107 + 1.108 + return 0; 1.109 +}