Compare commits

..

2 Commits

Author SHA1 Message Date
0c2501032e sysinfo: Strip trailing space on video card 2015-03-02 19:03:09 -05:00
4f891e21b3 sysinfo: Add display resolution 2015-03-02 18:34:03 -05:00
21 changed files with 421 additions and 326 deletions

View File

@ -608,27 +608,92 @@ AM_CONDITIONAL(WITH_TM, test "x$theme_manager" != "xno")
AM_CONDITIONAL(PLATFORM_OSX, test "x$platform_osx" == "xyes")
dnl *********************************************************************
dnl ** CFLAGS ***********************************************************
dnl ** GCC FLAGS ********************************************************
dnl *********************************************************************
dnl these flags might be unwanted
if test x$minimalflags != xyes; then
CC_CHECK_FLAGS_APPEND([CFLAGS], [CFLAGS], [-g])
dnl Only use -Wall and -pipe if we have gcc
if test "x$GCC" = "xyes"; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
CFLAGS="$CFLAGS -Wall"
fi
dnl these flags might be unwanted
if test x$minimalflags != xyes; then
if test "$system" = "Linux" -o "$system" = "FreeBSD"; then
if test -z "`echo "$CFLAGS" | grep "\-pipe" 2> /dev/null`" ; then
CFLAGS="$CFLAGS -pipe"
fi
fi
if test -z "`echo "$CFLAGS" | grep "\-g " 2> /dev/null`" ; then
CFLAGS="$CFLAGS -g"
fi
fi
fi
CC_CHECK_FLAGS_APPEND([CFLAGS], [CFLAGS], [ \
-pipe \
-funsigned-char \
-Wall \
-Wextra \
-Wno-unused-parameter \
-Wno-sign-compare \
-Wno-pointer-sign \
-Wno-missing-field-initializers \
-Wno-unused-result \
-Werror=format-security \
-Werror=declaration-after-statement \
dnl does this compiler support -Wno-pointer-sign ?
AC_MSG_CHECKING([if $CC accepts -Wno-pointer-sign ])
safe_CFLAGS=$CFLAGS
CFLAGS="-Wno-pointer-sign"
AC_TRY_COMPILE(, [
return 0;
],
[
no_pointer_sign=yes
AC_MSG_RESULT([yes])
], [
no_pointer_sign=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
if test x$no_pointer_sign = xyes; then
CFLAGS="$CFLAGS -Wno-pointer-sign"
fi
dnl does this compiler support -funsigned-char ?
AC_MSG_CHECKING([if $CC accepts -funsigned-char ])
safe_CFLAGS=$CFLAGS
CFLAGS="-funsigned-char"
AC_TRY_COMPILE(, [
return 0;
],
[
unsigned_char=yes
AC_MSG_RESULT([yes])
], [
unsigned_char=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
if test x$unsigned_char = xyes; then
CFLAGS="$CFLAGS -funsigned-char"
fi
dnl does this compiler support -Wno-unused-result ?
AC_MSG_CHECKING([if $CC accepts -Wno-unused-result ])
safe_CFLAGS=$CFLAGS
CFLAGS="-Wno-unused-result"
AC_TRY_COMPILE(, [
return 0;
],
[
no_unused_result=yes
AC_MSG_RESULT([yes])
], [
no_unused_result=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
if test x$no_unused_result = xyes; then
CFLAGS="$CFLAGS -Wno-unused-result"
fi
dnl *********************************************************************
dnl ** FUNCTIONS/LIBS/CFLAGS ********************************************
@ -682,6 +747,7 @@ AC_EGREP_CPP(lookupd, dnl
dnl freebsd needs this
LIBS="$LIBS $INTLLIBS"
CFLAGS="$CFLAGS $CPPFLAGS"
GUI_LIBS="$GUI_LIBS $COMMON_LIBS"

View File

@ -1,60 +0,0 @@
dnl Macros to check the presence of generic (non-typed) symbols.
dnl Copyright (c) 2006-2008 Diego Pettenò <flameeyes@gmail.com>
dnl Copyright (c) 2006-2008 xine project
dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2, or (at your option)
dnl any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
dnl 02110-1301, USA.
dnl
dnl As a special exception, the copyright owners of the
dnl macro gives unlimited permission to copy, distribute and modify the
dnl configure scripts that are the output of Autoconf when processing the
dnl Macro. You need not follow the terms of the GNU General Public
dnl License when using or distributing such scripts, even though portions
dnl of the text of the Macro appear in them. The GNU General Public
dnl License (GPL) does govern all other use of the material that
dnl constitutes the Autoconf Macro.
dnl
dnl This special exception to the GPL applies to versions of the
dnl Autoconf Macro released by this project. When you make and
dnl distribute a modified version of the Autoconf Macro, you may extend
dnl this special exception to the GPL to apply to your modified version as
dnl well.
dnl Check if FLAG in ENV-VAR is supported by compiler and append it
dnl to WHERE-TO-APPEND variable
dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
AC_DEFUN([CC_CHECK_FLAG_APPEND], [
AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
AS_TR_SH([cc_cv_$2_$3]),
[eval "AS_TR_SH([cc_save_$2])='${$2}'"
eval "AS_TR_SH([$2])='$3'"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a = 0; int main(void) { return a; } ])],
[eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
[eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
eval "AS_TR_SH([$2])='$cc_save_$2'"])
AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
[eval "$1='${$1} $3'"])
])
dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
for flag in $3; do
CC_CHECK_FLAG_APPEND($1, $2, $flag)
done
])

38
plugins/Make.plugin Normal file
View File

@ -0,0 +1,38 @@
# Makefile stub for creating standalone plugin distributions.
plugin_dist: pg_dist pg_dist/config.status
pgi=`cd $(srcdir)/.. && pwd`; cd pg_dist; \
$(MAKE) $(AM_MAKEFLAGS) PLUGIN_INCLUDES=-I$$pgi distcheck dist
pg_dist: pg_distdir pg_dist/configure.in pg_dist/install-sh
cd pg_dist \
&& libtoolize --copy --force --automake \
&& automake --copy --add-missing --foreign \
&& autoconf -l ../$(top_srcdir)
pg_distdir: $(DISTFILES)
test -d pg_dist || mkdir pg_dist
for dfile in $(DISTFILES); do \
test -f $$dfile && cp $$dfile pg_dist \
|| test -f $(srcdir)/$$dfile && cp $(srcdir)/$$dfile pg_dist; done
sed '/Make.plugin/d' < $(srcdir)/Makefile.am > pg_dist/Makefile.am
pg_dist/configure.in: $(srcdir)/../plugin-conf.in
rm -f pg_dist/configure.in
test -f $(srcdir)/config.stub \
&& cat $(srcdir)/config.stub > pg_dist/configure.in || true
cat $(srcdir)/../plugin-conf.in | \
sed 's%@PLUGIN_VERSION@%$(PLUGIN_VERSION)%; \
s%@PLUGIN@%$(PLUGIN)%' >> pg_dist/configure.in
pg_dist/install-sh: pg_distdir
cp $(top_srcdir)/install-sh pg_dist
pg_dist/config.status: pg_dist/configure
cd pg_dist \
&& test -f config.status && $(SHELL) ./config.status --recheck \
|| $(SHELL) ./configure --enable-maintainer-mode
DISTCLEANFILES = pg_dist/* pg_dist
#

19
plugins/plugin-conf.in Normal file
View File

@ -0,0 +1,19 @@
AC_INIT(@PLUGIN@-config.h.in)
AM_CONFIG_HEADER(@PLUGIN@-config.h)
AM_INIT_AUTOMAKE(hexchat-@PLUGIN@, @PLUGIN_VERSION@)
AM_MAINTAINER_MODE
AM_DISABLE_STATIC
AM_PROG_LIBTOOL
AC_ARG_WITH(plugin-includes,
[ --with-plugin-includes directory containing hexchat-plugin.h],
PLUGIN_INCLUDES=$enableval)
AC_SUBST(PLUGIN_INCLUDES)
hexchatlibdir=${libdir}/hexchat
AC_SUBST(hexchatlibdir)
AC_OUTPUT(
Makefile
)

View File

@ -26,6 +26,7 @@ char *sysinfo_backend_get_disk(void);
char *sysinfo_backend_get_memory(void);
char *sysinfo_backend_get_cpu(void);
char *sysinfo_backend_get_gpu(void);
char *sysinfo_backend_get_resolution (void);
char *sysinfo_backend_get_sound(void);
char *sysinfo_backend_get_uptime(void);
char *sysinfo_backend_get_network(void);

View File

@ -64,6 +64,7 @@ static hwinfo hwinfos[] = {
{"memory", "Memory", sysinfo_backend_get_memory},
{"storage", "Storage", sysinfo_backend_get_disk},
{"vga", "VGA", sysinfo_backend_get_gpu},
{"display", "Display", sysinfo_backend_get_resolution, TRUE},
{"sound", "Sound", sysinfo_backend_get_sound, TRUE},
{"ethernet", "Ethernet", sysinfo_backend_get_network, TRUE},
{"uptime", "Uptime", sysinfo_backend_get_uptime},

View File

@ -42,6 +42,7 @@ typedef enum
QUERY_WMI_CPU,
QUERY_WMI_VGA,
QUERY_WMI_HDD,
QUERY_WMI_RES,
} QueryWmiType;
void print_info (void);
@ -49,6 +50,7 @@ int get_cpu_arch (void);
char *query_wmi (QueryWmiType mode);
char *read_os_name (IWbemClassObject *object);
char *read_cpu_info (IWbemClassObject *object);
char *read_res_info (IWbemClassObject *object);
char *read_vga_name (IWbemClassObject *object);
guint64 hdd_capacity;
@ -117,6 +119,12 @@ sysinfo_backend_get_gpu (void)
return g_strdup (vga_name);
}
char *
sysinfo_backend_get_resolution (void)
{
return query_wmi (QUERY_WMI_RES);
}
char *
sysinfo_backend_get_os (void)
{
@ -203,6 +211,9 @@ static char *query_wmi (QueryWmiType type)
case QUERY_WMI_HDD:
query = SysAllocString (L"SELECT Name, Capacity, FreeSpace FROM Win32_Volume");
break;
case QUERY_WMI_RES:
query = SysAllocString (L"SELECT CurrentHorizontalResolution, CurrentVerticalResolution, CurrentRefreshRate FROM Win32_VideoController");
break;
default:
goto release_queryLanguageName;
}
@ -245,6 +256,10 @@ static char *query_wmi (QueryWmiType type)
line = read_hdd_info (object);
break;
case QUERY_WMI_RES:
line = read_res_info (object);
break;
default:
break;
}
@ -393,6 +408,42 @@ static char *read_vga_name (IWbemClassObject *object)
return g_strchomp (name_utf8);
}
static char *read_res_info (IWbemClassObject *object)
{
HRESULT hr;
VARIANT variant;
guint64 xres, yres, rate;
hr = object->lpVtbl->Get (object, L"CurrentHorizontalResolution", 0, &variant, NULL, NULL);
if (FAILED (hr))
{
return NULL;
}
xres = variant_to_uint64 (&variant);
VariantClear (&variant);
hr = object->lpVtbl->Get (object, L"CurrentVerticalResolution", 0, &variant, NULL, NULL);
if (FAILED (hr))
{
return NULL;
}
yres = variant_to_uint64 (&variant);
VariantClear (&variant);
hr = object->lpVtbl->Get (object, L"CurrentRefreshRate", 0, &variant, NULL, NULL);
if (FAILED (hr))
{
return NULL;
}
rate = variant_to_uint64 (&variant);
VariantClear (&variant);
return g_strdup_printf ("%"G_GUINT64_FORMAT"x%"G_GUINT64_FORMAT" (%"G_GUINT64_FORMAT"Hz)", xres, yres, rate);
}
static char *read_hdd_info (IWbemClassObject *object)
{
HRESULT hr;
@ -481,6 +532,9 @@ static guint64 variant_to_uint64 (VARIANT *variant)
{
switch (V_VT (variant))
{
case VT_I4:
return (guint64)MAX(variant->intVal, 0);
case VT_UI8:
return variant->ullVal;

View File

@ -32,7 +32,7 @@ src/fe-gtk/joind.c
src/fe-gtk/maingui.c
src/fe-gtk/menu.c
src/fe-gtk/notifygui.c
src/fe-gtk/plugin-notification.c
src/fe-gtk/plugin-notifications.c
src/fe-gtk/plugin-tray.c
src/fe-gtk/plugingui.c
src/fe-gtk/rawlog.c

View File

@ -226,12 +226,12 @@ cfg_put_str (int fh, char *var, char *value)
}
int
cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var)
cfg_put_color (int fh, int r, int g, int b, char *var)
{
char buf[400];
int len;
g_snprintf (buf, sizeof buf, "%s = %04hx %04hx %04hx\n", var, r, g, b);
g_snprintf (buf, sizeof buf, "%s = %04x %04x %04x\n", var, r, g, b);
len = strlen (buf);
return (write (fh, buf, len) == len);
}
@ -251,14 +251,14 @@ cfg_put_int (int fh, int value, char *var)
}
int
cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b)
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, "%04hx %04hx %04hx", r, g, b);
sscanf (str, "%04x %04x %04x", r, g, b);
return 1;
}

View File

@ -34,8 +34,8 @@ int cfg_get_bool (char *var);
int cfg_get_int_with_result (char *cfg, char *var, int *result);
int cfg_get_int (char *cfg, char *var);
int cfg_put_int (int fh, int value, char *var);
int cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b);
int cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var);
int cfg_get_color (char *cfg, char *var, int *r, int *g, int *b);
int cfg_put_color (int fh, int r, int g, int b, char *var);
char *get_xdir (void);
int check_config_dir (void);
void load_default_config (void);

View File

@ -39,16 +39,6 @@
#define HEXCHAT_EAT_PLUGIN 2 /* don't let other plugins see this event */
#define HEXCHAT_EAT_ALL (HEXCHAT_EAT_HEXCHAT|HEXCHAT_EAT_PLUGIN) /* don't let anything see this event */
/* Taken from glib/gmacros.h */
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define HEXCHAT_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
#define HEXCHAT_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
#else
#define HEXCHAT_DEPRECATED_FOR(f)
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -203,11 +193,6 @@ struct _hexchat_plugin
hexchat_event_attrs *(*hexchat_event_attrs_create) (hexchat_plugin *ph);
void (*hexchat_event_attrs_free) (hexchat_plugin *ph,
hexchat_event_attrs *attrs);
char *(*hexchat_pluginpref_get_str_ptr) (hexchat_plugin *ph,
const char *var);
char **(*hexchat_pluginpref_list_keys) (hexchat_plugin *ph);
void (*hexchat_free_array) (hexchat_plugin *ph,
char **arr);
};
#endif
@ -395,25 +380,16 @@ void
hexchat_free (hexchat_plugin *ph,
void *ptr);
void
hexchat_free_array (hexchat_plugin *ph,
char **arr);
int
hexchat_pluginpref_set_str (hexchat_plugin *ph,
const char *var,
const char *value);
HEXCHAT_DEPRECATED_FOR(hexchat_pluginpref_get_str_ptr)
int
hexchat_pluginpref_get_str (hexchat_plugin *ph,
const char *var,
char *dest);
char *
hexchat_pluginpref_get_str_ptr (hexchat_plugin *ph,
const char *var);
int
hexchat_pluginpref_set_int (hexchat_plugin *ph,
const char *var,
@ -426,14 +402,10 @@ int
hexchat_pluginpref_delete (hexchat_plugin *ph,
const char *var);
HEXCHAT_DEPRECATED_FOR(hexchat_pluginpref_list_keys)
int
hexchat_pluginpref_list (hexchat_plugin *ph,
char *dest);
char **
hexchat_pluginpref_list_keys (hexchat_plugin *ph);
#if !defined(PLUGIN_C) && defined(WIN32)
#ifndef HEXCHAT_PLUGIN_HANDLE
#define HEXCHAT_PLUGIN_HANDLE (ph)
@ -473,15 +445,12 @@ hexchat_pluginpref_list_keys (hexchat_plugin *ph);
#define hexchat_send_modes ((HEXCHAT_PLUGIN_HANDLE)->hexchat_send_modes)
#define hexchat_strip ((HEXCHAT_PLUGIN_HANDLE)->hexchat_strip)
#define hexchat_free ((HEXCHAT_PLUGIN_HANDLE)->hexchat_free)
#define hexchat_free_array ((HEXCHAT_PLUGIN_HANDLE)->hexchat_free_array)
#define hexchat_pluginpref_set_str ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_set_str)
#define hexchat_pluginpref_get_str ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_get_str)
#define hexchat_pluginpref_get_str_ptr ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_get_str_ptr)
#define hexchat_pluginpref_set_int ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_set_int)
#define hexchat_pluginpref_get_int ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_get_int)
#define hexchat_pluginpref_delete ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_delete)
#define hexchat_pluginpref_list ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_list)
#define hexchat_pluginpref_list_keys ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_list_keys)
#endif
#ifdef __cplusplus

View File

@ -3853,7 +3853,7 @@ const struct commands xc_cmds[] = {
N_("ALLCHANL <cmd>, sends a command to all channels on the current server")},
{"ALLSERV", cmd_allservers, 0, 0, 1,
N_("ALLSERV <cmd>, sends a command to all servers you're in")},
{"AWAY", cmd_away, 1, 0, 1, N_("AWAY [<reason>], sets you away (use /BACK to unset)")},
{"AWAY", cmd_away, 1, 0, 1, N_("AWAY [<reason>], sets you away")},
{"BACK", cmd_back, 1, 0, 1, N_("BACK, sets you back (not away)")},
{"BAN", cmd_ban, 1, 1, 1,
N_("BAN <mask> [<bantype>], bans everyone matching the mask from the current channel. If they are already on the channel this doesn't kick them (needs chanop)")},

View File

@ -27,12 +27,12 @@ static hexchat_plugin *ph;
static GSocketService *service;
static GHashTable *responses;
typedef struct ident_info
struct ident_info
{
GSocketConnection *conn;
gchar *username;
gchar read_buf[16];
} ident_info;
} typedef ident_info;
static int
identd_cleanup_response_cb (gpointer userdata)

View File

@ -120,7 +120,6 @@ static GSList *hook_list = NULL;
extern const struct prefs vars[]; /* cfgfiles.c */
static void pluginpref_save (hexchat_plugin *pl);
/* unload a plugin and remove it from our linked list */
@ -160,10 +159,6 @@ plugin_free (hexchat_plugin *pl, int do_deinit, int allow_refuse)
#endif
xit:
if (pl->keyfile)
{
g_key_file_free (pl->keyfile);
}
if (pl->free_strings)
{
g_free (pl->name);
@ -195,7 +190,6 @@ plugin_list_add (hexchat_context *ctx, char *filename, const char *name,
pl->context = ctx;
pl->name = (char *)name;
pl->desc = (char *)desc;
pl->keyfile = NULL;
pl->version = (char *)version;
pl->deinit_callback = deinit_func;
pl->fake = fake;
@ -284,19 +278,12 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func,
pl->hexchat_send_modes = hexchat_send_modes;
pl->hexchat_strip = hexchat_strip;
pl->hexchat_free = hexchat_free;
pl->hexchat_free_array = hexchat_free_array;
pl->hexchat_pluginpref_set_str = hexchat_pluginpref_set_str;
pl->hexchat_pluginpref_get_str_ptr = hexchat_pluginpref_get_str_ptr;
pl->hexchat_pluginpref_get_str = hexchat_pluginpref_get_str;
pl->hexchat_pluginpref_set_int = hexchat_pluginpref_set_int;
pl->hexchat_pluginpref_get_int = hexchat_pluginpref_get_int;
pl->hexchat_pluginpref_delete = hexchat_pluginpref_delete;
pl->hexchat_pluginpref_list_keys = hexchat_pluginpref_list_keys;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
pl->hexchat_pluginpref_get_str = hexchat_pluginpref_get_str;
pl->hexchat_pluginpref_list = hexchat_pluginpref_list;
G_GNUC_END_IGNORE_DEPRECATIONS
pl->hexchat_hook_server_attrs = hexchat_hook_server_attrs;
pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs;
pl->hexchat_emit_print_attrs = hexchat_emit_print_attrs;
@ -1756,229 +1743,258 @@ hexchat_free (hexchat_plugin *ph, void *ptr)
g_free (ptr);
}
void
hexchat_free_array (hexchat_plugin *ph, char **strv)
static int
hexchat_pluginpref_set_str_real (hexchat_plugin *pl, const char *var, const char *value, int mode) /* mode: 0 = delete, 1 = save */
{
g_strfreev (strv);
}
FILE *fpIn;
int fhOut;
int prevSetting;
char *confname;
char *confname_tmp;
char *escaped_value;
char *buffer;
char *buffer_tmp;
char line_buffer[512]; /* the same as in cfg_put_str */
char *line_bufp = line_buffer;
char *canon;
#define DEFAULT_GROUP "DEFAULT"
#define DEFAULT_GROUP_TEXT "[DEFAULT]\n"
#define DEFAULT_GROUP_TEXT_LEN 10
canon = g_strdup (pl->name);
canonalize_key (canon);
confname = g_strdup_printf ("addon_%s.conf", canon);
g_free (canon);
confname_tmp = g_strdup_printf ("%s.new", confname);
static char *
pluginpref_create_filename (hexchat_plugin *pl, const char *extension)
{
char *confname, *tmp, *filename;
fhOut = hexchat_open_file (confname_tmp, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
fpIn = hexchat_fopen_file (confname, "r", 0);
tmp = g_strdup (pl->name);
canonalize_key (tmp);
confname = g_strdup_printf ("%s%caddon_%s.%s", get_xdir(), G_DIR_SEPARATOR, tmp, extension);
filename = g_filename_from_utf8 (confname, -1, NULL, NULL, NULL);
g_free (confname);
g_free (tmp);
return filename;
}
/* Migration simply means prepending a valid group
* to the old format, it is otherwise compatable */
static gboolean
pluginpref_migrate_file_real (const char *old_filename, const char *new_filename)
{
char *contents;
gsize len, newlen;
gboolean ret;
/* Just read the entire file, ideally it is fairly small */
if (!g_file_get_contents (old_filename, &contents, &len, NULL))
return FALSE;
/* Avoid duplicating data and just prepend the new group */
newlen = len + DEFAULT_GROUP_TEXT_LEN;
contents = g_realloc_n (contents, newlen, sizeof(char));
memmove (contents + DEFAULT_GROUP_TEXT_LEN, contents, len);
memcpy (contents, DEFAULT_GROUP_TEXT, DEFAULT_GROUP_TEXT_LEN);
ret = g_file_set_contents (new_filename, contents, (gssize)MIN(newlen, G_MAXSSIZE), NULL);
g_free (contents);
return ret;
}
static void
pluginpref_migrate_file (hexchat_plugin *pl, char *filename)
{
char *old_filename;
if (g_file_test (filename, G_FILE_TEST_EXISTS))
return;
old_filename = pluginpref_create_filename (pl, "conf");
if (g_file_test (old_filename, G_FILE_TEST_EXISTS))
if (fhOut == -1) /* unable to save, abort */
{
if (pluginpref_migrate_file_real (old_filename, filename))
g_free (confname);
g_free (confname_tmp);
if (fpIn)
fclose (fpIn);
return 0;
}
else if (fpIn == NULL) /* no previous config file, no parsing */
{
if (mode)
{
/* Migration worked, move the old one as a backup incase
* keyfile is invalid and data lost but also to avoid confusion */
char *backup_filename = pluginpref_create_filename (pl, "bak");
g_rename (old_filename, backup_filename);
g_free (backup_filename);
escaped_value = g_strescape (value, NULL);
buffer = g_strdup_printf ("%s = %s\n", var, escaped_value);
g_free (escaped_value);
write (fhOut, buffer, strlen (buffer));
g_free (buffer);
close (fhOut);
buffer = g_build_filename (get_xdir (), confname, NULL);
g_free (confname);
buffer_tmp = g_build_filename (get_xdir (), confname_tmp, NULL);
g_free (confname_tmp);
#ifdef WIN32
g_unlink (buffer);
#endif
if (g_rename (buffer_tmp, buffer) == 0)
{
g_free (buffer);
g_free (buffer_tmp);
return 1;
}
else
{
g_free (buffer);
g_free (buffer_tmp);
return 0;
}
}
else
{
/* mode = 0, we want to delete but the config file and thus the given setting does not exist, we're ready */
close (fhOut);
g_free (confname);
g_free (confname_tmp);
return 1;
}
}
g_free (old_filename);
}
static GKeyFile *
pluginpref_load_file (hexchat_plugin *pl)
{
char *filename;
GKeyFile *file;
filename = pluginpref_create_filename (pl, "ini");
if (!filename)
return NULL;
file = g_key_file_new ();
pluginpref_migrate_file (pl, filename);
/* It failing doesn't matter, a new file will just be created */
g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, NULL);
g_free (filename);
return file;
}
#define PLUGINPREF_INIT_KEYFILE(pl,ret) G_STMT_START \
if (!pl->keyfile) \
{ \
if (!(pl->keyfile = pluginpref_load_file (pl))) \
return ret; \
} \
G_STMT_END
static void
pluginpref_save (hexchat_plugin *pl)
{
gchar *data, *filename;
gsize length;
filename = pluginpref_create_filename (pl, "ini");
if (!filename)
return;
if (!(data = g_key_file_to_data (pl->keyfile, &length, NULL)))
else /* existing config file, preserve settings and find & replace current var value if any */
{
g_free (filename);
return;
}
prevSetting = 0;
g_file_set_contents (filename, data, length, NULL);
g_free (data);
g_free (filename);
while (fscanf (fpIn, " %[^\n]", line_bufp) != EOF) /* read whole lines including whitespaces */
{
buffer_tmp = g_strdup_printf ("%s ", var); /* add one space, this way it works against var - var2 checks too */
if (strncmp (buffer_tmp, line_buffer, strlen (var) + 1) == 0) /* given setting already exists */
{
if (mode) /* overwrite the existing matching setting if we are in save mode */
{
escaped_value = g_strescape (value, NULL);
buffer = g_strdup_printf ("%s = %s\n", var, escaped_value);
g_free (escaped_value);
}
else /* erase the setting in delete mode */
{
buffer = g_strdup ("");
}
prevSetting = 1;
}
else
{
buffer = g_strdup_printf ("%s\n", line_buffer); /* preserve the existing different settings */
}
write (fhOut, buffer, strlen (buffer));
g_free (buffer);
g_free (buffer_tmp);
}
fclose (fpIn);
if (!prevSetting && mode) /* var doesn't exist currently, append if we're in save mode */
{
escaped_value = g_strescape (value, NULL);
buffer = g_strdup_printf ("%s = %s\n", var, escaped_value);
g_free (escaped_value);
write (fhOut, buffer, strlen (buffer));
g_free (buffer);
}
close (fhOut);
buffer = g_build_filename (get_xdir (), confname, NULL);
g_free (confname);
buffer_tmp = g_build_filename (get_xdir (), confname_tmp, NULL);
g_free (confname_tmp);
#ifdef WIN32
g_unlink (buffer);
#endif
if (g_rename (buffer_tmp, buffer) == 0)
{
g_free (buffer);
g_free (buffer_tmp);
return 1;
}
else
{
g_free (buffer);
g_free (buffer_tmp);
return 0;
}
}
}
int
hexchat_pluginpref_set_str (hexchat_plugin *pl, const char *var, const char *value)
{
PLUGINPREF_INIT_KEYFILE (pl, 0);
g_key_file_set_string (pl->keyfile, DEFAULT_GROUP, var, value);
pluginpref_save (pl);
return 1;
return hexchat_pluginpref_set_str_real (pl, var, value, 1);
}
char *
hexchat_pluginpref_get_str_ptr (hexchat_plugin *pl, const char *var)
static int
hexchat_pluginpref_get_str_real (hexchat_plugin *pl, const char *var, char *dest, int dest_len)
{
PLUGINPREF_INIT_KEYFILE (pl, 0);
char *confname, *canon, *cfg, *unescaped_value;
char buf[512];
return g_key_file_get_string (pl->keyfile, DEFAULT_GROUP, var, NULL);
canon = g_strdup (pl->name);
canonalize_key (canon);
confname = g_strdup_printf ("%s%caddon_%s.conf", get_xdir(), G_DIR_SEPARATOR, canon);
g_free (canon);
if (!g_file_get_contents (confname, &cfg, NULL, NULL))
{
g_free (confname);
return 0;
}
g_free (confname);
if (!cfg_get_str (cfg, var, buf, sizeof(buf)))
{
g_free (cfg);
return 0;
}
unescaped_value = g_strcompress (buf);
g_strlcpy (dest, unescaped_value, dest_len);
g_free (unescaped_value);
g_free (cfg);
return 1;
}
int
hexchat_pluginpref_get_str (hexchat_plugin *pl, const char *var, char *dest)
{
char *value;
if (!(value = hexchat_pluginpref_get_str_ptr (pl, var)))
return 0;
/* All users of this must ensure dest is >= 512... */
safe_strcpy (dest, value, 512);
g_free (value);
return 1;
return hexchat_pluginpref_get_str_real (pl, var, dest, 512);
}
int
hexchat_pluginpref_set_int (hexchat_plugin *pl, const char *var, int value)
{
PLUGINPREF_INIT_KEYFILE (pl, 0);
char buffer[12];
g_key_file_set_integer (pl->keyfile, DEFAULT_GROUP, var, value);
pluginpref_save (pl);
return 1;
g_snprintf (buffer, sizeof (buffer), "%d", value);
return hexchat_pluginpref_set_str_real (pl, var, buffer, 1);
}
int
hexchat_pluginpref_get_int (hexchat_plugin *pl, const char *var)
{
int value;
GError *error = NULL;
char buffer[12];
PLUGINPREF_INIT_KEYFILE (pl, -1);
value = g_key_file_get_integer (pl->keyfile, DEFAULT_GROUP, var, &error);
if (error)
if (hexchat_pluginpref_get_str_real (pl, var, buffer, sizeof(buffer)))
{
return atoi (buffer);
}
else
{
if (error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
{
g_error_free (error);
return 0; /* This is to duplicate previous behavior of atoi() */
}
g_error_free (error);
return -1;
}
return value;
}
int
hexchat_pluginpref_delete (hexchat_plugin *pl, const char *var)
{
gboolean ret;
PLUGINPREF_INIT_KEYFILE (pl, 0);
ret = g_key_file_remove_key (pl->keyfile, DEFAULT_GROUP, var, NULL);
pluginpref_save (pl);
return ret;
return hexchat_pluginpref_set_str_real (pl, var, 0, 0);
}
char **
hexchat_pluginpref_list_keys (hexchat_plugin *pl)
{
PLUGINPREF_INIT_KEYFILE (pl, NULL);
return g_key_file_get_keys (pl->keyfile, DEFAULT_GROUP, NULL, NULL);
}
int
hexchat_pluginpref_list (hexchat_plugin *pl, char* dest)
{
char **keys, *keystr;
FILE *fpIn;
char confname[64];
char buffer[512]; /* the same as in cfg_put_str */
char *bufp = buffer;
char *token;
if (!(keys = hexchat_pluginpref_list_keys (pl)))
token = g_strdup (pl->name);
canonalize_key (token);
sprintf (confname, "addon_%s.conf", token);
g_free (token);
fpIn = hexchat_fopen_file (confname, "r", 0);
if (fpIn == NULL) /* no existing config file, no parsing */
{
return 0;
}
else /* existing config file, get list of settings */
{
strcpy (dest, ""); /* clean up garbage */
while (fscanf (fpIn, " %[^\n]", bufp) != EOF) /* read whole lines including whitespaces */
{
token = strtok (buffer, "=");
g_strlcat (dest, g_strchomp (token), 4096); /* Dest must not be smaller than this */
g_strlcat (dest, ",", 4096);
}
keystr = g_strjoinv (",", keys);
safe_strcpy (dest, keystr, 4096);
g_strlcat (dest, ",", 4096); /* Must end in , for legacy reasons */
fclose (fpIn);
}
g_free (keystr);
g_strfreev (keys);
return 1;
}

View File

@ -149,11 +149,6 @@ struct _hexchat_plugin
hexchat_event_attrs *(*hexchat_event_attrs_create) (hexchat_plugin *ph);
void (*hexchat_event_attrs_free) (hexchat_plugin *ph,
hexchat_event_attrs *attrs);
char *(*hexchat_pluginpref_get_str_ptr) (hexchat_plugin *ph,
const char *var);
char **(*hexchat_pluginpref_list_keys) (hexchat_plugin *ph);
void (*hexchat_free_array) (hexchat_plugin *ph,
char **arr);
/* PRIVATE FIELDS! */
void *handle; /* from dlopen */
@ -161,7 +156,6 @@ struct _hexchat_plugin
char *name;
char *desc;
char *version;
GKeyFile *keyfile; /* pluginpref */
session *context;
void *deinit_callback; /* pointer to hexchat_plugin_deinit */
unsigned int fake:1; /* fake plugin. Added by hexchat_plugingui_add() */

View File

@ -1127,26 +1127,26 @@ static char * const pevt_chanrmlimit_help[] = {
};
static char * const pevt_chandeop_help[] = {
N_("The nick of the person who did the deop'ing"),
N_("The nick of the person of did the deop'ing"),
N_("The nick of the person who has been deop'ed"),
};
static char * const pevt_chandehop_help[] = {
N_("The nick of the person who did the dehalfop'ing"),
N_("The nick of the person of did the dehalfop'ing"),
N_("The nick of the person who has been dehalfop'ed"),
};
static char * const pevt_chandevoice_help[] = {
N_("The nick of the person who did the devoice'ing"),
N_("The nick of the person of did the devoice'ing"),
N_("The nick of the person who has been devoice'ed"),
};
static char * const pevt_chanunban_help[] = {
N_("The nick of the person who did the unban'ing"),
N_("The nick of the person of did the unban'ing"),
N_("The ban mask"),
};
static char * const pevt_chanunquiet_help[] = {
N_("The nick of the person who did the unquiet'ing"),
N_("The nick of the person of did the unquiet'ing"),
N_("The quiet mask"),
};

View File

@ -246,11 +246,11 @@ expand_homedir (char *file)
if (file[0] == '~')
{
char *slash_pos;
if (file[1] == '\0' || file[1] == '/')
return g_strconcat (g_get_home_dir (), &file[1], NULL);
char *slash_pos;
user = g_strdup(file);
slash_pos = strchr(user, '/');

View File

@ -80,5 +80,5 @@ char *encode_sasl_pass_blowfish (char *user, char *pass, char *data);
char *encode_sasl_pass_aes (char *user, char *pass, char *data);
char *challengeauth_response (char *username, char *password, char *challenge);
size_t strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time);
gsize strftime_utf8 (char *dest, gsize destsize, const char *format, time_t time);
size_t strftime_utf8 (char *dest, size_t destsize, const char *format, time_t time);
#endif

View File

@ -110,7 +110,7 @@ palette_load (void)
char prefname[256];
struct stat st;
char *cfg;
guint16 red, green, blue;
int red, green, blue;
fh = hexchat_open_file ("colors.conf", O_RDONLY, 0, 0);
if (fh != -1)

View File

@ -4,13 +4,13 @@
<!-- SPECIFY YOUR DEPENDENCY DIRECTORIES HERE -->
<YourDepsPath>c:\gtk-build\gtk</YourDepsPath>
<YourGendefPath>c:\gtk-build\gendef</YourGendefPath>
<YourMsgfmtPath>c:\gtk-build\msgfmt</YourMsgfmtPath>
<YourPerlPath>c:\gtk-build\perl-5.20</YourPerlPath>
<YourPython2Path>c:\gtk-build\python-2.7</YourPython2Path>
<YourPython3Path>c:\gtk-build\python-3.4</YourPython3Path>
<YourWinSparklePath>c:\gtk-build\WinSparkle</YourWinSparklePath>
<YourDepsPath>c:\mozilla-build\hexchat\gtk</YourDepsPath>
<YourGendefPath>c:\mozilla-build\gendef</YourGendefPath>
<YourMsgfmtPath>c:\mozilla-build\msgfmt</YourMsgfmtPath>
<YourPerlPath>c:\mozilla-build\perl-5.20</YourPerlPath>
<YourPython2Path>c:\mozilla-build\python-2.7</YourPython2Path>
<YourPython3Path>c:\mozilla-build\python-3.4</YourPython3Path>
<YourWinSparklePath>c:\mozilla-build\WinSparkle</YourWinSparklePath>
<!-- YOU SHOULDN'T TOUCH ANYTHING BELOW -->

View File

@ -127,9 +127,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "external", "external", "{021EC1D0-FF67-4700-9AB2-EAABF1159C09}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libenchant_win8", "..\src\libenchant_win8\libenchant_win8.vcxproj", "{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}"
ProjectSection(ProjectDependencies) = postProject
{87554B59-006C-4D94-9714-897B27067BA3} = {87554B59-006C-4D94-9714-897B27067BA3}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution