From 909b5e1edc01d95ebfaf39982b69831d8503c74c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 21 Jan 2014 07:55:44 +0000 Subject: [PATCH] worked on notes directory setting --- config.status | 6 +++--- po/Makefile | 2 +- po/Makefile.in | 2 +- src/Makefile.am | 1 + src/Makefile.in | 4 +++- src/glade/ptask.glade | 4 ++-- src/note.c | 36 +++++++++++++++++++++++++++--------- src/settings.c | 11 +++++++++++ src/settings.h | 3 +++ src/ui.c | 21 +++++++++++++++++---- 10 files changed, 69 insertions(+), 21 deletions(-) diff --git a/config.status b/config.status index 675ff48..7ac0c65 100755 --- a/config.status +++ b/config.status @@ -428,7 +428,7 @@ $config_commands Report bugs to . ptask home page: ." -ac_cs_config="'--prefix=/tmp'" +ac_cs_config="" ac_cs_version="\ ptask config.status 0.0.x configured by ./configure, generated by GNU Autoconf 2.69, @@ -520,7 +520,7 @@ if $ac_cs_silent; then fi if $ac_cs_recheck; then - set X /bin/bash './configure' '--prefix=/tmp' $ac_configure_extra_args --no-create --no-recursion + set X /bin/bash './configure' $ac_configure_extra_args --no-create --no-recursion shift $as_echo "running CONFIG_SHELL=/bin/bash $*" >&6 CONFIG_SHELL='/bin/bash' @@ -797,7 +797,7 @@ S["libexecdir"]="${exec_prefix}/libexec" S["sbindir"]="${exec_prefix}/sbin" S["bindir"]="${exec_prefix}/bin" S["program_transform_name"]="s,x,x," -S["prefix"]="/tmp" +S["prefix"]="/usr/local" S["exec_prefix"]="${prefix}" S["PACKAGE_URL"]="http://wpitchoune.net/ptask" S["PACKAGE_BUGREPORT"]="jeanfi@gmail.com" diff --git a/po/Makefile b/po/Makefile index ea8150b..430bf0b 100644 --- a/po/Makefile +++ b/po/Makefile @@ -21,7 +21,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp +prefix = /usr/local exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/po/Makefile.in b/po/Makefile.in index ca508b4..9db3564 100644 --- a/po/Makefile.in +++ b/po/Makefile.in @@ -21,7 +21,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp +prefix = /usr/local exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/src/Makefile.am b/src/Makefile.am index 3caecde..bb1cbfc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,7 @@ ptask_SOURCES = list.c list.h \ log.c log.h \ main.c \ note.c note.h \ + pio.c pio.h \ pstr.c pstr.h \ ptime.c ptime.h \ settings.c settings.h \ diff --git a/src/Makefile.in b/src/Makefile.in index 18239a3..b93cf56 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -93,7 +93,7 @@ CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) am_ptask_OBJECTS = list.$(OBJEXT) log.$(OBJEXT) main.$(OBJEXT) \ - note.$(OBJEXT) pstr.$(OBJEXT) ptime.$(OBJEXT) \ + note.$(OBJEXT) pio.$(OBJEXT) pstr.$(OBJEXT) ptime.$(OBJEXT) \ settings.$(OBJEXT) tw.$(OBJEXT) ui.$(OBJEXT) \ ui_newtask_diag.$(OBJEXT) ui_projecttree.$(OBJEXT) \ ui_taskpanel.$(OBJEXT) ui_tasktree.$(OBJEXT) @@ -364,6 +364,7 @@ ptask_SOURCES = list.c list.h \ log.c log.h \ main.c \ note.c note.h \ + pio.c pio.h \ pstr.c pstr.h \ ptime.c ptime.h \ settings.c settings.h \ @@ -468,6 +469,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/note.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pstr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/settings.Po@am__quote@ diff --git a/src/glade/ptask.glade b/src/glade/ptask.glade index 49d947d..a4fc97b 100644 --- a/src/glade/ptask.glade +++ b/src/glade/ptask.glade @@ -95,7 +95,7 @@ - + True False True @@ -120,7 +120,7 @@ - button3 + button3 button4 diff --git a/src/note.c b/src/note.c index 77f98cf..be9d87a 100644 --- a/src/note.c +++ b/src/note.c @@ -25,10 +25,14 @@ #include #include +#include +#include -static char *get_default_path(const char *uuid) +static const char *NOTE_SUF = ".note"; + +static char *get_default_path() { - char *home, *dir, *path; + char *home, *dir; home = getenv("HOME"); @@ -41,17 +45,31 @@ static char *get_default_path(const char *uuid) sprintf(dir, "%s/%s", home, ".task"); mkdir(dir, 0777); - path = malloc(strlen(dir) + 1 + strlen(uuid) + strlen(".note") + 1); - sprintf(path, "%s/%s.note", dir, uuid); - - free(dir); - - return path; + return dir; } static char *get_path(const char *uuid) { - return get_default_path(uuid); + const char *sdir; + char *path, *dir; + + sdir = settings_get_str(SETTINGS_KEY_NOTES_DIR); + + if (sdir == NULL || *sdir == '\0') { + dir = get_default_path(); + settings_set_str(SETTINGS_KEY_NOTES_DIR, dir); + } else { + dir = strdup(sdir); + } + + mkdirs(dir, 0777); + + path = malloc(strlen(dir) + 1 + strlen(uuid) + strlen(NOTE_SUF) + 1); + sprintf(path, "%s/%s%s", dir, uuid, NOTE_SUF); + + free(dir); + + return path; } void note_put(const char *uuid, const char *note) diff --git a/src/settings.c b/src/settings.c index 2f617c6..be6e87c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -27,6 +27,7 @@ const char *SETTINGS_KEY_SPLITER_VERTICAL_POS = "spliter-vertical-pos"; const char *SETTINGS_KEY_SPLITER_HORIZONTAL_POS = "spliter-horizontal-pos"; const char *SETTINGS_KEY_TASKS_SORT_COL = "tasks-sort-col"; const char *SETTINGS_KEY_TASKS_SORT_ORDER = "tasks-sort-order"; +const char *SETTINGS_KEY_NOTES_DIR = "notes-dir"; const char * const SETTINGS_VISIBLE_COL_KEYS[] = { "tasktree-id-visible", @@ -66,3 +67,13 @@ void settings_set_boolean(const gchar *key, gboolean value) { g_settings_set_boolean(settings, key, value); } + +gchar *settings_get_str(const gchar *key) +{ + return g_settings_get_string(settings, key); +} + +void settings_set_str(const gchar *key, const gchar *value) +{ + g_settings_set_string(settings, key, value); +} diff --git a/src/settings.h b/src/settings.h index d15fd4d..8453c10 100644 --- a/src/settings.h +++ b/src/settings.h @@ -30,6 +30,7 @@ extern const char *SETTINGS_KEY_SPLITER_VERTICAL_POS; extern const char *SETTINGS_KEY_SPLITER_HORIZONTAL_POS; extern const char *SETTINGS_KEY_TASKS_SORT_COL; extern const char *SETTINGS_KEY_TASKS_SORT_ORDER; +extern const char *SETTINGS_KEY_NOTES_DIR; extern const char * const SETTINGS_VISIBLE_COL_KEYS[]; void settings_init(); @@ -38,5 +39,7 @@ gint settings_get_int(const gchar *key); void settings_set_int(const gchar *key, gint value); gboolean settings_get_boolean(const gchar *key); void settings_set_boolean(const gchar *key, gboolean value); +gchar *settings_get_str(const gchar *key); +void settings_set_str(const gchar *key, const gchar *value); #endif diff --git a/src/ui.c b/src/ui.c index 57e5ade..d28d87b 100644 --- a/src/ui.c +++ b/src/ui.c @@ -18,6 +18,8 @@ */ #include +#include + #include #include @@ -163,13 +165,13 @@ void quit_activate_cbk(GtkWidget *menu_item, gpointer data) log_fct_exit(); } - - void preferences_activate_cbk(GtkWidget *menu_item, gpointer data) { gint result; static GtkDialog *diag; GtkBuilder *builder; + GtkFileChooser *w_dir; + char *dir; builder = gtk_builder_new(); gtk_builder_add_from_file @@ -179,12 +181,23 @@ void preferences_activate_cbk(GtkWidget *menu_item, gpointer data) diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_preferences")); gtk_builder_connect_signals(builder, NULL); + w_dir = GTK_FILE_CHOOSER(gtk_builder_get_object(builder, + "dir_chooser")); + result = gtk_dialog_run(diag); - if (result == GTK_RESPONSE_ACCEPT) + if (result) { log_debug("preferences_activate_cbk(): accept"); - else + dir = gtk_file_chooser_get_filename(w_dir); + + if (dir) { + log_debug("preferences_activate_cbk(): path=%s", dir); + free(dir); + } + + } else { log_debug("preferences_activate_cbk(): cancel"); + } g_object_unref(G_OBJECT(builder)); -- 2.7.4