summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Albright <eric_albright@sil.org>2008-02-26 04:15:26 +0000
committerEric Albright <eric_albright@sil.org>2008-02-26 04:15:26 +0000
commit0188ff9320a97c42e068526b461dc2b338c7c557 (patch)
treeea4c086cb0d8c12be1d6207550fd552f929fb034
parentd9981d00fc7e65c09d63f44fdbc706297df9f0c5 (diff)
downloadenchant-0188ff9320a97c42e068526b461dc2b338c7c557.tar.gz
On Windows adds the OpenOffice shared dictionary directory as one of the locations to find dictionaries for the myspell provider.
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@22946 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/myspell/myspell_checker.cpp78
1 files changed, 76 insertions, 2 deletions
diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp
index 83f1420..fe160fd 100644
--- a/src/myspell/myspell_checker.cpp
+++ b/src/myspell/myspell_checker.cpp
@@ -95,6 +95,56 @@ myspell_checker_get_prefix (void)
#endif
}
+#if defined(_WIN32)
+static WCHAR* GetRegistryValue(HKEY baseKey, const WCHAR * uKeyName, const WCHAR * uKey)
+{
+ HKEY hKey;
+ unsigned long lType;
+ DWORD dwSize;
+ WCHAR* wszValue = NULL;
+
+ if(RegOpenKeyEx(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
+ {
+ /* Determine size of string */
+ if(RegQueryValueEx( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS)
+ {
+ wszValue = g_new0(WCHAR, dwSize + 1);
+ RegQueryValueEx(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize);
+ }
+ }
+
+ return wszValue;
+}
+
+static char *
+myspell_checker_get_open_office_dicts_dir(void)
+{
+ WCHAR* wszDirectory;
+ char* open_office_dir, * open_office_dicts_dir;
+
+ /*start by trying current user*/
+ wszDirectory = GetRegistryValue (HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\soffice.exe", L"Path");
+ if(wszDirectory == NULL)
+ {
+ /*next try local machine*/
+ wszDirectory = GetRegistryValue (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\soffice.exe", L"Path");
+ }
+
+ if(wszDirectory == NULL)
+ {
+ return NULL;
+ }
+
+ else {
+ open_office_dir = g_utf16_to_utf8 ((gunichar2*)wszDirectory, -1, NULL, NULL, NULL);
+ open_office_dicts_dir = g_build_filename(open_office_dir, "share", "dict", "ooo", NULL);
+ g_free(wszDirectory);
+ g_free(open_office_dir);
+ return open_office_dicts_dir;
+ }
+}
+#endif
+
static bool
g_iconv_is_valid(GIConv i)
{
@@ -211,7 +261,20 @@ s_buildHashNames (std::vector<std::string> & names, const char * dict)
g_free (myspell_prefix);
}
- g_free(dict_dic);
+#if defined(_WIN32)
+ {
+ char* open_office_dicts_dir = myspell_checker_get_open_office_dicts_dir ();
+ if (open_office_dicts_dir)
+ {
+ tmp = g_build_filename (open_office_dicts_dir, dict_dic, NULL);
+ names.push_back (tmp);
+ g_free (tmp);
+ g_free (open_office_dicts_dir);
+ }
+ }
+#endif
+
+ g_free(dict_dic);
}
static char *
@@ -298,7 +361,10 @@ myspell_provider_enum_dicts (const char * const directory,
int hit = dir_entry.rfind (".dic");
if (hit != -1) {
- out_dicts.push_back (dir_entry.substr (0, hit));
+ /* don't include hyphenation dictionaries */
+ if(dir_entry.compare (0, 5, "hyph_") != 0){
+ out_dicts.push_back (dir_entry.substr (0, hit));
+ }
}
}
}
@@ -331,6 +397,14 @@ myspell_provider_list_dicts (EnchantProvider * me,
g_free (myspell_prefix);
}
+#if defined(_WIN32)
+ char * open_office_dicts_dir = myspell_checker_get_open_office_dicts_dir ();
+ if (open_office_dicts_dir) {
+ myspell_provider_enum_dicts (open_office_dicts_dir, dicts);
+ g_free (open_office_dicts_dir);
+ }
+#endif
+
if (dicts.size () > 0) {
dictionary_list = g_new0 (char *, dicts.size() + 1);