2011-02-24 06:14:30 +03:00
|
|
|
/* X-Chat
|
|
|
|
* Copyright (C) 1998 Peter Zelezny.
|
|
|
|
*
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
2012-12-23 23:36:54 +04:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2011-02-24 06:14:30 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2012-10-24 23:33:02 +04:00
|
|
|
#include "hexchat.h"
|
2011-02-24 06:14:30 +03:00
|
|
|
#include "cfgfiles.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "fe.h"
|
|
|
|
#include "text.h"
|
2012-10-24 23:33:02 +04:00
|
|
|
#include "hexchatc.h"
|
2012-10-31 01:13:40 +04:00
|
|
|
#include "typedef.h"
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-07-21 16:26:19 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#else
|
2011-12-11 20:34:02 +04:00
|
|
|
#include <unistd.h>
|
2012-07-13 18:38:39 +04:00
|
|
|
#define HEXCHAT_DIR "hexchat"
|
2011-02-24 06:14:30 +03:00
|
|
|
#endif
|
2011-12-11 20:34:02 +04:00
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
#define DEF_FONT "Monospace 9"
|
2012-09-01 18:12:40 +04:00
|
|
|
#define DEF_FONT_ALTER "Arial Unicode MS,Lucida Sans Unicode,MS Gothic,Unifont"
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2013-11-23 01:25:34 +04:00
|
|
|
const char * const languages[LANGUAGES_LENGTH] = {
|
2014-01-12 03:34:30 +04:00
|
|
|
"af", "sq", "am", "ast", "az", "eu", "be", "bg", "ca", "zh_CN", /* 0 .. 9 */
|
|
|
|
"zh_TW", "cs", "da", "nl", "en_GB", "en", "et", "fi", "fr", "gl", /* 10 .. 19 */
|
|
|
|
"de", "el", "gu", "hi", "hu", "id", "it", "ja_JP", "kn", "rw", /* 20 .. 29 */
|
|
|
|
"ko", "lv", "lt", "mk", "ml", "ms", "nb", "no", "pl", "pt", /* 30 .. 39 */
|
|
|
|
"pt_BR", "pa", "ru", "sr", "sk", "sl", "es", "sv", "th", "tr", /* 40 .. 49 */
|
|
|
|
"uk", "vi", "wa" /* 50 .. */
|
2013-06-08 05:34:01 +04:00
|
|
|
};
|
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
void
|
|
|
|
list_addentry (GSList ** list, char *cmd, char *name)
|
|
|
|
{
|
|
|
|
struct popup *pop;
|
2012-11-10 21:26:45 +04:00
|
|
|
size_t name_len;
|
|
|
|
size_t cmd_len = 1;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
/* remove <2.8.0 stuff */
|
|
|
|
if (!strcmp (cmd, "away") && !strcmp (name, "BACK"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cmd)
|
|
|
|
cmd_len = strlen (cmd) + 1;
|
|
|
|
name_len = strlen (name) + 1;
|
|
|
|
|
|
|
|
pop = malloc (sizeof (struct popup) + cmd_len + name_len);
|
|
|
|
pop->name = (char *) pop + sizeof (struct popup);
|
|
|
|
pop->cmd = pop->name + name_len;
|
|
|
|
|
|
|
|
memcpy (pop->name, name, name_len);
|
|
|
|
if (cmd)
|
|
|
|
memcpy (pop->cmd, cmd, cmd_len);
|
|
|
|
else
|
|
|
|
pop->cmd[0] = 0;
|
|
|
|
|
|
|
|
*list = g_slist_append (*list, pop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read it in from a buffer to our linked list */
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_load_from_data (GSList ** list, char *ibuf, int size)
|
|
|
|
{
|
|
|
|
char cmd[384];
|
|
|
|
char name[128];
|
|
|
|
char *buf;
|
|
|
|
int pnt = 0;
|
|
|
|
|
|
|
|
cmd[0] = 0;
|
|
|
|
name[0] = 0;
|
|
|
|
|
|
|
|
while (buf_get_line (ibuf, &buf, &pnt, size))
|
|
|
|
{
|
|
|
|
if (*buf != '#')
|
|
|
|
{
|
2012-06-16 15:01:47 +04:00
|
|
|
if (!g_ascii_strncasecmp (buf, "NAME ", 5))
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
safe_strcpy (name, buf + 5, sizeof (name));
|
|
|
|
}
|
2012-06-16 15:01:47 +04:00
|
|
|
else if (!g_ascii_strncasecmp (buf, "CMD ", 4))
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
safe_strcpy (cmd, buf + 4, sizeof (cmd));
|
|
|
|
if (*name)
|
|
|
|
{
|
|
|
|
list_addentry (list, cmd, name);
|
|
|
|
cmd[0] = 0;
|
|
|
|
name[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
list_loadconf (char *file, GSList ** list, char *defaultconf)
|
|
|
|
{
|
2012-11-03 21:24:25 +04:00
|
|
|
char *filebuf;
|
2011-02-24 06:14:30 +03:00
|
|
|
char *ibuf;
|
2012-11-03 21:24:25 +04:00
|
|
|
int fd;
|
2011-02-24 06:14:30 +03:00
|
|
|
struct stat st;
|
|
|
|
|
2013-05-04 20:21:48 +04:00
|
|
|
filebuf = g_build_filename (get_xdir (), file, NULL);
|
2012-11-03 21:24:25 +04:00
|
|
|
fd = g_open (filebuf, O_RDONLY | OFLAGS, 0);
|
|
|
|
g_free (filebuf);
|
|
|
|
|
|
|
|
if (fd == -1)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
if (defaultconf)
|
|
|
|
list_load_from_data (list, defaultconf, strlen (defaultconf));
|
|
|
|
return;
|
|
|
|
}
|
2012-11-03 21:24:25 +04:00
|
|
|
if (fstat (fd, &st) != 0)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
perror ("fstat");
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
ibuf = malloc (st.st_size);
|
2012-11-03 21:24:25 +04:00
|
|
|
read (fd, ibuf, st.st_size);
|
|
|
|
close (fd);
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
list_load_from_data (list, ibuf, st.st_size);
|
|
|
|
|
|
|
|
free (ibuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
list_free (GSList ** list)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
while (*list)
|
|
|
|
{
|
|
|
|
data = (void *) (*list)->data;
|
|
|
|
free (data);
|
|
|
|
*list = g_slist_remove (*list, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
list_delentry (GSList ** list, char *name)
|
|
|
|
{
|
|
|
|
struct popup *pop;
|
|
|
|
GSList *alist = *list;
|
|
|
|
|
|
|
|
while (alist)
|
|
|
|
{
|
|
|
|
pop = (struct popup *) alist->data;
|
2012-06-16 15:01:47 +04:00
|
|
|
if (!g_ascii_strcasecmp (name, pop->name))
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
*list = g_slist_remove (*list, pop);
|
|
|
|
free (pop);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
alist = alist->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2012-10-31 00:25:58 +04:00
|
|
|
cfg_get_str (char *cfg, const char *var, char *dest, int dest_len)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2011-12-02 00:25:17 +04:00
|
|
|
char buffer[128]; /* should be plenty for a variable name */
|
|
|
|
|
|
|
|
sprintf (buffer, "%s ", var); /* add one space, this way it works against var - var2 checks too */
|
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
while (1)
|
|
|
|
{
|
2012-06-16 15:01:47 +04:00
|
|
|
if (!g_ascii_strncasecmp (buffer, cfg, strlen (var) + 1))
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
char *value, t;
|
|
|
|
cfg += strlen (var);
|
|
|
|
while (*cfg == ' ')
|
|
|
|
cfg++;
|
|
|
|
if (*cfg == '=')
|
|
|
|
cfg++;
|
|
|
|
while (*cfg == ' ')
|
|
|
|
cfg++;
|
|
|
|
/*while (*cfg == ' ' || *cfg == '=')
|
|
|
|
cfg++; */
|
|
|
|
value = cfg;
|
|
|
|
while (*cfg != 0 && *cfg != '\n')
|
|
|
|
cfg++;
|
|
|
|
t = *cfg;
|
|
|
|
*cfg = 0;
|
|
|
|
safe_strcpy (dest, value, dest_len);
|
|
|
|
*cfg = t;
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
while (*cfg != 0 && *cfg != '\n')
|
|
|
|
cfg++;
|
|
|
|
if (*cfg == 0)
|
|
|
|
return 0;
|
|
|
|
cfg++;
|
|
|
|
if (*cfg == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 04:43:45 +04:00
|
|
|
static int
|
2011-02-24 06:14:30 +03:00
|
|
|
cfg_put_str (int fh, char *var, char *value)
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
snprintf (buf, sizeof buf, "%s = %s\n", var, value);
|
|
|
|
len = strlen (buf);
|
|
|
|
return (write (fh, buf, len) == len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cfg_put_color (int fh, int r, int g, int b, char *var)
|
|
|
|
{
|
|
|
|
char buf[400];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
snprintf (buf, sizeof buf, "%s = %04x %04x %04x\n", var, r, g, b);
|
|
|
|
len = strlen (buf);
|
|
|
|
return (write (fh, buf, len) == len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cfg_put_int (int fh, int value, char *var)
|
|
|
|
{
|
|
|
|
char buf[400];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (value == -1)
|
|
|
|
value = 1;
|
|
|
|
|
|
|
|
snprintf (buf, sizeof buf, "%s = %d\n", var, value);
|
|
|
|
len = strlen (buf);
|
|
|
|
return (write (fh, buf, len) == len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cfg_get_color (char *cfg, char *var, int *r, int *g, int *b)
|
|
|
|
{
|
|
|
|
char str[128];
|
|
|
|
|
|
|
|
if (!cfg_get_str (cfg, var, str, sizeof (str)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sscanf (str, "%04x %04x %04x", r, g, b);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cfg_get_int_with_result (char *cfg, char *var, int *result)
|
|
|
|
{
|
|
|
|
char str[128];
|
|
|
|
|
|
|
|
if (!cfg_get_str (cfg, var, str, sizeof (str)))
|
|
|
|
{
|
|
|
|
*result = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = 1;
|
|
|
|
return atoi (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cfg_get_int (char *cfg, char *var)
|
|
|
|
{
|
|
|
|
char str[128];
|
|
|
|
|
|
|
|
if (!cfg_get_str (cfg, var, str, sizeof (str)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return atoi (str);
|
|
|
|
}
|
|
|
|
|
2012-11-03 21:24:25 +04:00
|
|
|
char *xdir = NULL; /* utf-8 encoding */
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2014-04-21 20:58:04 +04:00
|
|
|
#include <Windows.h>
|
|
|
|
#include <ShlObj.h>
|
2012-11-05 00:40:59 +04:00
|
|
|
#endif
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
char *
|
2012-11-03 21:24:25 +04:00
|
|
|
get_xdir (void)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2012-11-03 21:24:25 +04:00
|
|
|
if (!xdir)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2014-04-21 20:58:04 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
xdir = g_build_filename (g_get_user_config_dir (), HEXCHAT_DIR, NULL);
|
|
|
|
#else
|
|
|
|
wchar_t* roaming_path_wide;
|
|
|
|
gchar* roaming_path;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2014-04-21 20:58:04 +04:00
|
|
|
if (portable_mode () || SHGetKnownFolderPath (&FOLDERID_RoamingAppData, 0, NULL, &roaming_path_wide) != S_OK)
|
2012-11-05 00:40:59 +04:00
|
|
|
{
|
2013-10-27 20:51:14 +04:00
|
|
|
char *path;
|
|
|
|
char file[MAX_PATH];
|
|
|
|
HMODULE hModule;
|
|
|
|
|
|
|
|
hModule = GetModuleHandle (NULL);
|
|
|
|
if (GetModuleFileName (hModule, file, sizeof(file)))
|
|
|
|
{
|
|
|
|
path = g_path_get_dirname (file);
|
|
|
|
xdir = g_build_filename (path, "config", NULL);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xdir = g_strdup (".\\config");
|
2012-11-05 00:40:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-21 20:58:04 +04:00
|
|
|
roaming_path = g_utf16_to_utf8 (roaming_path_wide, -1, NULL, NULL, NULL);
|
|
|
|
CoTaskMemFree (roaming_path_wide);
|
|
|
|
|
|
|
|
xdir = g_build_filename (roaming_path, "HexChat", NULL);
|
|
|
|
|
|
|
|
g_free (roaming_path);
|
2012-11-05 00:40:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-11-03 21:24:25 +04:00
|
|
|
return xdir;
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
int
|
|
|
|
check_config_dir (void)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2013-05-13 04:58:08 +04:00
|
|
|
return g_access (get_xdir (), F_OK);
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
default_file (void)
|
|
|
|
{
|
2012-11-03 21:24:25 +04:00
|
|
|
static char *dfile = NULL;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
if (!dfile)
|
|
|
|
{
|
2013-05-04 20:21:48 +04:00
|
|
|
dfile = g_build_filename (get_xdir (), "hexchat.conf", NULL);
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
return dfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep these sorted!! */
|
|
|
|
|
2012-10-22 14:10:55 +04:00
|
|
|
const struct prefs vars[] =
|
|
|
|
{
|
2012-10-22 11:53:28 +04:00
|
|
|
{"away_auto_unmark", P_OFFINT (hex_away_auto_unmark), TYPE_BOOL},
|
|
|
|
{"away_omit_alerts", P_OFFINT (hex_away_omit_alerts), TYPE_BOOL},
|
|
|
|
{"away_reason", P_OFFSET (hex_away_reason), TYPE_STR},
|
|
|
|
{"away_show_once", P_OFFINT (hex_away_show_once), TYPE_BOOL},
|
|
|
|
{"away_size_max", P_OFFINT (hex_away_size_max), TYPE_INT},
|
|
|
|
{"away_timeout", P_OFFINT (hex_away_timeout), TYPE_INT},
|
|
|
|
{"away_track", P_OFFINT (hex_away_track), TYPE_BOOL},
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 12:10:19 +04:00
|
|
|
{"completion_amount", P_OFFINT (hex_completion_amount), TYPE_INT},
|
|
|
|
{"completion_auto", P_OFFINT (hex_completion_auto), TYPE_BOOL},
|
|
|
|
{"completion_sort", P_OFFINT (hex_completion_sort), TYPE_INT},
|
|
|
|
{"completion_suffix", P_OFFSET (hex_completion_suffix), TYPE_STR},
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 14:10:55 +04:00
|
|
|
{"dcc_auto_chat", P_OFFINT (hex_dcc_auto_chat), TYPE_BOOL},
|
|
|
|
{"dcc_auto_recv", P_OFFINT (hex_dcc_auto_recv), TYPE_INT},
|
|
|
|
{"dcc_auto_resume", P_OFFINT (hex_dcc_auto_resume), TYPE_BOOL},
|
|
|
|
{"dcc_blocksize", P_OFFINT (hex_dcc_blocksize), TYPE_INT},
|
|
|
|
{"dcc_completed_dir", P_OFFSET (hex_dcc_completed_dir), TYPE_STR},
|
|
|
|
{"dcc_dir", P_OFFSET (hex_dcc_dir), TYPE_STR},
|
2011-12-11 20:34:02 +04:00
|
|
|
#ifndef WIN32
|
2012-10-22 14:10:55 +04:00
|
|
|
{"dcc_fast_send", P_OFFINT (hex_dcc_fast_send), TYPE_BOOL},
|
2011-12-11 20:34:02 +04:00
|
|
|
#endif
|
2012-10-22 14:10:55 +04:00
|
|
|
{"dcc_global_max_get_cps", P_OFFINT (hex_dcc_global_max_get_cps), TYPE_INT},
|
|
|
|
{"dcc_global_max_send_cps", P_OFFINT (hex_dcc_global_max_send_cps), TYPE_INT},
|
|
|
|
{"dcc_ip", P_OFFSET (hex_dcc_ip), TYPE_STR},
|
|
|
|
{"dcc_ip_from_server", P_OFFINT (hex_dcc_ip_from_server), TYPE_BOOL},
|
|
|
|
{"dcc_max_get_cps", P_OFFINT (hex_dcc_max_get_cps), TYPE_INT},
|
|
|
|
{"dcc_max_send_cps", P_OFFINT (hex_dcc_max_send_cps), TYPE_INT},
|
|
|
|
{"dcc_permissions", P_OFFINT (hex_dcc_permissions), TYPE_INT},
|
|
|
|
{"dcc_port_first", P_OFFINT (hex_dcc_port_first), TYPE_INT},
|
|
|
|
{"dcc_port_last", P_OFFINT (hex_dcc_port_last), TYPE_INT},
|
|
|
|
{"dcc_remove", P_OFFINT (hex_dcc_remove), TYPE_BOOL},
|
|
|
|
{"dcc_save_nick", P_OFFINT (hex_dcc_save_nick), TYPE_BOOL},
|
|
|
|
{"dcc_send_fillspaces", P_OFFINT (hex_dcc_send_fillspaces), TYPE_BOOL},
|
|
|
|
{"dcc_stall_timeout", P_OFFINT (hex_dcc_stall_timeout), TYPE_INT},
|
|
|
|
{"dcc_timeout", P_OFFINT (hex_dcc_timeout), TYPE_INT},
|
|
|
|
|
2012-10-22 14:20:47 +04:00
|
|
|
{"flood_ctcp_num", P_OFFINT (hex_flood_ctcp_num), TYPE_INT},
|
|
|
|
{"flood_ctcp_time", P_OFFINT (hex_flood_ctcp_time), TYPE_INT},
|
2012-10-22 22:00:08 +04:00
|
|
|
{"flood_msg_num", P_OFFINT (hex_flood_msg_num), TYPE_INT},
|
2012-10-22 14:20:47 +04:00
|
|
|
{"flood_msg_time", P_OFFINT (hex_flood_msg_time), TYPE_INT},
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_autoopen_chat", P_OFFINT (hex_gui_autoopen_chat), TYPE_BOOL},
|
|
|
|
{"gui_autoopen_dialog", P_OFFINT (hex_gui_autoopen_dialog), TYPE_BOOL},
|
|
|
|
{"gui_autoopen_recv", P_OFFINT (hex_gui_autoopen_recv), TYPE_BOOL},
|
|
|
|
{"gui_autoopen_send", P_OFFINT (hex_gui_autoopen_send), TYPE_BOOL},
|
|
|
|
{"gui_chanlist_maxusers", P_OFFINT (hex_gui_chanlist_maxusers), TYPE_INT},
|
|
|
|
{"gui_chanlist_minusers", P_OFFINT (hex_gui_chanlist_minusers), TYPE_INT},
|
|
|
|
{"gui_compact", P_OFFINT (hex_gui_compact), TYPE_BOOL},
|
|
|
|
{"gui_dialog_height", P_OFFINT (hex_gui_dialog_height), TYPE_INT},
|
|
|
|
{"gui_dialog_left", P_OFFINT (hex_gui_dialog_left), TYPE_INT},
|
|
|
|
{"gui_dialog_top", P_OFFINT (hex_gui_dialog_top), TYPE_INT},
|
2012-11-11 17:39:35 +04:00
|
|
|
{"gui_dialog_width", P_OFFINT (hex_gui_dialog_width), TYPE_INT},
|
2014-05-04 07:57:45 +04:00
|
|
|
{"gui_filesize_iec", P_OFFINT (hex_gui_filesize_iec), TYPE_BOOL},
|
2013-04-14 07:03:54 +04:00
|
|
|
{"gui_focus_omitalerts", P_OFFINT (hex_gui_focus_omitalerts), TYPE_BOOL},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_hide_menu", P_OFFINT (hex_gui_hide_menu), TYPE_BOOL},
|
2013-10-02 11:47:07 +04:00
|
|
|
{"gui_input_attr", P_OFFINT (hex_gui_input_attr), TYPE_BOOL},
|
2012-10-28 06:05:50 +04:00
|
|
|
{"gui_input_icon", P_OFFINT (hex_gui_input_icon), TYPE_BOOL},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_input_nick", P_OFFINT (hex_gui_input_nick), TYPE_BOOL},
|
|
|
|
{"gui_input_spell", P_OFFINT (hex_gui_input_spell), TYPE_BOOL},
|
|
|
|
{"gui_input_style", P_OFFINT (hex_gui_input_style), TYPE_BOOL},
|
|
|
|
{"gui_join_dialog", P_OFFINT (hex_gui_join_dialog), TYPE_BOOL},
|
|
|
|
{"gui_lagometer", P_OFFINT (hex_gui_lagometer), TYPE_INT},
|
|
|
|
{"gui_lang", P_OFFINT (hex_gui_lang), TYPE_INT},
|
|
|
|
{"gui_mode_buttons", P_OFFINT (hex_gui_mode_buttons), TYPE_BOOL},
|
2012-12-02 04:43:20 +04:00
|
|
|
{"gui_pane_divider_position", P_OFFINT (hex_gui_pane_divider_position), TYPE_INT},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_pane_left_size", P_OFFINT (hex_gui_pane_left_size), TYPE_INT},
|
|
|
|
{"gui_pane_right_size", P_OFFINT (hex_gui_pane_right_size), TYPE_INT},
|
|
|
|
{"gui_pane_right_size_min", P_OFFINT (hex_gui_pane_right_size_min), TYPE_INT},
|
|
|
|
{"gui_quit_dialog", P_OFFINT (hex_gui_quit_dialog), TYPE_BOOL},
|
2013-07-25 04:47:01 +04:00
|
|
|
{"gui_search_pos", P_OFFINT (hex_gui_search_pos), TYPE_INT},
|
2012-11-11 18:50:31 +04:00
|
|
|
/* {"gui_single", P_OFFINT (hex_gui_single), TYPE_BOOL}, */
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_slist_fav", P_OFFINT (hex_gui_slist_fav), TYPE_BOOL},
|
|
|
|
{"gui_slist_select", P_OFFINT (hex_gui_slist_select), TYPE_INT},
|
|
|
|
{"gui_slist_skip", P_OFFINT (hex_gui_slist_skip), TYPE_BOOL},
|
|
|
|
{"gui_tab_chans", P_OFFINT (hex_gui_tab_chans), TYPE_BOOL},
|
|
|
|
{"gui_tab_dialogs", P_OFFINT (hex_gui_tab_dialogs), TYPE_BOOL},
|
|
|
|
{"gui_tab_dots", P_OFFINT (hex_gui_tab_dots), TYPE_BOOL},
|
|
|
|
{"gui_tab_icons", P_OFFINT (hex_gui_tab_icons), TYPE_BOOL},
|
|
|
|
{"gui_tab_layout", P_OFFINT (hex_gui_tab_layout), TYPE_INT},
|
|
|
|
{"gui_tab_newtofront", P_OFFINT (hex_gui_tab_newtofront), TYPE_INT},
|
|
|
|
{"gui_tab_pos", P_OFFINT (hex_gui_tab_pos), TYPE_INT},
|
2013-10-09 02:16:10 +04:00
|
|
|
{"gui_tab_scrollchans", P_OFFINT (hex_gui_tab_scrollchans), TYPE_BOOL},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_tab_server", P_OFFINT (hex_gui_tab_server), TYPE_BOOL},
|
|
|
|
{"gui_tab_small", P_OFFINT (hex_gui_tab_small), TYPE_INT},
|
|
|
|
{"gui_tab_sort", P_OFFINT (hex_gui_tab_sort), TYPE_BOOL},
|
|
|
|
{"gui_tab_trunc", P_OFFINT (hex_gui_tab_trunc), TYPE_INT},
|
|
|
|
{"gui_tab_utils", P_OFFINT (hex_gui_tab_utils), TYPE_BOOL},
|
|
|
|
{"gui_throttlemeter", P_OFFINT (hex_gui_throttlemeter), TYPE_INT},
|
|
|
|
{"gui_topicbar", P_OFFINT (hex_gui_topicbar), TYPE_BOOL},
|
2013-09-27 07:24:27 +04:00
|
|
|
{"gui_transparency", P_OFFINT (hex_gui_transparency), TYPE_INT},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_tray", P_OFFINT (hex_gui_tray), TYPE_BOOL},
|
2012-12-21 04:39:52 +04:00
|
|
|
{"gui_tray_away", P_OFFINT (hex_gui_tray_away), TYPE_BOOL},
|
2012-12-21 04:53:58 +04:00
|
|
|
{"gui_tray_blink", P_OFFINT (hex_gui_tray_blink), TYPE_BOOL},
|
2012-11-10 22:29:12 +04:00
|
|
|
{"gui_tray_close", P_OFFINT (hex_gui_tray_close), TYPE_BOOL},
|
|
|
|
{"gui_tray_minimize", P_OFFINT (hex_gui_tray_minimize), TYPE_BOOL},
|
|
|
|
{"gui_tray_quiet", P_OFFINT (hex_gui_tray_quiet), TYPE_BOOL},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_ulist_buttons", P_OFFINT (hex_gui_ulist_buttons), TYPE_BOOL},
|
2013-03-10 02:57:06 +04:00
|
|
|
{"gui_ulist_color", P_OFFINT (hex_gui_ulist_color), TYPE_BOOL},
|
2012-10-22 20:59:45 +04:00
|
|
|
{"gui_ulist_count", P_OFFINT (hex_gui_ulist_count), TYPE_BOOL},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_ulist_doubleclick", P_OFFSET (hex_gui_ulist_doubleclick), TYPE_STR},
|
|
|
|
{"gui_ulist_hide", P_OFFINT (hex_gui_ulist_hide), TYPE_BOOL},
|
|
|
|
{"gui_ulist_icons", P_OFFINT (hex_gui_ulist_icons), TYPE_BOOL},
|
|
|
|
{"gui_ulist_pos", P_OFFINT (hex_gui_ulist_pos), TYPE_INT},
|
|
|
|
{"gui_ulist_resizable", P_OFFINT (hex_gui_ulist_resizable), TYPE_BOOL},
|
|
|
|
{"gui_ulist_show_hosts", P_OFFINT(hex_gui_ulist_show_hosts), TYPE_BOOL},
|
|
|
|
{"gui_ulist_sort", P_OFFINT (hex_gui_ulist_sort), TYPE_INT},
|
|
|
|
{"gui_ulist_style", P_OFFINT (hex_gui_ulist_style), TYPE_BOOL},
|
|
|
|
{"gui_url_mod", P_OFFINT (hex_gui_url_mod), TYPE_INT},
|
|
|
|
{"gui_usermenu", P_OFFINT (hex_gui_usermenu), TYPE_BOOL},
|
|
|
|
{"gui_win_height", P_OFFINT (hex_gui_win_height), TYPE_INT},
|
2013-09-20 01:52:17 +04:00
|
|
|
{"gui_win_fullscreen", P_OFFINT (hex_gui_win_fullscreen), TYPE_INT},
|
2012-10-22 15:49:28 +04:00
|
|
|
{"gui_win_left", P_OFFINT (hex_gui_win_left), TYPE_INT},
|
|
|
|
{"gui_win_modes", P_OFFINT (hex_gui_win_modes), TYPE_BOOL},
|
|
|
|
{"gui_win_save", P_OFFINT (hex_gui_win_save), TYPE_BOOL},
|
|
|
|
{"gui_win_state", P_OFFINT (hex_gui_win_state), TYPE_INT},
|
|
|
|
{"gui_win_swap", P_OFFINT (hex_gui_win_swap), TYPE_BOOL},
|
|
|
|
{"gui_win_top", P_OFFINT (hex_gui_win_top), TYPE_INT},
|
|
|
|
{"gui_win_ucount", P_OFFINT (hex_gui_win_ucount), TYPE_BOOL},
|
|
|
|
{"gui_win_width", P_OFFINT (hex_gui_win_width), TYPE_INT},
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 16:18:20 +04:00
|
|
|
{"identd", P_OFFINT (hex_identd), TYPE_BOOL},
|
|
|
|
|
|
|
|
{"input_balloon_chans", P_OFFINT (hex_input_balloon_chans), TYPE_BOOL},
|
|
|
|
{"input_balloon_hilight", P_OFFINT (hex_input_balloon_hilight), TYPE_BOOL},
|
|
|
|
{"input_balloon_priv", P_OFFINT (hex_input_balloon_priv), TYPE_BOOL},
|
|
|
|
{"input_balloon_time", P_OFFINT (hex_input_balloon_time), TYPE_INT},
|
|
|
|
{"input_beep_chans", P_OFFINT (hex_input_beep_chans), TYPE_BOOL},
|
|
|
|
{"input_beep_hilight", P_OFFINT (hex_input_beep_hilight), TYPE_BOOL},
|
|
|
|
{"input_beep_priv", P_OFFINT (hex_input_beep_priv), TYPE_BOOL},
|
|
|
|
{"input_command_char", P_OFFSET (hex_input_command_char), TYPE_STR},
|
|
|
|
{"input_filter_beep", P_OFFINT (hex_input_filter_beep), TYPE_BOOL},
|
|
|
|
{"input_flash_chans", P_OFFINT (hex_input_flash_chans), TYPE_BOOL},
|
|
|
|
{"input_flash_hilight", P_OFFINT (hex_input_flash_hilight), TYPE_BOOL},
|
|
|
|
{"input_flash_priv", P_OFFINT (hex_input_flash_priv), TYPE_BOOL},
|
|
|
|
{"input_perc_ascii", P_OFFINT (hex_input_perc_ascii), TYPE_BOOL},
|
|
|
|
{"input_perc_color", P_OFFINT (hex_input_perc_color), TYPE_BOOL},
|
|
|
|
{"input_tray_chans", P_OFFINT (hex_input_tray_chans), TYPE_BOOL},
|
|
|
|
{"input_tray_hilight", P_OFFINT (hex_input_tray_hilight), TYPE_BOOL},
|
|
|
|
{"input_tray_priv", P_OFFINT (hex_input_tray_priv), TYPE_BOOL},
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 16:50:36 +04:00
|
|
|
{"irc_auto_rejoin", P_OFFINT (hex_irc_auto_rejoin), TYPE_BOOL},
|
|
|
|
{"irc_ban_type", P_OFFINT (hex_irc_ban_type), TYPE_INT},
|
2013-06-24 23:13:18 +04:00
|
|
|
{"irc_cap_server_time", P_OFFINT (hex_irc_cap_server_time), TYPE_BOOL},
|
2012-10-22 16:50:36 +04:00
|
|
|
{"irc_conf_mode", P_OFFINT (hex_irc_conf_mode), TYPE_BOOL},
|
|
|
|
{"irc_extra_hilight", P_OFFSET (hex_irc_extra_hilight), TYPE_STR},
|
2014-05-06 21:22:09 +04:00
|
|
|
{"irc_hide_nickchange", P_OFFINT (hex_irc_hide_nickchange), TYPE_BOOL},
|
2012-10-22 16:50:36 +04:00
|
|
|
{"irc_hide_version", P_OFFINT (hex_irc_hide_version), TYPE_BOOL},
|
2013-10-18 07:43:58 +04:00
|
|
|
{"irc_hidehost", P_OFFINT (hex_irc_hidehost), TYPE_BOOL},
|
2012-10-22 16:50:36 +04:00
|
|
|
{"irc_id_ntext", P_OFFSET (hex_irc_id_ntext), TYPE_STR},
|
|
|
|
{"irc_id_ytext", P_OFFSET (hex_irc_id_ytext), TYPE_STR},
|
|
|
|
{"irc_invisible", P_OFFINT (hex_irc_invisible), TYPE_BOOL},
|
|
|
|
{"irc_join_delay", P_OFFINT (hex_irc_join_delay), TYPE_INT},
|
|
|
|
{"irc_logging", P_OFFINT (hex_irc_logging), TYPE_BOOL},
|
|
|
|
{"irc_logmask", P_OFFSET (hex_irc_logmask), TYPE_STR},
|
|
|
|
{"irc_nick1", P_OFFSET (hex_irc_nick1), TYPE_STR},
|
|
|
|
{"irc_nick2", P_OFFSET (hex_irc_nick2), TYPE_STR},
|
|
|
|
{"irc_nick3", P_OFFSET (hex_irc_nick3), TYPE_STR},
|
|
|
|
{"irc_nick_hilight", P_OFFSET (hex_irc_nick_hilight), TYPE_STR},
|
|
|
|
{"irc_no_hilight", P_OFFSET (hex_irc_no_hilight), TYPE_STR},
|
2013-03-10 02:09:38 +04:00
|
|
|
{"irc_notice_pos", P_OFFINT (hex_irc_notice_pos), TYPE_INT},
|
2012-10-22 16:50:36 +04:00
|
|
|
{"irc_part_reason", P_OFFSET (hex_irc_part_reason), TYPE_STR},
|
|
|
|
{"irc_quit_reason", P_OFFSET (hex_irc_quit_reason), TYPE_STR},
|
|
|
|
{"irc_raw_modes", P_OFFINT (hex_irc_raw_modes), TYPE_BOOL},
|
|
|
|
{"irc_real_name", P_OFFSET (hex_irc_real_name), TYPE_STR},
|
|
|
|
{"irc_servernotice", P_OFFINT (hex_irc_servernotice), TYPE_BOOL},
|
|
|
|
{"irc_skip_motd", P_OFFINT (hex_irc_skip_motd), TYPE_BOOL},
|
|
|
|
{"irc_user_name", P_OFFSET (hex_irc_user_name), TYPE_STR},
|
|
|
|
{"irc_wallops", P_OFFINT (hex_irc_wallops), TYPE_BOOL},
|
|
|
|
{"irc_who_join", P_OFFINT (hex_irc_who_join), TYPE_BOOL},
|
|
|
|
{"irc_whois_front", P_OFFINT (hex_irc_whois_front), TYPE_BOOL},
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 17:55:43 +04:00
|
|
|
{"net_auto_reconnect", P_OFFINT (hex_net_auto_reconnect), TYPE_BOOL},
|
2013-05-20 16:39:24 +04:00
|
|
|
#ifndef WIN32 /* FIXME fix reconnect crashes and remove this ifdef! */
|
2012-10-22 17:55:43 +04:00
|
|
|
{"net_auto_reconnectonfail", P_OFFINT (hex_net_auto_reconnectonfail), TYPE_BOOL},
|
2013-05-20 16:39:24 +04:00
|
|
|
#endif
|
2012-10-22 17:55:43 +04:00
|
|
|
{"net_bind_host", P_OFFSET (hex_net_bind_host), TYPE_STR},
|
|
|
|
{"net_ping_timeout", P_OFFINT (hex_net_ping_timeout), TYPE_INT},
|
|
|
|
{"net_proxy_auth", P_OFFINT (hex_net_proxy_auth), TYPE_BOOL},
|
|
|
|
{"net_proxy_host", P_OFFSET (hex_net_proxy_host), TYPE_STR},
|
|
|
|
{"net_proxy_pass", P_OFFSET (hex_net_proxy_pass), TYPE_STR},
|
|
|
|
{"net_proxy_port", P_OFFINT (hex_net_proxy_port), TYPE_INT},
|
|
|
|
{"net_proxy_type", P_OFFINT (hex_net_proxy_type), TYPE_INT},
|
|
|
|
{"net_proxy_use", P_OFFINT (hex_net_proxy_use), TYPE_INT},
|
|
|
|
{"net_proxy_user", P_OFFSET (hex_net_proxy_user), TYPE_STR},
|
|
|
|
{"net_reconnect_delay", P_OFFINT (hex_net_reconnect_delay), TYPE_INT},
|
|
|
|
{"net_throttle", P_OFFINT (hex_net_throttle), TYPE_BOOL},
|
|
|
|
|
|
|
|
{"notify_timeout", P_OFFINT (hex_notify_timeout), TYPE_INT},
|
|
|
|
{"notify_whois_online", P_OFFINT (hex_notify_whois_online), TYPE_BOOL},
|
|
|
|
|
|
|
|
{"perl_warnings", P_OFFINT (hex_perl_warnings), TYPE_BOOL},
|
|
|
|
|
|
|
|
{"stamp_log", P_OFFINT (hex_stamp_log), TYPE_BOOL},
|
|
|
|
{"stamp_log_format", P_OFFSET (hex_stamp_log_format), TYPE_STR},
|
|
|
|
{"stamp_text", P_OFFINT (hex_stamp_text), TYPE_BOOL},
|
|
|
|
{"stamp_text_format", P_OFFSET (hex_stamp_text_format), TYPE_STR},
|
|
|
|
|
|
|
|
{"text_autocopy_color", P_OFFINT (hex_text_autocopy_color), TYPE_BOOL},
|
|
|
|
{"text_autocopy_stamp", P_OFFINT (hex_text_autocopy_stamp), TYPE_BOOL},
|
|
|
|
{"text_autocopy_text", P_OFFINT (hex_text_autocopy_text), TYPE_BOOL},
|
|
|
|
{"text_background", P_OFFSET (hex_text_background), TYPE_STR},
|
|
|
|
{"text_color_nicks", P_OFFINT (hex_text_color_nicks), TYPE_BOOL},
|
|
|
|
{"text_font", P_OFFSET (hex_text_font), TYPE_STR},
|
|
|
|
{"text_font_main", P_OFFSET (hex_text_font_main), TYPE_STR},
|
|
|
|
{"text_font_alternative", P_OFFSET (hex_text_font_alternative), TYPE_STR},
|
|
|
|
{"text_indent", P_OFFINT (hex_text_indent), TYPE_BOOL},
|
|
|
|
{"text_max_indent", P_OFFINT (hex_text_max_indent), TYPE_INT},
|
|
|
|
{"text_max_lines", P_OFFINT (hex_text_max_lines), TYPE_INT},
|
|
|
|
{"text_replay", P_OFFINT (hex_text_replay), TYPE_BOOL},
|
|
|
|
{"text_search_case_match", P_OFFINT (hex_text_search_case_match), TYPE_BOOL},
|
|
|
|
{"text_search_highlight_all", P_OFFINT (hex_text_search_highlight_all), TYPE_BOOL},
|
|
|
|
{"text_search_follow", P_OFFINT (hex_text_search_follow), TYPE_BOOL},
|
|
|
|
{"text_search_regexp", P_OFFINT (hex_text_search_regexp), TYPE_BOOL},
|
|
|
|
{"text_show_marker", P_OFFINT (hex_text_show_marker), TYPE_BOOL},
|
|
|
|
{"text_show_sep", P_OFFINT (hex_text_show_sep), TYPE_BOOL},
|
|
|
|
{"text_spell_langs", P_OFFSET (hex_text_spell_langs), TYPE_STR},
|
|
|
|
{"text_stripcolor_msg", P_OFFINT (hex_text_stripcolor_msg), TYPE_BOOL},
|
|
|
|
{"text_stripcolor_replay", P_OFFINT (hex_text_stripcolor_replay), TYPE_BOOL},
|
|
|
|
{"text_stripcolor_topic", P_OFFINT (hex_text_stripcolor_topic), TYPE_BOOL},
|
|
|
|
{"text_thin_sep", P_OFFINT (hex_text_thin_sep), TYPE_BOOL},
|
|
|
|
{"text_transparent", P_OFFINT (hex_text_transparent), TYPE_BOOL},
|
|
|
|
{"text_wordwrap", P_OFFINT (hex_text_wordwrap), TYPE_BOOL},
|
|
|
|
|
|
|
|
{"url_grabber", P_OFFINT (hex_url_grabber), TYPE_BOOL},
|
|
|
|
{"url_grabber_limit", P_OFFINT (hex_url_grabber_limit), TYPE_INT},
|
|
|
|
{"url_logging", P_OFFINT (hex_url_logging), TYPE_BOOL},
|
2011-02-24 06:14:30 +03:00
|
|
|
{0, 0, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *
|
|
|
|
convert_with_fallback (const char *str, const char *fallback)
|
|
|
|
{
|
|
|
|
char *utf;
|
|
|
|
|
2014-04-21 19:08:18 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
/* On non-Windows, g_get_user_name and g_get_real_name return a string in system locale, so convert it to utf-8. */
|
|
|
|
utf = g_locale_to_utf8 (str, -1, NULL, NULL, 0);
|
|
|
|
|
2014-04-30 06:59:04 +04:00
|
|
|
g_free ((char*)str);
|
2014-04-21 19:08:18 +04:00
|
|
|
|
|
|
|
/* The returned string is NULL if conversion from locale to utf-8 failed for any reason. Return the fallback. */
|
2011-02-24 06:14:30 +03:00
|
|
|
if (!utf)
|
2014-04-21 19:08:18 +04:00
|
|
|
utf = g_strdup (fallback);
|
|
|
|
#else
|
|
|
|
/* On Windows, they return a string in utf-8, so don't do anything to it. The fallback isn't needed. */
|
|
|
|
utf = str;
|
|
|
|
#endif
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
return utf;
|
|
|
|
}
|
|
|
|
|
2013-06-08 05:34:01 +04:00
|
|
|
static int
|
2013-11-23 01:25:34 +04:00
|
|
|
find_language_number (const char * const lang)
|
2013-06-08 05:34:01 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < LANGUAGES_LENGTH; i++)
|
|
|
|
if (!strcmp (lang, languages[i]))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of the system language if found, or english otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_default_language (void)
|
|
|
|
{
|
|
|
|
const char *locale;
|
|
|
|
char *lang;
|
|
|
|
char *p;
|
|
|
|
int lang_no;
|
|
|
|
|
|
|
|
/* LC_ALL overrides LANG, so we must check it first */
|
|
|
|
locale = g_getenv ("LC_ALL");
|
|
|
|
|
|
|
|
if (!locale)
|
|
|
|
locale = g_getenv ("LANG") ? g_getenv ("LANG") : "en";
|
|
|
|
|
|
|
|
/* we might end up with something like "en_US.UTF-8". We will try to
|
|
|
|
* search for "en_US"; if it fails we search for "en".
|
|
|
|
*/
|
|
|
|
lang = g_strdup (locale);
|
|
|
|
|
|
|
|
if ((p = strchr (lang, '.')))
|
|
|
|
*p='\0';
|
|
|
|
|
|
|
|
lang_no = find_language_number (lang);
|
|
|
|
|
|
|
|
if (lang_no >= 0)
|
|
|
|
{
|
2013-06-08 06:14:24 +04:00
|
|
|
free (lang);
|
2013-06-08 05:34:01 +04:00
|
|
|
return lang_no;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = strchr (lang, '_')))
|
|
|
|
*p='\0';
|
|
|
|
|
|
|
|
lang_no = find_language_number (lang);
|
|
|
|
|
2013-06-08 06:14:24 +04:00
|
|
|
free (lang);
|
2013-06-08 05:34:01 +04:00
|
|
|
|
|
|
|
return lang_no >= 0 ? lang_no : find_language_number ("en");
|
|
|
|
}
|
|
|
|
|
2013-10-02 11:47:07 +04:00
|
|
|
static char *
|
|
|
|
get_default_spell_languages (void)
|
|
|
|
{
|
|
|
|
const gchar* const *langs = g_get_language_names ();
|
|
|
|
char *last = NULL;
|
|
|
|
char *p;
|
|
|
|
char lang_list[64];
|
|
|
|
char *ret = lang_list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (langs != NULL)
|
|
|
|
{
|
|
|
|
memset (lang_list, 0, sizeof(lang_list));
|
|
|
|
|
|
|
|
for (i = 0; langs[i]; i++)
|
|
|
|
{
|
|
|
|
if (g_ascii_strncasecmp (langs[i], "C", 1) != 0 && strlen (langs[i]) >= 2)
|
|
|
|
{
|
|
|
|
/* Avoid duplicates */
|
|
|
|
if (!last || !g_str_has_prefix (langs[i], last))
|
|
|
|
{
|
|
|
|
if (last != NULL)
|
|
|
|
{
|
|
|
|
g_free(last);
|
|
|
|
g_strlcat (lang_list, ",", sizeof(lang_list));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore .utf8 */
|
|
|
|
if ((p = strchr (langs[i], '.')))
|
|
|
|
*p='\0';
|
|
|
|
|
|
|
|
last = g_strndup (langs[i], 2);
|
|
|
|
|
|
|
|
g_strlcat (lang_list, langs[i], sizeof(lang_list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (last != NULL)
|
|
|
|
g_free(last);
|
|
|
|
|
|
|
|
if (lang_list[0])
|
2014-02-12 18:27:28 +04:00
|
|
|
return g_strdup (ret);
|
2013-10-02 11:47:07 +04:00
|
|
|
}
|
|
|
|
|
2014-02-12 18:27:28 +04:00
|
|
|
return g_strdup ("en");
|
2013-10-02 11:47:07 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
void
|
2013-05-13 04:58:08 +04:00
|
|
|
load_default_config(void)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2014-02-12 18:27:28 +04:00
|
|
|
const char *username, *realname, *font, *langs;
|
2013-05-13 04:58:08 +04:00
|
|
|
char *sp;
|
2012-10-22 22:00:08 +04:00
|
|
|
#ifdef WIN32
|
2014-04-21 20:58:04 +04:00
|
|
|
wchar_t* roaming_path_wide;
|
|
|
|
gchar* roaming_path;
|
2012-10-22 22:00:08 +04:00
|
|
|
#endif
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
username = g_get_user_name ();
|
|
|
|
if (!username)
|
2014-04-21 19:08:18 +04:00
|
|
|
username = g_strdup ("root");
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-06-10 11:20:58 +04:00
|
|
|
/* We hid Real name from the Network List, so don't use the user's name unnoticeably */
|
|
|
|
/* realname = g_get_real_name ();
|
2011-02-24 06:14:30 +03:00
|
|
|
if ((realname && realname[0] == 0) || !realname)
|
2012-06-10 11:20:58 +04:00
|
|
|
realname = username; */
|
2014-04-21 19:08:18 +04:00
|
|
|
realname = g_strdup ("realname");
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
username = convert_with_fallback (username, "username");
|
|
|
|
realname = convert_with_fallback (realname, "realname");
|
|
|
|
|
2012-10-22 11:00:35 +04:00
|
|
|
memset (&prefs, 0, sizeof (struct hexchatprefs));
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
/* put in default values, anything left out is automatically zero */
|
2012-10-22 22:00:08 +04:00
|
|
|
|
|
|
|
/* BOOLEANS */
|
|
|
|
prefs.hex_away_show_once = 1;
|
2012-10-22 11:53:28 +04:00
|
|
|
prefs.hex_away_track = 1;
|
2012-10-22 14:10:55 +04:00
|
|
|
prefs.hex_dcc_auto_resume = 1;
|
2012-10-22 10:51:54 +04:00
|
|
|
#ifndef WIN32
|
2012-10-22 14:10:55 +04:00
|
|
|
prefs.hex_dcc_fast_send = 1;
|
2011-12-11 20:34:02 +04:00
|
|
|
#endif
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_autoopen_chat = 1;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_autoopen_dialog = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_autoopen_recv = 1;
|
|
|
|
prefs.hex_gui_autoopen_send = 1;
|
2014-01-13 02:00:26 +04:00
|
|
|
#ifdef HAVE_GTK_MAC
|
|
|
|
prefs.hex_gui_hide_menu = 1;
|
|
|
|
#endif
|
2013-10-02 11:47:07 +04:00
|
|
|
prefs.hex_gui_input_attr = 1;
|
2012-10-28 06:05:50 +04:00
|
|
|
prefs.hex_gui_input_icon = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_input_nick = 1;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_input_spell = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_input_style = 1;
|
|
|
|
prefs.hex_gui_join_dialog = 1;
|
|
|
|
prefs.hex_gui_quit_dialog = 1;
|
2012-10-28 01:46:37 +04:00
|
|
|
/* prefs.hex_gui_slist_skip = 1; */
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_tab_chans = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_tab_dialogs = 1;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_tab_icons = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_tab_server = 1;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_tab_sort = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_topicbar = 1;
|
2013-09-27 07:24:27 +04:00
|
|
|
prefs.hex_gui_transparency = 255;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_tray = 1;
|
2012-12-21 04:53:58 +04:00
|
|
|
prefs.hex_gui_tray_blink = 1;
|
2012-10-22 20:59:45 +04:00
|
|
|
prefs.hex_gui_ulist_count = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_ulist_icons = 1;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_ulist_resizable = 1;
|
|
|
|
prefs.hex_gui_ulist_style = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_win_save = 1;
|
|
|
|
prefs.hex_identd = 1;
|
|
|
|
prefs.hex_input_flash_hilight = 1;
|
|
|
|
prefs.hex_input_flash_priv = 1;
|
|
|
|
prefs.hex_input_tray_hilight = 1;
|
|
|
|
prefs.hex_input_tray_priv = 1;
|
2014-05-24 02:57:44 +04:00
|
|
|
prefs.hex_irc_cap_server_time = 1;
|
2013-04-04 01:35:40 +04:00
|
|
|
prefs.hex_irc_who_join = 1; /* Can kick with inordinate amount of channels, required for some of our features though, TODO: add cap like away check? */
|
2012-12-29 10:23:00 +04:00
|
|
|
prefs.hex_irc_whois_front = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_net_auto_reconnect = 1;
|
|
|
|
prefs.hex_net_throttle = 1;
|
|
|
|
prefs.hex_stamp_log = 1;
|
|
|
|
prefs.hex_stamp_text = 1;
|
|
|
|
prefs.hex_text_autocopy_text = 1;
|
|
|
|
prefs.hex_text_indent = 1;
|
|
|
|
prefs.hex_text_replay = 1;
|
|
|
|
prefs.hex_text_search_follow = 1;
|
|
|
|
prefs.hex_text_show_marker = 1;
|
2012-10-22 17:55:43 +04:00
|
|
|
prefs.hex_text_show_sep = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_text_stripcolor_replay = 1;
|
|
|
|
prefs.hex_text_stripcolor_topic = 1;
|
|
|
|
prefs.hex_text_thin_sep = 1;
|
|
|
|
prefs.hex_text_wordwrap = 1;
|
|
|
|
prefs.hex_url_grabber = 1;
|
|
|
|
|
|
|
|
/* NUMBERS */
|
|
|
|
prefs.hex_away_size_max = 300;
|
|
|
|
prefs.hex_away_timeout = 60;
|
|
|
|
prefs.hex_completion_amount = 5;
|
2014-05-12 13:10:26 +04:00
|
|
|
prefs.hex_completion_sort = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_dcc_auto_recv = 1; /* browse mode */
|
2012-10-22 14:10:55 +04:00
|
|
|
prefs.hex_dcc_blocksize = 1024;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_dcc_permissions = 0600;
|
|
|
|
prefs.hex_dcc_stall_timeout = 60;
|
|
|
|
prefs.hex_dcc_timeout = 180;
|
2012-10-22 14:20:47 +04:00
|
|
|
prefs.hex_flood_ctcp_num = 5;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_flood_ctcp_time = 30;
|
|
|
|
prefs.hex_flood_msg_num = 5;
|
|
|
|
/*FIXME*/ prefs.hex_flood_msg_time = 30;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_chanlist_maxusers = 9999;
|
|
|
|
prefs.hex_gui_chanlist_minusers = 5;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_dialog_height = 256;
|
|
|
|
prefs.hex_gui_dialog_width = 500;
|
|
|
|
prefs.hex_gui_lagometer = 1;
|
2013-06-08 05:34:01 +04:00
|
|
|
prefs.hex_gui_lang = get_default_language();
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_pane_left_size = 128; /* with treeview icons we need a bit bigger space */
|
|
|
|
prefs.hex_gui_pane_right_size = 100;
|
|
|
|
prefs.hex_gui_pane_right_size_min = 80;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_tab_layout = 2; /* 0=Tabs 1=Reserved 2=Tree */
|
|
|
|
prefs.hex_gui_tab_newtofront = 2;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_tab_pos = 1;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_tab_trunc = 20;
|
|
|
|
prefs.hex_gui_throttlemeter = 1;
|
2012-10-22 15:49:28 +04:00
|
|
|
prefs.hex_gui_ulist_pos = 3;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_gui_win_height = 400;
|
|
|
|
prefs.hex_gui_win_width = 640;
|
2012-10-22 16:18:20 +04:00
|
|
|
prefs.hex_input_balloon_time = 20;
|
2013-06-07 16:55:56 +04:00
|
|
|
prefs.hex_irc_ban_type = 1;
|
2013-05-17 12:32:53 +04:00
|
|
|
prefs.hex_irc_join_delay = 5;
|
2012-10-22 22:00:08 +04:00
|
|
|
prefs.hex_net_reconnect_delay = 10;
|
|
|
|
prefs.hex_notify_timeout = 15;
|
|
|
|
prefs.hex_text_max_indent = 256;
|
|
|
|
prefs.hex_text_max_lines = 500;
|
|
|
|
prefs.hex_url_grabber_limit = 100; /* 0 means unlimited */
|
|
|
|
|
|
|
|
/* STRINGS */
|
|
|
|
strcpy (prefs.hex_away_reason, _("I'm busy"));
|
2012-10-22 12:10:19 +04:00
|
|
|
strcpy (prefs.hex_completion_suffix, ",");
|
2012-10-22 22:00:08 +04:00
|
|
|
#ifdef WIN32
|
2014-04-21 20:58:04 +04:00
|
|
|
if (portable_mode () || SHGetKnownFolderPath (&FOLDERID_Downloads, 0, NULL, &roaming_path_wide) != S_OK)
|
2012-10-22 22:00:08 +04:00
|
|
|
{
|
2012-11-03 21:24:25 +04:00
|
|
|
snprintf (prefs.hex_dcc_dir, sizeof (prefs.hex_dcc_dir), "%s\\downloads", get_xdir ());
|
2012-10-22 22:00:08 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-21 20:58:04 +04:00
|
|
|
roaming_path = g_utf16_to_utf8 (roaming_path_wide, -1, NULL, NULL, NULL);
|
|
|
|
CoTaskMemFree (roaming_path_wide);
|
|
|
|
|
|
|
|
g_strlcpy (prefs.hex_dcc_dir, roaming_path, sizeof (prefs.hex_dcc_dir));
|
|
|
|
|
|
|
|
g_free (roaming_path);
|
2012-10-22 22:00:08 +04:00
|
|
|
}
|
|
|
|
#else
|
2013-05-11 06:19:18 +04:00
|
|
|
if (g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD))
|
|
|
|
{
|
|
|
|
strcpy (prefs.hex_dcc_dir, g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD));
|
|
|
|
}
|
2013-02-18 09:30:57 +04:00
|
|
|
else
|
2013-05-11 06:19:18 +04:00
|
|
|
{
|
2013-02-18 09:30:57 +04:00
|
|
|
strcpy (prefs.hex_dcc_dir, g_build_filename (g_get_home_dir (), "Downloads", NULL));
|
2013-05-11 06:19:18 +04:00
|
|
|
}
|
2012-10-22 22:00:08 +04:00
|
|
|
#endif
|
2012-11-04 03:41:25 +04:00
|
|
|
strcpy (prefs.hex_gui_ulist_doubleclick, "QUERY %s");
|
2012-10-22 16:18:20 +04:00
|
|
|
strcpy (prefs.hex_input_command_char, "/");
|
2013-05-11 06:18:44 +04:00
|
|
|
strcpy (prefs.hex_irc_logmask, g_build_filename ("%n", "%c.log", NULL));
|
2012-10-22 16:50:36 +04:00
|
|
|
strcpy (prefs.hex_irc_nick1, username);
|
|
|
|
strcpy (prefs.hex_irc_nick2, username);
|
|
|
|
strcat (prefs.hex_irc_nick2, "_");
|
|
|
|
strcpy (prefs.hex_irc_nick3, username);
|
|
|
|
strcat (prefs.hex_irc_nick3, "__");
|
2012-10-22 22:00:08 +04:00
|
|
|
strcpy (prefs.hex_irc_no_hilight, "NickServ,ChanServ,InfoServ,N,Q");
|
|
|
|
strcpy (prefs.hex_irc_part_reason, _("Leaving"));
|
|
|
|
strcpy (prefs.hex_irc_quit_reason, prefs.hex_irc_part_reason);
|
2012-10-22 16:50:36 +04:00
|
|
|
strcpy (prefs.hex_irc_real_name, realname);
|
|
|
|
strcpy (prefs.hex_irc_user_name, username);
|
2012-10-22 22:00:08 +04:00
|
|
|
strcpy (prefs.hex_stamp_log_format, "%b %d %H:%M:%S ");
|
|
|
|
strcpy (prefs.hex_stamp_text_format, "[%H:%M:%S] ");
|
2014-02-01 02:20:17 +04:00
|
|
|
|
|
|
|
font = fe_get_default_font ();
|
|
|
|
if (font)
|
2012-10-28 05:08:36 +04:00
|
|
|
{
|
2014-02-01 02:20:17 +04:00
|
|
|
strcpy (prefs.hex_text_font, font);
|
|
|
|
strcpy (prefs.hex_text_font_main, font);
|
2012-10-28 05:08:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy (prefs.hex_text_font, DEF_FONT);
|
|
|
|
strcpy (prefs.hex_text_font_main, DEF_FONT);
|
|
|
|
}
|
2014-02-01 02:20:17 +04:00
|
|
|
|
2012-10-22 17:55:43 +04:00
|
|
|
strcpy (prefs.hex_text_font_alternative, DEF_FONT_ALTER);
|
2014-02-12 18:27:28 +04:00
|
|
|
langs = get_default_spell_languages ();
|
|
|
|
strcpy (prefs.hex_text_spell_langs, langs);
|
2013-10-02 11:47:07 +04:00
|
|
|
|
2012-10-22 22:00:08 +04:00
|
|
|
|
|
|
|
/* private variables */
|
|
|
|
prefs.local_ip = 0xffffffff;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
sp = strchr (prefs.hex_irc_user_name, ' ');
|
|
|
|
if (sp)
|
|
|
|
sp[0] = 0; /* spaces in username would break the login */
|
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
g_free ((char *)username);
|
|
|
|
g_free ((char *)realname);
|
2014-02-12 18:27:28 +04:00
|
|
|
g_free ((char *)langs);
|
2013-05-13 04:58:08 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
int
|
|
|
|
make_config_dirs (void)
|
|
|
|
{
|
|
|
|
char *buf;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2014-01-31 06:42:03 +04:00
|
|
|
if (g_mkdir_with_parents (get_xdir (), 0700) != 0)
|
2013-05-13 04:58:08 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
buf = g_build_filename (get_xdir (), "addons", NULL);
|
|
|
|
if (g_mkdir (buf, 0700) != 0)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2013-05-13 04:58:08 +04:00
|
|
|
g_free (buf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
g_free (buf);
|
|
|
|
|
|
|
|
buf = g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL);
|
|
|
|
if (g_mkdir (buf, 0700) != 0)
|
|
|
|
{
|
|
|
|
g_free (buf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
g_free (buf);
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
int
|
|
|
|
make_dcc_dirs (void)
|
|
|
|
{
|
|
|
|
if (g_mkdir (prefs.hex_dcc_dir, 0700) != 0)
|
|
|
|
return -1;
|
2013-04-27 14:32:30 +04:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
if (g_mkdir (prefs.hex_dcc_completed_dir, 0700) != 0)
|
|
|
|
return -1;
|
2013-02-16 18:28:44 +04:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-14 12:30:51 +04:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
int
|
|
|
|
load_config (void)
|
|
|
|
{
|
|
|
|
char *cfg, *sp;
|
|
|
|
int res, val, i;
|
|
|
|
|
|
|
|
g_assert(check_config_dir () == 0);
|
|
|
|
|
|
|
|
if (!g_file_get_contents (default_file (), &cfg, NULL, NULL))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* If the config is incomplete we have the default values loaded */
|
|
|
|
load_default_config();
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (vars[i].type)
|
|
|
|
{
|
|
|
|
case TYPE_STR:
|
|
|
|
cfg_get_str (cfg, vars[i].name, (char *) &prefs + vars[i].offset,
|
|
|
|
vars[i].len);
|
|
|
|
break;
|
|
|
|
case TYPE_BOOL:
|
|
|
|
case TYPE_INT:
|
|
|
|
val = cfg_get_int_with_result (cfg, vars[i].name, &res);
|
|
|
|
if (res)
|
|
|
|
*((int *) &prefs + vars[i].offset) = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
2013-05-13 04:58:08 +04:00
|
|
|
while (vars[i].name);
|
|
|
|
|
|
|
|
g_free (cfg);
|
|
|
|
|
2012-10-22 15:49:28 +04:00
|
|
|
if (prefs.hex_gui_win_height < 138)
|
|
|
|
prefs.hex_gui_win_height = 138;
|
|
|
|
if (prefs.hex_gui_win_width < 106)
|
|
|
|
prefs.hex_gui_win_width = 106;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-10-22 16:50:36 +04:00
|
|
|
sp = strchr (prefs.hex_irc_user_name, ' ');
|
2011-02-24 06:14:30 +03:00
|
|
|
if (sp)
|
|
|
|
sp[0] = 0; /* spaces in username would break the login */
|
2013-05-13 04:58:08 +04:00
|
|
|
|
|
|
|
return 0;
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
save_config (void)
|
|
|
|
{
|
|
|
|
int fh, i;
|
2012-11-12 12:06:05 +04:00
|
|
|
char *config, *new_config;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2013-05-13 04:58:08 +04:00
|
|
|
if (check_config_dir () != 0)
|
|
|
|
make_config_dirs ();
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
config = default_file ();
|
2012-11-12 21:04:47 +04:00
|
|
|
new_config = g_strconcat (config, ".new", NULL);
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-11-12 07:34:09 +04:00
|
|
|
fh = g_open (new_config, OFLAGS | O_TRUNC | O_WRONLY | O_CREAT, 0600);
|
2011-02-24 06:14:30 +03:00
|
|
|
if (fh == -1)
|
|
|
|
{
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg_put_str (fh, "version", PACKAGE_VERSION))
|
|
|
|
{
|
2014-02-12 19:28:53 +04:00
|
|
|
close (fh);
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (vars[i].type)
|
|
|
|
{
|
|
|
|
case TYPE_STR:
|
|
|
|
if (!cfg_put_str (fh, vars[i].name, (char *) &prefs + vars[i].offset))
|
|
|
|
{
|
2014-02-12 19:28:53 +04:00
|
|
|
close (fh);
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_INT:
|
|
|
|
case TYPE_BOOL:
|
|
|
|
if (!cfg_put_int (fh, *((int *) &prefs + vars[i].offset), vars[i].name))
|
|
|
|
{
|
2014-02-12 19:28:53 +04:00
|
|
|
close (fh);
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (vars[i].name);
|
|
|
|
|
|
|
|
if (close (fh) == -1)
|
|
|
|
{
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-11-12 12:06:05 +04:00
|
|
|
g_unlink (config); /* win32 can't rename to an existing file */
|
2011-02-24 06:14:30 +03:00
|
|
|
#endif
|
2012-11-12 12:06:05 +04:00
|
|
|
if (g_rename (new_config, config) == -1)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-12 12:06:05 +04:00
|
|
|
g_free (new_config);
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_showval (session *sess, const struct prefs *var, char *tbuf)
|
|
|
|
{
|
2012-11-10 21:26:45 +04:00
|
|
|
size_t len;
|
|
|
|
size_t dots;
|
|
|
|
size_t j;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
len = strlen (var->name);
|
|
|
|
memcpy (tbuf, var->name, len);
|
2013-11-23 01:53:50 +04:00
|
|
|
if (len > 29)
|
2011-02-24 06:14:30 +03:00
|
|
|
dots = 0;
|
2013-11-23 01:53:50 +04:00
|
|
|
else
|
|
|
|
dots = 29 - len;
|
2012-11-10 21:26:45 +04:00
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
tbuf[len++] = '\003';
|
|
|
|
tbuf[len++] = '2';
|
2012-11-10 21:26:45 +04:00
|
|
|
|
|
|
|
for (j = 0; j < dots; j++)
|
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
tbuf[j + len] = '.';
|
2012-11-10 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
len += j;
|
2012-11-10 21:26:45 +04:00
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
switch (var->type)
|
|
|
|
{
|
2012-11-10 21:26:45 +04:00
|
|
|
case TYPE_STR:
|
|
|
|
sprintf (tbuf + len, "\0033:\017 %s\n", (char *) &prefs + var->offset);
|
|
|
|
break;
|
|
|
|
case TYPE_INT:
|
|
|
|
sprintf (tbuf + len, "\0033:\017 %d\n", *((int *) &prefs + var->offset));
|
|
|
|
break;
|
|
|
|
case TYPE_BOOL:
|
|
|
|
if (*((int *) &prefs + var->offset))
|
|
|
|
{
|
|
|
|
sprintf (tbuf + len, "\0033:\017 %s\n", "ON");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf (tbuf + len, "\0033:\017 %s\n", "OFF");
|
|
|
|
}
|
|
|
|
break;
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
2012-11-10 21:26:45 +04:00
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
PrintText (sess, tbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_list (session * sess, char *tbuf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
set_showval (sess, &vars[i], tbuf);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (vars[i].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cfg_get_bool (char *var)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2012-06-16 15:01:47 +04:00
|
|
|
if (!g_ascii_strcasecmp (var, vars[i].name))
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
return *((int *) &prefs + vars[i].offset);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (vars[i].name);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
|
|
|
|
{
|
|
|
|
int wild = FALSE;
|
|
|
|
int or = FALSE;
|
|
|
|
int off = FALSE;
|
|
|
|
int quiet = FALSE;
|
|
|
|
int erase = FALSE;
|
|
|
|
int i = 0, finds = 0, found;
|
|
|
|
int idx = 2;
|
2012-10-15 18:01:26 +04:00
|
|
|
int prev_numeric;
|
|
|
|
char *var, *val, *prev_string;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
2012-06-16 15:01:47 +04:00
|
|
|
if (g_ascii_strcasecmp (word[2], "-e") == 0)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
erase = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn a bit OFF */
|
2012-06-16 15:01:47 +04:00
|
|
|
if (g_ascii_strcasecmp (word[idx], "-off") == 0)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
off = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn a bit ON */
|
2012-06-16 15:01:47 +04:00
|
|
|
if (g_ascii_strcasecmp (word[idx], "-or") == 0 || g_ascii_strcasecmp (word[idx], "-on") == 0)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
or = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-16 15:01:47 +04:00
|
|
|
if (g_ascii_strcasecmp (word[idx], "-quiet") == 0)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
quiet = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = word[idx];
|
|
|
|
val = word_eol[idx+1];
|
|
|
|
|
|
|
|
if (!*var)
|
|
|
|
{
|
|
|
|
set_list (sess, tbuf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strchr (var, '*') || strchr (var, '?')) && !*val)
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
wild = TRUE;
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
if (*val == '=')
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
val++;
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (wild)
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
found = !match (var, vars[i].name);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
else
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2012-06-16 15:01:47 +04:00
|
|
|
found = g_ascii_strcasecmp (var, vars[i].name);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
if (found == 0)
|
|
|
|
{
|
|
|
|
finds++;
|
|
|
|
switch (vars[i].type)
|
|
|
|
{
|
|
|
|
case TYPE_STR:
|
|
|
|
if (erase || *val)
|
|
|
|
{
|
2012-10-15 18:01:26 +04:00
|
|
|
/* save the previous value until we print it out */
|
|
|
|
prev_string = (char*) malloc (vars[i].len + 1);
|
|
|
|
strncpy (prev_string, (char *) &prefs + vars[i].offset, vars[i].len);
|
|
|
|
|
|
|
|
/* update the variable */
|
2011-02-24 06:14:30 +03:00
|
|
|
strncpy ((char *) &prefs + vars[i].offset, val, vars[i].len);
|
|
|
|
((char *) &prefs)[vars[i].offset + vars[i].len - 1] = 0;
|
2012-10-15 18:00:07 +04:00
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
if (!quiet)
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2012-10-15 18:01:26 +04:00
|
|
|
PrintTextf (sess, "%s set to: %s (was: %s)\n", var, (char *) &prefs + vars[i].offset, prev_string);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2012-10-15 18:01:26 +04:00
|
|
|
|
|
|
|
free (prev_string);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
|
|
|
else
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
set_showval (sess, &vars[i], tbuf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_INT:
|
|
|
|
case TYPE_BOOL:
|
|
|
|
if (*val)
|
|
|
|
{
|
2012-10-15 18:01:26 +04:00
|
|
|
prev_numeric = *((int *) &prefs + vars[i].offset);
|
2011-02-24 06:14:30 +03:00
|
|
|
if (vars[i].type == TYPE_BOOL)
|
|
|
|
{
|
|
|
|
if (atoi (val))
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) = 1;
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
else
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) = 0;
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2012-06-16 15:01:47 +04:00
|
|
|
if (!g_ascii_strcasecmp (val, "YES") || !g_ascii_strcasecmp (val, "ON"))
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) = 1;
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2012-06-16 15:01:47 +04:00
|
|
|
if (!g_ascii_strcasecmp (val, "NO") || !g_ascii_strcasecmp (val, "OFF"))
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) = 0;
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
if (or)
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) |= atoi (val);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
else if (off)
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) &= ~(atoi (val));
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
else
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
*((int *) &prefs + vars[i].offset) = atoi (val);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
if (!quiet)
|
2012-10-15 18:00:07 +04:00
|
|
|
{
|
2012-10-15 18:01:26 +04:00
|
|
|
PrintTextf (sess, "%s set to: %d (was: %d)\n", var, *((int *) &prefs + vars[i].offset), prev_numeric);
|
2012-10-15 18:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
|
|
|
set_showval (sess, &vars[i], tbuf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (vars[i].name);
|
|
|
|
|
|
|
|
if (!finds && !quiet)
|
2011-11-23 16:58:50 +04:00
|
|
|
{
|
2011-02-24 06:14:30 +03:00
|
|
|
PrintText (sess, "No such variable.\n");
|
2011-11-23 16:58:50 +04:00
|
|
|
}
|
2012-10-13 10:43:57 +04:00
|
|
|
else if (!save_config ())
|
2011-11-23 16:58:50 +04:00
|
|
|
{
|
|
|
|
PrintText (sess, "Error saving changes to disk.\n");
|
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-10-30 14:35:39 +04:00
|
|
|
hexchat_open_file (char *file, int flags, int mode, int xof_flags)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2012-11-03 21:24:25 +04:00
|
|
|
char *buf;
|
|
|
|
int fd;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
if (xof_flags & XOF_FULLPATH)
|
|
|
|
{
|
|
|
|
if (xof_flags & XOF_DOMODE)
|
2012-11-03 21:24:25 +04:00
|
|
|
return g_open (file, flags | OFLAGS, mode);
|
2011-02-24 06:14:30 +03:00
|
|
|
else
|
2012-11-03 21:24:25 +04:00
|
|
|
return g_open (file, flags | OFLAGS, 0);
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
|
2013-05-04 20:21:48 +04:00
|
|
|
buf = g_build_filename (get_xdir (), file, NULL);
|
2012-11-03 21:24:25 +04:00
|
|
|
|
2011-02-24 06:14:30 +03:00
|
|
|
if (xof_flags & XOF_DOMODE)
|
2012-11-03 21:24:25 +04:00
|
|
|
{
|
|
|
|
fd = g_open (buf, flags | OFLAGS, mode);
|
|
|
|
}
|
2011-02-24 06:14:30 +03:00
|
|
|
else
|
2012-11-03 21:24:25 +04:00
|
|
|
{
|
|
|
|
fd = g_open (buf, flags | OFLAGS, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (buf);
|
|
|
|
|
|
|
|
return fd;
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
2012-10-30 14:35:39 +04:00
|
|
|
hexchat_fopen_file (const char *file, const char *mode, int xof_flags)
|
2011-02-24 06:14:30 +03:00
|
|
|
{
|
2012-11-03 21:24:25 +04:00
|
|
|
char *buf;
|
|
|
|
FILE *fh;
|
2011-02-24 06:14:30 +03:00
|
|
|
|
|
|
|
if (xof_flags & XOF_FULLPATH)
|
|
|
|
return fopen (file, mode);
|
|
|
|
|
2013-05-04 20:21:48 +04:00
|
|
|
buf = g_build_filename (get_xdir (), file, NULL);
|
2012-11-03 21:24:25 +04:00
|
|
|
fh = g_fopen (buf, mode);
|
|
|
|
g_free (buf);
|
|
|
|
|
|
|
|
return fh;
|
2011-02-24 06:14:30 +03:00
|
|
|
}
|