tazweb rev 6

main.c goes in src/
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 04 02:53:50 2011 +0200 (2011-04-04)
parents e42c4fc09009
children 91b4ac7a72a9
files main.c src/main.c
line diff
     1.1 --- a/main.c	Mon Apr 04 02:48:16 2011 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,106 +0,0 @@
     1.4 -/*
     1.5 - * TazWeb is a radicaly simple web browser providing a single window
     1.6 - * with no toolbar, menu or tabs.
     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 -/* Page title to window title */
    1.25 -static void
    1.26 -update_title (GtkWindow* window)
    1.27 -{
    1.28 -    GString* string = g_string_new (main_title);
    1.29 -    g_string_append (string, " - TazWeb");
    1.30 -    if (load_progress < 100)
    1.31 -        g_string_append_printf (string, " (%f%%)", load_progress);
    1.32 -    gchar* title = g_string_free (string, FALSE);
    1.33 -    gtk_window_set_title (window, title);
    1.34 -    g_free (title);
    1.35 -}
    1.36 -
    1.37 -static void
    1.38 -notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
    1.39 -{
    1.40 -    if (main_title)
    1.41 -        g_free (main_title);
    1.42 -    main_title = g_strdup (webkit_web_view_get_title(web_view));
    1.43 -    update_title (GTK_WINDOW (main_window));
    1.44 -}
    1.45 -
    1.46 -/* Request progress in window title */
    1.47 -static void
    1.48 -notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
    1.49 -{
    1.50 -    load_progress = webkit_web_view_get_progress (web_view) * 100;
    1.51 -    update_title (GTK_WINDOW (main_window));
    1.52 -}
    1.53 -
    1.54 -static void
    1.55 -destroy_cb (GtkWidget* widget, gpointer data)
    1.56 -{
    1.57 -    gtk_main_quit ();
    1.58 -}
    1.59 -
    1.60 -static GtkWidget*
    1.61 -create_browser ()
    1.62 -{
    1.63 -    GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    1.64 -    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    1.65 -
    1.66 -    web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
    1.67 -    gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
    1.68 -
    1.69 -    g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view);
    1.70 -    g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
    1.71 -
    1.72 -    return scrolled_window;
    1.73 -}
    1.74 -
    1.75 -static GtkWidget*
    1.76 -create_window ()
    1.77 -{
    1.78 -    GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    1.79 -    /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/
    1.80 -    gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
    1.81 -    gtk_widget_set_name (window, "TazWeb");
    1.82 -    g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
    1.83 -
    1.84 -    return window;
    1.85 -}
    1.86 -
    1.87 -int
    1.88 -main (int argc, char* argv[])
    1.89 -{
    1.90 -    gtk_init (&argc, &argv);
    1.91 -    if (!g_thread_supported ())
    1.92 -        g_thread_init (NULL);
    1.93 -
    1.94 -    GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
    1.95 -    gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
    1.96 -
    1.97 -    main_window = create_window ();
    1.98 -    gtk_container_add (GTK_CONTAINER (main_window), vbox);
    1.99 -
   1.100 -	/* Home page url or file */
   1.101 -    gchar* uri = (gchar*) (argc > 1 ? argv[1] : "file:///usr/share/webhome/index.html");
   1.102 -    webkit_web_view_load_uri (web_view, uri);
   1.103 -
   1.104 -    gtk_widget_grab_focus (GTK_WIDGET (web_view));
   1.105 -    gtk_widget_show_all (main_window);
   1.106 -    gtk_main ();
   1.107 -
   1.108 -    return 0;
   1.109 -}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/main.c	Mon Apr 04 02:53:50 2011 +0200
     2.3 @@ -0,0 +1,106 @@
     2.4 +/*
     2.5 + * TazWeb is a radicaly simple web browser providing a single window
     2.6 + * with no toolbar, menu or tabs.
     2.7 + *
     2.8 + * 
     2.9 + * Copyright (C) 2011 SliTaz GNU/Linux <devel@slitaz.org>
    2.10 + * 
    2.11 + * 
    2.12 + */
    2.13 +
    2.14 +#include <gtk/gtk.h>
    2.15 +#include <webkit/webkit.h>
    2.16 +
    2.17 +static GtkWidget* main_window;
    2.18 +static GtkWidget* uri_entry;
    2.19 +static WebKitWebView* web_view;
    2.20 +static gchar* main_title;
    2.21 +static gdouble load_progress;
    2.22 +static guint status_context_id;
    2.23 +
    2.24 +/* Page title to window title */
    2.25 +static void
    2.26 +update_title (GtkWindow* window)
    2.27 +{
    2.28 +    GString* string = g_string_new (main_title);
    2.29 +    g_string_append (string, " - TazWeb");
    2.30 +    if (load_progress < 100)
    2.31 +        g_string_append_printf (string, " (%f%%)", load_progress);
    2.32 +    gchar* title = g_string_free (string, FALSE);
    2.33 +    gtk_window_set_title (window, title);
    2.34 +    g_free (title);
    2.35 +}
    2.36 +
    2.37 +static void
    2.38 +notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
    2.39 +{
    2.40 +    if (main_title)
    2.41 +        g_free (main_title);
    2.42 +    main_title = g_strdup (webkit_web_view_get_title(web_view));
    2.43 +    update_title (GTK_WINDOW (main_window));
    2.44 +}
    2.45 +
    2.46 +/* Request progress in window title */
    2.47 +static void
    2.48 +notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
    2.49 +{
    2.50 +    load_progress = webkit_web_view_get_progress (web_view) * 100;
    2.51 +    update_title (GTK_WINDOW (main_window));
    2.52 +}
    2.53 +
    2.54 +static void
    2.55 +destroy_cb (GtkWidget* widget, gpointer data)
    2.56 +{
    2.57 +    gtk_main_quit ();
    2.58 +}
    2.59 +
    2.60 +static GtkWidget*
    2.61 +create_browser ()
    2.62 +{
    2.63 +    GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    2.64 +    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    2.65 +
    2.66 +    web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
    2.67 +    gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
    2.68 +
    2.69 +    g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view);
    2.70 +    g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
    2.71 +
    2.72 +    return scrolled_window;
    2.73 +}
    2.74 +
    2.75 +static GtkWidget*
    2.76 +create_window ()
    2.77 +{
    2.78 +    GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    2.79 +    /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/
    2.80 +    gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
    2.81 +    gtk_widget_set_name (window, "TazWeb");
    2.82 +    g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
    2.83 +
    2.84 +    return window;
    2.85 +}
    2.86 +
    2.87 +int
    2.88 +main (int argc, char* argv[])
    2.89 +{
    2.90 +    gtk_init (&argc, &argv);
    2.91 +    if (!g_thread_supported ())
    2.92 +        g_thread_init (NULL);
    2.93 +
    2.94 +    GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
    2.95 +    gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
    2.96 +
    2.97 +    main_window = create_window ();
    2.98 +    gtk_container_add (GTK_CONTAINER (main_window), vbox);
    2.99 +
   2.100 +	/* Home page url or file */
   2.101 +    gchar* uri = (gchar*) (argc > 1 ? argv[1] : "file:///usr/share/webhome/index.html");
   2.102 +    webkit_web_view_load_uri (web_view, uri);
   2.103 +
   2.104 +    gtk_widget_grab_focus (GTK_WIDGET (web_view));
   2.105 +    gtk_widget_show_all (main_window);
   2.106 +    gtk_main ();
   2.107 +
   2.108 +    return 0;
   2.109 +}