r15095 - gnucash/trunk/src - Default directory tweaks:
Andreas Köhler
andi5 at cvs.gnucash.org
Wed Nov 8 11:40:45 EST 2006
Author: andi5
Date: 2006-11-08 11:40:41 -0500 (Wed, 08 Nov 2006)
New Revision: 15095
Trac: http://svn.gnucash.org/trac/changeset/15095
Modified:
gnucash/trunk/src/app-utils/gnc-ui-util.c
gnucash/trunk/src/app-utils/gnc-ui-util.h
gnucash/trunk/src/gnome-utils/gnc-file.c
gnucash/trunk/src/import-export/hbci/gnc-file-aqb-import.c
gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c
gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
Log:
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
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2006-11-08 16:40:41 UTC (rev 15095)
@@ -174,30 +174,22 @@
}
-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 *
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.h 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.h 2006-11-08 16:40:41 UTC (rev 15095)
@@ -49,32 +49,10 @@
/* 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);
AccountGroup * gnc_get_current_group (void);
Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c 2006-11-08 16:40:41 UTC (rev 15095)
@@ -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,15 +128,10 @@
gtk_dialog_add_button(GTK_DIALOG(file_box),
okbutton, GTK_RESPONSE_ACCEPT);
- if (starting_dir) {
- gchar *dir_name;
+ if (starting_dir)
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (file_box),
+ starting_dir);
- /* 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);
- }
-
gtk_window_set_modal(GTK_WINDOW(file_box), TRUE);
/*
gtk_window_set_transient_for(GTK_WINDOW(file_box),
@@ -845,8 +839,7 @@
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 @@
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 @@
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
Modified: gnucash/trunk/src/import-export/hbci/gnc-file-aqb-import.c
===================================================================
--- gnucash/trunk/src/import-export/hbci/gnc-file-aqb-import.c 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/import-export/hbci/gnc-file-aqb-import.c 2006-11-08 16:40:41 UTC (rev 15095)
@@ -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 @@
/* 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 @@
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);*/
Modified: gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c
===================================================================
--- gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c 2006-11-08 16:40:41 UTC (rev 15095)
@@ -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 @@
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 @@
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 @@
}
g_free(selected_filename);
}
- g_free(default_dir);
}
Modified: gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c 2006-11-08 16:40:41 UTC (rev 15095)
@@ -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 @@
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);
Modified: gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/druid-qif-import.c 2006-11-07 15:56:39 UTC (rev 15094)
+++ gnucash/trunk/src/import-export/qif-import/druid-qif-import.c 2006-11-08 16:40:41 UTC (rev 15095)
@@ -378,9 +378,7 @@
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 @@
/* 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);
}
More information about the gnucash-changes
mailing list