2
* Copyright (C) 2006-2009 Anders Brander <anders@brander.dk> and
3
* Anders Kvist <akv@lnxbx.dk>
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "rawstudio.h"
24
#include "conf_interface.h"
32
static GStaticMutex lock = G_STATIC_MUTEX_INIT;
35
#include <gconf/gconf-client.h>
36
#define GCONF_PATH "/apps/rawstudio/"
41
#define REGISTRY_KEY "Software\\Rawstudio"
46
rs_conf_get_boolean(const gchar *name, gboolean *boolean_value)
51
GConfClient *client = gconf_client_get_default();
52
GString *fullname = g_string_new(GCONF_PATH);
53
g_string_append(fullname, name);
56
g_static_mutex_lock(&lock);
57
gvalue = gconf_client_get(client, fullname->str, NULL);
58
g_static_mutex_unlock(&lock);
61
if (gvalue->type == GCONF_VALUE_BOOL)
65
*boolean_value = gconf_value_get_bool(gvalue);
67
gconf_value_free(gvalue);
69
g_object_unref(client);
71
g_string_free(fullname, TRUE);
74
ret = rs_conf_get_integer(name, boolean_value);
80
rs_conf_get_boolean_with_default(const gchar *name, gboolean *boolean_value, gboolean default_value)
84
*boolean_value = default_value;
87
GConfClient *client = gconf_client_get_default();
88
GString *fullname = g_string_new(GCONF_PATH);
89
g_string_append(fullname, name);
92
g_static_mutex_lock(&lock);
93
gvalue = gconf_client_get(client, fullname->str, NULL);
94
g_static_mutex_unlock(&lock);
97
if (gvalue->type == GCONF_VALUE_BOOL)
101
*boolean_value = gconf_value_get_bool(gvalue);
103
gconf_value_free(gvalue);
105
g_object_unref(client);
107
g_string_free(fullname, TRUE);
110
ret = rs_conf_get_integer(name, boolean_value);
116
rs_conf_set_boolean(const gchar *name, gboolean bool_value)
118
gboolean ret = FALSE;
120
GConfClient *client = gconf_client_get_default();
121
GString *fullname = g_string_new(GCONF_PATH);
122
g_string_append(fullname, name);
123
g_static_mutex_lock(&lock);
126
ret = gconf_client_set_bool(client, fullname->str, bool_value, NULL);
127
g_object_unref(client);
129
g_static_mutex_unlock(&lock);
130
g_string_free(fullname, TRUE);
133
ret = rs_conf_set_integer(name, bool_value);
139
rs_conf_get_string(const gchar *name)
144
GConfClient *client = gconf_client_get_default();
145
GString *fullname = g_string_new(GCONF_PATH);
146
g_string_append(fullname, name);
149
g_static_mutex_lock(&lock);
150
gvalue = gconf_client_get(client, fullname->str, NULL);
151
g_static_mutex_unlock(&lock);
154
if (gvalue->type == GCONF_VALUE_STRING)
155
ret = g_strdup(gconf_value_get_string(gvalue));
156
gconf_value_free(gvalue);
158
g_object_unref(client);
160
g_string_free(fullname, TRUE);
168
if (RegOpenKeyEx( HKEY_CURRENT_USER, REGISTRY_KEY, 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS)
170
lRet = RegQueryValueEx( hKey, name, NULL, NULL, NULL, &dwBufLen);
173
szLwd = g_malloc(dwBufLen);
174
lRet = RegQueryValueEx( hKey, name, NULL, NULL, (LPBYTE) szLwd, &dwBufLen);
176
if (lRet == ERROR_SUCCESS)
187
rs_conf_set_string(const gchar *name, const gchar *string_value)
189
gboolean ret = FALSE;
191
GConfClient *client = gconf_client_get_default();
192
GString *fullname = g_string_new(GCONF_PATH);
193
g_string_append(fullname, name);
196
g_static_mutex_lock(&lock);
197
ret = gconf_client_set_string(client, fullname->str, string_value, NULL);
198
g_static_mutex_unlock(&lock);
199
g_object_unref(client);
201
g_string_free(fullname, TRUE);
206
if (RegCreateKeyEx(HKEY_CURRENT_USER, REGISTRY_KEY, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
208
if (RegSetValueEx(hKey, name, 0, REG_SZ, (LPBYTE) string_value, (DWORD) (lstrlen(string_value)+1))==ERROR_SUCCESS)
217
rs_conf_get_integer(const gchar *name, gint *integer_value)
222
GConfClient *client = gconf_client_get_default();
223
GString *fullname = g_string_new(GCONF_PATH);
224
g_string_append(fullname, name);
227
g_static_mutex_lock(&lock);
228
gvalue = gconf_client_get(client, fullname->str, NULL);
229
g_static_mutex_unlock(&lock);
232
if (gvalue->type == GCONF_VALUE_INT)
235
*integer_value = gconf_value_get_int(gvalue);
237
gconf_value_free(gvalue);
239
g_object_unref(client);
241
g_string_free(fullname, TRUE);
248
if (RegOpenKeyEx( HKEY_CURRENT_USER, REGISTRY_KEY, 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS)
250
lRet = RegQueryValueEx( hKey, name, NULL, NULL, NULL, &dwBufLen);
254
DWORD size = sizeof(gint);
255
lRet = RegQueryValueEx( hKey, name, NULL, NULL, (LPBYTE) &val, &size);
257
if ((lRet == ERROR_SUCCESS) && (size == sizeof(gint)))
260
*integer_value = val;
269
rs_conf_set_integer(const gchar *name, const gint integer_value)
271
gboolean ret = FALSE;
273
GConfClient *client = gconf_client_get_default();
274
GString *fullname = g_string_new(GCONF_PATH);
275
g_string_append(fullname, name);
276
g_static_mutex_lock(&lock);
279
ret = gconf_client_set_int(client, fullname->str, integer_value, NULL);
280
g_object_unref(client);
282
g_static_mutex_unlock(&lock);
283
g_string_free(fullname, TRUE);
288
if (RegCreateKeyEx(HKEY_CURRENT_USER, REGISTRY_KEY, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
290
if (RegSetValueEx(hKey, name, 0, REG_DWORD, (LPBYTE) &integer_value, sizeof(gint))==ERROR_SUCCESS)
299
rs_conf_get_color(const gchar *name, GdkColor *color)
302
gboolean ret = FALSE;
304
str = rs_conf_get_string(name);
307
ret = gdk_color_parse(str, color);
314
rs_conf_set_color(const gchar *name, GdkColor *color)
317
gboolean ret = FALSE;
319
str = g_strdup_printf ("#%02x%02x%02x", color->red>>8, color->green>>8, color->blue>>8);
322
ret = rs_conf_set_string(name, str);
328
static const struct {
332
{INTENT_PERCEPTUAL, "perceptual"},
333
{INTENT_RELATIVE_COLORIMETRIC, "relative"},
334
{INTENT_SATURATION, "saturation"},
335
{INTENT_ABSOLUTE_COLORIMETRIC, "absolute"},
340
rs_conf_get_cms_intent(const gchar *name, gint *intent)
343
gboolean ret = FALSE;
346
str = rs_conf_get_string(name);
349
while(intents[n].name)
351
if (g_ascii_strncasecmp(intents[n].name, str, 15) == 0)
353
*intent = intents[n].intent;
366
rs_conf_set_cms_intent(const gchar *name, gint *intent)
368
gboolean ret = FALSE;
372
while(intents[n].name)
374
if (*intent == intents[n].intent)
376
str = intents[n].name;
384
ret = rs_conf_set_string(name, str);
390
rs_conf_get_cms_profile(gint type)
394
if (type == CMS_PROFILE_INPUT)
396
rs_conf_get_integer(CONF_CMS_IN_PROFILE_SELECTED, &selected);
398
ret = rs_conf_get_nth_string_from_list_string(CONF_CMS_IN_PROFILE_LIST, --selected);
400
else if (type == CMS_PROFILE_DISPLAY)
402
rs_conf_get_integer(CONF_CMS_DI_PROFILE_SELECTED, &selected);
404
ret = rs_conf_get_nth_string_from_list_string(CONF_CMS_DI_PROFILE_LIST, --selected);
406
else if (type == CMS_PROFILE_EXPORT)
408
rs_conf_get_integer(CONF_CMS_EX_PROFILE_SELECTED, &selected);
410
ret = rs_conf_get_nth_string_from_list_string(CONF_CMS_EX_PROFILE_LIST, --selected);
417
rs_conf_get_filetype(const gchar *name, RS_FILETYPE **target)
419
extern RS_FILETYPE *filetypes;
420
RS_FILETYPE *filetype = filetypes, *def=NULL;
422
str = rs_conf_get_string(name);
425
if (0==g_ascii_strcasecmp(filetype->id, DEFAULT_CONF_EXPORT_FILETYPE))
428
if (0==g_ascii_strcasecmp(filetype->id, str))
434
filetype = filetype->next;
443
rs_conf_set_filetype(const gchar *name, const RS_FILETYPE *filetype)
446
gboolean ret = FALSE;
451
ret = rs_conf_set_string(name, str);
457
rs_conf_get_double(const gchar *name, gdouble *float_value)
462
GConfClient *client = gconf_client_get_default();
463
GString *fullname = g_string_new(GCONF_PATH);
464
g_string_append(fullname, name);
467
g_static_mutex_lock(&lock);
468
gvalue = gconf_client_get(client, fullname->str, NULL);
469
g_static_mutex_unlock(&lock);
472
if (gvalue->type == GCONF_VALUE_FLOAT)
475
*float_value = gconf_value_get_float(gvalue);
477
gconf_value_free(gvalue);
479
g_object_unref(client);
481
g_string_free(fullname, TRUE);
488
if (RegOpenKeyEx( HKEY_CURRENT_USER, REGISTRY_KEY, 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS)
490
lRet = RegQueryValueEx( hKey, name, NULL, NULL, NULL, &dwBufLen);
494
DWORD size = sizeof(gdouble);
495
lRet = RegQueryValueEx( hKey, name, NULL, NULL, (LPBYTE) &val, &size);
497
if ((lRet == ERROR_SUCCESS) && (size == sizeof(gdouble)))
509
rs_conf_set_double(const gchar *name, const gdouble float_value)
511
gboolean ret = FALSE;
513
GConfClient *client = gconf_client_get_default();
514
GString *fullname = g_string_new(GCONF_PATH);
515
g_string_append(fullname, name);
516
g_static_mutex_lock(&lock);
519
ret = gconf_client_set_float(client, fullname->str, float_value, NULL);
520
g_object_unref(client);
522
g_static_mutex_unlock(&lock);
523
g_string_free(fullname, TRUE);
528
if (RegCreateKeyEx(HKEY_CURRENT_USER, REGISTRY_KEY, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
530
if (RegSetValueEx(hKey, name, 0, REG_BINARY, (LPBYTE) &float_value, sizeof(gdouble))==ERROR_SUCCESS)
539
rs_conf_get_list_string(const gchar *name)
543
GConfClient *client = gconf_client_get_default();
544
GString *fullname = g_string_new(GCONF_PATH);
546
g_string_append(fullname, name);
547
g_static_mutex_lock(&lock);
550
list = gconf_client_get_list(client, fullname->str, GCONF_VALUE_STRING, NULL);
551
g_object_unref(client);
553
g_static_mutex_unlock(&lock);
554
g_string_free(fullname, TRUE);
556
/* FIXME: windows stub */
562
rs_conf_set_list_string(const gchar *name, GSList *list)
564
gboolean ret = FALSE;
566
GConfClient *client = gconf_client_get_default();
567
GString *fullname = g_string_new(GCONF_PATH);
569
g_string_append(fullname, name);
570
g_static_mutex_lock(&lock);
573
ret = gconf_client_set_list(client, fullname->str, GCONF_VALUE_STRING, list, NULL);
574
g_object_unref(client);
576
g_static_mutex_unlock(&lock);
577
g_string_free(fullname, TRUE);
579
/* FIXME: windows stub */
585
rs_conf_add_string_to_list_string(const gchar *name, gchar *value)
587
gboolean ret = FALSE;
589
GSList *newlist = NULL;
590
GSList *oldlist = rs_conf_get_list_string(name);
594
newlist = g_slist_append(newlist, oldlist->data);
595
oldlist = oldlist->next;
598
newlist = g_slist_append(newlist, value);
599
ret = rs_conf_set_list_string(name, newlist);
605
rs_conf_get_nth_string_from_list_string(const gchar *name, gint num)
607
GSList *list = rs_conf_get_list_string(name);
613
for (i = 0; i < num; i++)
616
value = (gchar *) list->data;