roundabout,
created on Monday, 17 November 2025, 19:51:28 (1763409088),
received on Monday, 17 November 2025, 19:51:39 (1763409099)
Author identity: Vlad <vlad.muntoiu@gmail.com>
d801b6afc9ff4f0455cb5306abd8a2fc8e1490b8
panthera-www.cc
@@ -317,6 +317,8 @@ private:
static void on_forward_pressed(GtkGestureClick* gesture, int n_press, double x, double y, gpointer user_data);
static gboolean on_decide_policy(WebKitWebView* source, WebKitPolicyDecision* decision, WebKitPolicyDecisionType type, gpointer user_data);
static void close_callback(WebKitWebView *source, gpointer user_data);
static void download_callback(WebKitNetworkSession *source, WebKitDownload *download, gpointer user_data);
static bool decide_destination_callback(WebKitDownload *download, gchar* suggested_filename, gpointer user_data);
protected:
void on_startup() override;
@@ -814,6 +816,35 @@ void PantheraWww::close_callback(WebKitWebView *source, gpointer user_data) {
}
}
void PantheraWww::download_callback(WebKitNetworkSession *source, WebKitDownload *download, gpointer user_data) {
if(auto self = static_cast<PantheraWww*>(user_data)) {
// TODO: free the WebKitDownload
g_signal_connect(download, "decide-destination", G_CALLBACK(decide_destination_callback), self);
}
}
bool PantheraWww::decide_destination_callback(WebKitDownload *download, gchar *suggested_filename, gpointer user_data) {
if(auto self = static_cast<PantheraWww*>(user_data)) {
auto file_dialog = Gtk::FileDialog::create();
file_dialog->set_accept_label(_("Download"));
file_dialog->set_modal(false);
file_dialog->set_initial_name(std::string(suggested_filename));
if(auto *window = dynamic_cast<Gtk::Window*>(Glib::wrap_auto(G_OBJECT(gtk_widget_get_root(GTK_WIDGET(webkit_download_get_web_view(download))))))) {
file_dialog->save(*window, Gio::SlotAsyncReady([file_dialog, download](Glib::RefPtr<Gio::AsyncResult> &result) {
try {
auto file = file_dialog->save_finish(result);
webkit_download_set_destination(download, file->get_path().c_str());
} catch(Gtk::DialogError &e) {
// Download rejected
}
}));
}
//g_free(suggested_filename);
return true;
}
return true;
}
void PantheraWww::on_new_tab(gPanthera::ContentStack *stack, const Glib::ustring &url, bool focus, bool new_window) {
if(!stack) {
// Find the current area
@@ -845,10 +876,10 @@ void PantheraWww::on_new_tab(gPanthera::ContentStack *stack, const Glib::ustring
g_signal_connect(webview, "load-changed", G_CALLBACK(load_change_callback), this);
g_signal_connect(webview, "decide-policy", G_CALLBACK(on_decide_policy), this);
webkit_web_view_load_uri(webview, url_.data());
auto cookie_manager = webkit_network_session_get_cookie_manager(webkit_web_view_get_network_session(webview));
auto cookie_manager = webkit_network_session_get_cookie_manager(webkit_network_session_get_default());
webkit_cookie_manager_set_persistent_storage(cookie_manager, cookie_file.c_str(), WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
webkit_cookie_manager_set_accept_policy(cookie_manager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
auto website_data_manager = webkit_network_session_get_website_data_manager(webkit_web_view_get_network_session(webview));
auto website_data_manager = webkit_network_session_get_website_data_manager(webkit_network_session_get_default());
webkit_website_data_manager_set_favicons_enabled(website_data_manager, true);
GtkEventController *click_controller_back = GTK_EVENT_CONTROLLER(gtk_gesture_click_new());
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(click_controller_back), 8);
@@ -1010,6 +1041,9 @@ void PantheraWww::on_startup() {
main_menu->append_submenu(_("_Go"), go_menu);
set_menubar(main_menu);
// Download handling
g_signal_connect(webkit_network_session_get_default(), "download-started", G_CALLBACK(download_callback), this);
}
void PantheraWww::on_activate() {