tazweb 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 5b1f0e7d09a8
children 020cf8b6e14e
files README src/main.c
line diff
     1.1 --- a/README	Mon Apr 18 15:27:20 2011 +0200
     1.2 +++ b/README	Tue Apr 19 00:42:04 2011 +0200
     1.3 @@ -36,4 +36,15 @@
     1.4  Install with 'make install' (PREFIX and DESTDIR are supported for packaging)
     1.5  
     1.6  
     1.7 +Coding notes
     1.8 +------------
     1.9 +
    1.10 +    * To get the filename of a WebKitDownload
    1.11 +      const gchar* file = webkit_download_get_suggested_filename (download);
    1.12 +      
    1.13 +    * Check mime-type before download (needs a callback function)
    1.14 +      g_signal_connect (web_view, "mime-type-policy-decision-requested",
    1.15 +                        G_CALLBACK (mime_type_decision_cb), web_view);
    1.16 +
    1.17 +
    1.18  ================================================================================
     2.1 --- a/src/main.c	Mon Apr 18 15:27:20 2011 +0200
     2.2 +++ b/src/main.c	Tue Apr 19 00:42:04 2011 +0200
     2.3 @@ -2,10 +2,10 @@
     2.4   * TazWeb is a radically simple web browser providing a single window
     2.5   * with a single toolbar with buttons and an URL entry, but no menu or
     2.6   * 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   */
    2.15  
    2.16  #include <gtk/gtk.h>
    2.17 @@ -34,9 +34,9 @@
    2.18  static void
    2.19  activate_uri_entry_cb (GtkWidget* entry, gpointer data)
    2.20  {
    2.21 -	const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
    2.22 -	g_assert (uri);
    2.23 -	webkit_web_view_load_uri (web_view, uri);
    2.24 +    const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
    2.25 +    g_assert (uri);
    2.26 +    webkit_web_view_load_uri (web_view, uri);
    2.27  }
    2.28  
    2.29  static void
    2.30 @@ -77,7 +77,7 @@
    2.31  static void
    2.32  go_home_cb (GtkWidget* widget, gpointer data)
    2.33  {
    2.34 -	const gchar* uri = ("file:///usr/share/webhome/index.html");	
    2.35 +    const gchar* uri = ("file:///usr/share/webhome/index.html");
    2.36      g_assert (uri);
    2.37      webkit_web_view_load_uri (web_view, uri);
    2.38  }
    2.39 @@ -112,7 +112,7 @@
    2.40  }
    2.41  
    2.42  /* Fullscreen and unfullscreen action */
    2.43 -static void 
    2.44 +static void
    2.45  fullscreen_cb (GtkWindow* window, gpointer data)
    2.46  {
    2.47      GdkWindowState state;
    2.48 @@ -133,18 +133,35 @@
    2.49      webkit_web_view_load_uri (web_view, uri);
    2.50  }
    2.51  
    2.52 +/* Download function */
    2.53 +static gboolean
    2.54 +download_requested_cb (WebKitWebView *web_view, WebKitDownload *download,
    2.55 +                       gpointer user_data)
    2.56 +{
    2.57 +    const gchar* uri = webkit_download_get_uri (download);
    2.58 +    gchar *buffer;
    2.59 +    asprintf (&buffer, "xterm -e \"wget -P $HOME/Downloads %s\"", uri);
    2.60 +    system (buffer);
    2.61 +}
    2.62 +
    2.63  static GtkWidget*
    2.64  create_browser ()
    2.65  {
    2.66      GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    2.67 -    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    2.68 +    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
    2.69 +                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    2.70  
    2.71      web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
    2.72      gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
    2.73  
    2.74 -    g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view);
    2.75 -    g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
    2.76 -    g_signal_connect (web_view, "notify::load-status", G_CALLBACK (notify_load_status_cb), web_view);
    2.77 +    g_signal_connect (web_view, "notify::title",
    2.78 +                      G_CALLBACK (notify_title_cb), web_view);
    2.79 +    g_signal_connect (web_view, "notify::progress",
    2.80 +                      G_CALLBACK (notify_progress_cb), web_view);
    2.81 +    g_signal_connect (web_view, "notify::load-status",
    2.82 +                      G_CALLBACK (notify_load_status_cb), web_view);
    2.83 +    g_signal_connect (web_view, "download-requested",
    2.84 +                      G_CALLBACK (download_requested_cb), NULL);
    2.85  
    2.86      return scrolled_window;
    2.87  }
    2.88 @@ -183,16 +200,16 @@
    2.89      g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (refresh_cb), NULL);
    2.90      gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
    2.91  
    2.92 -	/* The URL entry */
    2.93 -	item = gtk_tool_item_new ();
    2.94 -	gtk_tool_item_set_expand (item, TRUE);
    2.95 -	uri_entry = gtk_entry_new ();
    2.96 -	gtk_container_add (GTK_CONTAINER (item), uri_entry);
    2.97 -	g_signal_connect (G_OBJECT (uri_entry), "activate",
    2.98 -		              G_CALLBACK (activate_uri_entry_cb), NULL);
    2.99 -	gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   2.100 +    /* The URL entry */
   2.101 +    item = gtk_tool_item_new ();
   2.102 +    gtk_tool_item_set_expand (item, TRUE);
   2.103 +    uri_entry = gtk_entry_new ();
   2.104 +    gtk_container_add (GTK_CONTAINER (item), uri_entry);
   2.105 +    g_signal_connect (G_OBJECT (uri_entry), "activate",
   2.106 +                      G_CALLBACK (activate_uri_entry_cb), NULL);
   2.107 +    gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   2.108  
   2.109 -	/* The Home button */
   2.110 +    /* The Home button */
   2.111      item = gtk_tool_button_new_from_stock (GTK_STOCK_HOME);
   2.112      g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_home_cb), NULL);
   2.113      gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   2.114 @@ -219,10 +236,11 @@
   2.115  create_window ()
   2.116  {
   2.117      GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   2.118 +
   2.119      /* Default tazweb window size ratio to 3/4 ?? --> 720, 540*/
   2.120      gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
   2.121      gtk_window_set_icon (GTK_WINDOW (window),
   2.122 -		                 create_pixbuf ("/usr/share/pixmaps/tazweb.png"));
   2.123 +                         create_pixbuf ("/usr/share/pixmaps/tazweb.png"));
   2.124      gtk_widget_set_name (window, "TazWeb");
   2.125      g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
   2.126  
   2.127 @@ -236,12 +254,12 @@
   2.128      if (!g_thread_supported ())
   2.129          g_thread_init (NULL);
   2.130  
   2.131 -    /* Get a default bookmark.html if missing */
   2.132 -	const gchar* config = g_strdup_printf ("%s/.config/tazweb", g_get_home_dir ());
   2.133 +    /* Get a default page.html if missing */
   2.134 +    const gchar* config = g_strdup_printf ("%s/.config/tazweb", g_get_home_dir ());
   2.135      if (!g_file_test(config, G_FILE_TEST_EXISTS)) {
   2.136 -	    g_mkdir(config, 0700);
   2.137 -        system("cp /usr/share/tazweb/*.html $HOME/.config/tazweb");
   2.138 -        system("cp /usr/share/tazweb/*.css $HOME/.config/tazweb");
   2.139 +        g_mkdir (config, 0700);
   2.140 +        system ("cp /usr/share/tazweb/*.html $HOME/.config/tazweb");
   2.141 +        system ("cp /usr/share/tazweb/*.css $HOME/.config/tazweb");
   2.142      }
   2.143  
   2.144      GtkWidget* vbox = gtk_vbox_new (FALSE, 2);
   2.145 @@ -251,9 +269,9 @@
   2.146      main_window = create_window ();
   2.147      gtk_container_add (GTK_CONTAINER (main_window), vbox);
   2.148  
   2.149 -	/* Home page url or file */
   2.150 +    /* Home page url or file */
   2.151      gchar* uri = (gchar*) (argc > 1 ? argv[1] :
   2.152 -		                   "file:///usr/share/webhome/index.html");
   2.153 +                           "file:///usr/share/webhome/index.html");
   2.154      webkit_web_view_load_uri (web_view, uri);
   2.155  
   2.156      gtk_widget_grab_focus (GTK_WIDGET (web_view));