tazweb rev 13
Just keep one source file (we will have a small toolbar!
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Apr 04 19:23:04 2011 +0200 (2011-04-04) |
parents | 2d3ce36d0c3d |
children | b92f7602029a |
files | src/with-toolbar.c |
line diff
1.1 --- a/src/with-toolbar.c Mon Apr 04 17:31:19 2011 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,227 +0,0 @@ 1.4 -/* 1.5 - * This is a version of TazWeb with a simple toolbar with home, 1.6 - * go-back, go-next and URL entry 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 -static void 1.25 -activate_uri_entry_cb (GtkWidget* entry, gpointer data) 1.26 -{ 1.27 - const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry)); 1.28 - g_assert (uri); 1.29 - webkit_web_view_load_uri (web_view, uri); 1.30 -} 1.31 - 1.32 -/* Page title to window title */ 1.33 -static void 1.34 -update_title (GtkWindow* window) 1.35 -{ 1.36 - GString* string = g_string_new (main_title); 1.37 - g_string_append (string, " - TazWeb"); 1.38 - if (load_progress < 100) 1.39 - g_string_append_printf (string, " (%f%%)", load_progress); 1.40 - gchar* title = g_string_free (string, FALSE); 1.41 - gtk_window_set_title (window, title); 1.42 - g_free (title); 1.43 -} 1.44 - 1.45 -static void 1.46 -notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.47 -{ 1.48 - if (main_title) 1.49 - g_free (main_title); 1.50 - main_title = g_strdup (webkit_web_view_get_title(web_view)); 1.51 - update_title (GTK_WINDOW (main_window)); 1.52 -} 1.53 - 1.54 -static void 1.55 -notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.56 -{ 1.57 - if (webkit_web_view_get_load_status (web_view) == WEBKIT_LOAD_COMMITTED) { 1.58 - WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view); 1.59 - const gchar* uri = webkit_web_frame_get_uri (frame); 1.60 - if (uri) 1.61 - gtk_entry_set_text (GTK_ENTRY (uri_entry), uri); 1.62 - } 1.63 -} 1.64 - 1.65 -/* Request progress in window title */ 1.66 -static void 1.67 -notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.68 -{ 1.69 - load_progress = webkit_web_view_get_progress (web_view) * 100; 1.70 - update_title (GTK_WINDOW (main_window)); 1.71 -} 1.72 - 1.73 -static void 1.74 -destroy_cb (GtkWidget* widget, gpointer data) 1.75 -{ 1.76 - gtk_main_quit (); 1.77 -} 1.78 - 1.79 -/* Go Home function */ 1.80 -static void 1.81 -go_home (GtkWidget* widget, gpointer data) 1.82 -{ 1.83 - const gchar* uri = ("file:///usr/share/webhome/index.html"); 1.84 - g_assert (uri); 1.85 - webkit_web_view_load_uri (web_view, uri); 1.86 -} 1.87 - 1.88 -/* TazPanel function */ 1.89 -static void 1.90 -slitaz_panel (GtkWidget* widget, gpointer data) 1.91 -{ 1.92 - const gchar* uri = ("http://tazpanel:8080/"); 1.93 - g_assert (uri); 1.94 - webkit_web_view_load_uri (web_view, uri); 1.95 -} 1.96 - 1.97 -/* TazWeb doc function */ 1.98 -static void 1.99 -tazweb_doc (GtkWidget* widget, gpointer data) 1.100 -{ 1.101 - const gchar* uri = ("file:///usr/share/doc/slitaz/tazweb.html"); 1.102 - g_assert (uri); 1.103 - webkit_web_view_load_uri (web_view, uri); 1.104 -} 1.105 - 1.106 -static void 1.107 -go_back_cb (GtkWidget* widget, gpointer data) 1.108 -{ 1.109 - webkit_web_view_go_back (web_view); 1.110 -} 1.111 - 1.112 -static void 1.113 -go_forward_cb (GtkWidget* widget, gpointer data) 1.114 -{ 1.115 - webkit_web_view_go_forward (web_view); 1.116 -} 1.117 - 1.118 -static GtkWidget* 1.119 -create_browser () 1.120 -{ 1.121 - GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); 1.122 - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 1.123 - 1.124 - web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); 1.125 - gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view)); 1.126 - 1.127 - g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view); 1.128 - g_signal_connect (web_view, "notify::load-status", G_CALLBACK (notify_load_status_cb), web_view); 1.129 - g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view); 1.130 - 1.131 - return scrolled_window; 1.132 -} 1.133 - 1.134 -static GtkWidget* 1.135 -create_toolbar () 1.136 -{ 1.137 - GtkWidget* toolbar = gtk_toolbar_new (); 1.138 - 1.139 - gtk_toolbar_set_orientation (GTK_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL); 1.140 - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); 1.141 - 1.142 - GtkToolItem* item; 1.143 - 1.144 - /* The Home button */ 1.145 - item = gtk_tool_button_new_from_stock (GTK_STOCK_HOME); 1.146 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_home), NULL); 1.147 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.148 - 1.149 - /* The TazPanel button */ 1.150 - item = gtk_tool_button_new_from_stock (GTK_STOCK_PREFERENCES); 1.151 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (slitaz_panel), NULL); 1.152 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.153 - 1.154 - /* The back button */ 1.155 - /* 1.156 - * item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK); 1.157 - * g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_back_cb), NULL); 1.158 - * gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.159 - */ 1.160 - 1.161 - /* The forward button */ 1.162 - /* 1.163 - * item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD); 1.164 - * g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_forward_cb), NULL); 1.165 - * gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.166 - */ 1.167 - 1.168 - /* The URL entry */ 1.169 - item = gtk_tool_item_new (); 1.170 - gtk_tool_item_set_expand (item, TRUE); 1.171 - uri_entry = gtk_entry_new (); 1.172 - gtk_container_add (GTK_CONTAINER (item), uri_entry); 1.173 - g_signal_connect (G_OBJECT (uri_entry), "activate", G_CALLBACK (activate_uri_entry_cb), NULL); 1.174 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.175 - 1.176 - /* The TazWeb doc button */ 1.177 - item = gtk_tool_button_new_from_stock (GTK_STOCK_INFO); 1.178 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (tazweb_doc), NULL); 1.179 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.180 - 1.181 - return toolbar; 1.182 -} 1.183 - 1.184 -/* Create an icon */ 1.185 -static GdkPixbuf* 1.186 -create_pixbuf (const gchar * image) 1.187 -{ 1.188 - GdkPixbuf *pixbuf; 1.189 - pixbuf = gdk_pixbuf_new_from_file (image, NULL); 1.190 - 1.191 - return pixbuf; 1.192 -} 1.193 - 1.194 -static GtkWidget* 1.195 -create_window () 1.196 -{ 1.197 - GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 1.198 - /* Default tazweb window size ratio to 3/4 --> 720, 540 */ 1.199 - gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); 1.200 - gtk_window_set_icon (GTK_WINDOW (window), 1.201 - create_pixbuf ("/usr/share/pixmaps/tazweb.png")); 1.202 - gtk_widget_set_name (window, "TazWeb"); 1.203 - g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL); 1.204 - 1.205 - return window; 1.206 -} 1.207 - 1.208 -int 1.209 -main (int argc, char* argv[]) 1.210 -{ 1.211 - gtk_init (&argc, &argv); 1.212 - if (!g_thread_supported ()) 1.213 - g_thread_init (NULL); 1.214 - 1.215 - GtkWidget* vbox = gtk_vbox_new (FALSE, 0); 1.216 - gtk_box_pack_start (GTK_BOX (vbox), create_toolbar (), FALSE, FALSE, 0); 1.217 - gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0); 1.218 - 1.219 - main_window = create_window (); 1.220 - gtk_container_add (GTK_CONTAINER (main_window), vbox); 1.221 - 1.222 - gchar* uri = (gchar*) (argc > 1 ? argv[1] : "file:///usr/share/webhome/index.html"); 1.223 - webkit_web_view_load_uri (web_view, uri); 1.224 - 1.225 - gtk_widget_grab_focus (GTK_WIDGET (web_view)); 1.226 - gtk_widget_show_all (main_window); 1.227 - gtk_main (); 1.228 - 1.229 - return 0; 1.230 -}