v0.0.62 - Release: remember last save directory in download file chooser
This commit is contained in:
+2
-2
@@ -11,9 +11,9 @@
|
||||
#ifndef 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_MINOR 0
|
||||
#define SB_VERSION_PATCH 61
|
||||
#define SB_VERSION_PATCH 62
|
||||
|
||||
#endif /* SOVEREIGN_BROWSER_VERSION_H */
|
||||
|
||||
@@ -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
|
||||
* setting a destination is explicitly supported since 2.40 and pauses
|
||||
* 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,
|
||||
const char *suggested,
|
||||
gpointer user) {
|
||||
@@ -115,6 +122,14 @@ static gboolean on_download_decide_destination(WebKitDownload *dl,
|
||||
if (parent) g_object_unref(parent);
|
||||
|
||||
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_do_overwrite_confirmation(chooser, TRUE);
|
||||
|
||||
@@ -131,6 +146,16 @@ static gboolean on_download_decide_destination(WebKitDownload *dl,
|
||||
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);
|
||||
g_free(path);
|
||||
if (uri == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user