summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDom Lachowicz <domlachowicz@gmail.com>2003-07-29 00:01:20 +0000
committerDom Lachowicz <domlachowicz@gmail.com>2003-07-29 00:01:20 +0000
commite95db345556159c0264fe36198bcd8a66cd9f59f (patch)
treefde5747cea7acd7d073b5e427a1f9dc342007f56
parent1233bcc4005c6b83c39b955b284c0e682fb9c1fc (diff)
downloadenchant-e95db345556159c0264fe36198bcd8a66cd9f59f.tar.gz
enchant is now win32 (and possibly soon gconf) registry ready
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@20778 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/enchant-provider.h3
-rw-r--r--src/enchant.c74
-rw-r--r--src/ispell/ispell_checker.cpp8
-rw-r--r--src/myspell/myspell_checker.cpp8
-rw-r--r--src/uspell/uspell_provider.cpp8
5 files changed, 89 insertions, 12 deletions
diff --git a/src/enchant-provider.h b/src/enchant-provider.h
index ea8b38f..16c3399 100644
--- a/src/enchant-provider.h
+++ b/src/enchant-provider.h
@@ -42,6 +42,9 @@ typedef struct str_enchant_provider EnchantProvider;
ENCHANT_MODULE_EXPORT (char *)
enchant_get_user_home_dir (void);
+ENCHANT_MODULE_EXPORT (char *)
+ enchant_get_registry_value (const char * const prefix, const char * const key);
+
struct str_enchant_dict
{
void *user_data;
diff --git a/src/enchant.c b/src/enchant.c
index 4e48ee1..d549e0a 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -38,9 +38,54 @@
#include "enchant.h"
#include "enchant-provider.h"
-/* TODO: use the win32 registry in these following functions PLUS the
- * macro, if it exists (registry gets precedence)
+#ifdef _WIN32
+#include <windows.h>
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+static char *
+enchant_get_registry_value_ex (int current_user, const char * const prefix, const char * const key)
+{
+#ifndef _WIN32
+ return NULL;
+#else
+ HKEY hKey;
+ HKEY baseKey;
+ unsigned long lType;
+ DWORD dwSize;
+ char* szValue = NULL;
+
+ if (current_user)
+ baseKey = HKEY_CURRENT_USER;
+ else
+ baseKey = HKEY_LOCAL_MACHINE;
+
+ if( ::RegOpenKeyEx( baseKey, "Software\\Enchant", 0, KEY_READ, &hKey) == ERROR_SUCCESS )
+ {
+ // Determine size of string
+ if( ::RegQueryValueEx( hKey, key, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS )
+ {
+ szValue = g_new0(char, dwSize + 1);
+ ::RegQueryValueEx( hKey, key, NULL, &lType, szValue, &dwSize);
+ }
+ }
+
+ return szValue;
+#endif
+}
+
+/**
+ * enchant_get_registry_value
+ * @prefix:
+ * @key:
+ *
+ * Returns:
*/
+ENCHANT_MODULE_EXPORT (char *)
+enchant_get_registry_value (const char * const prefix, const char * const key)
+{
+ return enchant_get_registry_value_ex (0, prefix, key);
+}
/**
* enchant_get_user_home_dir
@@ -51,16 +96,27 @@
ENCHANT_MODULE_EXPORT (char *)
enchant_get_user_home_dir (void)
{
- const char * home_dir = g_get_home_dir ();
+ const char * home_dir = NULL;
- if (!home_dir)
- return NULL;
- return g_strdup (home_dir);
+ home_dir = enchant_get_registry_value_ex (1, "Config", "Home_Dir");
+ if (home_dir)
+ return (char *)home_dir;
+
+ home_dir = g_get_home_dir ();
+ if (home_dir)
+ return g_strdup (home_dir);
+ return NULL;
}
static char *
enchant_get_module_dir (void)
{
+ char * module_dir = NULL;
+
+ module_dir = enchant_get_registry_value ("Config", "Module_Dir");
+ if (module_dir)
+ return module_dir;
+
#ifdef ENCHANT_GLOBAL_MODULE_DIR
return g_strdup (ENCHANT_GLOBAL_MODULE_DIR);
#else
@@ -71,6 +127,12 @@ enchant_get_module_dir (void)
static char *
enchant_get_conf_dir (void)
{
+ char * ordering_dir = NULL;
+
+ ordering_dir = enchant_get_registry_value ("Config", "Data_Dir");
+ if (ordering_dir)
+ return ordering_dir;
+
#ifdef ENCHANT_GLOBAL_ORDERING
return g_strdup (ENCHANT_GLOBAL_ORDERING);
#else
diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp
index 0dbba05..09154f0 100644
--- a/src/ispell/ispell_checker.cpp
+++ b/src/ispell/ispell_checker.cpp
@@ -333,11 +333,15 @@ ISpellChecker::suggestWord(const char * const utf8Word, size_t length,
return sugg_arr;
}
-/* in preparation for using win32 registry keys, if necessary */
-
static char *
ispell_checker_get_prefix (void)
{
+ char * ispell_prefix = NULL;
+
+ ispell_prefix = enchant_get_registry_value ("Ispell", "Data_Dir");
+ if (ispell_prefix)
+ return ispell_prefix;
+
#ifdef ENCHANT_ISPELL_DICT_DIR
return g_strdup (ENCHANT_ISPELL_DICT_DIR);
#else
diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp
index 435f7ff..872ed49 100644
--- a/src/myspell/myspell_checker.cpp
+++ b/src/myspell/myspell_checker.cpp
@@ -42,11 +42,15 @@
/***************************************************************************/
-/* in preparation for using win32 registry keys, if necessary */
-
static char *
myspell_checker_get_prefix (void)
{
+ char * data_dir = NULL;
+
+ data_dir = enchant_get_registry_value ("Myspell", "Data_Dir");
+ if (data_dir)
+ return data_dir;
+
#ifdef ENCHANT_MYSPELL_DICT_DIR
return g_strdup (ENCHANT_MYSPELL_DICT_DIR);
#else
diff --git a/src/uspell/uspell_provider.cpp b/src/uspell/uspell_provider.cpp
index 348d091..e22f538 100644
--- a/src/uspell/uspell_provider.cpp
+++ b/src/uspell/uspell_provider.cpp
@@ -50,11 +50,15 @@
static const size_t MAXALTERNATIVE = 20; // we won't return more than this number of suggestions
static const size_t MAXCHARS = 100; // maximum number of bytes of utf8 or chars of UCS4 in a word
-/* in preparation for using win32 registry keys, if necessary */
-
static char *
uspell_checker_get_prefix (void)
{
+ char * data_dir = NULL;
+
+ data_dir = enchant_get_registry_value ("Uspell", "Data_Dir");
+ if (data_dir)
+ return data_dir;
+
#ifdef ENCHANT_USPELL_DICT_DIR
return g_strdup (ENCHANT_USPELL_DICT_DIR);
#else