2014-04-07 10:42:10 +02:00
|
|
|
/* settings.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-07-21 01:12:13 +02:00
|
|
|
#include <libconfig.h>
|
2014-07-30 08:46:08 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
|
|
|
#include "configdir.h"
|
2014-07-21 01:12:13 +02:00
|
|
|
#include "notify.h"
|
2014-08-28 04:45:11 +02:00
|
|
|
#include "misc_tools.h"
|
2014-05-29 23:25:09 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2016-09-25 03:07:04 +02:00
|
|
|
#include "audio_device.h"
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2014-05-29 23:25:09 +02:00
|
|
|
|
2014-04-07 10:42:10 +02:00
|
|
|
#include "settings.h"
|
2014-06-22 02:18:23 +02:00
|
|
|
#include "line_info.h"
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-07-23 11:25:38 +02:00
|
|
|
#ifndef PACKAGE_DATADIR
|
2016-09-25 03:07:04 +02:00
|
|
|
#define PACKAGE_DATADIR "."
|
2014-07-23 11:25:38 +02:00
|
|
|
#endif
|
|
|
|
|
2014-08-27 05:21:32 +02:00
|
|
|
#define NO_SOUND "silent"
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
static struct ui_strings {
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *self;
|
|
|
|
const char *timestamps;
|
|
|
|
const char *time_format;
|
|
|
|
const char *timestamp_format;
|
|
|
|
const char *log_timestamp_format;
|
|
|
|
const char *alerts;
|
|
|
|
const char *bell_on_message;
|
|
|
|
const char *bell_on_filetrans;
|
|
|
|
const char *bell_on_filetrans_accept;
|
|
|
|
const char *bell_on_invite;
|
|
|
|
const char *native_colors;
|
|
|
|
const char *autolog;
|
|
|
|
const char *history_size;
|
|
|
|
const char *show_typing_self;
|
|
|
|
const char *show_typing_other;
|
|
|
|
const char *show_welcome_msg;
|
|
|
|
const char *show_connection_msg;
|
|
|
|
const char *nodeslist_update_freq;
|
2018-10-28 21:18:17 +01:00
|
|
|
const char *autosave_freq;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
|
|
|
const char *line_join;
|
|
|
|
const char *line_quit;
|
|
|
|
const char *line_alert;
|
|
|
|
const char *line_normal;
|
|
|
|
|
|
|
|
const char *mplex_away;
|
|
|
|
const char *mplex_away_note;
|
2014-07-21 01:12:13 +02:00
|
|
|
} ui_strings = {
|
|
|
|
"ui",
|
|
|
|
"timestamps",
|
2015-02-20 00:20:38 +01:00
|
|
|
"time_format",
|
|
|
|
"timestamp_format",
|
|
|
|
"log_timestamp_format",
|
2014-07-21 01:12:13 +02:00
|
|
|
"alerts",
|
2016-07-21 11:25:40 +02:00
|
|
|
"bell_on_message",
|
|
|
|
"bell_on_filetrans",
|
|
|
|
"bell_on_filetrans_accept",
|
|
|
|
"bell_on_invite",
|
2014-07-21 01:12:13 +02:00
|
|
|
"native_colors",
|
|
|
|
"autolog",
|
2014-07-30 02:10:28 +02:00
|
|
|
"history_size",
|
|
|
|
"show_typing_self",
|
|
|
|
"show_typing_other",
|
2014-09-19 07:06:18 +02:00
|
|
|
"show_welcome_msg",
|
2016-02-25 23:06:49 +01:00
|
|
|
"show_connection_msg",
|
2016-09-20 19:13:12 +02:00
|
|
|
"nodeslist_update_freq",
|
2018-10-28 21:18:17 +01:00
|
|
|
"autosave_freq",
|
2015-02-08 13:49:05 +01:00
|
|
|
"line_join",
|
|
|
|
"line_quit",
|
|
|
|
"line_alert",
|
|
|
|
"line_normal",
|
2015-02-26 22:51:20 +01:00
|
|
|
"mplex_away",
|
|
|
|
"mplex_away_note",
|
2014-04-07 10:42:10 +02:00
|
|
|
};
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
static void ui_defaults(struct user_settings *settings)
|
2014-04-08 23:20:21 +02:00
|
|
|
{
|
2014-07-21 01:12:13 +02:00
|
|
|
settings->timestamps = TIMESTAMPS_ON;
|
2015-02-20 00:20:38 +01:00
|
|
|
snprintf(settings->timestamp_format, sizeof(settings->timestamp_format), "%s", TIMESTAMP_DEFAULT);
|
|
|
|
snprintf(settings->log_timestamp_format, sizeof(settings->log_timestamp_format), "%s", LOG_TIMESTAMP_DEFAULT);
|
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
settings->autolog = AUTOLOG_OFF;
|
|
|
|
settings->alerts = ALERTS_ENABLED;
|
2016-07-21 11:25:40 +02:00
|
|
|
settings->bell_on_message = 0;
|
|
|
|
settings->bell_on_filetrans = 0;
|
|
|
|
settings->bell_on_filetrans_accept = 0;
|
|
|
|
settings->bell_on_invite = 0;
|
2014-07-21 01:12:13 +02:00
|
|
|
settings->colour_theme = DFLT_COLS;
|
|
|
|
settings->history_size = 700;
|
2014-07-30 02:10:28 +02:00
|
|
|
settings->show_typing_self = SHOW_TYPING_ON;
|
|
|
|
settings->show_typing_other = SHOW_TYPING_ON;
|
2014-09-19 07:06:18 +02:00
|
|
|
settings->show_welcome_msg = SHOW_WELCOME_MSG_ON;
|
2016-02-25 23:06:49 +01:00
|
|
|
settings->show_connection_msg = SHOW_CONNECTION_MSG_ON;
|
2016-09-21 18:51:57 +02:00
|
|
|
settings->nodeslist_update_freq = 7;
|
2018-10-28 21:18:17 +01:00
|
|
|
settings->autosave_freq = 600;
|
2015-02-08 13:49:05 +01:00
|
|
|
|
|
|
|
snprintf(settings->line_join, LINE_HINT_MAX + 1, "%s", LINE_JOIN);
|
|
|
|
snprintf(settings->line_quit, LINE_HINT_MAX + 1, "%s", LINE_QUIT);
|
|
|
|
snprintf(settings->line_alert, LINE_HINT_MAX + 1, "%s", LINE_ALERT);
|
|
|
|
snprintf(settings->line_normal, LINE_HINT_MAX + 1, "%s", LINE_NORMAL);
|
2015-02-26 22:51:20 +01:00
|
|
|
|
|
|
|
settings->mplex_away = MPLEX_ON;
|
2018-07-18 17:33:16 +02:00
|
|
|
snprintf(settings->mplex_away_note,
|
|
|
|
sizeof(settings->mplex_away_note),
|
|
|
|
"%s",
|
|
|
|
MPLEX_AWAY_NOTE);
|
2014-04-07 10:42:10 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
static const struct keys_strings {
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *self;
|
|
|
|
const char *next_tab;
|
|
|
|
const char *prev_tab;
|
|
|
|
const char *scroll_line_up;
|
|
|
|
const char *scroll_line_down;
|
|
|
|
const char *half_page_up;
|
|
|
|
const char *half_page_down;
|
|
|
|
const char *page_bottom;
|
|
|
|
const char *peer_list_up;
|
|
|
|
const char *peer_list_down;
|
|
|
|
const char *toggle_peerlist;
|
|
|
|
const char *toggle_pastemode;
|
2014-07-28 01:06:25 +02:00
|
|
|
} key_strings = {
|
2014-10-08 20:53:09 +02:00
|
|
|
"keys",
|
|
|
|
"next_tab",
|
|
|
|
"prev_tab",
|
|
|
|
"scroll_line_up",
|
|
|
|
"scroll_line_down",
|
|
|
|
"half_page_up",
|
|
|
|
"half_page_down",
|
|
|
|
"page_bottom",
|
|
|
|
"peer_list_up",
|
|
|
|
"peer_list_down",
|
2014-10-08 08:56:54 +02:00
|
|
|
"toggle_peerlist",
|
2016-02-28 21:53:33 +01:00
|
|
|
"toggle_paste_mode",
|
2014-07-28 01:06:25 +02:00
|
|
|
};
|
2014-07-29 03:40:06 +02:00
|
|
|
|
|
|
|
/* defines from toxic.h */
|
2016-09-25 03:07:04 +02:00
|
|
|
static void key_defaults(struct user_settings *settings)
|
2014-07-28 01:06:25 +02:00
|
|
|
{
|
2015-02-08 11:26:36 +01:00
|
|
|
settings->key_next_tab = T_KEY_NEXT;
|
|
|
|
settings->key_prev_tab = T_KEY_PREV;
|
|
|
|
settings->key_scroll_line_up = KEY_PPAGE;
|
|
|
|
settings->key_scroll_line_down = KEY_NPAGE;
|
|
|
|
settings->key_half_page_up = T_KEY_C_F;
|
|
|
|
settings->key_half_page_down = T_KEY_C_V;
|
|
|
|
settings->key_page_bottom = T_KEY_C_H;
|
|
|
|
settings->key_peer_list_up = T_KEY_C_LB;
|
|
|
|
settings->key_peer_list_down = T_KEY_C_RB;
|
2014-10-08 08:56:54 +02:00
|
|
|
settings->key_toggle_peerlist = T_KEY_C_B;
|
2016-02-28 21:53:33 +01:00
|
|
|
settings->key_toggle_pastemode = T_KEY_C_T;
|
2014-07-28 01:06:25 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
static const struct tox_strings {
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *self;
|
|
|
|
const char *download_path;
|
|
|
|
const char *chatlogs_path;
|
|
|
|
const char *avatar_path;
|
2017-05-17 02:31:23 +02:00
|
|
|
const char *autorun_path;
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *password_eval;
|
2014-07-21 01:12:13 +02:00
|
|
|
} tox_strings = {
|
|
|
|
"tox",
|
|
|
|
"download_path",
|
2014-08-27 05:21:32 +02:00
|
|
|
"chatlogs_path",
|
2014-09-26 09:10:44 +02:00
|
|
|
"avatar_path",
|
2017-05-17 02:31:23 +02:00
|
|
|
"autorun_path",
|
2016-01-19 22:45:52 +01:00
|
|
|
"password_eval",
|
2014-07-21 01:12:13 +02:00
|
|
|
};
|
2014-04-12 09:10:01 +02:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
static void tox_defaults(struct user_settings *settings)
|
2014-04-07 10:42:10 +02:00
|
|
|
{
|
2014-08-27 05:21:32 +02:00
|
|
|
strcpy(settings->download_path, "");
|
|
|
|
strcpy(settings->chatlogs_path, "");
|
2014-09-26 09:10:44 +02:00
|
|
|
strcpy(settings->avatar_path, "");
|
2017-05-24 01:12:53 +02:00
|
|
|
strcpy(settings->autorun_path, "");
|
2016-01-19 22:45:52 +01:00
|
|
|
strcpy(settings->password_eval, "");
|
2014-04-07 10:42:10 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
static const struct audio_strings {
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *self;
|
|
|
|
const char *input_device;
|
|
|
|
const char *output_device;
|
|
|
|
const char *VAD_treshold;
|
2014-07-21 01:12:13 +02:00
|
|
|
} audio_strings = {
|
|
|
|
"audio",
|
|
|
|
"input_device",
|
|
|
|
"output_device",
|
|
|
|
"VAD_treshold",
|
|
|
|
};
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
static void audio_defaults(struct user_settings *settings)
|
2014-06-22 02:18:23 +02:00
|
|
|
{
|
2014-07-21 01:12:13 +02:00
|
|
|
settings->audio_in_dev = 0;
|
|
|
|
settings->audio_out_dev = 0;
|
|
|
|
settings->VAD_treshold = 40.0;
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
2014-07-21 01:12:13 +02:00
|
|
|
#endif
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
|
|
|
static const struct sound_strings {
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *self;
|
|
|
|
const char *notif_error;
|
|
|
|
const char *self_log_in;
|
|
|
|
const char *self_log_out;
|
|
|
|
const char *user_log_in;
|
|
|
|
const char *user_log_out;
|
|
|
|
const char *call_incoming;
|
|
|
|
const char *call_outgoing;
|
|
|
|
const char *generic_message;
|
|
|
|
const char *transfer_pending;
|
|
|
|
const char *transfer_completed;
|
2014-07-21 01:12:13 +02:00
|
|
|
} sound_strings = {
|
|
|
|
"sounds",
|
2015-03-28 07:56:54 +01:00
|
|
|
"notif_error",
|
2014-07-21 01:12:13 +02:00
|
|
|
"self_log_in",
|
|
|
|
"self_log_out",
|
|
|
|
"user_log_in",
|
|
|
|
"user_log_out",
|
|
|
|
"call_incoming",
|
|
|
|
"call_outgoing",
|
|
|
|
"generic_message",
|
|
|
|
"transfer_pending",
|
|
|
|
"transfer_completed",
|
|
|
|
};
|
2014-06-22 02:18:23 +02:00
|
|
|
#endif
|
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
static int key_parse(const char **bind)
|
|
|
|
{
|
2014-07-29 03:40:06 +02:00
|
|
|
int len = strlen(*bind);
|
|
|
|
|
|
|
|
if (len > 5) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strncasecmp(*bind, "ctrl+", 5) == 0 && toupper(bind[0][5]) != 'M') { /* ctrl+m cannot be used */
|
2014-07-30 08:46:08 +02:00
|
|
|
return toupper(bind[0][5]) - 'A' + 1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strncasecmp(*bind, "tab", 3) == 0) {
|
2014-07-29 03:40:06 +02:00
|
|
|
return T_KEY_TAB;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strncasecmp(*bind, "page", 4) == 0) {
|
2014-07-29 03:40:06 +02:00
|
|
|
return len == 6 ? KEY_PPAGE : KEY_NPAGE;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
static void set_key_binding(int *key, const char **bind)
|
|
|
|
{
|
2016-05-01 20:57:46 +02:00
|
|
|
int code = key_parse(bind);
|
|
|
|
|
|
|
|
if (code != -1) {
|
|
|
|
*key = code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 00:14:06 +02:00
|
|
|
int settings_load(struct user_settings *s, const char *patharg)
|
2014-04-07 10:42:10 +02:00
|
|
|
{
|
2014-07-21 01:12:13 +02:00
|
|
|
config_t cfg[1];
|
|
|
|
config_setting_t *setting;
|
2014-08-27 20:30:06 +02:00
|
|
|
const char *str = NULL;
|
2015-02-08 11:26:36 +01:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
/* Load default settings */
|
|
|
|
ui_defaults(s);
|
|
|
|
tox_defaults(s);
|
2014-07-29 03:40:06 +02:00
|
|
|
key_defaults(s);
|
2014-08-31 20:17:33 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-07-21 01:12:13 +02:00
|
|
|
audio_defaults(s);
|
|
|
|
#endif
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
config_init(cfg);
|
2014-07-22 00:14:06 +02:00
|
|
|
|
|
|
|
char path[MAX_STR_SIZE];
|
|
|
|
|
|
|
|
/* use default config file path */
|
|
|
|
if (patharg == NULL) {
|
|
|
|
char *user_config_dir = get_user_config_dir();
|
|
|
|
snprintf(path, sizeof(path), "%s%stoxic.conf", user_config_dir, CONFIGDIR);
|
|
|
|
free(user_config_dir);
|
|
|
|
|
|
|
|
/* make sure path exists or is created on first time running */
|
2014-08-28 04:45:11 +02:00
|
|
|
if (!file_exists(path)) {
|
|
|
|
FILE *fp = fopen(path, "w");
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (fp == NULL) {
|
2014-07-22 00:14:06 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-22 00:14:06 +02:00
|
|
|
|
2014-08-28 04:45:11 +02:00
|
|
|
fclose(fp);
|
|
|
|
}
|
2014-07-22 00:14:06 +02:00
|
|
|
} else {
|
|
|
|
snprintf(path, sizeof(path), "%s", patharg);
|
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-07-22 00:14:06 +02:00
|
|
|
if (!config_read_file(cfg, path)) {
|
2014-07-21 01:12:13 +02:00
|
|
|
config_destroy(cfg);
|
2014-04-20 22:42:37 +02:00
|
|
|
return -1;
|
2014-04-08 00:16:38 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
/* ui */
|
|
|
|
if ((setting = config_lookup(cfg, ui_strings.self)) != NULL) {
|
|
|
|
config_setting_lookup_bool(setting, ui_strings.timestamps, &s->timestamps);
|
2015-02-20 00:20:38 +01:00
|
|
|
|
|
|
|
int time = 24;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_int(setting, ui_strings.time_format, &time)) {
|
2015-02-20 00:20:38 +01:00
|
|
|
if (time == 12) {
|
|
|
|
snprintf(s->timestamp_format, sizeof(s->timestamp_format), "%s", "%I:%M:%S %p");
|
|
|
|
snprintf(s->log_timestamp_format, sizeof(s->log_timestamp_format), "%s", "%Y/%m/%d [%I:%M:%S %p]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.timestamp_format, &str)) {
|
2015-02-20 00:20:38 +01:00
|
|
|
snprintf(s->timestamp_format, sizeof(s->timestamp_format), "%s", str);
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.log_timestamp_format, &str)) {
|
2015-02-20 00:20:38 +01:00
|
|
|
snprintf(s->log_timestamp_format, sizeof(s->log_timestamp_format), "%s", str);
|
|
|
|
}
|
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
|
2015-11-01 19:53:31 +01:00
|
|
|
|
2016-07-21 11:25:40 +02:00
|
|
|
if (config_setting_lookup_bool(setting, ui_strings.bell_on_message, &s->bell_on_message)) {
|
|
|
|
s->bell_on_message = s->bell_on_message ? NT_BEEP : 0;
|
2015-11-01 19:53:31 +01:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2016-07-21 11:25:40 +02:00
|
|
|
if (config_setting_lookup_bool(setting, ui_strings.bell_on_filetrans, &s->bell_on_filetrans)) {
|
|
|
|
s->bell_on_filetrans = s->bell_on_filetrans ? NT_BEEP : 0;
|
2015-11-01 19:53:31 +01:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2016-07-21 11:25:40 +02:00
|
|
|
if (config_setting_lookup_bool(setting, ui_strings.bell_on_filetrans_accept, &s->bell_on_filetrans_accept)) {
|
|
|
|
s->bell_on_filetrans_accept = s->bell_on_filetrans_accept ? NT_BEEP : 0;
|
2015-11-01 19:53:31 +01:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2016-07-21 11:25:40 +02:00
|
|
|
if (config_setting_lookup_bool(setting, ui_strings.bell_on_invite, &s->bell_on_invite)) {
|
|
|
|
s->bell_on_invite = s->bell_on_invite ? NT_BEEP : 0;
|
2015-11-01 19:53:31 +01:00
|
|
|
}
|
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
|
|
|
|
config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
|
2014-07-30 02:10:28 +02:00
|
|
|
config_setting_lookup_bool(setting, ui_strings.show_typing_self, &s->show_typing_self);
|
|
|
|
config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other);
|
2014-09-19 07:06:18 +02:00
|
|
|
config_setting_lookup_bool(setting, ui_strings.show_welcome_msg, &s->show_welcome_msg);
|
2016-02-25 23:06:49 +01:00
|
|
|
config_setting_lookup_bool(setting, ui_strings.show_connection_msg, &s->show_connection_msg);
|
2015-02-08 13:49:05 +01:00
|
|
|
|
2016-09-20 19:13:12 +02:00
|
|
|
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
|
|
|
|
config_setting_lookup_int(setting, ui_strings.nodeslist_update_freq, &s->nodeslist_update_freq);
|
2018-10-28 21:18:17 +01:00
|
|
|
config_setting_lookup_int(setting, ui_strings.autosave_freq, &s->autosave_freq);
|
2016-09-20 19:13:12 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.line_join, &str)) {
|
2015-02-08 13:49:05 +01:00
|
|
|
snprintf(s->line_join, sizeof(s->line_join), "%s", str);
|
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.line_quit, &str)) {
|
2015-02-08 13:49:05 +01:00
|
|
|
snprintf(s->line_quit, sizeof(s->line_quit), "%s", str);
|
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.line_alert, &str)) {
|
2015-02-08 13:49:05 +01:00
|
|
|
snprintf(s->line_alert, sizeof(s->line_alert), "%s", str);
|
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.line_normal, &str)) {
|
2015-02-08 13:49:05 +01:00
|
|
|
snprintf(s->line_normal, sizeof(s->line_normal), "%s", str);
|
|
|
|
}
|
2015-02-26 22:51:20 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
config_setting_lookup_bool(setting, ui_strings.mplex_away, &s->mplex_away);
|
2015-02-26 22:51:20 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, ui_strings.mplex_away_note, &str)) {
|
|
|
|
snprintf(s->mplex_away_note, sizeof(s->mplex_away_note), "%s", str);
|
2015-02-26 22:51:20 +01:00
|
|
|
}
|
2014-07-21 01:12:13 +02:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-08-27 05:21:32 +02:00
|
|
|
/* paths */
|
2014-07-21 01:12:13 +02:00
|
|
|
if ((setting = config_lookup(cfg, tox_strings.self)) != NULL) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, tox_strings.download_path, &str)) {
|
2014-08-27 05:21:32 +02:00
|
|
|
snprintf(s->download_path, sizeof(s->download_path), "%s", str);
|
|
|
|
int len = strlen(s->download_path);
|
|
|
|
|
|
|
|
/* make sure path ends with a '/' */
|
2018-07-18 17:33:16 +02:00
|
|
|
if (len >= sizeof(s->download_path) - 2) {
|
2014-08-27 05:21:32 +02:00
|
|
|
s->download_path[0] = '\0';
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (s->download_path[len - 1] != '/') {
|
2014-08-27 05:21:32 +02:00
|
|
|
strcat(&s->download_path[len - 1], "/");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-27 05:21:32 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, tox_strings.chatlogs_path, &str)) {
|
2014-08-27 05:21:32 +02:00
|
|
|
snprintf(s->chatlogs_path, sizeof(s->chatlogs_path), "%s", str);
|
|
|
|
int len = strlen(s->chatlogs_path);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (len >= sizeof(s->chatlogs_path) - 2) {
|
2014-08-27 05:21:32 +02:00
|
|
|
s->chatlogs_path[0] = '\0';
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (s->chatlogs_path[len - 1] != '/') {
|
2014-08-27 05:21:32 +02:00
|
|
|
strcat(&s->chatlogs_path[len - 1], "/");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-07 10:42:10 +02:00
|
|
|
}
|
2014-09-26 09:10:44 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, tox_strings.avatar_path, &str)) {
|
2014-09-26 09:10:44 +02:00
|
|
|
snprintf(s->avatar_path, sizeof(s->avatar_path), "%s", str);
|
2015-01-25 20:17:32 +01:00
|
|
|
int len = strlen(str);
|
2014-09-26 09:10:44 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (len >= sizeof(s->avatar_path)) {
|
2014-09-26 09:10:44 +02:00
|
|
|
s->avatar_path[0] = '\0';
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-26 09:10:44 +02:00
|
|
|
}
|
2016-01-19 22:45:52 +01:00
|
|
|
|
2017-05-17 02:31:23 +02:00
|
|
|
#ifdef PYTHON
|
2017-05-24 01:12:53 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, tox_strings.autorun_path, &str)) {
|
2017-05-17 02:31:23 +02:00
|
|
|
snprintf(s->autorun_path, sizeof(s->autorun_path), "%s", str);
|
|
|
|
int len = strlen(str);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (len >= sizeof(s->autorun_path) - 2) {
|
2017-05-17 02:31:23 +02:00
|
|
|
s->autorun_path[0] = '\0';
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (s->autorun_path[len - 1] != '/') {
|
2017-05-17 02:31:23 +02:00
|
|
|
strcat(&s->autorun_path[len - 1], "/");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2017-05-17 02:31:23 +02:00
|
|
|
}
|
2017-05-24 01:12:53 +02:00
|
|
|
|
2017-05-17 02:31:23 +02:00
|
|
|
#endif
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, tox_strings.password_eval, &str)) {
|
2016-01-19 22:45:52 +01:00
|
|
|
snprintf(s->password_eval, sizeof(s->password_eval), "%s", str);
|
|
|
|
int len = strlen(str);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (len >= sizeof(s->password_eval)) {
|
2016-01-19 22:45:52 +01:00
|
|
|
s->password_eval[0] = '\0';
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-01-19 22:45:52 +01:00
|
|
|
}
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
2014-07-30 02:10:28 +02:00
|
|
|
|
2015-02-08 11:26:36 +01:00
|
|
|
/* keys */
|
|
|
|
if ((setting = config_lookup(cfg, key_strings.self)) != NULL) {
|
2016-09-25 03:07:04 +02:00
|
|
|
const char *tmp = NULL;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.next_tab, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_next_tab, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.prev_tab, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_prev_tab, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_scroll_line_up, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_scroll_line_down, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.half_page_up, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_half_page_up, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.half_page_down, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_half_page_down, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.page_bottom, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_page_bottom, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_peer_list_up, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_peer_list_down, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.toggle_peerlist, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_toggle_peerlist, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (config_setting_lookup_string(setting, key_strings.toggle_pastemode, &tmp)) {
|
2016-05-01 20:57:46 +02:00
|
|
|
set_key_binding(&s->key_toggle_pastemode, &tmp);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-02-08 11:26:36 +01:00
|
|
|
}
|
2014-07-29 03:40:06 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
if ((setting = config_lookup(cfg, audio_strings.self)) != NULL) {
|
|
|
|
config_setting_lookup_int(setting, audio_strings.input_device, &s->audio_in_dev);
|
|
|
|
s->audio_in_dev = s->audio_in_dev < 0 || s->audio_in_dev > MAX_DEVICES ? 0 : s->audio_in_dev;
|
2015-02-08 11:26:36 +01:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
config_setting_lookup_int(setting, audio_strings.output_device, &s->audio_out_dev);
|
|
|
|
s->audio_out_dev = s->audio_out_dev < 0 || s->audio_out_dev > MAX_DEVICES ? 0 : s->audio_out_dev;
|
2015-02-08 11:26:36 +01:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
config_setting_lookup_float(setting, audio_strings.VAD_treshold, &s->VAD_treshold);
|
2015-02-08 11:26:36 +01:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
#endif
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
if ((setting = config_lookup(cfg, sound_strings.self)) != NULL) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if ((config_setting_lookup_string(setting, sound_strings.notif_error, &str) != CONFIG_TRUE) ||
|
|
|
|
!set_sound(notif_error, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2015-03-28 07:56:54 +01:00
|
|
|
set_sound(notif_error, PACKAGE_DATADIR "/sounds/ToxicError.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
2015-02-08 11:26:36 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.user_log_in, &str) ||
|
|
|
|
!set_sound(user_log_in, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ToxicContactOnline.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.user_log_out, &str) ||
|
|
|
|
!set_sound(user_log_out, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ToxicContactOffline.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.call_incoming, &str) ||
|
|
|
|
!set_sound(call_incoming, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-02 01:38:09 +02:00
|
|
|
set_sound(call_incoming, PACKAGE_DATADIR "/sounds/ToxicIncomingCall.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) ||
|
|
|
|
!set_sound(call_outgoing, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-02 01:38:09 +02:00
|
|
|
set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/ToxicOutgoingCall.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.generic_message, &str) ||
|
|
|
|
!set_sound(generic_message, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(generic_message, PACKAGE_DATADIR "/sounds/ToxicRecvMessage.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) ||
|
|
|
|
!set_sound(transfer_pending, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/ToxicTransferStart.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) ||
|
|
|
|
!set_sound(transfer_completed, str)) {
|
|
|
|
if (str && strcasecmp(str, NO_SOUND) != 0) {
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/ToxicTransferComplete.wav");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-23 20:59:36 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
} else {
|
2015-03-28 07:56:54 +01:00
|
|
|
set_sound(notif_error, PACKAGE_DATADIR "/sounds/ToxicError.wav");
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ToxicContactOnline.wav");
|
|
|
|
set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ToxicContactOffline.wav");
|
2014-10-02 01:38:09 +02:00
|
|
|
set_sound(call_incoming, PACKAGE_DATADIR "/sounds/ToxicIncomingCall.wav");
|
|
|
|
set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/ToxicOutgoingCall.wav");
|
2014-10-01 06:53:45 +02:00
|
|
|
set_sound(generic_message, PACKAGE_DATADIR "/sounds/ToxicRecvMessage.wav");
|
|
|
|
set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/ToxicTransferStart.wav");
|
|
|
|
set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/ToxicTransferComplete.wav");
|
2014-07-21 01:12:13 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
config_destroy(cfg);
|
2014-04-07 10:42:10 +02:00
|
|
|
return 0;
|
2014-07-23 11:25:38 +02:00
|
|
|
}
|