2012-10-21 15:02:20 -04:00
|
|
|
/*
|
2012-05-09 22:29:48 -04:00
|
|
|
* preferences.c
|
|
|
|
*
|
2014-03-08 20:18:19 -05:00
|
|
|
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
|
2012-10-21 15:02:20 -04:00
|
|
|
*
|
2012-05-09 22:29:48 -04:00
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity 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.
|
|
|
|
*
|
|
|
|
* Profanity 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 Profanity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-02-02 15:55:58 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-05-09 22:37:24 -04:00
|
|
|
#include <stdlib.h>
|
2014-01-20 13:40:48 -05:00
|
|
|
#include <stdio.h>
|
2012-05-10 17:18:08 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-05-09 22:29:48 -04:00
|
|
|
#include <glib.h>
|
2013-01-02 15:27:37 -05:00
|
|
|
#ifdef HAVE_NCURSESW_NCURSES_H
|
|
|
|
#include <ncursesw/ncurses.h>
|
2013-01-03 19:35:54 -05:00
|
|
|
#elif HAVE_NCURSES_H
|
|
|
|
#include <ncurses.h>
|
2012-09-08 11:51:09 -04:00
|
|
|
#endif
|
2012-05-09 22:29:48 -04:00
|
|
|
|
2013-02-02 17:18:08 -05:00
|
|
|
#include "common.h"
|
2013-02-02 15:55:58 -05:00
|
|
|
#include "log.h"
|
2013-02-02 17:18:08 -05:00
|
|
|
#include "preferences.h"
|
2013-02-02 16:43:59 -05:00
|
|
|
#include "tools/autocomplete.h"
|
2012-05-10 18:51:06 -04:00
|
|
|
|
2013-02-02 21:35:04 -05:00
|
|
|
#define PREF_GROUP_LOGGING "logging"
|
|
|
|
#define PREF_GROUP_CHATSTATES "chatstates"
|
|
|
|
#define PREF_GROUP_UI "ui"
|
|
|
|
#define PREF_GROUP_NOTIFICATIONS "notifications"
|
|
|
|
#define PREF_GROUP_PRESENCE "presence"
|
|
|
|
#define PREF_GROUP_CONNECTION "connection"
|
2014-01-23 17:29:53 -05:00
|
|
|
#define PREF_GROUP_ALIAS "alias"
|
2013-02-02 21:35:04 -05:00
|
|
|
|
2012-11-25 16:40:49 -05:00
|
|
|
static gchar *prefs_loc;
|
2012-05-10 04:55:55 -04:00
|
|
|
static GKeyFile *prefs;
|
2012-11-12 04:13:03 -05:00
|
|
|
gint log_maxsize = 0;
|
2012-05-09 22:29:48 -04:00
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
static Autocomplete boolean_choice_ac;
|
2012-05-10 17:44:23 -04:00
|
|
|
|
2012-05-10 05:12:02 -04:00
|
|
|
static void _save_prefs(void);
|
2013-02-02 17:18:08 -05:00
|
|
|
static gchar * _get_preferences_file(void);
|
2013-02-02 21:51:15 -05:00
|
|
|
static const char * _get_group(preference_t pref);
|
|
|
|
static const char * _get_key(preference_t pref);
|
|
|
|
static gboolean _get_default_boolean(preference_t pref);
|
2013-02-02 22:24:13 -05:00
|
|
|
static char * _get_default_string(preference_t pref);
|
2012-05-10 05:02:03 -04:00
|
|
|
|
2012-07-24 18:19:48 -04:00
|
|
|
void
|
|
|
|
prefs_load(void)
|
2012-05-09 22:29:48 -04:00
|
|
|
{
|
2012-11-12 04:13:03 -05:00
|
|
|
GError *err;
|
|
|
|
|
2012-08-25 19:54:18 -04:00
|
|
|
log_info("Loading preferences");
|
2013-02-02 17:18:08 -05:00
|
|
|
prefs_loc = _get_preferences_file();
|
2012-05-09 22:29:48 -04:00
|
|
|
|
2012-05-10 04:55:55 -04:00
|
|
|
prefs = g_key_file_new();
|
2012-11-25 16:40:49 -05:00
|
|
|
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
|
2012-09-09 17:32:39 -04:00
|
|
|
NULL);
|
2012-05-10 17:44:23 -04:00
|
|
|
|
2012-11-12 04:13:03 -05:00
|
|
|
err = NULL;
|
2013-02-02 21:35:04 -05:00
|
|
|
log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
|
2012-11-12 04:13:03 -05:00
|
|
|
if (err != NULL) {
|
|
|
|
log_maxsize = 0;
|
|
|
|
g_error_free(err);
|
|
|
|
}
|
|
|
|
|
2013-01-24 20:11:49 -05:00
|
|
|
boolean_choice_ac = autocomplete_new();
|
2013-08-25 20:29:50 -04:00
|
|
|
autocomplete_add(boolean_choice_ac, "on");
|
|
|
|
autocomplete_add(boolean_choice_ac, "off");
|
2012-06-18 17:16:57 -04:00
|
|
|
}
|
|
|
|
|
2012-07-31 18:01:15 -04:00
|
|
|
void
|
|
|
|
prefs_close(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_free(boolean_choice_ac);
|
2012-07-31 18:01:15 -04:00
|
|
|
g_key_file_free(prefs);
|
2014-01-20 13:40:48 -05:00
|
|
|
prefs = NULL;
|
2012-07-31 18:01:15 -04:00
|
|
|
}
|
|
|
|
|
2012-10-22 17:15:06 -04:00
|
|
|
char *
|
|
|
|
prefs_autocomplete_boolean_choice(char *prefix)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
return autocomplete_complete(boolean_choice_ac, prefix);
|
2012-10-22 17:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_reset_boolean_choice(void)
|
|
|
|
{
|
2013-01-24 20:11:49 -05:00
|
|
|
autocomplete_reset(boolean_choice_ac);
|
2012-05-09 22:29:48 -04:00
|
|
|
}
|
2012-05-10 04:55:55 -04:00
|
|
|
|
2012-07-24 18:19:48 -04:00
|
|
|
gboolean
|
2013-02-02 21:35:04 -05:00
|
|
|
prefs_get_boolean(preference_t pref)
|
2012-05-10 04:55:55 -04:00
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
const char *group = _get_group(pref);
|
|
|
|
const char *key = _get_key(pref);
|
|
|
|
gboolean def = _get_default_boolean(pref);
|
|
|
|
|
|
|
|
if (!g_key_file_has_key(prefs, group, key, NULL)) {
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_key_file_get_boolean(prefs, group, key, NULL);
|
2012-05-10 04:55:55 -04:00
|
|
|
}
|
|
|
|
|
2012-07-24 18:19:48 -04:00
|
|
|
void
|
2013-02-02 21:51:15 -05:00
|
|
|
prefs_set_boolean(preference_t pref, gboolean value)
|
2012-05-10 04:55:55 -04:00
|
|
|
{
|
2013-02-02 21:51:15 -05:00
|
|
|
const char *group = _get_group(pref);
|
|
|
|
const char *key = _get_key(pref);
|
|
|
|
g_key_file_set_boolean(prefs, group, key, value);
|
2012-05-10 05:02:03 -04:00
|
|
|
_save_prefs();
|
2012-05-10 04:55:55 -04:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:24:13 -05:00
|
|
|
char *
|
|
|
|
prefs_get_string(preference_t pref)
|
2012-11-21 16:24:10 -05:00
|
|
|
{
|
2013-02-02 22:24:13 -05:00
|
|
|
const char *group = _get_group(pref);
|
|
|
|
const char *key = _get_key(pref);
|
|
|
|
char *def = _get_default_string(pref);
|
|
|
|
|
|
|
|
if (!g_key_file_has_key(prefs, group, key, NULL)) {
|
|
|
|
return def;
|
|
|
|
}
|
2013-02-03 18:46:20 -05:00
|
|
|
|
2013-02-02 22:24:13 -05:00
|
|
|
char *result = g_key_file_get_string(prefs, group, key, NULL);
|
|
|
|
|
|
|
|
if (result == NULL) {
|
|
|
|
return def;
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
2012-11-21 16:24:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-02 22:24:13 -05:00
|
|
|
prefs_set_string(preference_t pref, char *value)
|
2012-11-21 16:24:10 -05:00
|
|
|
{
|
2013-02-02 22:24:13 -05:00
|
|
|
const char *group = _get_group(pref);
|
|
|
|
const char *key = _get_key(pref);
|
|
|
|
if (value == NULL) {
|
|
|
|
g_key_file_remove_key(prefs, group, key, NULL);
|
|
|
|
} else {
|
|
|
|
g_key_file_set_string(prefs, group, key, value);
|
|
|
|
}
|
2012-11-21 16:24:10 -05:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2012-12-19 18:31:25 -05:00
|
|
|
gint
|
|
|
|
prefs_get_gone(void)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
return g_key_file_get_integer(prefs, PREF_GROUP_CHATSTATES, "gone", NULL);
|
2012-12-19 18:31:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_gone(gint value)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_CHATSTATES, "gone", value);
|
2012-12-19 18:31:25 -05:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2012-10-27 17:05:08 -04:00
|
|
|
gint
|
|
|
|
prefs_get_notify_remind(void)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
return g_key_file_get_integer(prefs, PREF_GROUP_NOTIFICATIONS, "remind", NULL);
|
2012-10-27 17:05:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_notify_remind(gint value)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "remind", value);
|
2012-08-15 19:50:32 -04:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2012-11-11 16:44:55 -05:00
|
|
|
gint
|
|
|
|
prefs_get_max_log_size(void)
|
|
|
|
{
|
2012-11-12 04:13:03 -05:00
|
|
|
if (log_maxsize < PREFS_MIN_LOG_SIZE)
|
|
|
|
return PREFS_MAX_LOG_SIZE;
|
|
|
|
else
|
|
|
|
return log_maxsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_max_log_size(gint value)
|
|
|
|
{
|
|
|
|
log_maxsize = value;
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_LOGGING, "maxsize", value);
|
2012-11-12 04:13:03 -05:00
|
|
|
_save_prefs();
|
2012-11-11 16:44:55 -05:00
|
|
|
}
|
|
|
|
|
2012-11-13 05:51:28 -05:00
|
|
|
gint
|
|
|
|
prefs_get_priority(void)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
return g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "priority", NULL);
|
2012-11-13 05:51:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_priority(gint value)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "priority", value);
|
2012-11-13 05:51:28 -05:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2012-11-24 21:14:38 -05:00
|
|
|
gint
|
|
|
|
prefs_get_reconnect(void)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
return g_key_file_get_integer(prefs, PREF_GROUP_CONNECTION, "reconnect", NULL);
|
2012-11-24 21:14:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_reconnect(gint value)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "reconnect", value);
|
2012-11-24 21:14:38 -05:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 -05:00
|
|
|
gint
|
|
|
|
prefs_get_autoping(void)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
return g_key_file_get_integer(prefs, PREF_GROUP_CONNECTION, "autoping", NULL);
|
2012-11-26 18:58:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_autoping(gint value)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "autoping", value);
|
2012-11-26 18:58:24 -05:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2012-11-30 18:34:14 -05:00
|
|
|
gint
|
|
|
|
prefs_get_autoaway_time(void)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
gint result = g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL);
|
2012-11-30 18:34:14 -05:00
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
return 15;
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_set_autoaway_time(gint value)
|
|
|
|
{
|
2013-02-02 21:35:04 -05:00
|
|
|
g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.time", value);
|
2012-11-30 18:34:14 -05:00
|
|
|
_save_prefs();
|
|
|
|
}
|
|
|
|
|
2014-01-23 17:38:12 -05:00
|
|
|
gboolean
|
2014-01-23 17:29:53 -05:00
|
|
|
prefs_add_alias(const char * const name, const char * const value)
|
|
|
|
{
|
2014-01-23 17:38:12 -05:00
|
|
|
if (g_key_file_has_key(prefs, PREF_GROUP_ALIAS, name, NULL)) {
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
g_key_file_set_string(prefs, PREF_GROUP_ALIAS, name, value);
|
|
|
|
_save_prefs();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-01-23 17:29:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
prefs_get_alias(const char * const name)
|
|
|
|
{
|
|
|
|
return g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
prefs_remove_alias(const char * const name)
|
|
|
|
{
|
|
|
|
if (!g_key_file_has_key(prefs, PREF_GROUP_ALIAS, name, NULL)) {
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
g_key_file_remove_key(prefs, PREF_GROUP_ALIAS, name, NULL);
|
|
|
|
_save_prefs();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
_alias_cmp(gconstpointer *p1, gconstpointer *p2)
|
|
|
|
{
|
|
|
|
ProfAlias *alias1 = (ProfAlias*)p1;
|
|
|
|
ProfAlias *alias2 = (ProfAlias*)p2;
|
|
|
|
|
|
|
|
return strcmp(alias1->name, alias2->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
prefs_get_aliases(void)
|
|
|
|
{
|
|
|
|
if (!g_key_file_has_group(prefs, PREF_GROUP_ALIAS)) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
GList *result = NULL;
|
|
|
|
gsize len;
|
|
|
|
gchar **keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL);
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
char *name = keys[i];
|
|
|
|
char *value = g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL);
|
|
|
|
|
|
|
|
ProfAlias *alias = malloc(sizeof(struct prof_alias_t));
|
|
|
|
alias->name = strdup(name);
|
|
|
|
alias->value = strdup(value);
|
|
|
|
|
|
|
|
result = g_list_insert_sorted(result, alias, (GCompareFunc)_alias_cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev(keys);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_free_alias(ProfAlias *alias)
|
|
|
|
{
|
|
|
|
FREE_SET_NULL(alias->name);
|
|
|
|
FREE_SET_NULL(alias->value);
|
|
|
|
FREE_SET_NULL(alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prefs_free_aliases(GList *aliases)
|
|
|
|
{
|
|
|
|
g_list_free_full(aliases, (GDestroyNotify)_free_alias);
|
|
|
|
}
|
|
|
|
|
2012-07-24 18:19:48 -04:00
|
|
|
static void
|
|
|
|
_save_prefs(void)
|
2012-05-10 05:02:03 -04:00
|
|
|
{
|
|
|
|
gsize g_data_size;
|
|
|
|
char *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
|
2012-11-25 16:40:49 -05:00
|
|
|
g_file_set_contents(prefs_loc, g_prefs_data, g_data_size, NULL);
|
2012-05-10 04:55:55 -04:00
|
|
|
}
|
2013-02-02 17:18:08 -05:00
|
|
|
|
|
|
|
static gchar *
|
|
|
|
_get_preferences_file(void)
|
|
|
|
{
|
|
|
|
gchar *xdg_config = xdg_get_config_home();
|
|
|
|
GString *prefs_file = g_string_new(xdg_config);
|
|
|
|
g_string_append(prefs_file, "/profanity/profrc");
|
|
|
|
gchar *result = strdup(prefs_file->str);
|
|
|
|
g_free(xdg_config);
|
|
|
|
g_string_free(prefs_file, TRUE);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2013-02-02 21:51:15 -05:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
_get_group(preference_t pref)
|
|
|
|
{
|
|
|
|
switch (pref)
|
|
|
|
{
|
|
|
|
case PREF_SPLASH:
|
|
|
|
case PREF_BEEP:
|
|
|
|
case PREF_THEME:
|
|
|
|
case PREF_VERCHECK:
|
2014-04-03 16:46:43 -04:00
|
|
|
case PREF_TITLEBAR:
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_FLASH:
|
|
|
|
case PREF_INTYPE:
|
|
|
|
case PREF_HISTORY:
|
|
|
|
case PREF_MOUSE:
|
|
|
|
case PREF_STATUSES:
|
2014-01-19 11:17:34 -05:00
|
|
|
case PREF_STATUSES_CONSOLE:
|
|
|
|
case PREF_STATUSES_CHAT:
|
|
|
|
case PREF_STATUSES_MUC:
|
2014-01-16 17:44:23 -05:00
|
|
|
case PREF_OTR_WARN:
|
2014-01-23 17:29:53 -05:00
|
|
|
return PREF_GROUP_UI;
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_STATES:
|
|
|
|
case PREF_OUTTYPE:
|
2014-01-23 17:29:53 -05:00
|
|
|
return PREF_GROUP_CHATSTATES;
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_NOTIFY_TYPING:
|
|
|
|
case PREF_NOTIFY_MESSAGE:
|
2013-04-22 18:48:23 -04:00
|
|
|
case PREF_NOTIFY_INVITE:
|
2013-04-27 18:46:49 -04:00
|
|
|
case PREF_NOTIFY_SUB:
|
2014-01-23 17:29:53 -05:00
|
|
|
return PREF_GROUP_NOTIFICATIONS;
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_CHLOG:
|
2013-05-04 19:16:10 -04:00
|
|
|
case PREF_GRLOG:
|
2014-01-13 15:17:45 -05:00
|
|
|
case PREF_OTR_LOG:
|
2014-04-13 15:41:11 -04:00
|
|
|
case PREF_LOG_ROTATE:
|
2014-04-13 16:56:35 -04:00
|
|
|
case PREF_LOG_SHARED:
|
2014-01-23 17:29:53 -05:00
|
|
|
return PREF_GROUP_LOGGING;
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_AUTOAWAY_CHECK:
|
2013-02-02 22:24:13 -05:00
|
|
|
case PREF_AUTOAWAY_MODE:
|
|
|
|
case PREF_AUTOAWAY_MESSAGE:
|
2014-01-23 17:29:53 -05:00
|
|
|
return PREF_GROUP_PRESENCE;
|
2013-11-07 18:04:12 -05:00
|
|
|
case PREF_CONNECT_ACCOUNT:
|
2014-01-23 17:29:53 -05:00
|
|
|
return PREF_GROUP_CONNECTION;
|
2013-02-02 21:51:15 -05:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_get_key(preference_t pref)
|
|
|
|
{
|
|
|
|
switch (pref)
|
|
|
|
{
|
|
|
|
case PREF_SPLASH:
|
|
|
|
return "splash";
|
|
|
|
case PREF_BEEP:
|
|
|
|
return "beep";
|
|
|
|
case PREF_THEME:
|
|
|
|
return "theme";
|
|
|
|
case PREF_VERCHECK:
|
|
|
|
return "vercheck";
|
2014-04-03 16:46:43 -04:00
|
|
|
case PREF_TITLEBAR:
|
|
|
|
return "titlebar";
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_FLASH:
|
|
|
|
return "flash";
|
|
|
|
case PREF_INTYPE:
|
|
|
|
return "intype";
|
|
|
|
case PREF_HISTORY:
|
|
|
|
return "history";
|
|
|
|
case PREF_MOUSE:
|
|
|
|
return "mouse";
|
|
|
|
case PREF_STATUSES:
|
|
|
|
return "statuses";
|
2014-01-19 11:17:34 -05:00
|
|
|
case PREF_STATUSES_CONSOLE:
|
|
|
|
return "statuses.console";
|
|
|
|
case PREF_STATUSES_CHAT:
|
|
|
|
return "statuses.chat";
|
|
|
|
case PREF_STATUSES_MUC:
|
|
|
|
return "statuses.muc";
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_STATES:
|
|
|
|
return "enabled";
|
|
|
|
case PREF_OUTTYPE:
|
|
|
|
return "outtype";
|
|
|
|
case PREF_NOTIFY_TYPING:
|
|
|
|
return "typing";
|
|
|
|
case PREF_NOTIFY_MESSAGE:
|
|
|
|
return "message";
|
2013-04-22 18:48:23 -04:00
|
|
|
case PREF_NOTIFY_INVITE:
|
|
|
|
return "invite";
|
2013-04-27 18:46:49 -04:00
|
|
|
case PREF_NOTIFY_SUB:
|
|
|
|
return "sub";
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_CHLOG:
|
|
|
|
return "chlog";
|
2013-05-04 19:16:10 -04:00
|
|
|
case PREF_GRLOG:
|
|
|
|
return "grlog";
|
2013-02-02 21:51:15 -05:00
|
|
|
case PREF_AUTOAWAY_CHECK:
|
|
|
|
return "autoaway.check";
|
2013-02-02 22:24:13 -05:00
|
|
|
case PREF_AUTOAWAY_MODE:
|
|
|
|
return "autoaway.mode";
|
|
|
|
case PREF_AUTOAWAY_MESSAGE:
|
|
|
|
return "autoaway.message";
|
2013-11-07 18:04:12 -05:00
|
|
|
case PREF_CONNECT_ACCOUNT:
|
|
|
|
return "account";
|
2014-01-13 15:17:45 -05:00
|
|
|
case PREF_OTR_LOG:
|
|
|
|
return "otr";
|
2014-01-16 17:44:23 -05:00
|
|
|
case PREF_OTR_WARN:
|
|
|
|
return "otr.warn";
|
2014-04-19 04:00:41 -04:00
|
|
|
case PREF_OTR_POLICY:
|
|
|
|
return "otr.policy";
|
2014-04-13 15:41:11 -04:00
|
|
|
case PREF_LOG_ROTATE:
|
|
|
|
return "rotate";
|
2014-04-13 16:56:35 -04:00
|
|
|
case PREF_LOG_SHARED:
|
|
|
|
return "shared";
|
2013-02-02 21:51:15 -05:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_get_default_boolean(preference_t pref)
|
|
|
|
{
|
|
|
|
switch (pref)
|
|
|
|
{
|
2014-04-03 16:46:43 -04:00
|
|
|
case PREF_TITLEBAR:
|
2014-01-16 17:44:23 -05:00
|
|
|
case PREF_OTR_WARN:
|
2014-04-03 16:46:43 -04:00
|
|
|
case PREF_AUTOAWAY_CHECK:
|
2014-04-13 15:41:11 -04:00
|
|
|
case PREF_LOG_ROTATE:
|
2014-04-13 16:56:35 -04:00
|
|
|
case PREF_LOG_SHARED:
|
2014-04-03 16:46:43 -04:00
|
|
|
return TRUE;
|
2013-02-02 21:51:15 -05:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:24:13 -05:00
|
|
|
static char *
|
|
|
|
_get_default_string(preference_t pref)
|
|
|
|
{
|
|
|
|
switch (pref)
|
|
|
|
{
|
|
|
|
case PREF_AUTOAWAY_MODE:
|
|
|
|
return "off";
|
2014-01-13 15:17:45 -05:00
|
|
|
case PREF_OTR_LOG:
|
|
|
|
return "redact";
|
2014-04-19 04:00:41 -04:00
|
|
|
case PREF_OTR_POLICY:
|
|
|
|
return "manual";
|
2014-01-19 12:20:31 -05:00
|
|
|
case PREF_STATUSES_CONSOLE:
|
|
|
|
case PREF_STATUSES_CHAT:
|
2014-03-15 18:25:15 -04:00
|
|
|
case PREF_STATUSES_MUC:
|
2014-01-19 12:20:31 -05:00
|
|
|
return "all";
|
2013-02-02 22:24:13 -05:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|