src/win32/wspell.c

changeset 14253
b63ebf84c42b
parent 14252
d10dda2777a9
child 14254
77edc7a6191a
equal deleted inserted replaced
14252:d10dda2777a9 14253:b63ebf84c42b
1 /*
2 * gaim
3 *
4 * File: wspell.c
5 * Date: March, 2003
6 * Description: Windows Gaim gtkspell interface.
7 *
8 * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25 #include <windows.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <glib.h>
29 #include <gtk/gtk.h>
30 #include <gtkspell/gtkspell.h>
31 #include "debug.h"
32 #include "win32dep.h"
33
34 /* GTKSPELL DUMMY FUNCS */
35 GtkSpell* wgtkspell_new_attach(GtkTextView *view,
36 const gchar *lang,
37 GError **error) {return NULL;}
38 GtkSpell* wgtkspell_get_from_text_view(GtkTextView *view) {return NULL;}
39 void wgtkspell_detach(GtkSpell *spell) {}
40 gboolean wgtkspell_set_language(GtkSpell *spell,
41 const gchar *lang,
42 GError **error) {return 0;}
43 void wgtkspell_recheck_all(GtkSpell *spell) {}
44
45 /* GTKSPELL PROTOS */
46 GtkSpell* (*wgaim_gtkspell_new_attach) (GtkTextView *,
47 const gchar *,
48 GError **) = wgtkspell_new_attach;
49
50 GtkSpell* (*wgaim_gtkspell_get_from_text_view) (GtkTextView*) = wgtkspell_get_from_text_view;
51
52 void (*wgaim_gtkspell_detach) (GtkSpell*) = wgtkspell_detach;
53
54 gboolean (*wgaim_gtkspell_set_language) (GtkSpell*,
55 const gchar*,
56 GError**) = wgtkspell_set_language;
57
58 void (*wgaim_gtkspell_recheck_all) (GtkSpell*) = wgtkspell_recheck_all;
59
60 static void load_gtkspell() {
61 wgaim_gtkspell_new_attach = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_new_attach" );
62 wgaim_gtkspell_get_from_text_view = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_get_from_text_view");
63 wgaim_gtkspell_detach = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_detach");
64 wgaim_gtkspell_set_language = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_set_language");
65 wgaim_gtkspell_recheck_all = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_recheck_all");
66 }
67
68 static char* lookup_aspell_path() {
69 char *path = NULL;
70 const char *tmp;
71 HKEY reg_key;
72 DWORD type;
73 DWORD nbytes;
74 gboolean found_reg_key;
75 LPCTSTR subkey = NULL;
76
77 if ((tmp = g_getenv("GAIM_ASPELL_DIR")))
78 return g_strdup(tmp);
79
80 if (G_WIN32_HAVE_WIDECHAR_API ()) {
81 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Aspell", 0,
82 KEY_QUERY_VALUE,
83 &reg_key) == ERROR_SUCCESS) {
84 subkey = (LPCTSTR) L"Path";
85 if (!(found_reg_key = RegQueryValueExW(reg_key,
86 (WCHAR*) subkey, NULL,
87 &type, NULL, &nbytes
88 ) == ERROR_SUCCESS)) {
89 subkey = NULL;
90 found_reg_key = (RegQueryValueExW(reg_key,
91 (WCHAR*) subkey, NULL,
92 &type, NULL, &nbytes
93 ) == ERROR_SUCCESS);
94 }
95 if (found_reg_key) {
96 wchar_t *wc_temp = g_new (wchar_t, (nbytes + 1) / 2 + 1);
97 RegQueryValueExW(reg_key, (WCHAR*) subkey,
98 NULL, &type, (LPBYTE) wc_temp,
99 &nbytes);
100 wc_temp[nbytes / 2] = '\0';
101 path = g_utf16_to_utf8(
102 wc_temp, -1, NULL, NULL, NULL);
103 g_free (wc_temp);
104 }
105 }
106 } else {
107 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Aspell", 0,
108 KEY_QUERY_VALUE, &reg_key
109 ) == ERROR_SUCCESS) {
110 subkey = "Path";
111 if (!(found_reg_key = RegQueryValueExA(reg_key, subkey,
112 NULL, &type, NULL,
113 &nbytes
114 ) == ERROR_SUCCESS)) {
115 subkey = NULL;
116 found_reg_key = (RegQueryValueExA(reg_key,
117 subkey, NULL, &type,
118 NULL, &nbytes
119 ) == ERROR_SUCCESS);
120 }
121 if (found_reg_key) {
122 char *cp_temp = g_malloc (nbytes + 1);
123 RegQueryValueExA(reg_key, subkey, NULL, &type,
124 cp_temp, &nbytes);
125 cp_temp[nbytes] = '\0';
126 path = g_locale_to_utf8(
127 cp_temp, -1, NULL, NULL, NULL);
128 g_free (cp_temp);
129 }
130 }
131 }
132
133 if (reg_key != NULL) {
134 RegCloseKey(reg_key);
135 }
136
137 return path;
138 }
139
140 void wgaim_gtkspell_init() {
141 char *aspell_path = lookup_aspell_path();
142
143 if (aspell_path != NULL) {
144 char *tmp = g_strconcat(aspell_path, "\\aspell-15.dll", NULL);
145 if (g_file_test(tmp, G_FILE_TEST_EXISTS)) {
146 const char *path = g_getenv("PATH");
147 gaim_debug_info("wspell", "Found Aspell in %s\n", aspell_path);
148
149 g_free(tmp);
150
151 tmp = g_strdup_printf("%s%s%s", (path ? path : ""),
152 (path ? G_SEARCHPATH_SEPARATOR_S : ""),
153 aspell_path);
154
155 g_setenv("PATH", tmp, TRUE);
156
157 load_gtkspell();
158 } else {
159 gaim_debug_warning("wspell", "Couldn't find aspell-15.dll\n");
160 }
161
162 g_free(tmp);
163 g_free(aspell_path);
164 } else {
165 gaim_debug_warning("wspell", "Couldn't find path for Aspell\n");
166 }
167 }

mercurial