tazweb rev 74
More consitency in code, dont use underscore in variables
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Apr 24 00:03:07 2011 +0200 (2011-04-24) |
parents | 43428bee91d4 |
children | 27fbc3a5a826 |
files | src/main.c |
line diff
1.1 --- a/src/main.c Sat Apr 23 23:37:34 2011 +0200 1.2 +++ b/src/main.c Sun Apr 24 00:03:07 2011 +0200 1.3 @@ -1,7 +1,8 @@ 1.4 /* 1.5 * TazWeb is a radically simple web browser providing a single window 1.6 * with a single toolbar with buttons, an URL entry and search as well 1.7 - * as a contextual menu, but no menu bar or tabs. 1.8 + * as a contextual menu, but no menu bar or tabs. Commented line code 1.9 + * starts with // and comments are between * * 1.10 * 1.11 * Copyright (C) 2011 SliTaz GNU/Linux - BSD License 1.12 * See AUTHORS and LICENSE for detailed information 1.13 @@ -14,16 +15,17 @@ 1.14 #define CONFIG g_strdup_printf ("%s/.config/tazweb", g_get_home_dir ()) 1.15 #define START "file:///usr/share/webhome/index.html" 1.16 1.17 -/* Loader color - #d66018 #7b705c */ 1.18 -static gchar *loader_color = "#351a0a"; 1.19 +/* Colors (Loader: #d66018 #7b705c) */ 1.20 +static gchar *loadfg = "#351a0a"; 1.21 +static gchar *toolbarbg = "#f1efeb"; 1.22 1.23 -static GtkWidget *main_window, *scrolled, *loader, *toolbar; 1.24 -static GtkWidget *uri_entry, *search_entry; 1.25 -static WebKitWebView* web_view; 1.26 +static gchar* pagetitle; 1.27 +static gchar* title; 1.28 +static GtkWidget *mainwindow, *scrolled, *loader, *toolbar; 1.29 +static GtkWidget *urientry, *search; 1.30 +static WebKitWebView* webview; 1.31 static WebKitWebFrame* frame; 1.32 static gint progress; 1.33 -static gchar* main_title; 1.34 -static gchar* title; 1.35 const gchar* uri; 1.36 1.37 /* Create an icon */ 1.38 @@ -54,7 +56,7 @@ 1.39 gc = gdk_gc_new (loader->window); 1.40 width = progress * loader->allocation.width / 100; 1.41 1.42 - gdk_color_parse (loader_color, &fg); 1.43 + gdk_color_parse (loadfg, &fg); 1.44 gdk_gc_set_rgb_fg_color (gc, &fg); 1.45 gdk_draw_rectangle (loader->window, 1.46 loader->style->bg_gc [GTK_WIDGET_STATE (loader)], 1.47 @@ -76,35 +78,35 @@ 1.48 static void 1.49 update () 1.50 { 1.51 - title = g_strdup (main_title); 1.52 - if (! main_title) 1.53 - title = g_strdup_printf ("Unknow - TazWeb", main_title); 1.54 + title = g_strdup (pagetitle); 1.55 + if (! pagetitle) 1.56 + title = g_strdup_printf ("Unknow - TazWeb", pagetitle); 1.57 draw_loader (); 1.58 - gtk_window_set_title (GTK_WINDOW (main_window), title); 1.59 + gtk_window_set_title (GTK_WINDOW (mainwindow), title); 1.60 g_free (title); 1.61 } 1.62 1.63 /* Get the page title */ 1.64 static void 1.65 -notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.66 +notify_title_cb (WebKitWebView* webview, GParamSpec* pspec, gpointer data) 1.67 { 1.68 - main_title = g_strdup (webkit_web_view_get_title (web_view)); 1.69 + pagetitle = g_strdup (webkit_web_view_get_title (webview)); 1.70 update (); 1.71 } 1.72 1.73 /* Request progress in window title */ 1.74 static void 1.75 -notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.76 +notify_progress_cb (WebKitWebView* webview, GParamSpec* pspec, gpointer data) 1.77 { 1.78 - progress = webkit_web_view_get_progress (web_view) * 100; 1.79 + progress = webkit_web_view_get_progress (webview) * 100; 1.80 update (); 1.81 } 1.82 1.83 /* Notify loader and url entry */ 1.84 static void 1.85 -notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.86 +notify_load_status_cb (WebKitWebView* webview, GParamSpec* pspec, gpointer data) 1.87 { 1.88 - switch (webkit_web_view_get_load_status (web_view)) 1.89 + switch (webkit_web_view_get_load_status (webview)) 1.90 { 1.91 case WEBKIT_LOAD_COMMITTED: 1.92 break; 1.93 @@ -113,10 +115,10 @@ 1.94 update (); 1.95 break; 1.96 } 1.97 - frame = webkit_web_view_get_main_frame (web_view); 1.98 + frame = webkit_web_view_get_main_frame (webview); 1.99 uri = webkit_web_frame_get_uri (frame); 1.100 if (uri) 1.101 - gtk_entry_set_text (GTK_ENTRY (uri_entry), uri); 1.102 + gtk_entry_set_text (GTK_ENTRY (urientry), uri); 1.103 } 1.104 1.105 static void 1.106 @@ -131,12 +133,12 @@ 1.107 { 1.108 gboolean source; 1.109 1.110 - frame = webkit_web_view_get_main_frame (web_view); 1.111 + frame = webkit_web_view_get_main_frame (webview); 1.112 uri = webkit_web_frame_get_uri (frame); 1.113 - source = webkit_web_view_get_view_source_mode (web_view); 1.114 + source = webkit_web_view_get_view_source_mode (webview); 1.115 1.116 - webkit_web_view_set_view_source_mode(web_view, !source); 1.117 - webkit_web_view_load_uri (web_view, uri); 1.118 + webkit_web_view_set_view_source_mode(webview, !source); 1.119 + webkit_web_view_load_uri (webview, uri); 1.120 } 1.121 1.122 /* URL entry callback function */ 1.123 @@ -146,7 +148,7 @@ 1.124 uri = gtk_entry_get_text (GTK_ENTRY (entry)); 1.125 g_assert (uri); 1.126 check_requested_uri (); 1.127 - webkit_web_view_load_uri (web_view, uri); 1.128 + webkit_web_view_load_uri (webview, uri); 1.129 } 1.130 1.131 /* Search entry callback function */ 1.132 @@ -156,7 +158,7 @@ 1.133 uri = g_strdup_printf ("http://www.google.com/search?q=%s", 1.134 gtk_entry_get_text (GTK_ENTRY (entry))); 1.135 g_assert (uri); 1.136 - webkit_web_view_load_uri (web_view, uri); 1.137 + webkit_web_view_load_uri (webview, uri); 1.138 } 1.139 1.140 /* Home button callback function */ 1.141 @@ -165,20 +167,20 @@ 1.142 { 1.143 uri = g_strdup_printf ("file://%s/home.html", CONFIG); 1.144 g_assert (uri); 1.145 - webkit_web_view_load_uri (web_view, uri); 1.146 + webkit_web_view_load_uri (webview, uri); 1.147 } 1.148 1.149 /* Navigation button function */ 1.150 static void 1.151 go_back_cb (GtkWidget* widget, gpointer data) 1.152 { 1.153 - webkit_web_view_go_back (web_view); 1.154 + webkit_web_view_go_back (webview); 1.155 } 1.156 1.157 static void 1.158 go_forward_cb (GtkWidget* widget, gpointer data) 1.159 { 1.160 - webkit_web_view_go_forward (web_view); 1.161 + webkit_web_view_go_forward (webview); 1.162 } 1.163 1.164 /* Fullscreen and unfullscreen callback function */ 1.165 @@ -186,12 +188,12 @@ 1.166 fullscreen_cb (GtkWindow* window, gpointer data) 1.167 { 1.168 GdkWindowState state; 1.169 - state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (main_window))); 1.170 + state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (mainwindow))); 1.171 1.172 if (state & GDK_WINDOW_STATE_FULLSCREEN) 1.173 - gtk_window_unfullscreen (GTK_WINDOW (main_window)); 1.174 + gtk_window_unfullscreen (GTK_WINDOW (mainwindow)); 1.175 else 1.176 - gtk_window_fullscreen (GTK_WINDOW (main_window)); 1.177 + gtk_window_fullscreen (GTK_WINDOW (mainwindow)); 1.178 } 1.179 1.180 /* TazWeb doc callback function */ 1.181 @@ -200,12 +202,12 @@ 1.182 { 1.183 uri = ("file:///usr/share/doc/tazweb/tazweb.html"); 1.184 g_assert (uri); 1.185 - webkit_web_view_load_uri (web_view, uri); 1.186 + webkit_web_view_load_uri (webview, uri); 1.187 } 1.188 1.189 /* Download function */ 1.190 static gboolean 1.191 -download_requested_cb (WebKitWebView *web_view, WebKitDownload *download, 1.192 +download_requested_cb (WebKitWebView *webview, WebKitDownload *download, 1.193 gpointer user_data) 1.194 { 1.195 uri = webkit_download_get_uri (download); 1.196 @@ -218,20 +220,20 @@ 1.197 1.198 /* Zoom out and in callback function */ 1.199 static void 1.200 -zoom_out_cb (GtkWidget *main_window) 1.201 +zoom_out_cb (GtkWidget *mainwindow) 1.202 { 1.203 - webkit_web_view_zoom_out (web_view); 1.204 + webkit_web_view_zoom_out (webview); 1.205 } 1.206 1.207 static void 1.208 -zoom_in_cb (GtkWidget *main_window) 1.209 +zoom_in_cb (GtkWidget *mainwindow) 1.210 { 1.211 - webkit_web_view_zoom_in (web_view); 1.212 + webkit_web_view_zoom_in (webview); 1.213 } 1.214 1.215 /* Add items to WebKit contextual menu */ 1.216 static void 1.217 -populate_menu_cb (WebKitWebView *web_view, GtkMenu *menu, gpointer data) 1.218 +populate_menu_cb (WebKitWebView *webview, GtkMenu *menu, gpointer data) 1.219 { 1.220 GtkWidget* item; 1.221 1.222 @@ -276,12 +278,12 @@ 1.223 1.224 /* Open in a new window from menu */ 1.225 static WebKitWebView* 1.226 -create_web_view_cb (WebKitWebView* web_view, GtkWidget* window) 1.227 +create_web_view_cb (WebKitWebView* webview, GtkWidget* window) 1.228 { 1.229 - return WEBKIT_WEB_VIEW (web_view); 1.230 + return WEBKIT_WEB_VIEW (webview); 1.231 } 1.232 1.233 -/* Scrolled window for the web_view */ 1.234 +/* Scrolled window for the webview */ 1.235 static GtkWidget* 1.236 create_browser () 1.237 { 1.238 @@ -289,24 +291,24 @@ 1.239 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), 1.240 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 1.241 1.242 - web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); 1.243 - gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (web_view)); 1.244 + webview = WEBKIT_WEB_VIEW (webkit_web_view_new ()); 1.245 + gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (webview)); 1.246 1.247 - /* Connect events */ 1.248 - g_signal_connect (web_view, "notify::title", 1.249 - G_CALLBACK (notify_title_cb), web_view); 1.250 - g_signal_connect (web_view, "notify::progress", 1.251 - G_CALLBACK (notify_progress_cb), web_view); 1.252 - g_signal_connect (web_view, "notify::load-status", 1.253 - G_CALLBACK (notify_load_status_cb), web_view); 1.254 - g_signal_connect (web_view, "download-requested", 1.255 + /* Connect WebKit events */ 1.256 + g_signal_connect (webview, "notify::title", 1.257 + G_CALLBACK (notify_title_cb), webview); 1.258 + g_signal_connect (webview, "notify::progress", 1.259 + G_CALLBACK (notify_progress_cb), webview); 1.260 + g_signal_connect (webview, "notify::load-status", 1.261 + G_CALLBACK (notify_load_status_cb), webview); 1.262 + g_signal_connect (webview, "download-requested", 1.263 G_CALLBACK (download_requested_cb), NULL); 1.264 - g_signal_connect (web_view, "create-web-view", 1.265 - G_CALLBACK (create_web_view_cb), web_view); 1.266 + g_signal_connect (webview, "create-web-view", 1.267 + G_CALLBACK (create_web_view_cb), webview); 1.268 1.269 /* Connect WebKit contextual menu items */ 1.270 - g_object_connect (G_OBJECT (web_view), "signal::populate-popup", 1.271 - G_CALLBACK (populate_menu_cb), web_view, NULL); 1.272 + g_object_connect (G_OBJECT (webview), "signal::populate-popup", 1.273 + G_CALLBACK (populate_menu_cb), webview, NULL); 1.274 1.275 return scrolled; 1.276 } 1.277 @@ -327,15 +329,15 @@ 1.278 create_toolbar () 1.279 { 1.280 GtkToolItem* item; 1.281 - 1.282 + GdkColor bg; 1.283 + 1.284 toolbar = gtk_toolbar_new (); 1.285 //gtk_widget_set_size_request (toolbar, 0, 24); 1.286 gtk_toolbar_set_orientation (GTK_TOOLBAR (toolbar), 1.287 GTK_ORIENTATION_HORIZONTAL); 1.288 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), 1.289 GTK_TOOLBAR_BOTH_HORIZ); 1.290 - GdkColor bg; 1.291 - gdk_color_parse ("#f1efeb", &bg); 1.292 + gdk_color_parse (toolbarbg, &bg); 1.293 gtk_widget_modify_bg (toolbar, GTK_STATE_NORMAL, &bg); 1.294 1.295 /* The back button */ 1.296 @@ -358,14 +360,14 @@ 1.297 item = gtk_tool_item_new (); 1.298 gtk_tool_item_set_expand (item, TRUE); 1.299 1.300 - uri_entry = gtk_entry_new (); 1.301 - gtk_widget_modify_base ( GTK_WIDGET (uri_entry), 1.302 + urientry = gtk_entry_new (); 1.303 + gtk_widget_modify_base ( GTK_WIDGET (urientry), 1.304 GTK_STATE_NORMAL, &bg); 1.305 - gtk_entry_set_inner_border (GTK_ENTRY (uri_entry), NULL); 1.306 - gtk_entry_set_has_frame (GTK_ENTRY (uri_entry), FALSE); 1.307 + gtk_entry_set_inner_border (GTK_ENTRY (urientry), NULL); 1.308 + gtk_entry_set_has_frame (GTK_ENTRY (urientry), FALSE); 1.309 1.310 - gtk_container_add (GTK_CONTAINER (item), uri_entry); 1.311 - g_signal_connect (G_OBJECT (uri_entry), "activate", 1.312 + gtk_container_add (GTK_CONTAINER (item), urientry); 1.313 + g_signal_connect (G_OBJECT (urientry), "activate", 1.314 G_CALLBACK (uri_entry_cb), NULL); 1.315 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.316 1.317 @@ -375,10 +377,10 @@ 1.318 1.319 /* Search entry */ 1.320 item = gtk_tool_item_new (); 1.321 - search_entry = gtk_entry_new (); 1.322 - gtk_widget_set_size_request (search_entry, 150, 20); 1.323 - gtk_container_add (GTK_CONTAINER (item), search_entry); 1.324 - g_signal_connect (G_OBJECT (search_entry), "activate", 1.325 + search = gtk_entry_new (); 1.326 + gtk_widget_set_size_request (search, 150, 20); 1.327 + gtk_container_add (GTK_CONTAINER (item), search); 1.328 + g_signal_connect (G_OBJECT (search), "activate", 1.329 G_CALLBACK (search_entry_cb), NULL); 1.330 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.331 1.332 @@ -432,10 +434,11 @@ 1.333 if (argv[1]) 1.334 check_requested_uri (); 1.335 1.336 - main_window = create_window (); 1.337 - gtk_widget_show_all (main_window); 1.338 - webkit_web_view_load_uri (web_view, uri); 1.339 - gtk_widget_grab_focus (GTK_WIDGET (web_view)); 1.340 + mainwindow = create_window (); 1.341 + gtk_widget_show_all (mainwindow); 1.342 + webkit_web_view_load_uri (webview, uri); 1.343 + gtk_widget_grab_focus (GTK_WIDGET (webview)); 1.344 gtk_main (); 1.345 + 1.346 return 0; 1.347 }