mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Default directory tweaks:
* replace gnc_init_default_directory by gnc_get_default_directory and do gconf query there * remove gnc_extract_directory, but add gnc_set_default_directory * do not save default directory with trailing (back)slash anymore git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15095 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -174,30 +174,22 @@ gnc_reverse_balance (const Account *account)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_init_default_directory (char **dirname)
|
||||
gchar *
|
||||
gnc_get_default_directory (const gchar *gconf_section)
|
||||
{
|
||||
if (*dirname == NULL)
|
||||
*dirname = g_strdup_printf("%s/", g_get_home_dir());
|
||||
gchar *dir;
|
||||
|
||||
dir = gnc_gconf_get_string (gconf_section, KEY_LAST_PATH, NULL);
|
||||
if (!dir)
|
||||
dir = g_strdup (g_get_home_dir ());
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_extract_directory (char **dirname, const char *filename)
|
||||
gnc_set_default_directory (const gchar *gconf_section, const gchar *directory)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
if (*dirname)
|
||||
free(*dirname);
|
||||
|
||||
/* Parse out the directory. */
|
||||
if ((filename == NULL) || (strrchr(filename, '/') == NULL)) {
|
||||
*dirname = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
*dirname = g_strdup(filename);
|
||||
tmp = strrchr(*dirname, '/');
|
||||
*(tmp+1) = '\0';
|
||||
gnc_gconf_set_string(gconf_section, KEY_LAST_PATH, directory, NULL);
|
||||
}
|
||||
|
||||
QofBook *
|
||||
|
||||
@@ -49,31 +49,9 @@ gboolean gnc_reverse_balance_type(GNCAccountType type);
|
||||
|
||||
/* Default directories **********************************************/
|
||||
|
||||
void gnc_init_default_directory (char **dirname);
|
||||
/**
|
||||
* Extracts the directory part of the given 'filename' into the char
|
||||
* pointer variable '*dirname'. If the 'filename' is NULL or does not
|
||||
* contain any directory separator '/', then '*dirname' will be set to
|
||||
* NULL.
|
||||
*
|
||||
* WATCH OUT: If '*dirname' (i.e. the underlying char pointer
|
||||
* variable) is non-NULL, then it will be free()'d. Make sure that you
|
||||
* have initialized it to NULL, or otherwise you will get a bogus
|
||||
* free() or a double-free() here. FIXME: This is probably not-so-good
|
||||
* behaviour and should be changed (2005-10-08, cstim).
|
||||
*
|
||||
* Again watch out: The caller takes ownership of the char buffer
|
||||
* '*dirname', i.e. the caller has to do a g_free(*dirname) when that
|
||||
* buffer is no longer in use.
|
||||
*
|
||||
* NOTE: We strongly recommend to use g_path_get_dirname() from glib
|
||||
* instead of this function. (There's one slight functional difference:
|
||||
* If filename is NULL or does not contain a separator,
|
||||
* g_path_get_dirname will return "." whereas this function here will
|
||||
* return NULL. 2006-03-02, cstim)
|
||||
*/
|
||||
void gnc_extract_directory (char **dirname, const char *filename);
|
||||
|
||||
gchar *gnc_get_default_directory (const gchar *gconf_section);
|
||||
void gnc_set_default_directory (const gchar *gconf_section,
|
||||
const gchar *directory);
|
||||
|
||||
/* Engine enhancements & i18n ***************************************/
|
||||
QofBook * gnc_get_current_book (void);
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "gnc-ui.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "gnc-window.h"
|
||||
#include "gnc-gconf-utils.h"
|
||||
#include "gnc-plugin-file-history.h"
|
||||
#include "qof.h"
|
||||
#include "TransLog.h"
|
||||
@@ -129,14 +128,9 @@ gnc_file_dialog (const char * title,
|
||||
gtk_dialog_add_button(GTK_DIALOG(file_box),
|
||||
okbutton, GTK_RESPONSE_ACCEPT);
|
||||
|
||||
if (starting_dir) {
|
||||
gchar *dir_name;
|
||||
|
||||
/* Ensure we have a directory name. The set function fails otherwise. */
|
||||
dir_name = g_path_get_dirname(starting_dir);
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (file_box), dir_name);
|
||||
g_free(dir_name);
|
||||
}
|
||||
if (starting_dir)
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (file_box),
|
||||
starting_dir);
|
||||
|
||||
gtk_window_set_modal(GTK_WINDOW(file_box), TRUE);
|
||||
/*
|
||||
@@ -845,8 +839,7 @@ gnc_file_open (void)
|
||||
|
||||
lastfile = gnc_history_get_last();
|
||||
newfile = gnc_file_dialog (_("Open"), NULL, lastfile, GNC_FILE_DIALOG_OPEN);
|
||||
if (lastfile)
|
||||
g_free(lastfile);
|
||||
g_free(lastfile);
|
||||
result = gnc_post_file_open (newfile);
|
||||
|
||||
/* This dialogue can show up early in the startup process. If the
|
||||
@@ -877,21 +870,17 @@ gnc_file_export_file(const char * newfile)
|
||||
QofBackendError io_err = ERR_BACKEND_NO_ERR;
|
||||
gchar *default_dir;
|
||||
|
||||
default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
|
||||
if (default_dir == NULL)
|
||||
gnc_init_default_directory(&default_dir);
|
||||
|
||||
if (!newfile) {
|
||||
default_dir = gnc_get_default_directory (GCONF_SECTION);
|
||||
newfile = gnc_file_dialog (_("Export"), NULL, default_dir, GNC_FILE_DIALOG_EXPORT);
|
||||
g_free(default_dir);
|
||||
default_dir = NULL;
|
||||
if (!newfile)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remember the directory as the default. */
|
||||
gnc_extract_directory(&default_dir, newfile);
|
||||
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
|
||||
default_dir = g_path_get_dirname(newfile);
|
||||
gnc_set_default_directory (GCONF_SECTION, default_dir);
|
||||
g_free(default_dir);
|
||||
|
||||
qof_event_suspend();
|
||||
@@ -1020,15 +1009,14 @@ gnc_file_save_as (void)
|
||||
|
||||
last = gnc_history_get_last();
|
||||
if (last) {
|
||||
gnc_extract_directory(&default_dir, last);
|
||||
default_dir = g_path_get_dirname(last);
|
||||
g_free(last);
|
||||
} else {
|
||||
gnc_init_default_directory(&default_dir);
|
||||
default_dir = gnc_get_default_directory(GCONF_SECTION);
|
||||
}
|
||||
filename = gnc_file_dialog (_("Save"), NULL, default_dir,
|
||||
GNC_FILE_DIALOG_SAVE);
|
||||
if (default_dir)
|
||||
free(default_dir);
|
||||
GNC_FILE_DIALOG_SAVE);
|
||||
g_free(default_dir);
|
||||
if (!filename) return;
|
||||
|
||||
/* Check to see if the user specified the same file as the current
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-file.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "gnc-gconf-utils.h"
|
||||
|
||||
#include "gnc-hbci-utils.h"
|
||||
#include "gnc-hbci-gettrans.h"
|
||||
@@ -153,9 +152,7 @@ void gnc_file_aqbanking_import (const gchar *aqbanking_importername,
|
||||
/* qof_log_check(MOD_IMPORT, QOF_LOG_TRACE); */
|
||||
DEBUG("gnc_file_dtaus_import(): Begin...\n");
|
||||
|
||||
default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
|
||||
if (default_dir == NULL)
|
||||
gnc_init_default_directory(&default_dir);
|
||||
default_dir = gnc_get_default_directory(GCONF_SECTION);
|
||||
selected_filename = gnc_file_dialog(_("Select an DTAUS file to process"),
|
||||
NULL,
|
||||
default_dir,
|
||||
@@ -165,7 +162,7 @@ void gnc_file_aqbanking_import (const gchar *aqbanking_importername,
|
||||
if(selected_filename!=NULL) {
|
||||
/* Remember the directory as the default. */
|
||||
default_dir = g_path_get_dirname(selected_filename);
|
||||
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
|
||||
gnc_set_default_directory(GCONF_SECTION, default_dir);
|
||||
g_free(default_dir);
|
||||
|
||||
/*strncpy(file,selected_filename, 255);*/
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#include "qof.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "gnc-gconf-utils.h"
|
||||
#include "gnc-gui-query.h"
|
||||
|
||||
#define GCONF_SECTION "dialogs/log_replay"
|
||||
@@ -515,9 +514,7 @@ void gnc_file_log_replay (void)
|
||||
qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
|
||||
ENTER(" ");
|
||||
|
||||
default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
|
||||
if (default_dir == NULL)
|
||||
gnc_init_default_directory(&default_dir);
|
||||
default_dir = gnc_get_default_directory(GCONF_SECTION);
|
||||
|
||||
filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter, "*.log");
|
||||
@@ -526,12 +523,14 @@ void gnc_file_log_replay (void)
|
||||
g_list_prepend(NULL, filter),
|
||||
default_dir,
|
||||
GNC_FILE_DIALOG_OPEN);
|
||||
g_free(default_dir);
|
||||
|
||||
if(selected_filename!=NULL)
|
||||
{
|
||||
/* Remember the directory as the default. */
|
||||
gnc_extract_directory(&default_dir, selected_filename);
|
||||
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
|
||||
default_dir = g_path_get_dirname(selected_filename);
|
||||
gnc_set_default_directory(GCONF_SECTION, default_dir);
|
||||
g_free(default_dir);
|
||||
|
||||
/*strncpy(file,selected_filename, 255);*/
|
||||
DEBUG("Filename found: %s",selected_filename);
|
||||
@@ -582,7 +581,6 @@ void gnc_file_log_replay (void)
|
||||
}
|
||||
g_free(selected_filename);
|
||||
}
|
||||
g_free(default_dir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "gnc-gconf-utils.h"
|
||||
#include "gnc-glib-utils.h"
|
||||
|
||||
#define GCONF_SECTION "dialogs/import/ofx"
|
||||
@@ -648,23 +647,19 @@ void gnc_file_ofx_import (void)
|
||||
qof_log_check(GNC_MOD_IMPORT, QOF_LOG_TRACE);
|
||||
DEBUG("gnc_file_ofx_import(): Begin...\n");
|
||||
|
||||
default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
|
||||
if (default_dir == NULL)
|
||||
gnc_init_default_directory(&default_dir);
|
||||
default_dir = gnc_get_default_directory(GCONF_SECTION);
|
||||
selected_filename = gnc_file_dialog(_("Select an OFX/QFX file to process"),
|
||||
NULL,
|
||||
default_dir,
|
||||
GNC_FILE_DIALOG_IMPORT);
|
||||
g_free(default_dir);
|
||||
default_dir = NULL;
|
||||
|
||||
if(selected_filename!=NULL)
|
||||
{
|
||||
/* Remember the directory as the default. */
|
||||
gnc_extract_directory(&default_dir, selected_filename);
|
||||
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
|
||||
default_dir = g_path_get_dirname(selected_filename);
|
||||
gnc_set_default_directory(GCONF_SECTION, default_dir);
|
||||
g_free(default_dir);
|
||||
default_dir = NULL;
|
||||
|
||||
/*strncpy(file,selected_filename, 255);*/
|
||||
DEBUG("Filename found: %s",selected_filename);
|
||||
|
||||
@@ -378,9 +378,7 @@ gnc_ui_qif_import_select_file_cb(GtkButton * button,
|
||||
char *file_name, *default_dir;
|
||||
|
||||
/* Default to whatever's already present */
|
||||
default_dir = gnc_gconf_get_string(GCONF_SECTION, KEY_LAST_PATH, NULL);
|
||||
if (default_dir == NULL)
|
||||
gnc_init_default_directory(&default_dir);
|
||||
default_dir = gnc_get_default_directory(GCONF_SECTION);
|
||||
|
||||
filter = gtk_file_filter_new ();
|
||||
gtk_file_filter_set_name (filter, "*.qif");
|
||||
@@ -393,20 +391,20 @@ gnc_ui_qif_import_select_file_cb(GtkButton * button,
|
||||
/* Insure valid data, and something that can be freed. */
|
||||
if (new_file_name == NULL) {
|
||||
file_name = g_strdup(default_dir);
|
||||
} else if (*new_file_name != '/') {
|
||||
file_name = g_strdup_printf("%s%s", default_dir, new_file_name);
|
||||
} else if (!g_path_is_absolute(new_file_name)) {
|
||||
file_name = g_build_filename(default_dir, new_file_name);
|
||||
g_free(new_file_name);
|
||||
} else {
|
||||
file_name = new_file_name;
|
||||
/* Update the working directory */
|
||||
g_free(default_dir);
|
||||
default_dir = g_path_get_dirname(file_name);
|
||||
gnc_set_default_directory(GCONF_SECTION, default_dir);
|
||||
}
|
||||
g_free(default_dir);
|
||||
|
||||
/* set the filename entry for what was selected */
|
||||
gtk_entry_set_text(GTK_ENTRY(wind->filename_entry), file_name);
|
||||
|
||||
/* Update the working directory */
|
||||
gnc_extract_directory(&default_dir, file_name);
|
||||
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
|
||||
g_free(default_dir);
|
||||
g_free(file_name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user