tazweb rev 51
Code clean-up (use tab to ident)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Apr 21 19:43:42 2011 +0200 (2011-04-21) |
parents | 22991c13b29b |
children | 6995fa0828c0 |
files | src/main.c |
line diff
1.1 --- a/src/main.c Thu Apr 21 17:33:27 2011 +0200 1.2 +++ b/src/main.c Thu Apr 21 19:43:42 2011 +0200 1.3 @@ -43,215 +43,219 @@ 1.4 static void 1.5 update_title (GtkWindow* window) 1.6 { 1.7 - GString* string = g_string_new (main_title); 1.8 - /* g_string_append (string, " - TazWeb"); */ 1.9 - if (load_progress < 100) 1.10 - g_string_append_printf (string, " (%f%%)", load_progress); 1.11 - gchar* title = g_string_free (string, FALSE); 1.12 - gtk_window_set_title (window, title); 1.13 - g_free (title); 1.14 + GString* string = g_string_new (main_title); 1.15 + /* g_string_append (string, " - TazWeb"); */ 1.16 + if (load_progress < 100) 1.17 + g_string_append_printf (string, " [ %f%% ] ", load_progress); 1.18 + gchar* title = g_string_free (string, FALSE); 1.19 + gtk_window_set_title (window, title); 1.20 + g_free (title); 1.21 } 1.22 1.23 static void 1.24 notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.25 { 1.26 - if (main_title) 1.27 - g_free (main_title); 1.28 - main_title = g_strdup (webkit_web_view_get_title(web_view)); 1.29 - update_title (GTK_WINDOW (main_window)); 1.30 + if (main_title) 1.31 + g_free (main_title); 1.32 + main_title = g_strdup (webkit_web_view_get_title(web_view)); 1.33 + update_title (GTK_WINDOW (main_window)); 1.34 } 1.35 1.36 /* Request progress in window title */ 1.37 static void 1.38 notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.39 { 1.40 - load_progress = webkit_web_view_get_progress (web_view) * 100; 1.41 - update_title (GTK_WINDOW (main_window)); 1.42 + load_progress = webkit_web_view_get_progress (web_view) * 100; 1.43 + update_title (GTK_WINDOW (main_window)); 1.44 } 1.45 1.46 static void 1.47 notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 1.48 { 1.49 - if (webkit_web_view_get_load_status (web_view) == WEBKIT_LOAD_COMMITTED) { 1.50 - WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view); 1.51 - const gchar* uri = webkit_web_frame_get_uri (frame); 1.52 - if (uri) 1.53 - gtk_entry_set_text (GTK_ENTRY (uri_entry), uri); 1.54 - } 1.55 + if (webkit_web_view_get_load_status (web_view) == WEBKIT_LOAD_COMMITTED) { 1.56 + WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view); 1.57 + const gchar* uri = webkit_web_frame_get_uri (frame); 1.58 + if (uri) 1.59 + gtk_entry_set_text (GTK_ENTRY (uri_entry), uri); 1.60 + } 1.61 } 1.62 1.63 /* URL entry callback function */ 1.64 static void 1.65 activate_uri_entry_cb (GtkWidget* entry, gpointer data) 1.66 { 1.67 - const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry)); 1.68 - g_assert (uri); 1.69 - webkit_web_view_load_uri (web_view, uri); 1.70 + const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry)); 1.71 + g_assert (uri); 1.72 + webkit_web_view_load_uri (web_view, uri); 1.73 } 1.74 1.75 static void 1.76 destroy_cb (GtkWidget* widget, gpointer data) 1.77 { 1.78 - gtk_main_quit (); 1.79 + gtk_main_quit (); 1.80 } 1.81 1.82 /* Home button function */ 1.83 static void 1.84 go_home_cb (GtkWidget* widget, gpointer data) 1.85 { 1.86 - const gchar* uri = ("file:///usr/share/webhome/index.html"); 1.87 - g_assert (uri); 1.88 - webkit_web_view_load_uri (web_view, uri); 1.89 + const gchar* uri = ("file:///usr/share/webhome/index.html"); 1.90 + g_assert (uri); 1.91 + webkit_web_view_load_uri (web_view, uri); 1.92 } 1.93 1.94 /* My page button function */ 1.95 static void 1.96 my_page_cb (GtkWidget* widget, gpointer data) 1.97 { 1.98 - const gchar* uri = g_strdup_printf ("file://%s/.config/tazweb/page.html", 1.99 - g_get_home_dir ()); 1.100 - g_assert (uri); 1.101 - webkit_web_view_load_uri (web_view, uri); 1.102 + const gchar* uri = g_strdup_printf ("file://%s/.config/tazweb/page.html", 1.103 + g_get_home_dir ()); 1.104 + g_assert (uri); 1.105 + webkit_web_view_load_uri (web_view, uri); 1.106 } 1.107 1.108 /* Fullscreen and unfullscreen function */ 1.109 static void 1.110 fullscreen_cb (GtkWindow* window, gpointer data) 1.111 { 1.112 - GdkWindowState state; 1.113 - state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (main_window))); 1.114 + GdkWindowState state; 1.115 + state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (main_window))); 1.116 1.117 - if (state & GDK_WINDOW_STATE_FULLSCREEN) 1.118 - gtk_window_unfullscreen (GTK_WINDOW (main_window)); 1.119 - else 1.120 - gtk_window_fullscreen (GTK_WINDOW (main_window)); 1.121 + if (state & GDK_WINDOW_STATE_FULLSCREEN) 1.122 + gtk_window_unfullscreen (GTK_WINDOW (main_window)); 1.123 + else 1.124 + gtk_window_fullscreen (GTK_WINDOW (main_window)); 1.125 } 1.126 1.127 /* TazWeb doc function */ 1.128 static void 1.129 tazweb_doc_cb (GtkWidget* widget, gpointer data) 1.130 { 1.131 - const gchar* uri = ("file:///usr/share/doc/tazweb/tazweb.html"); 1.132 - g_assert (uri); 1.133 - webkit_web_view_load_uri (web_view, uri); 1.134 + const gchar* uri = ("file:///usr/share/doc/tazweb/tazweb.html"); 1.135 + g_assert (uri); 1.136 + webkit_web_view_load_uri (web_view, uri); 1.137 } 1.138 1.139 /* Download function */ 1.140 static gboolean 1.141 download_requested_cb (WebKitWebView *web_view, WebKitDownload *download, 1.142 - gpointer user_data) 1.143 + gpointer user_data) 1.144 { 1.145 - const gchar* uri = webkit_download_get_uri (download); 1.146 - gchar *buffer; 1.147 - asprintf (&buffer, "tazbox dl-out %s", uri); 1.148 - system (buffer); 1.149 + const gchar* uri = webkit_download_get_uri (download); 1.150 + gchar *buffer; 1.151 + asprintf (&buffer, "tazbox dl-out %s", uri); 1.152 + system (buffer); 1.153 } 1.154 1.155 static GtkWidget* 1.156 create_browser () 1.157 { 1.158 - GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); 1.159 - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), 1.160 - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 1.161 + GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); 1.162 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), 1.163 + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 1.164 1.165 - web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); 1.166 - gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view)); 1.167 + web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); 1.168 + gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view)); 1.169 1.170 - g_signal_connect (web_view, "notify::title", 1.171 - G_CALLBACK (notify_title_cb), web_view); 1.172 - g_signal_connect (web_view, "notify::progress", 1.173 - G_CALLBACK (notify_progress_cb), web_view); 1.174 - g_signal_connect (web_view, "notify::load-status", 1.175 - G_CALLBACK (notify_load_status_cb), web_view); 1.176 - g_signal_connect (web_view, "download-requested", 1.177 - G_CALLBACK (download_requested_cb), NULL); 1.178 + g_signal_connect (web_view, "notify::title", 1.179 + G_CALLBACK (notify_title_cb), web_view); 1.180 + g_signal_connect (web_view, "notify::progress", 1.181 + G_CALLBACK (notify_progress_cb), web_view); 1.182 + g_signal_connect (web_view, "notify::load-status", 1.183 + G_CALLBACK (notify_load_status_cb), web_view); 1.184 + g_signal_connect (web_view, "download-requested", 1.185 + G_CALLBACK (download_requested_cb), NULL); 1.186 1.187 - return scrolled_window; 1.188 + return scrolled_window; 1.189 } 1.190 1.191 - 1.192 - 1.193 static GtkWidget* 1.194 create_toolbar () 1.195 { 1.196 - GtkToolItem* item; 1.197 - 1.198 - GtkWidget* toolbar = gtk_toolbar_new (); 1.199 - gtk_widget_set_size_request (toolbar, 0, 31); 1.200 - gtk_toolbar_set_orientation (GTK_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL); 1.201 - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); 1.202 + GtkToolItem* item; 1.203 1.204 - /* The Home button */ 1.205 - item = gtk_tool_button_new_from_stock (GTK_STOCK_HOME); 1.206 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_home_cb), NULL); 1.207 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.208 + GtkWidget* toolbar = gtk_toolbar_new (); 1.209 + gtk_widget_set_size_request (toolbar, 0, 31); 1.210 + gtk_toolbar_set_orientation (GTK_TOOLBAR (toolbar), 1.211 + GTK_ORIENTATION_HORIZONTAL); 1.212 + gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), 1.213 + GTK_TOOLBAR_BOTH_HORIZ); 1.214 1.215 - /* The personal page button */ 1.216 - item = gtk_tool_button_new_from_stock (GTK_STOCK_PREFERENCES); 1.217 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (my_page_cb), NULL); 1.218 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.219 - 1.220 - /* The URL entry */ 1.221 - item = gtk_tool_item_new (); 1.222 - gtk_tool_item_set_expand (item, TRUE); 1.223 - uri_entry = gtk_entry_new (); 1.224 - gtk_container_add (GTK_CONTAINER (item), uri_entry); 1.225 - g_signal_connect (G_OBJECT (uri_entry), "activate", 1.226 - G_CALLBACK (activate_uri_entry_cb), NULL); 1.227 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.228 + /* The Home button */ 1.229 + item = gtk_tool_button_new_from_stock (GTK_STOCK_HOME); 1.230 + g_signal_connect (G_OBJECT (item), "clicked", 1.231 + G_CALLBACK (go_home_cb), NULL); 1.232 + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.233 1.234 - /* The TazWeb doc button */ 1.235 - item = gtk_tool_button_new_from_stock (GTK_STOCK_INFO); 1.236 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (tazweb_doc_cb), NULL); 1.237 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.238 + /* The personal page button */ 1.239 + item = gtk_tool_button_new_from_stock (GTK_STOCK_PREFERENCES); 1.240 + g_signal_connect (G_OBJECT (item), "clicked", 1.241 + G_CALLBACK (my_page_cb), NULL); 1.242 + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.243 1.244 - /* The Fullscreen button */ 1.245 - item = gtk_tool_button_new_from_stock (GTK_STOCK_FULLSCREEN); 1.246 - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (fullscreen_cb), NULL); 1.247 - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.248 + /* The URL entry */ 1.249 + item = gtk_tool_item_new (); 1.250 + gtk_tool_item_set_expand (item, TRUE); 1.251 + uri_entry = gtk_entry_new (); 1.252 + gtk_container_add (GTK_CONTAINER (item), uri_entry); 1.253 + g_signal_connect (G_OBJECT (uri_entry), "activate", 1.254 + G_CALLBACK (activate_uri_entry_cb), NULL); 1.255 + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.256 1.257 - return toolbar; 1.258 + /* The TazWeb doc button */ 1.259 + item = gtk_tool_button_new_from_stock (GTK_STOCK_INFO); 1.260 + g_signal_connect (G_OBJECT (item), "clicked", 1.261 + G_CALLBACK (tazweb_doc_cb), NULL); 1.262 + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.263 + 1.264 + /* The Fullscreen button */ 1.265 + item = gtk_tool_button_new_from_stock (GTK_STOCK_FULLSCREEN); 1.266 + g_signal_connect (G_OBJECT (item), "clicked", 1.267 + G_CALLBACK (fullscreen_cb), NULL); 1.268 + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); 1.269 + 1.270 + return toolbar; 1.271 } 1.272 1.273 static GtkWidget* 1.274 create_window () 1.275 { 1.276 - GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 1.277 + GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 1.278 1.279 - /* Default tazweb window size ratio to 3/4 --> 720, 540*/ 1.280 - gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); 1.281 - gtk_window_set_icon (GTK_WINDOW (window), 1.282 - create_pixbuf ("/usr/share/pixmaps/tazweb.png")); 1.283 - gtk_widget_set_name (window, "TazWeb"); 1.284 - g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL); 1.285 + /* Default tazweb window size ratio to 3/4 --> 720, 540*/ 1.286 + gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); 1.287 + gtk_window_set_icon (GTK_WINDOW (window), 1.288 + create_pixbuf ("/usr/share/pixmaps/tazweb.png")); 1.289 + gtk_widget_set_name (window, "TazWeb"); 1.290 + g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL); 1.291 1.292 - return window; 1.293 + return window; 1.294 } 1.295 1.296 int 1.297 main (int argc, char* argv[]) 1.298 { 1.299 - gtk_init (&argc, &argv); 1.300 - if (!g_thread_supported ()) 1.301 - g_thread_init (NULL); 1.302 + gtk_init (&argc, &argv); 1.303 + if (!g_thread_supported ()) 1.304 + g_thread_init (NULL); 1.305 1.306 - get_config (); 1.307 + get_config (); 1.308 1.309 - GtkWidget* vbox = gtk_vbox_new (FALSE, 0); 1.310 - gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0); 1.311 - gtk_box_pack_start (GTK_BOX (vbox), create_toolbar (), FALSE, FALSE, 0); 1.312 + GtkWidget* vbox = gtk_vbox_new (FALSE, 0); 1.313 + gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0); 1.314 + gtk_box_pack_start (GTK_BOX (vbox), create_toolbar (), FALSE, FALSE, 0); 1.315 1.316 - main_window = create_window (); 1.317 - gtk_container_add (GTK_CONTAINER (main_window), vbox); 1.318 + main_window = create_window (); 1.319 + gtk_container_add (GTK_CONTAINER (main_window), vbox); 1.320 1.321 - /* Home page url or file */ 1.322 - gchar* uri = (gchar*) (argc > 1 ? argv[1] : 1.323 - "file:///usr/share/webhome/index.html"); 1.324 - webkit_web_view_load_uri (web_view, uri); 1.325 + /* Home page url or file */ 1.326 + gchar* uri = (gchar*) (argc > 1 ? argv[1] : 1.327 + "file:///usr/share/webhome/index.html"); 1.328 + webkit_web_view_load_uri (web_view, uri); 1.329 1.330 - gtk_widget_grab_focus (GTK_WIDGET (web_view)); 1.331 - gtk_widget_show_all (main_window); 1.332 - gtk_main (); 1.333 + gtk_widget_grab_focus (GTK_WIDGET (web_view)); 1.334 + gtk_widget_show_all (main_window); 1.335 + gtk_main (); 1.336 1.337 - return 0; 1.338 + return 0; 1.339 }