tazweb diff src/main.c @ rev 44

Handle download-requested and finally use xterm/wget for now
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 19 00:42:04 2011 +0200 (2011-04-19)
parents 435fdb863811
children 020cf8b6e14e
line diff
     1.1 --- a/src/main.c	Fri Apr 15 20:57:18 2011 +0100
     1.2 +++ b/src/main.c	Tue Apr 19 00:42:04 2011 +0200
     1.3 @@ -2,10 +2,10 @@
     1.4   * TazWeb is a radically simple web browser providing a single window
     1.5   * with a single toolbar with buttons and an URL entry, but no menu or
     1.6   * 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   */
    1.15  
    1.16  #include <gtk/gtk.h>
    1.17 @@ -34,9 +34,9 @@
    1.18  static void
    1.19  activate_uri_entry_cb (GtkWidget* entry, gpointer data)
    1.20  {
    1.21 -	const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
    1.22 -	g_assert (uri);
    1.23 -	webkit_web_view_load_uri (web_view, uri);
    1.24 +    const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
    1.25 +    g_assert (uri);
    1.26 +    webkit_web_view_load_uri (web_view, uri);
    1.27  }
    1.28  
    1.29  static void
    1.30 @@ -77,7 +77,7 @@
    1.31  static void
    1.32  go_home_cb (GtkWidget* widget, gpointer data)
    1.33  {
    1.34 -	const gchar* uri = ("file:///usr/share/webhome/index.html");	
    1.35 +    const gchar* uri = ("file:///usr/share/webhome/index.html");
    1.36      g_assert (uri);
    1.37      webkit_web_view_load_uri (web_view, uri);
    1.38  }
    1.39 @@ -112,7 +112,7 @@
    1.40  }
    1.41  
    1.42  /* Fullscreen and unfullscreen action */
    1.43 -static void 
    1.44 +static void
    1.45  fullscreen_cb (GtkWindow* window, gpointer data)
    1.46  {
    1.47      GdkWindowState state;
    1.48 @@ -133,18 +133,35 @@
    1.49      webkit_web_view_load_uri (web_view, uri);
    1.50  }
    1.51  
    1.52 +/* Download function */
    1.53 +static gboolean
    1.54 +download_requested_cb (WebKitWebView *web_view, WebKitDownload *download,
    1.55 +                       gpointer user_data)
    1.56 +{
    1.57 +    const gchar* uri = webkit_download_get_uri (download);
    1.58 +    gchar *buffer;
    1.59 +    asprintf (&buffer, "xterm -e \"wget -P $HOME/Downloads %s\"", uri);
    1.60 +    system (buffer);
    1.61 +}
    1.62 +
    1.63  static GtkWidget*
    1.64  create_browser ()
    1.65  {
    1.66      GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    1.67 -    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    1.68 +    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
    1.69 +                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    1.70  
    1.71      web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
    1.72      gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
    1.73  
    1.74 -    g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view);
    1.75 -    g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
    1.76 -    g_signal_connect (web_view, "notify::load-status", G_CALLBACK (notify_load_status_cb), web_view);
    1.77 +    g_signal_connect (web_view, "notify::title",
    1.78 +                      G_CALLBACK (notify_title_cb), web_view);
    1.79 +    g_signal_connect (web_view, "notify::progress",
    1.80 +                      G_CALLBACK (notify_progress_cb), web_view);
    1.81 +    g_signal_connect (web_view, "notify::load-status",
    1.82 +                      G_CALLBACK (notify_load_status_cb), web_view);
    1.83 +    g_signal_connect (web_view, "download-requested",
    1.84 +                      G_CALLBACK (download_requested_cb), NULL);
    1.85  
    1.86      return scrolled_window;
    1.87  }
    1.88 @@ -183,16 +200,16 @@
    1.89      g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (refresh_cb), NULL);
    1.90      gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
    1.91  
    1.92 -	/* The URL entry */
    1.93 -	item = gtk_tool_item_new ();
    1.94 -	gtk_tool_item_set_expand (item, TRUE);
    1.95 -	uri_entry = gtk_entry_new ();
    1.96 -	gtk_container_add (GTK_CONTAINER (item), uri_entry);
    1.97 -	g_signal_connect (G_OBJECT (uri_entry), "activate",
    1.98 -		              G_CALLBACK (activate_uri_entry_cb), NULL);
    1.99 -	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   1.100 +    /* The URL entry */
   1.101 +    item = gtk_tool_item_new ();
   1.102 +    gtk_tool_item_set_expand (item, TRUE);
   1.103 +    uri_entry = gtk_entry_new ();
   1.104 +    gtk_container_add (GTK_CONTAINER (item), uri_entry);
   1.105 +    g_signal_connect (G_OBJECT (uri_entry), "activate",
   1.106 +                      G_CALLBACK (activate_uri_entry_cb), NULL);
   1.107 +    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   1.108  
   1.109 -	/* The Home button */
   1.110 +    /* The Home button */
   1.111      item = gtk_tool_button_new_from_stock (GTK_STOCK_HOME);
   1.112      g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_home_cb), NULL);
   1.113      gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   1.114 @@ -219,10 +236,11 @@
   1.115  create_window ()
   1.116  {
   1.117      GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   1.118 +
   1.119      /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/
   1.120      gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
   1.121      gtk_window_set_icon (GTK_WINDOW (window),
   1.122 -		                 create_pixbuf ("/usr/share/pixmaps/tazweb.png"));
   1.123 +                         create_pixbuf ("/usr/share/pixmaps/tazweb.png"));
   1.124      gtk_widget_set_name (window, "TazWeb");
   1.125      g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
   1.126  
   1.127 @@ -236,12 +254,12 @@
   1.128      if (!g_thread_supported ())
   1.129          g_thread_init (NULL);
   1.130  
   1.131 -    /* Get a default bookmark.html if missing */
   1.132 -	const gchar* config = g_strdup_printf ("%s/.config/tazweb", g_get_home_dir ());
   1.133 +    /* Get a default page.html if missing */
   1.134 +    const gchar* config = g_strdup_printf ("%s/.config/tazweb", g_get_home_dir ());
   1.135      if (!g_file_test(config, G_FILE_TEST_EXISTS)) {
   1.136 -	    g_mkdir(config, 0700);
   1.137 -        system("cp /usr/share/tazweb/*.html $HOME/.config/tazweb");
   1.138 -        system("cp /usr/share/tazweb/*.css $HOME/.config/tazweb");
   1.139 +        g_mkdir (config, 0700);
   1.140 +        system ("cp /usr/share/tazweb/*.html $HOME/.config/tazweb");
   1.141 +        system ("cp /usr/share/tazweb/*.css $HOME/.config/tazweb");
   1.142      }
   1.143  
   1.144      GtkWidget* vbox = gtk_vbox_new (FALSE, 2);
   1.145 @@ -251,9 +269,9 @@
   1.146      main_window = create_window ();
   1.147      gtk_container_add (GTK_CONTAINER (main_window), vbox);
   1.148  
   1.149 -	/* Home page url or file */
   1.150 +    /* Home page url or file */
   1.151      gchar* uri = (gchar*) (argc > 1 ? argv[1] :
   1.152 -		                   "file:///usr/share/webhome/index.html");
   1.153 +                           "file:///usr/share/webhome/index.html");
   1.154      webkit_web_view_load_uri (web_view, uri);
   1.155  
   1.156      gtk_widget_grab_focus (GTK_WIDGET (web_view));