From 14bcdb42b729942729314c21fc5ff32605843b27 Mon Sep 17 00:00:00 2001 From: Kaian Date: Fri, 5 Aug 2016 11:50:13 +0200 Subject: [PATCH] options: set default savepath to current directory --- src/curses/ui_save.c | 16 +++++++++++----- src/option.c | 10 +++++++++- src/setting.c | 2 +- src/setting.h | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/curses/ui_save.c b/src/curses/ui_save.c index 87fa9f7..7f07024 100644 --- a/src/curses/ui_save.c +++ b/src/curses/ui_save.c @@ -54,7 +54,7 @@ void save_create(ui_t *ui) { save_info_t *info; - char savepath[128]; + char savepath[MAX_SETTING_LEN]; // Pause the capture while saving capture_set_paused(1); @@ -84,13 +84,19 @@ save_create(ui_t *ui) info->fields[FLD_SAVE_COUNT] = NULL; // Set fields options + field_opts_off(info->fields[FLD_SAVE_PATH], O_STATIC); field_opts_off(info->fields[FLD_SAVE_PATH], O_AUTOSKIP); + field_opts_off(info->fields[FLD_SAVE_FILE], O_STATIC); field_opts_off(info->fields[FLD_SAVE_FILE], O_AUTOSKIP); field_opts_off(info->fields[FLD_SAVE_ALL], O_AUTOSKIP); field_opts_off(info->fields[FLD_SAVE_SELECTED], O_AUTOSKIP); field_opts_off(info->fields[FLD_SAVE_DISPLAYED], O_AUTOSKIP); field_opts_off(info->fields[FLD_SAVE_MESSAGE], O_VISIBLE); + // Limit max save path and file length + set_max_field(info->fields[FLD_SAVE_PATH], MAX_SETTING_LEN); + set_max_field(info->fields[FLD_SAVE_FILE], MAX_SETTING_LEN); + // Change background of input fields set_field_back(info->fields[FLD_SAVE_PATH], A_UNDERLINE); set_field_back(info->fields[FLD_SAVE_FILE], A_UNDERLINE); @@ -204,7 +210,7 @@ save_info(ui_t *ui) int save_draw(ui_t *ui) { - char field_value[80]; + char field_value[MAX_SETTING_LEN]; // Get panel information save_info_t *info = save_info(ui); @@ -402,9 +408,9 @@ save_set_msg(ui_t *ui, sip_msg_t *msg) int save_to_file(ui_t *ui) { - char savepath[256]; - char savefile[256]; - char fullfile[512]; + char savepath[MAX_SETTING_LEN]; + char savefile[MAX_SETTING_LEN]; + char fullfile[MAX_SETTING_LEN*2]; sip_call_t *call = NULL; sip_msg_t *msg = NULL; pcap_dumper_t *pd = NULL; diff --git a/src/option.c b/src/option.c index 43914e3..87fe429 100644 --- a/src/option.c +++ b/src/option.c @@ -26,9 +26,11 @@ * @brief Source code of functions defined in option.h * */ +#include "config.h" #include #include #include +#include #include #include "keybinding.h" #include "option.h" @@ -50,9 +52,15 @@ init_options() // Custom user conf file char userconf[128]; char *home = getenv("HOME"); + char *pwd = get_current_dir_name(); + + // Defualt savepath is current directory + if (pwd) { + setting_set_value(SETTING_SAVEPATH, pwd); + free(pwd); + } // Initialize settings - setting_set_value(SETTING_SAVEPATH, home); setting_set_value(SETTING_FILTER_METHODS, "REGISTER,INVITE,SUBSCRIBE,NOTIFY,OPTIONS,PUBLISH,MESSAGE"); // Add Call list column options diff --git a/src/setting.c b/src/setting.c index 8f31a3d..88cf612 100644 --- a/src/setting.c +++ b/src/setting.c @@ -158,7 +158,7 @@ setting_set_value(int id, const char *value) if (strlen(value) < MAX_SETTING_LEN) { strcpy(sett->value, value); } else { - fprintf(stderr, "Setting value %s for %s is to long\n", sett->value, sett->name); + fprintf(stderr, "Setting value %s for %s is too long\n", sett->value, sett->name); exit(1); } } diff --git a/src/setting.h b/src/setting.h index eca0dd2..9d8c557 100644 --- a/src/setting.h +++ b/src/setting.h @@ -42,7 +42,7 @@ #define __SNGREP_SETTING_H //! Max setting value -#define MAX_SETTING_LEN 80 +#define MAX_SETTING_LEN 1024 //! Shorter declarartion of setting_option struct typedef struct setting_option setting_t;