v0.0.62 - Release: remember last save directory in download file chooser

This commit is contained in:
Laan Tungir
2026-07-29 10:41:13 -04:00
parent 992b09357a
commit 2bc5ec7771
3 changed files with 28 additions and 3 deletions
+1 -1
View File
@@ -1 +1 @@
0.0.61 0.0.62
+2 -2
View File
@@ -11,9 +11,9 @@
#ifndef SOVEREIGN_BROWSER_VERSION_H #ifndef SOVEREIGN_BROWSER_VERSION_H
#define SOVEREIGN_BROWSER_VERSION_H #define SOVEREIGN_BROWSER_VERSION_H
#define SB_VERSION "v0.0.61" #define SB_VERSION "v0.0.62"
#define SB_VERSION_MAJOR 0 #define SB_VERSION_MAJOR 0
#define SB_VERSION_MINOR 0 #define SB_VERSION_MINOR 0
#define SB_VERSION_PATCH 61 #define SB_VERSION_PATCH 62
#endif /* SOVEREIGN_BROWSER_VERSION_H */ #endif /* SOVEREIGN_BROWSER_VERSION_H */
+25
View File
@@ -94,6 +94,13 @@ static void on_download_failed(WebKitDownload *dl, GError *err, gpointer user) {
* dialog, set the destination, and return TRUE. Returning TRUE without * dialog, set the destination, and return TRUE. Returning TRUE without
* setting a destination is explicitly supported since 2.40 and pauses * setting a destination is explicitly supported since 2.40 and pauses
* the download until we set one (or cancel). */ * the download until we set one (or cancel). */
/* Remember the directory the user last saved a download to, so the next
* save dialog opens in the same folder instead of the default. Owned by
* this module (g_free'd on teardown). NULL until the first successful
* save. */
static char *g_last_save_dir = NULL;
static gboolean on_download_decide_destination(WebKitDownload *dl, static gboolean on_download_decide_destination(WebKitDownload *dl,
const char *suggested, const char *suggested,
gpointer user) { gpointer user) {
@@ -115,6 +122,14 @@ static gboolean on_download_decide_destination(WebKitDownload *dl,
if (parent) g_object_unref(parent); if (parent) g_object_unref(parent);
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog); GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
/* If the user saved a download before, open the dialog in that same
* directory. Otherwise GTK falls back to the current working
* directory / last-used folder for the application. */
if (g_last_save_dir != NULL && g_last_save_dir[0] != '\0') {
gtk_file_chooser_set_current_folder(chooser, g_last_save_dir);
}
gtk_file_chooser_set_current_name(chooser, default_name); gtk_file_chooser_set_current_name(chooser, default_name);
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE); gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
@@ -131,6 +146,16 @@ static gboolean on_download_decide_destination(WebKitDownload *dl,
return TRUE; /* we handled it (by cancelling) */ return TRUE; /* we handled it (by cancelling) */
} }
/* Remember the directory the user chose for next time. */
char *dir = g_path_get_dirname(path);
if (dir != NULL && dir[0] != '\0' &&
(g_last_save_dir == NULL ||
g_strcmp0(dir, g_last_save_dir) != 0)) {
g_free(g_last_save_dir);
g_last_save_dir = g_strdup(dir);
}
g_free(dir);
char *uri = g_filename_to_uri(path, NULL, NULL); char *uri = g_filename_to_uri(path, NULL, NULL);
g_free(path); g_free(path);
if (uri == NULL) { if (uri == NULL) {