1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00
profanity/src/config/preferences.c

896 lines
23 KiB
C
Raw Normal View History

/*
2012-05-10 02:29:48 +00:00
* preferences.c
*
2015-02-10 23:16:09 +00:00
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
*
2012-05-10 02:29:48 +00: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/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
2012-05-10 02:29:48 +00:00
*/
2013-02-02 20:55:58 +00:00
#include "config.h"
2012-05-10 02:37:24 +00:00
#include <stdlib.h>
2014-01-20 18:40:48 +00:00
#include <stdio.h>
2012-05-10 21:18:08 +00:00
#include <string.h>
2012-05-10 02:29:48 +00:00
#include <glib.h>
#include <glib/gstdio.h>
2013-02-02 22:18:08 +00:00
#include "common.h"
2013-02-02 20:55:58 +00:00
#include "log.h"
2013-02-02 22:18:08 +00:00
#include "preferences.h"
#include "tools/autocomplete.h"
2012-05-10 22:51:06 +00:00
2015-01-10 19:22:38 +00:00
// preference groups refer to the sections in .profrc, for example [ui]
2013-02-03 02:35:04 +00: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"
#define PREF_GROUP_ALIAS "alias"
#define PREF_GROUP_OTR "otr"
2015-06-21 20:42:58 +00:00
#define PREF_GROUP_PGP "pgp"
2013-02-03 02:35:04 +00:00
#define INPBLOCK_DEFAULT 1000
2014-12-21 18:15:29 +00:00
static gchar *prefs_loc;
static GKeyFile *prefs;
gint log_maxsize = 0;
2012-05-10 02:29:48 +00:00
static Autocomplete boolean_choice_ac;
2012-05-10 09:12:02 +00:00
static void _save_prefs(void);
2015-10-25 22:23:38 +00:00
static gchar* _get_preferences_file(void);
static const char* _get_group(preference_t pref);
static const char* _get_key(preference_t pref);
2013-02-03 02:51:15 +00:00
static gboolean _get_default_boolean(preference_t pref);
2015-10-25 22:23:38 +00:00
static char* _get_default_string(preference_t pref);
2012-05-10 09:02:03 +00:00
2012-07-24 22:19:48 +00:00
void
prefs_load(void)
2012-05-10 02:29:48 +00:00
{
GError *err;
2013-02-02 22:18:08 +00:00
prefs_loc = _get_preferences_file();
2012-05-10 02:29:48 +00:00
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
}
prefs = g_key_file_new();
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
NULL);
err = NULL;
2013-02-03 02:35:04 +00:00
log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
if (err) {
log_maxsize = 0;
g_error_free(err);
}
// move pre 0.4.8 autoaway.time to autoaway.awaytime
if (g_key_file_has_key(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL)) {
gint time = g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL);
g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.awaytime", time);
g_key_file_remove_key(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL);
}
// move pre 0.4.8 autoaway.message to autoaway.awaymessage
if (g_key_file_has_key(prefs, PREF_GROUP_PRESENCE, "autoaway.message", NULL)) {
char *message = g_key_file_get_string(prefs, PREF_GROUP_PRESENCE, "autoaway.message", NULL);
g_key_file_set_string(prefs, PREF_GROUP_PRESENCE, "autoaway.awaymessage", message);
g_key_file_remove_key(prefs, PREF_GROUP_PRESENCE, "autoaway.message", NULL);
prefs_free_string(message);
}
// migrate pre 0.4.8 time settings
if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) {
char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL);
char *val = NULL;
if (time) {
val = time;
} else {
val = "off";
}
g_key_file_set_string(prefs, PREF_GROUP_UI, "time.console", val);
g_key_file_set_string(prefs, PREF_GROUP_UI, "time.chat", val);
g_key_file_set_string(prefs, PREF_GROUP_UI, "time.muc", val);
g_key_file_set_string(prefs, PREF_GROUP_UI, "time.mucconfig", val);
g_key_file_set_string(prefs, PREF_GROUP_UI, "time.private", val);
g_key_file_set_string(prefs, PREF_GROUP_UI, "time.xmlconsole", val);
g_key_file_remove_key(prefs, PREF_GROUP_UI, "time", NULL);
2015-08-08 23:20:17 +00:00
prefs_free_string(time);
}
_save_prefs();
boolean_choice_ac = autocomplete_new();
2013-08-26 00:29:50 +00:00
autocomplete_add(boolean_choice_ac, "on");
autocomplete_add(boolean_choice_ac, "off");
2012-06-18 21:16:57 +00:00
}
void
prefs_close(void)
{
autocomplete_free(boolean_choice_ac);
g_key_file_free(prefs);
2014-01-20 18:40:48 +00:00
prefs = NULL;
}
2015-10-25 22:23:38 +00:00
char*
prefs_autocomplete_boolean_choice(const char *const prefix)
{
return autocomplete_complete(boolean_choice_ac, prefix, TRUE);
}
void
prefs_reset_boolean_choice(void)
{
autocomplete_reset(boolean_choice_ac);
2012-05-10 02:29:48 +00:00
}
2012-07-24 22:19:48 +00:00
gboolean
2013-02-03 02:35:04 +00:00
prefs_get_boolean(preference_t pref)
{
2013-02-03 02:35:04 +00: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-07-24 22:19:48 +00:00
void
2013-02-03 02:51:15 +00:00
prefs_set_boolean(preference_t pref, gboolean value)
{
2013-02-03 02:51:15 +00: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 09:02:03 +00:00
_save_prefs();
}
2015-10-25 22:23:38 +00:00
char*
2013-02-03 03:24:13 +00:00
prefs_get_string(preference_t pref)
{
2013-02-03 03:24:13 +00:00
const char *group = _get_group(pref);
const char *key = _get_key(pref);
char *def = _get_default_string(pref);
char *result = g_key_file_get_string(prefs, group, key, NULL);
if (result == NULL) {
if (def) {
2015-06-24 12:50:04 +00:00
return g_strdup(def);
} else {
return NULL;
}
2013-02-03 03:24:13 +00:00
} else {
return result;
}
}
void
prefs_free_string(char *pref)
{
if (pref) {
2015-06-24 12:50:04 +00:00
g_free(pref);
}
}
void
2013-02-03 03:24:13 +00:00
prefs_set_string(preference_t pref, char *value)
{
2013-02-03 03:24:13 +00: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);
}
_save_prefs();
}
gint
prefs_get_gone(void)
{
2013-02-03 02:35:04 +00:00
return g_key_file_get_integer(prefs, PREF_GROUP_CHATSTATES, "gone", NULL);
}
void
prefs_set_gone(gint value)
{
2013-02-03 02:35:04 +00:00
g_key_file_set_integer(prefs, PREF_GROUP_CHATSTATES, "gone", value);
_save_prefs();
}
gint
prefs_get_notify_remind(void)
{
2013-02-03 02:35:04 +00:00
return g_key_file_get_integer(prefs, PREF_GROUP_NOTIFICATIONS, "remind", NULL);
}
void
prefs_set_notify_remind(gint value)
{
2013-02-03 02:35:04 +00:00
g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "remind", value);
_save_prefs();
}
2012-11-11 21:44:55 +00:00
gint
prefs_get_max_log_size(void)
{
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-03 02:35:04 +00:00
g_key_file_set_integer(prefs, PREF_GROUP_LOGGING, "maxsize", value);
_save_prefs();
2012-11-11 21:44:55 +00:00
}
2015-10-25 22:23:38 +00:00
gint
prefs_get_inpblock(void)
2014-12-21 18:15:29 +00:00
{
int val = g_key_file_get_integer(prefs, PREF_GROUP_UI, "inpblock", NULL);
if (val == 0) {
return INPBLOCK_DEFAULT;
} else {
return val;
}
}
2015-10-25 22:23:38 +00:00
void
prefs_set_inpblock(gint value)
2014-12-21 18:15:29 +00:00
{
g_key_file_set_integer(prefs, PREF_GROUP_UI, "inpblock", value);
_save_prefs();
}
gint
prefs_get_priority(void)
{
2013-02-03 02:35:04 +00:00
return g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "priority", NULL);
}
gint
prefs_get_reconnect(void)
{
if (!g_key_file_has_key(prefs, PREF_GROUP_CONNECTION, "reconnect", NULL)) {
return 30;
} else {
return g_key_file_get_integer(prefs, PREF_GROUP_CONNECTION, "reconnect", NULL);
}
}
void
prefs_set_reconnect(gint value)
{
2013-02-03 02:35:04 +00:00
g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "reconnect", value);
_save_prefs();
}
gint
prefs_get_autoping(void)
{
2015-07-01 23:10:31 +00:00
if (!g_key_file_has_key(prefs, PREF_GROUP_CONNECTION, "autoping", NULL)) {
return 60;
} else {
return g_key_file_get_integer(prefs, PREF_GROUP_CONNECTION, "autoping", NULL);
}
}
void
prefs_set_autoping(gint value)
{
2013-02-03 02:35:04 +00:00
g_key_file_set_integer(prefs, PREF_GROUP_CONNECTION, "autoping", value);
_save_prefs();
}
2012-11-30 23:34:14 +00:00
gint
prefs_get_autoaway_time(void)
{
gint result = g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.awaytime", NULL);
2012-11-30 23:34:14 +00:00
if (result == 0) {
return 15;
} else {
return result;
}
}
gint
prefs_get_autoxa_time(void)
{
return g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.xatime", NULL);
}
2012-11-30 23:34:14 +00:00
void
prefs_set_autoaway_time(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.awaytime", value);
_save_prefs();
}
void
prefs_set_autoxa_time(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.xatime", value);
2012-11-30 23:34:14 +00:00
_save_prefs();
}
void
prefs_set_occupants_size(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_UI, "occupants.size", value);
_save_prefs();
}
gint
prefs_get_occupants_size(void)
{
gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "occupants.size", NULL);
if (result > 99 || result < 1) {
2015-02-24 22:53:57 +00:00
return 15;
} else {
return result;
}
}
void
prefs_set_roster_size(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.size", value);
_save_prefs();
}
gint
prefs_get_roster_size(void)
{
gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.size", NULL);
if (result > 99 || result < 1) {
2015-02-24 22:53:57 +00:00
return 25;
} else {
return result;
}
}
2015-08-26 00:06:10 +00:00
char
prefs_get_otr_char(void)
{
char result = '~';
char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_OTR, "otr.char", NULL);
if (!resultstr) {
result = '~';
} else {
result = resultstr[0];
}
free(resultstr);
return result;
}
void
prefs_set_otr_char(char ch)
{
char str[2];
str[0] = ch;
str[1] = '\0';
g_key_file_set_string(prefs, PREF_GROUP_OTR, "otr.char", str);
_save_prefs();
}
char
prefs_get_pgp_char(void)
{
char result = '~';
char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_PGP, "pgp.char", NULL);
if (!resultstr) {
result = '~';
} else {
result = resultstr[0];
}
free(resultstr);
return result;
}
void
prefs_set_pgp_char(char ch)
{
char str[2];
str[0] = ch;
str[1] = '\0';
g_key_file_set_string(prefs, PREF_GROUP_PGP, "pgp.char", str);
_save_prefs();
}
gboolean
2015-10-25 22:23:38 +00:00
prefs_add_alias(const char *const name, const char *const value)
{
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;
}
}
2015-10-25 22:23:38 +00:00
char*
prefs_get_alias(const char *const name)
{
return g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL);
}
gboolean
2015-10-25 22:23:38 +00:00
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);
}
2015-10-25 22:23:38 +00:00
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);
if (value) {
2014-06-18 20:36:09 +00:00
ProfAlias *alias = malloc(sizeof(struct prof_alias_t));
alias->name = strdup(name);
alias->value = strdup(value);
2014-06-18 20:36:09 +00:00
free(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 22:19:48 +00:00
static void
_save_prefs(void)
2012-05-10 09:02:03 +00:00
{
gsize g_data_size;
gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
gchar *xdg_config = xdg_get_config_home();
GString *base_str = g_string_new(xdg_config);
g_string_append(base_str, "/profanity/");
gchar *true_loc = get_file_or_linked(prefs_loc, base_str->str);
g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL);
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
g_free(xdg_config);
free(true_loc);
g_free(g_prefs_data);
g_string_free(base_str, TRUE);
}
2013-02-02 22:18:08 +00:00
2015-10-25 22:23:38 +00:00
static gchar*
2013-02-02 22:18:08 +00:00
_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-03 02:51:15 +00:00
2015-01-10 19:22:38 +00:00
// get the preference group for a specific preference
// for example the PREF_BEEP setting ("beep" in .profrc, see _get_key) belongs
// to the [ui] section.
2015-10-25 22:23:38 +00:00
static const char*
2013-02-03 02:51:15 +00:00
_get_group(preference_t pref)
{
switch (pref)
{
case PREF_SPLASH:
case PREF_BEEP:
case PREF_THEME:
case PREF_VERCHECK:
2015-01-12 00:43:42 +00:00
case PREF_TITLEBAR_SHOW:
case PREF_TITLEBAR_GOODBYE:
2013-02-03 02:51:15 +00:00
case PREF_FLASH:
case PREF_INTYPE:
case PREF_HISTORY:
2014-10-09 21:02:39 +00:00
case PREF_OCCUPANTS:
case PREF_OCCUPANTS_JID:
2013-02-03 02:51:15 +00:00
case PREF_STATUSES:
2014-01-19 16:17:34 +00:00
case PREF_STATUSES_CONSOLE:
case PREF_STATUSES_CHAT:
case PREF_STATUSES_MUC:
case PREF_MUC_PRIVILEGES:
case PREF_PRESENCE:
case PREF_WRAP:
2015-05-29 13:25:14 +00:00
case PREF_WINS_AUTO_TIDY:
case PREF_TIME_CONSOLE:
case PREF_TIME_CHAT:
case PREF_TIME_MUC:
case PREF_TIME_MUCCONFIG:
case PREF_TIME_PRIVATE:
case PREF_TIME_XMLCONSOLE:
2015-03-10 23:35:08 +00:00
case PREF_TIME_STATUSBAR:
2015-09-29 22:30:23 +00:00
case PREF_TIME_LASTACTIVITY:
case PREF_ROSTER:
case PREF_ROSTER_OFFLINE:
case PREF_ROSTER_RESOURCE:
2015-11-15 21:33:48 +00:00
case PREF_ROSTER_PRESENCE:
case PREF_ROSTER_STATUS:
case PREF_ROSTER_EMPTY:
case PREF_ROSTER_BY:
2015-11-17 23:37:33 +00:00
case PREF_ROSTER_ORDER:
2015-11-18 02:02:49 +00:00
case PREF_ROSTER_COUNT:
case PREF_ROSTER_PRIORITY:
case PREF_RESOURCE_TITLE:
case PREF_RESOURCE_MESSAGE:
2015-06-21 20:07:57 +00:00
case PREF_ENC_WARN:
case PREF_INPBLOCK_DYNAMIC:
case PREF_TLS_SHOW:
return PREF_GROUP_UI;
2013-02-03 02:51:15 +00:00
case PREF_STATES:
case PREF_OUTTYPE:
return PREF_GROUP_CHATSTATES;
2013-02-03 02:51:15 +00:00
case PREF_NOTIFY_TYPING:
case PREF_NOTIFY_TYPING_CURRENT:
2013-02-03 02:51:15 +00:00
case PREF_NOTIFY_MESSAGE:
case PREF_NOTIFY_MESSAGE_CURRENT:
case PREF_NOTIFY_MESSAGE_TEXT:
case PREF_NOTIFY_ROOM:
case PREF_NOTIFY_ROOM_CURRENT:
case PREF_NOTIFY_ROOM_TEXT:
case PREF_NOTIFY_INVITE:
case PREF_NOTIFY_SUB:
return PREF_GROUP_NOTIFICATIONS;
2013-02-03 02:51:15 +00:00
case PREF_CHLOG:
2013-05-04 23:16:10 +00:00
case PREF_GRLOG:
2014-04-13 19:41:11 +00:00
case PREF_LOG_ROTATE:
2014-04-13 20:56:35 +00:00
case PREF_LOG_SHARED:
return PREF_GROUP_LOGGING;
2013-02-03 02:51:15 +00:00
case PREF_AUTOAWAY_CHECK:
2013-02-03 03:24:13 +00:00
case PREF_AUTOAWAY_MODE:
case PREF_AUTOAWAY_MESSAGE:
case PREF_AUTOXA_MESSAGE:
2015-10-14 20:17:46 +00:00
case PREF_LASTACTIVITY:
return PREF_GROUP_PRESENCE;
case PREF_CONNECT_ACCOUNT:
case PREF_DEFAULT_ACCOUNT:
2015-02-02 10:10:05 +00:00
case PREF_CARBONS:
case PREF_RECEIPTS_SEND:
case PREF_RECEIPTS_REQUEST:
case PREF_TLS_CERTPATH:
return PREF_GROUP_CONNECTION;
case PREF_OTR_LOG:
case PREF_OTR_POLICY:
return PREF_GROUP_OTR;
2015-06-21 20:42:58 +00:00
case PREF_PGP_LOG:
return PREF_GROUP_PGP;
2013-02-03 02:51:15 +00:00
default:
return NULL;
}
}
2015-01-10 19:22:38 +00:00
// get the key used in .profrc for the preference
// for example the PREF_AUTOAWAY_MODE maps to "autoaway.mode" in .profrc
2015-10-25 22:23:38 +00:00
static const char*
2013-02-03 02:51:15 +00:00
_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";
2015-01-12 00:43:42 +00:00
case PREF_TITLEBAR_SHOW:
return "titlebar.show";
case PREF_TITLEBAR_GOODBYE:
return "titlebar.goodbye";
2013-02-03 02:51:15 +00:00
case PREF_FLASH:
return "flash";
case PREF_INTYPE:
return "intype";
case PREF_HISTORY:
return "history";
2015-02-02 10:10:05 +00:00
case PREF_CARBONS:
return "carbons";
case PREF_RECEIPTS_SEND:
return "receipts.send";
case PREF_RECEIPTS_REQUEST:
return "receipts.request";
2014-10-09 21:02:39 +00:00
case PREF_OCCUPANTS:
return "occupants";
case PREF_OCCUPANTS_JID:
return "occupants.jid";
case PREF_MUC_PRIVILEGES:
return "privileges";
2013-02-03 02:51:15 +00:00
case PREF_STATUSES:
return "statuses";
2014-01-19 16:17:34 +00:00
case PREF_STATUSES_CONSOLE:
return "statuses.console";
case PREF_STATUSES_CHAT:
return "statuses.chat";
case PREF_STATUSES_MUC:
return "statuses.muc";
2013-02-03 02:51:15 +00:00
case PREF_STATES:
return "enabled";
case PREF_OUTTYPE:
return "outtype";
case PREF_NOTIFY_TYPING:
return "typing";
case PREF_NOTIFY_TYPING_CURRENT:
return "typing.current";
2013-02-03 02:51:15 +00:00
case PREF_NOTIFY_MESSAGE:
return "message";
case PREF_NOTIFY_MESSAGE_CURRENT:
return "message.current";
case PREF_NOTIFY_MESSAGE_TEXT:
return "message.text";
case PREF_NOTIFY_ROOM:
return "room";
case PREF_NOTIFY_ROOM_CURRENT:
return "room.current";
case PREF_NOTIFY_ROOM_TEXT:
return "room.text";
case PREF_NOTIFY_INVITE:
return "invite";
case PREF_NOTIFY_SUB:
return "sub";
2013-02-03 02:51:15 +00:00
case PREF_CHLOG:
return "chlog";
2013-05-04 23:16:10 +00:00
case PREF_GRLOG:
return "grlog";
2013-02-03 02:51:15 +00:00
case PREF_AUTOAWAY_CHECK:
return "autoaway.check";
2013-02-03 03:24:13 +00:00
case PREF_AUTOAWAY_MODE:
return "autoaway.mode";
case PREF_AUTOAWAY_MESSAGE:
return "autoaway.awaymessage";
case PREF_AUTOXA_MESSAGE:
return "autoaway.xamessage";
case PREF_CONNECT_ACCOUNT:
return "account";
case PREF_DEFAULT_ACCOUNT:
return "defaccount";
2014-01-13 20:17:45 +00:00
case PREF_OTR_LOG:
return "log";
case PREF_OTR_POLICY:
return "policy";
2014-04-13 19:41:11 +00:00
case PREF_LOG_ROTATE:
return "rotate";
2014-04-13 20:56:35 +00:00
case PREF_LOG_SHARED:
return "shared";
case PREF_PRESENCE:
return "presence";
case PREF_WRAP:
return "wrap";
2015-05-29 13:25:14 +00:00
case PREF_WINS_AUTO_TIDY:
return "wins.autotidy";
case PREF_TIME_CONSOLE:
return "time.console";
case PREF_TIME_CHAT:
return "time.chat";
case PREF_TIME_MUC:
return "time.muc";
case PREF_TIME_MUCCONFIG:
return "time.mucconfig";
case PREF_TIME_PRIVATE:
return "time.private";
case PREF_TIME_XMLCONSOLE:
return "time.xmlconsole";
2015-03-10 23:35:08 +00:00
case PREF_TIME_STATUSBAR:
return "time.statusbar";
2015-09-29 22:30:23 +00:00
case PREF_TIME_LASTACTIVITY:
return "time.lastactivity";
case PREF_ROSTER:
return "roster";
case PREF_ROSTER_OFFLINE:
return "roster.offline";
case PREF_ROSTER_RESOURCE:
return "roster.resource";
2015-11-15 21:33:48 +00:00
case PREF_ROSTER_PRESENCE:
return "roster.presence";
case PREF_ROSTER_STATUS:
return "roster.status";
case PREF_ROSTER_EMPTY:
return "roster.empty";
case PREF_ROSTER_BY:
return "roster.by";
2015-11-17 23:37:33 +00:00
case PREF_ROSTER_ORDER:
return "roster.order";
2015-11-18 02:02:49 +00:00
case PREF_ROSTER_COUNT:
return "roster.count";
case PREF_ROSTER_PRIORITY:
return "roster.priority";
case PREF_RESOURCE_TITLE:
return "resource.title";
case PREF_RESOURCE_MESSAGE:
return "resource.message";
case PREF_INPBLOCK_DYNAMIC:
return "inpblock.dynamic";
2015-06-21 20:07:57 +00:00
case PREF_ENC_WARN:
return "enc.warn";
2015-06-21 20:42:58 +00:00
case PREF_PGP_LOG:
return "log";
case PREF_TLS_CERTPATH:
return "tls.certpath";
case PREF_TLS_SHOW:
return "tls.show";
2015-10-14 20:17:46 +00:00
case PREF_LASTACTIVITY:
return "lastactivity";
2013-02-03 02:51:15 +00:00
default:
return NULL;
}
}
2015-01-10 19:22:38 +00:00
// the default setting for a boolean type preference
// if it is not specified in .profrc
2013-02-03 02:51:15 +00:00
static gboolean
_get_default_boolean(preference_t pref)
{
switch (pref)
{
2015-06-21 20:07:57 +00:00
case PREF_ENC_WARN:
case PREF_AUTOAWAY_CHECK:
2014-04-13 19:41:11 +00:00
case PREF_LOG_ROTATE:
2014-04-13 20:56:35 +00:00
case PREF_LOG_SHARED:
2015-02-24 22:53:57 +00:00
case PREF_NOTIFY_MESSAGE:
case PREF_NOTIFY_MESSAGE_CURRENT:
case PREF_NOTIFY_ROOM_CURRENT:
2015-02-24 22:53:57 +00:00
case PREF_NOTIFY_TYPING:
case PREF_NOTIFY_TYPING_CURRENT:
2015-02-24 22:53:57 +00:00
case PREF_NOTIFY_SUB:
case PREF_NOTIFY_INVITE:
2014-08-09 18:00:59 +00:00
case PREF_SPLASH:
2014-10-09 21:02:39 +00:00
case PREF_OCCUPANTS:
case PREF_MUC_PRIVILEGES:
case PREF_PRESENCE:
case PREF_WRAP:
2015-05-29 13:25:14 +00:00
case PREF_WINS_AUTO_TIDY:
case PREF_INPBLOCK_DYNAMIC:
2015-02-24 22:53:57 +00:00
case PREF_RESOURCE_TITLE:
case PREF_RESOURCE_MESSAGE:
case PREF_ROSTER:
case PREF_ROSTER_OFFLINE:
case PREF_ROSTER_EMPTY:
2015-11-18 02:02:49 +00:00
case PREF_ROSTER_COUNT:
case PREF_ROSTER_PRIORITY:
case PREF_TLS_SHOW:
2015-10-14 20:17:46 +00:00
case PREF_LASTACTIVITY:
return TRUE;
2013-02-03 02:51:15 +00:00
default:
return FALSE;
}
}
2015-01-10 19:22:38 +00:00
// the default setting for a string type preference
// if it is not specified in .profrc
2015-10-25 22:23:38 +00:00
static char*
2013-02-03 03:24:13 +00:00
_get_default_string(preference_t pref)
{
switch (pref)
{
case PREF_AUTOAWAY_MODE:
return "off";
2014-05-24 15:46:05 +00:00
case PREF_NOTIFY_ROOM:
2015-02-24 22:53:57 +00:00
return "on";
2014-01-13 20:17:45 +00:00
case PREF_OTR_LOG:
return "redact";
case PREF_OTR_POLICY:
return "manual";
2014-01-19 17:20:31 +00:00
case PREF_STATUSES_CONSOLE:
case PREF_STATUSES_CHAT:
case PREF_STATUSES_MUC:
2014-01-19 17:20:31 +00:00
return "all";
case PREF_ROSTER_BY:
2015-02-24 22:53:57 +00:00
return "presence";
2015-11-17 23:37:33 +00:00
case PREF_ROSTER_ORDER:
return "presence";
case PREF_TIME_CONSOLE:
return "%H:%M:%S";
case PREF_TIME_CHAT:
return "%H:%M:%S";
case PREF_TIME_MUC:
return "%H:%M:%S";
case PREF_TIME_MUCCONFIG:
return "%H:%M:%S";
case PREF_TIME_PRIVATE:
return "%H:%M:%S";
case PREF_TIME_XMLCONSOLE:
return "%H:%M:%S";
2015-03-10 23:35:08 +00:00
case PREF_TIME_STATUSBAR:
2015-05-30 00:53:37 +00:00
return "%H:%M";
2015-09-29 22:30:23 +00:00
case PREF_TIME_LASTACTIVITY:
return "%d/%m/%y %H:%M:%S";
2015-06-21 20:42:58 +00:00
case PREF_PGP_LOG:
return "redact";
2013-02-03 03:24:13 +00:00
default:
return NULL;
}
2015-05-17 21:05:43 +00:00
}