download.h File Reference

#include "main.h"
Include dependency graph for download.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

G_BEGIN_DECLS gboolean download_requested_cb (WebKitWebView *web_view, WebKitDownload *download, BrowserWindow *browser_window)

Function Documentation

G_BEGIN_DECLS gboolean download_requested_cb ( WebKitWebView *  web_view,
WebKitDownload *  download,
BrowserWindow browser_window 
)

File Name : download.h

Description: File download Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 120 of file download.c.

References add_folder_to_metadata(), box_spacing, _DowloadDialog::browser_window, _DowloadDialog::button, _DowloadDialog::download, download_button_cancel_cb(), download_destroy_cb(), download_error_cb(), download_folder, download_response_cb(), download_status_changed_cb(), ERRORPRINTF, filename, g_mountpoint, g_update_progress, ipc_sys_bg_busy(), is_local_file(), LOGPRINTF, make_unique_filename(), _DowloadDialog::progress_bar, progress_interval, update_progress_cb(), _DowloadDialog::uri_label, uri_label_width, view_show_error(), widget, and _DowloadDialog::window.

Referenced by create_web_view().

00123 {
00124     LOGPRINTF("entry window [%p]", browser_window);
00125     
00126     DownloadDialog *dialog = NULL;
00127 
00128     if (is_local_file(webkit_download_get_uri(download))) 
00129     {
00130         LOGPRINTF("You could open the file [%s] without transferring it", webkit_download_get_uri(download));
00131         
00132         gchar *title;
00133         title = g_strdup_printf(_("Unable to open %s"), webkit_download_get_uri(download));
00134         view_show_error(title, _("The web browser is unable to display the document. "
00135                                  "Since it is on the SD card, you can open it from Documents."));
00136         g_free(title);
00137         return FALSE;
00138     }
00139     
00140     if (!g_mountpoint)
00141     {
00142         ERRORPRINTF("No mountpoint, cannot download");
00143         
00144         // Webkit will continue loading which ends in an error
00145         // so stop here. This may be an error in Webkit. 
00146         webkit_web_view_stop_loading(web_view);
00147 
00148         GtkWidget *widget;    
00149         widget = gtk_message_dialog_new(GTK_WINDOW(browser_window->window),
00150                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00151                                     GTK_MESSAGE_WARNING,
00152                                     GTK_BUTTONS_OK,
00153                                     _("The download cannot be started because there is no SD card in this device. "
00154                                       "Please insert a card and try again."));
00155     
00156         gtk_dialog_run(GTK_DIALOG(widget));
00157         gtk_widget_destroy(widget);
00158             
00159         return FALSE;
00160     }
00161     
00162 
00163     // check uri
00164     gchar *extension = g_strrstr(webkit_download_get_suggested_filename(download),".");
00165     if (extension && (strncmp(extension, ".acsm", 5) == 0))
00166     {
00167         LOGPRINTF("found .acsm file, download and open with Adobe Fullfilment");
00168         browser_window->open_download = TRUE;
00169     }
00170         
00171     // create path for download
00172     gchar *download_path;
00173 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00174     if (browser_window->open_download)
00175     {
00176         LOGPRINTF("open_download, set temp path");
00177         download_path = g_strdup(g_get_tmp_dir());
00178     }
00179     else
00180 #endif        
00181     {
00182         download_path = g_build_path("/", g_mountpoint, download_folder, NULL);
00183     
00184         // create and add download directory when necessary
00185         if (!g_file_test(download_path, G_FILE_TEST_IS_DIR))
00186         {
00187             if (g_mkdir_with_parents(download_path, 0777) >= 0)
00188             {
00189                 add_folder_to_metadata(g_mountpoint, download_folder);
00190             }
00191         }
00192         
00193         if (!g_file_test(download_path, G_FILE_TEST_IS_DIR))
00194         {
00195             ERRORPRINTF("Failed to create %s, error [%d] [%s]", download_path, errno, g_strerror(errno));
00196 
00197             // Webkit will continue loading which ends in an error
00198             // so stop here. This may be an error in Webkit. 
00199             webkit_web_view_stop_loading(web_view);
00200             
00201             GtkWidget *widget;    
00202             widget = gtk_message_dialog_new(GTK_WINDOW(browser_window->window),
00203                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
00204                                         GTK_MESSAGE_WARNING,
00205                                         GTK_BUTTONS_OK,
00206                                         _("An error has occurred while saving the file to the SD card. It is possible the card is full or locked."));
00207 
00208             gtk_dialog_run(GTK_DIALOG(widget));
00209             gtk_widget_destroy(widget);
00210             
00211             g_free(download_path);
00212             return FALSE;
00213         }
00214     }
00215     
00216     // create download filename
00217     gchar *filename = make_unique_filename(download_path, webkit_download_get_suggested_filename(download));
00218 
00219     dialog = g_new0(DownloadDialog, 1);
00220     dialog->browser_window = browser_window;
00221     dialog->download       = g_object_ref(download);
00222     
00223     // object hierarchy:
00224     //     dialog
00225     //       |    
00226     dialog->window = gtk_dialog_new_with_buttons(_("Download Progress"),
00227                          GTK_WINDOW(browser_window->window), 
00228                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
00229                          NULL);
00230     gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog->window)->vbox), box_spacing);
00231     //       |
00232     //       |-- uri_label (label)
00233     //       |    
00234     gchar *message;
00235     dialog->uri_label = gtk_label_new(NULL);
00236     message = g_strdup_printf(_("Downloading '%s'..."), filename);
00237     gtk_label_set_label(GTK_LABEL(dialog->uri_label), message);
00238     gtk_label_set_line_wrap(GTK_LABEL(dialog->uri_label), TRUE);
00239     gtk_widget_set_size_request(dialog->uri_label, uri_label_width, -1);
00240     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog->window)->vbox), dialog->uri_label, FALSE, FALSE, 0);
00241     g_free(message);
00242     //       |
00243     //       |-- progress_bar (progress bar)
00244     //       |    
00245     dialog->progress_bar = gtk_progress_bar_new();         
00246     gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(dialog->progress_bar), GTK_PROGRESS_LEFT_TO_RIGHT);
00247     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dialog->progress_bar), 0.0); 
00248     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog->window)->vbox), dialog->progress_bar, FALSE, FALSE, 0);
00249     //       |
00250     //       |-- button_box (hbutton box)
00251     //       |    
00252     GtkWidget *button_box = gtk_hbutton_box_new();
00253     GTK_DIALOG(dialog->window)->action_area = button_box;
00254     gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_END);
00255     dialog->button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
00256     g_signal_connect(G_OBJECT(dialog->button), "clicked", G_CALLBACK(download_button_cancel_cb), dialog);
00257     gtk_box_pack_start(GTK_BOX(button_box), dialog->button, FALSE, FALSE, 0);
00258     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog->window)->vbox), button_box, FALSE, FALSE, 0);
00259     
00260     gtk_widget_show_all(GTK_WIDGET(dialog->window));
00261 
00262     // create URI for download target
00263     gchar *local_uri = NULL;
00264     local_uri = g_strconcat("file://", filename, NULL);
00265     
00266     LOGPRINTF("Download file to [%s]", local_uri);
00267     
00268     webkit_download_set_destination_uri(dialog->download, local_uri);
00269     g_free(local_uri);
00270     g_free(download_path);
00271     g_free(filename);
00272     
00273     g_signal_connect(dialog->window, "close",               G_CALLBACK(download_destroy_cb), dialog);
00274     g_signal_connect(dialog->window, "response",            G_CALLBACK(download_response_cb), dialog);
00275     
00276     g_signal_connect(G_OBJECT(download), "error",           G_CALLBACK(download_error_cb), dialog);
00277     g_signal_connect(G_OBJECT(download), "notify::status",  G_CALLBACK(download_status_changed_cb), dialog);
00278     
00279     // schedule next update after n seconds
00280     g_update_progress = g_timeout_add_seconds(progress_interval, update_progress_cb, dialog);
00281     
00282     ipc_sys_bg_busy(TRUE);
00283 
00284     return TRUE;
00285 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208