#include "prefs_gtk.h"
#include "utils.h"
#include "gtkutils.h"
+#include "passcrypt.h"
+#include "base64.h"
+
+#define CL(x) (((gulong) (x) >> (gulong) 8) & 0xFFUL)
+#define RGB_FROM_GDK_COLOR(c) \
+ ((CL(c.red) << (gulong) 16) | \
+ (CL(c.green) << (gulong) 8) | \
+ (CL(c.blue)))
typedef enum
{
gint i;
gint name_len;
const gchar *value;
+ GdkColor color;
for (i = 0; param[i].name != NULL; i++) {
name_len = strlen(param[i].name);
*((gushort *)param[i].data) =
(gushort)atoi(value);
break;
+ case P_COLOR:
+ if (gdk_color_parse(value, &color))
+ *((gulong *)param[i].data) = RGB_FROM_GDK_COLOR(color);
+ else
+ /* be compatible and accept ints */
+ *((gulong *)param[i].data) = strtoul(value, 0, 10);
+ break;
+ case P_PASSWORD:
+ g_free(*((gchar **)param[i].data));
+ if (value[0] == '!') {
+ gchar tmp[1024];
+ gint len;
+
+ len = base64_decode(tmp, &value[1], strlen(value) - 1);
+ passcrypt_decrypt(tmp, len);
+ tmp[len] = '\0';
+ *((gchar **)param[i].data) =
+ *tmp ? g_strdup(tmp) : NULL;
+ } else {
+ *((gchar **)param[i].data) =
+ *value ? g_strdup(value) : NULL;
+ }
+ break;
default:
break;
}
g_snprintf(buf, sizeof(buf), "%s=%d\n", param[i].name,
*((gushort *)param[i].data));
break;
+ case P_COLOR:
+ g_snprintf(buf, sizeof buf, "%s=#%6.6lx\n", param[i].name,
+ *((gulong *) param[i].data));
+ break;
+ case P_PASSWORD:
+ {
+ gchar *tmp = NULL, tmp2[1024] = {0};
+
+ tmp = *((gchar **)param[i].data);
+ if (tmp) {
+ gint len;
+
+ tmp = g_strdup(tmp);
+ len = strlen(tmp);
+ passcrypt_encrypt(tmp, len);
+ base64_encode(tmp2, tmp, len);
+ g_free(tmp);
+ tmp = tmp2;
+ }
+ g_snprintf(buf, sizeof(buf), "%s=!%s\n", param[i].name,
+ tmp ?
+ tmp : "");
+ }
+ break;
default:
buf[0] = '\0';
}
void prefs_set_default(PrefParam *param)
{
gint i;
+ GdkColor color;
g_return_if_fail(param != NULL);
switch (param[i].type) {
case P_STRING:
+ case P_PASSWORD:
+ g_free(*((gchar **)param[i].data));
if (param[i].defval != NULL) {
if (!strncasecmp(param[i].defval, "ENV_", 4))
*((gchar **)param[i].data) =
else
*((gushort *)param[i].data) = 0;
break;
+ case P_COLOR:
+ if (param[i].defval != NULL && gdk_color_parse(param[i].defval, &color))
+ *((gulong *)param[i].data) =
+ RGB_FROM_GDK_COLOR(color);
+ else if (param[i].defval)
+ /* be compatible and accept ints */
+ *((gulong *)param[i].data) = strtoul(param[i].defval, 0, 10);
+ else
+ *((gulong *)param[i].data) = 0;
+ break;
default:
break;
}
switch (param[i].type) {
case P_STRING:
+ case P_PASSWORD:
g_free(*((gchar **)param[i].data));
break;
default:
switch (tmpparam.type) {
case P_STRING:
+ case P_PASSWORD:
if (tmpparam.defval) {
if (!strncasecmp(tmpparam.defval, "ENV_", 4)) {
str_data = g_strdup(g_getenv(param[i].defval + 4));
tmpparam.data = &enum_data;
break;
case P_OTHER:
+ default:
break;
}
tmpparam.widget_set_func(&tmpparam);
switch (pparam->type) {
case P_STRING:
+ case P_PASSWORD:
str = (gchar **)pparam->data;
g_free(*str);
*str = entry_str[0] ? g_strdup(entry_str) : NULL;
switch (pparam->type) {
case P_STRING:
+ case P_PASSWORD:
str = (gchar **)pparam->data;
gtk_entry_set_text(GTK_ENTRY(*pparam->widget),
*str ? *str : "");
switch (pparam->type) {
case P_STRING:
+ case P_PASSWORD:
str = (gchar **)pparam->data;
g_free(*str);
tp = text = gtk_editable_get_chars
switch (pparam->type) {
case P_STRING:
+ case P_PASSWORD:
str = (gchar **)pparam->data;
if (*str) {
bufp = buf = alloca(strlen(*str) + 1);
static GSList *prefs_pages = NULL;
-void prefs_gtk_open()
+void prefs_gtk_open(void)
{
- prefswindow_open(prefs_pages, NULL);
+ prefswindow_open(_("Preferences"), prefs_pages, NULL);
}
void prefs_gtk_register_page(PrefsPage *page)