tazweb view src/main.c @ rev 8

main.c add tazweb window icon
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 04 16:53:14 2011 +0200 (2011-04-04)
parents 06a7b5b861f8
children 181b77ec9d9f
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 /* Create an icon */
73 static GdkPixbuf *create_pixbuf (const gchar * image)
74 {
75 GdkPixbuf *pixbuf;
76 pixbuf = gdk_pixbuf_new_from_file (image, NULL);
78 return pixbuf;
79 }
81 static GtkWidget*
82 create_window ()
83 {
84 GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
85 /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/
86 gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
87 gtk_window_set_icon (GTK_WINDOW(window),
88 create_pixbuf ("/usr/share/pixmaps/tazweb.png"));
89 gtk_widget_set_name (window, "TazWeb");
90 g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
92 return window;
93 }
95 int
96 main (int argc, char* argv[])
97 {
98 gtk_init (&argc, &argv);
99 if (!g_thread_supported ())
100 g_thread_init (NULL);
102 GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
103 gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
105 main_window = create_window ();
106 gtk_container_add (GTK_CONTAINER (main_window), vbox);
108 /* Home page url or file */
109 gchar* uri = (gchar*) (argc > 1 ? argv[1] : "file:///usr/share/webhome/index.html");
110 webkit_web_view_load_uri (web_view, uri);
112 gtk_widget_grab_focus (GTK_WIDGET (web_view));
113 gtk_widget_show_all (main_window);
114 gtk_main ();
116 return 0;
117 }