~evfool/midori/lp792536

« back to all changes in this revision

Viewing changes to midori/midori-view.c

  • Committer: Christian Dywan
  • Date: 2009-03-19 17:28:50 UTC
  • Revision ID: git-v1:7af8baee8bdd5cbfcfb24ff5e2c304c25094d385
Initial support for WebKitDownload

At this point all downloads run automatically and appear in the
statusbar. The destination folder can be chosen in the preferences.
Download can be cancelled. The context menu works as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
    NEW_TAB,
144
144
    NEW_WINDOW,
145
145
    NEW_VIEW,
 
146
    DOWNLOAD_REQUESTED,
146
147
    SEARCH_TEXT,
147
148
    ADD_BOOKMARK,
148
149
    SAVE_AS,
272
273
        MIDORI_TYPE_NEW_VIEW);
273
274
 
274
275
    /**
 
276
     * MidoriView::download-requested:
 
277
     * @view: the object on which the signal is emitted
 
278
     * @download: a new download
 
279
     *
 
280
     * Emitted when a new download is requested, if a
 
281
     * file cannot be displayed or a download was started
 
282
     * from the context menu.
 
283
     *
 
284
     * If the download should be accepted, a callback
 
285
     * has to return %TRUE, and the download will also
 
286
     * be started automatically.
 
287
     *
 
288
     * Note: This requires WebKitGTK 1.1.3.
 
289
     *
 
290
     * Return value: %TRUE if the download was handled
 
291
     *
 
292
     * Since: 0.1.5
 
293
     */
 
294
    signals[DOWNLOAD_REQUESTED] = g_signal_new (
 
295
        "download-requested",
 
296
        G_TYPE_FROM_CLASS (class),
 
297
        (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
 
298
        0,
 
299
        g_signal_accumulator_true_handled,
 
300
        NULL,
 
301
        midori_cclosure_marshal_BOOLEAN__OBJECT,
 
302
        G_TYPE_BOOLEAN, 1,
 
303
        G_TYPE_OBJECT);
 
304
 
 
305
    /**
275
306
     * MidoriView::search-text:
276
307
     * @view: the object on which the signal is emitted
277
308
     * @found: whether the search was successful
619
650
    gchar* title;
620
651
    gchar* data;
621
652
 
 
653
    #if WEBKIT_CHECK_VERSION (1, 1, 3)
 
654
    if (!success && webkit_web_view_can_show_mime_type (
 
655
        WEBKIT_WEB_VIEW (view->web_view), view->mime_type))
 
656
    #else
622
657
    if (!success)
 
658
    #endif
623
659
    {
624
660
        /* i18n: The title of the 404 - Not found error page */
625
661
        title = g_strdup_printf (_("Not found - %s"), view->uri);
886
922
    g_free (uri);
887
923
}
888
924
 
 
925
#if !WEBKIT_CHECK_VERSION (1, 1, 3)
889
926
static void
890
927
midori_web_view_menu_save_as_activate_cb (GtkWidget*  widget,
891
928
                                          MidoriView* view)
899
936
{
900
937
    sokoke_spawn_program (view->download_manager, view->link_uri);
901
938
}
 
939
#endif
902
940
 
903
941
static void
904
942
midori_web_view_menu_add_bookmark_activate_cb (GtkWidget*  widget,
977
1015
            G_CALLBACK (midori_web_view_menu_new_window_activate_cb), view);
978
1016
        menuitem = (GtkWidget*)g_list_nth_data (items, 3);
979
1017
        g_list_free (items);
 
1018
        #if WEBKIT_CHECK_VERSION (1, 1, 3)
 
1019
        /* hack to localize menu item */
 
1020
        label = gtk_bin_get_child (GTK_BIN (menuitem));
 
1021
        gtk_label_set_label (GTK_LABEL (label), _("_Download Link destination"));
 
1022
        #else
980
1023
        /* hack to disable non-functional Download File
981
1024
           FIXME: Make sure this really is the right menu item */
982
1025
        gtk_widget_hide (menuitem);
998
1041
                G_CALLBACK (midori_web_view_menu_download_activate_cb), view);
999
1042
            gtk_widget_show (menuitem);
1000
1043
        }
 
1044
        #endif
1001
1045
        menuitem = gtk_image_menu_item_new_from_stock (STOCK_BOOKMARK_ADD, NULL);
1002
1046
        gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 5);
1003
1047
        g_signal_connect (menuitem, "activate",
1144
1188
    midori_view_update_icon (view, NULL);
1145
1189
    g_object_notify (G_OBJECT (view), "mime-type");
1146
1190
 
1147
 
    /* TODO: Display contents with a Viewable if WebKit can't do it */
1148
 
    /* TODO: Offer downloading file if it cannot be displayed at all */
1149
 
 
1150
1191
    if (webkit_web_view_can_show_mime_type (WEBKIT_WEB_VIEW (web_view), mime_type))
1151
1192
        return FALSE;
1152
1193
 
 
1194
    #if WEBKIT_CHECK_VERSION (1, 1, 3)
 
1195
    webkit_web_policy_decision_download (decision);
 
1196
    return TRUE;
 
1197
    #endif
 
1198
 
1153
1199
    uri = g_strdup_printf ("error:nodisplay %s",
1154
1200
        webkit_network_request_get_uri (request));
1155
1201
    midori_view_set_uri (view, uri);
1158
1204
    return TRUE;
1159
1205
}
1160
1206
 
 
1207
#if WEBKIT_CHECK_VERSION (1, 1, 3)
 
1208
static gboolean
 
1209
webkit_web_view_download_requested_cb (GtkWidget*      web_view,
 
1210
                                       WebKitDownload* download,
 
1211
                                       MidoriView*     view)
 
1212
{
 
1213
    gboolean handled;
 
1214
    g_signal_emit (view, signals[DOWNLOAD_REQUESTED], 0, download, &handled);
 
1215
    return handled;
 
1216
}
 
1217
#endif
 
1218
 
1161
1219
static void
1162
1220
webkit_web_view_console_message_cb (GtkWidget*   web_view,
1163
1221
                                    const gchar* message,
1576
1634
                      webkit_web_view_create_web_view_cb, view,
1577
1635
                      "signal::mime-type-policy-decision-requested",
1578
1636
                      webkit_web_view_mime_type_decision_cb, view,
 
1637
                      #if WEBKIT_CHECK_VERSION (1, 1, 3)
 
1638
                      "signal::download-requested",
 
1639
                      webkit_web_view_download_requested_cb, view,
 
1640
                      #endif
1579
1641
                      NULL);
 
1642
 
1580
1643
    g_object_connect (web_frame,
1581
1644
                      "signal::load-done",
1582
1645
                      webkit_web_frame_load_done_cb, view,