1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-22 22:53:24 +01:00

add setting to set path for chatlogs

This commit is contained in:
Jfreegman 2014-08-26 23:21:32 -04:00
parent f2aa57c4fa
commit 7edcf6cb45
7 changed files with 76 additions and 36 deletions

View File

@ -126,11 +126,16 @@ Voice Activity Detection treshold\&. Float value\&. Recommended values are aroun
.PP
\fBtox\fR
.RS 4
Configuration related to file transfer\&.
Configuration related to paths\&.
.PP
\fBdownload_path\fR
.RS 4
Default path for downloads\&. String value\&. Absolute path where to store downloaded files
Default path for downloads\&. String value\&. Absolute path for downloaded files\&.
.RE
.PP
\fBchatlogs_path\fR
.RS 4
Default path for chatlogs\&. String value\&. Absolute path for chatlog files\&.
.RE
.RE
.PP

View File

@ -78,11 +78,14 @@ OPTIONS
around 40.0
*tox*::
Configuration related to file transfer.
Configuration related to paths.
*download_path*;;
Default path for downloads. String value. Absolute path where to store
downloaded files
Default path for downloads. String value. Absolute path for downloaded
files.
*chatlogs_path*;;
Default path for chatlogs. String value. Absolute path for chatlog files.
*sounds*::
Configuration related to notification sounds.

View File

@ -39,8 +39,11 @@ audio = {
};
tox = {
// where to store received files
//download_path="/home/USERNAME/Downloads/";
// Path for downloaded files
// download_path="/home/USERNAME/Downloads/";
// Path for chatlogs
// chatlogs_path="/home/USERNAME/toxic_chatlogs/";
};
// To disable a sound set the path to "silent"

View File

@ -42,15 +42,17 @@ void init_logging_session(char *name, const char *key, struct chatlog *log)
if (!valid_nick(name))
name = UNKNOWN_NAME;
const char *set_path = user_settings_->chatlogs_path;
char *user_config_dir = get_user_config_dir();
int path_len = strlen(user_config_dir) + strlen(LOGDIR) + strlen(name);
int path_len = strlen(set_path) + strlen(name) ? *set_path
: strlen(user_config_dir) + strlen(LOGDIR) + strlen(name);
/* use first 4 digits of key as log ident. If no key use a timestamp */
char ident[32];
if (key != NULL) {
path_len += (KEY_IDENT_DIGITS * 2 + 5);
sprintf(&ident[0], "%02X", key[0] & 0xff);
sprintf(&ident[2], "%02X", key[1] & 0xff);
ident[KEY_IDENT_DIGITS * 2 + 1] = '\0';
@ -66,7 +68,11 @@ void init_logging_session(char *name, const char *key, struct chatlog *log)
}
char log_path[MAX_STR_SIZE];
snprintf(log_path, MAX_STR_SIZE, "%s%s%s-%s.log", user_config_dir, LOGDIR, name, ident);
if (*set_path)
snprintf(log_path, sizeof(log_path), "%s%s-%s.log", set_path, name, ident);
else
snprintf(log_path, sizeof(log_path), "%s%s%s-%s.log", user_config_dir, LOGDIR, name, ident);
free(user_config_dir);

View File

@ -41,7 +41,9 @@
#define PACKAGE_DATADIR "."
#endif
const struct _ui_strings {
#define NO_SOUND "silent"
static struct _ui_strings {
const char* self;
const char* timestamps;
const char* alerts;
@ -75,7 +77,7 @@ static void ui_defaults(struct user_settings* settings)
settings->show_typing_other = SHOW_TYPING_ON;
}
const struct _keys_strings {
static const struct _keys_strings {
const char* self;
const char* next_tab;
const char* prev_tab;
@ -113,21 +115,24 @@ static void key_defaults(struct user_settings* settings)
settings->key_peer_list_down = T_KEY_C_RB;
}
const struct _tox_strings {
static const struct _tox_strings {
const char* self;
const char* download_path;
const char* chatlogs_path;
} tox_strings = {
"tox",
"download_path",
"chatlogs_path",
};
static void tox_defaults(struct user_settings* settings)
{
strcpy(settings->download_path, ""); /* explicitly set default to pwd */
strcpy(settings->download_path, "");
strcpy(settings->chatlogs_path, "");
}
#ifdef _AUDIO
const struct _audio_strings {
static const struct _audio_strings {
const char* self;
const char* input_device;
const char* output_device;
@ -148,7 +153,7 @@ static void audio_defaults(struct user_settings* settings)
#endif
#ifdef _SOUND_NOTIFY
const struct _sound_strings {
static const struct _sound_strings {
const char* self;
const char* error;
const char* self_log_in;
@ -246,24 +251,42 @@ int settings_load(struct user_settings *s, const char *patharg)
s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */
}
/* paths */
if ((setting = config_lookup(cfg, tox_strings.self)) != NULL) {
if ( config_setting_lookup_string(setting, tox_strings.download_path, &str) ) {
strcpy(s->download_path, str);
snprintf(s->download_path, sizeof(s->download_path), "%s", str);
int len = strlen(s->download_path);
/* make sure path ends with a '/' */
if (len >= sizeof(s->download_path) - 2)
s->download_path[0] = '\0';
else if (s->download_path[len - 1] != '/')
strcat(&s->download_path[len - 1], "/");
}
if ( config_setting_lookup_string(setting, tox_strings.chatlogs_path, &str) ) {
snprintf(s->chatlogs_path, sizeof(s->chatlogs_path), "%s", str);
int len = strlen(s->chatlogs_path);
if (len >= sizeof(s->chatlogs_path) - 2)
s->chatlogs_path[0] = '\0';
else if (s->chatlogs_path[len - 1] != '/')
strcat(&s->chatlogs_path[len - 1], "/");
}
}
/* keys */
if((setting = config_lookup(cfg, key_strings.self)) != NULL) {
if ((setting = config_lookup(cfg, key_strings.self)) != NULL) {
const char* tmp = NULL;
if(config_setting_lookup_string(setting, key_strings.next_tab, &tmp)) s->key_next_tab = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.prev_tab, &tmp)) s->key_prev_tab = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp)) s->key_scroll_line_up = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp)) s->key_scroll_line_down= key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.half_page_up, &tmp)) s->key_half_page_up = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.half_page_down, &tmp)) s->key_half_page_down = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.page_bottom, &tmp)) s->key_page_bottom = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp)) s->key_peer_list_up = key_parse(&tmp);
if(config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp)) s->key_peer_list_down = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.next_tab, &tmp)) s->key_next_tab = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.prev_tab, &tmp)) s->key_prev_tab = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp)) s->key_scroll_line_up = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp)) s->key_scroll_line_down= key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.half_page_up, &tmp)) s->key_half_page_up = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.half_page_down, &tmp)) s->key_half_page_down = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.page_bottom, &tmp)) s->key_page_bottom = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp)) s->key_peer_list_up = key_parse(&tmp);
if (config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp)) s->key_peer_list_down = key_parse(&tmp);
}
#ifdef _AUDIO

View File

@ -23,7 +23,7 @@
#ifndef _settings_h
#define _settings_h
#define NO_SOUND "silent"
#include <limits.h>
/* holds user setting values */
struct user_settings {
@ -36,7 +36,8 @@ struct user_settings {
int show_typing_self; /* boolean */
int show_typing_other; /* boolean */
char download_path[MAX_STR_SIZE];
char download_path[PATH_MAX];
char chatlogs_path[PATH_MAX];
int key_next_tab; /* character code */
int key_prev_tab; /* character code */

View File

@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <limits.h>
#include <tox/tox.h>
@ -180,7 +181,7 @@ static struct _init_messages {
int num;
} init_messages;
/* queues messages during init until prompt window is initialized. */
/* One-time queue for messages created during init. Do not use after program init. */
static void queue_init_message(const char *msg)
{
int i = init_messages.num;
@ -200,7 +201,7 @@ static void queue_init_message(const char *msg)
init_messages.msgs = new_msgs;
}
/* call this after messages have been printed to console and are no longer needed */
/* called after messages have been printed to console and are no longer needed */
static void cleanup_init_messages(void)
{
if (init_messages.num <= 0)
@ -214,15 +215,12 @@ static void cleanup_init_messages(void)
free(init_messages.msgs);
}
/* prints all init_messages and frees them */
static void print_init_messages(ToxWindow *toxwin)
{
int i;
for (i = 0; i < init_messages.num; ++i)
line_info_add(toxwin, NULL, NULL, NULL, SYS_MSG, 0, 0, init_messages.msgs[i]);
cleanup_init_messages();
}
static Tox *init_tox(void)
@ -645,7 +643,7 @@ static void parse_args(int argc, char *argv[])
queue_init_message("Config file not found");
else
fclose(conf_fp);
break;
case 'd':
@ -664,7 +662,7 @@ static void parse_args(int argc, char *argv[])
strcpy(BLOCK_FILE, optarg);
strcat(BLOCK_FILE, "-blocklist");
char tmp[48];
char tmp[PATH_MAX];
snprintf(tmp, sizeof(tmp), "Using '%s' data file", DATA_FILE);
queue_init_message(tmp);
break;
@ -852,6 +850,7 @@ int main(int argc, char *argv[])
queue_init_message("Failed to load user settings");
print_init_messages(prompt);
cleanup_init_messages();
uint64_t last_save = (uint64_t) time(NULL);
uint64_t looptimer = last_save;