tazweb view main.c @ rev 4

Add a desktop file and tazweb icon
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 04 02:44:23 2011 +0200 (2011-04-04)
parents
children
line source
1 /*
2 * TazWeb is a radicaly simple web browser providing a single window
3 * with no toolbar, menu or tabs.
4 *
5 *
6 * Copyright (C) 2011 SliTaz GNU/Linux <devel@slitaz.org>
7 *
8 *
9 */
11 #include <gtk/gtk.h>
12 #include <webkit/webkit.h>
14 static GtkWidget* main_window;
15 static GtkWidget* uri_entry;
16 static WebKitWebView* web_view;
17 static gchar* main_title;
18 static gdouble load_progress;
19 static guint status_context_id;
21 /* Page title to window title */
22 static void
23 update_title (GtkWindow* window)
24 {
25 GString* string = g_string_new (main_title);
26 g_string_append (string, " - TazWeb");
27 if (load_progress < 100)
28 g_string_append_printf (string, " (%f%%)", load_progress);
29 gchar* title = g_string_free (string, FALSE);
30 gtk_window_set_title (window, title);
31 g_free (title);
32 }
34 static void
35 notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
36 {
37 if (main_title)
38 g_free (main_title);
39 main_title = g_strdup (webkit_web_view_get_title(web_view));
40 update_title (GTK_WINDOW (main_window));
41 }
43 /* Request progress in window title */
44 static void
45 notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
46 {
47 load_progress = webkit_web_view_get_progress (web_view) * 100;
48 update_title (GTK_WINDOW (main_window));
49 }
51 static void
52 destroy_cb (GtkWidget* widget, gpointer data)
53 {
54 gtk_main_quit ();
55 }
57 static GtkWidget*
58 create_browser ()
59 {
60 GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
61 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
63 web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
64 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
66 g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view);
67 g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
69 return scrolled_window;
70 }
72 static GtkWidget*
73 create_window ()
74 {
75 GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
76 /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/
77 gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
78 gtk_widget_set_name (window, "TazWeb");
79 g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
81 return window;
82 }
84 int
85 main (int argc, char* argv[])
86 {
87 gtk_init (&argc, &argv);
88 if (!g_thread_supported ())
89 g_thread_init (NULL);
91 GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
92 gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
94 main_window = create_window ();
95 gtk_container_add (GTK_CONTAINER (main_window), vbox);
97 /* Home page url or file */
98 gchar* uri = (gchar*) (argc > 1 ? argv[1] : "file:///usr/share/webhome/index.html");
99 webkit_web_view_load_uri (web_view, uri);
101 gtk_widget_grab_focus (GTK_WIDGET (web_view));
102 gtk_widget_show_all (main_window);
103 gtk_main ();
105 return 0;
106 }