Updated Spanish translation
[evolution.git] / e-util / e-win32-defaults.c
blobf44770614c45cd9d698f00ca349b9a17cde45a59
1 /*
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10 * for more details.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Authors:
17 * Fridrich Strba <fridrich.strba@bluewin.ch>
19 * Copyright (C) 2010 Fridrich Strba
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <windows.h>
29 #include "e-win32-defaults.h"
30 #include "e-util-private.h"
32 #define MAX_VALUE_NAME 4096
33 #define EVOBINARY "evolution.exe"
34 #define EUTILDLL "libeutil-0.dll"
35 #define CANONICALNAME "Evolution"
37 static gchar *
38 _e_win32_sanitize_path (gchar *path)
40 gchar *p = path;
41 while (*p != '\0') {
42 if (G_IS_DIR_SEPARATOR (*p))
43 *p = G_DIR_SEPARATOR;
44 p = g_utf8_find_next_char (p, NULL);
46 return path;
50 * Addressbook Client registration
53 static void
54 _e_register_vcard_structure (HKEY hKey)
57 LONG returnValue;
58 DWORD dwDisposition;
59 gchar *defaultIcon = NULL;
60 gchar *evolutionBinary = NULL;
61 gchar *vcardCommand = NULL;
62 BYTE editFlags[4] = { 0x02, 0x00, 0x00, 0x00 };
64 static HKEY tmp_subkey = (HKEY) INVALID_HANDLE_VALUE;
66 if ((returnValue = RegCreateKeyExA (hKey, ".vcf", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
67 goto cleanup;
69 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)"vcard_evo_auto_file", strlen ("vcard_evo_auto_file") + 1)))
70 goto cleanup;
71 if ((returnValue = RegSetValueExA (tmp_subkey, "Content Type", 0, REG_SZ, (const BYTE *)"text/x-vcard", strlen ("text/x-vcard") + 1)))
72 goto cleanup;
74 RegFlushKey (tmp_subkey);
76 RegCloseKey (tmp_subkey);
78 if ((returnValue = RegCreateKeyExA (hKey, "MIME\\Database\\Content Type\\text/x-vcard", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
79 goto cleanup;
81 if ((returnValue = RegSetValueExA (tmp_subkey, "Extension", 0, REG_SZ, (const BYTE *)".vcf", strlen (".vcf") + 1)))
82 goto cleanup;
84 RegFlushKey (tmp_subkey);
86 RegCloseKey (tmp_subkey);
88 if ((returnValue = RegCreateKeyExA (hKey, "vcard_evo_auto_file", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
89 goto cleanup;
91 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)"vCard File", strlen ("vCard File") + 1)))
92 goto cleanup;
93 if ((returnValue = RegSetValueExA (tmp_subkey, "EditFlags", 0, REG_BINARY, editFlags, G_N_ELEMENTS (editFlags))))
94 goto cleanup;
96 RegFlushKey (tmp_subkey);
98 RegCloseKey (tmp_subkey);
100 if ((returnValue = RegCreateKeyExA (hKey, "vcard_evo_auto_file\\DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
101 goto cleanup;
103 evolutionBinary = _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S, _e_get_bindir (), EVOBINARY, NULL));
104 defaultIcon = g_strconcat (evolutionBinary, ",0", NULL);
106 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)defaultIcon, strlen (defaultIcon) + 1)))
107 goto cleanup;
110 RegFlushKey (tmp_subkey);
112 RegCloseKey (tmp_subkey);
114 if ((returnValue = RegCreateKeyExA (hKey, "vcard_evo_auto_file\\shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
115 goto cleanup;
117 vcardCommand = g_strconcat("\"", evolutionBinary, "\" --component=addressbook \%1", NULL);
119 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)vcardCommand, strlen (vcardCommand) + 1)))
120 goto cleanup;
122 RegFlushKey (tmp_subkey);
124 RegCloseKey (tmp_subkey);
126 cleanup:
127 g_free (defaultIcon);
128 g_free (evolutionBinary);
129 g_free (vcardCommand);
132 static void
133 _e_register_ldif_structure (HKEY hKey)
136 LONG returnValue;
137 DWORD dwDisposition;
138 gchar *defaultIcon = NULL;
139 gchar *evolutionBinary = NULL;
140 gchar *vcardCommand = NULL;
141 BYTE editFlags[4] = { 0x02, 0x00, 0x00, 0x00 };
143 static HKEY tmp_subkey = (HKEY) INVALID_HANDLE_VALUE;
145 if ((returnValue = RegCreateKeyExA (hKey, ".ldi", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
146 goto cleanup;
148 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)"ldif_evo_auto_file", strlen ("ldif_evo_auto_file") + 1)))
149 goto cleanup;
150 if ((returnValue = RegSetValueExA (tmp_subkey, "Content Type", 0, REG_SZ, (const BYTE *)"text/x-ldif", strlen ("text/x-ldif") + 1)))
151 goto cleanup;
153 RegFlushKey (tmp_subkey);
155 RegCloseKey (tmp_subkey);
157 if ((returnValue = RegCreateKeyExA (hKey, ".ldif", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
158 goto cleanup;
160 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)"ldif_evo_auto_file", strlen ("ldif_evo_auto_file") + 1)))
161 goto cleanup;
162 if ((returnValue = RegSetValueExA (tmp_subkey, "Content Type", 0, REG_SZ, (const BYTE *)"text/x-ldif", strlen ("text/x-ldif") + 1)))
163 goto cleanup;
165 RegFlushKey (tmp_subkey);
167 RegCloseKey (tmp_subkey);
169 if ((returnValue = RegCreateKeyExA (hKey, "MIME\\Database\\Content Type\\text/x-ldif", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
170 goto cleanup;
172 if ((returnValue = RegSetValueExA (tmp_subkey, "Extension", 0, REG_SZ, (const BYTE *)".ldi", strlen (".ldi") + 1)))
173 goto cleanup;
175 RegFlushKey (tmp_subkey);
177 RegCloseKey (tmp_subkey);
179 if ((returnValue = RegCreateKeyExA (hKey, "ldif_evo_auto_file", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
180 goto cleanup;
182 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)"LDIF File", strlen ("LDIF File") + 1)))
183 goto cleanup;
184 if ((returnValue = RegSetValueExA (tmp_subkey, "EditFlags", 0, REG_BINARY, editFlags, G_N_ELEMENTS (editFlags))))
185 goto cleanup;
187 RegFlushKey (tmp_subkey);
189 RegCloseKey (tmp_subkey);
191 if ((returnValue = RegCreateKeyExA (hKey, "ldif_evo_auto_file\\DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
192 goto cleanup;
194 evolutionBinary = _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S, _e_get_bindir (), EVOBINARY, NULL));
195 defaultIcon = g_strconcat (evolutionBinary, ",0", NULL);
197 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)defaultIcon, strlen (defaultIcon) + 1)))
198 goto cleanup;
201 RegFlushKey (tmp_subkey);
203 RegCloseKey (tmp_subkey);
205 if ((returnValue = RegCreateKeyExA (hKey, "ldif_evo_auto_file\\shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
206 goto cleanup;
208 vcardCommand = g_strconcat("\"", evolutionBinary, "\" --component=addressbook \%1", NULL);
210 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)vcardCommand, strlen (vcardCommand) + 1)))
211 goto cleanup;
213 RegFlushKey (tmp_subkey);
215 RegCloseKey (tmp_subkey);
217 cleanup:
218 g_free (defaultIcon);
219 g_free (evolutionBinary);
220 g_free (vcardCommand);
223 static void
224 _e_win32_register_addressbook_impl (gboolean system)
226 LONG returnValue;
227 DWORD dwDisposition;
228 gchar *evolutionBinary = NULL;
229 gchar *openCommand = NULL;
231 static HKEY reg_key = (HKEY) INVALID_HANDLE_VALUE;
232 static HKEY reg_subkey = (HKEY) INVALID_HANDLE_VALUE;
235 if ((returnValue = RegCreateKeyExA (system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
236 "Software\\Clients\\Contacts\\" CANONICALNAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_key, &dwDisposition)))
237 goto cleanup;
239 if ((returnValue = RegSetValueExA (reg_key, NULL, 0, REG_SZ, (const BYTE *)CANONICALNAME, strlen (CANONICALNAME) + 1)))
240 goto cleanup;
242 RegFlushKey (reg_key);
244 if ((returnValue = RegCreateKeyExA (reg_key, "shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_subkey, &dwDisposition)))
245 goto cleanup;
247 evolutionBinary = _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S, _e_get_bindir (), EVOBINARY, NULL));
248 openCommand = g_strconcat("\"", evolutionBinary, "\" --component=addressbook", NULL);
249 if ((returnValue = RegSetValueExA (reg_subkey, NULL, 0, REG_SZ, (const BYTE *)openCommand, strlen (openCommand) + 1)))
250 goto cleanup;
252 RegFlushKey (reg_subkey);
254 RegCloseKey (reg_subkey);
257 if ((returnValue = RegCreateKeyExA (reg_key, "Protocols", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_subkey, &dwDisposition)))
258 goto cleanup;
260 _e_register_vcard_structure (reg_subkey);
261 _e_register_ldif_structure (reg_subkey);
263 RegCloseKey (reg_subkey);
265 RegCloseKey (reg_key);
267 if ((returnValue = RegCreateKeyExA (system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
268 "Software\\Classes", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_key, &dwDisposition)))
269 return;
271 _e_register_ldif_structure (reg_key);
273 RegFlushKey (reg_key);
275 RegCloseKey (reg_key);
277 cleanup:
278 g_free (evolutionBinary);
279 g_free (openCommand);
282 void
283 _e_win32_register_addressbook (void)
285 _e_win32_register_addressbook_impl (TRUE);
286 _e_win32_register_addressbook_impl (FALSE);
289 void
290 _e_win32_unregister_addressbook (void)
295 * Mail Client registration
298 static void
299 _e_register_mailto_structure (HKEY hKey)
301 LONG returnValue;
302 DWORD dwDisposition;
303 gchar *defaultIcon = NULL;
304 gchar *evolutionBinary = NULL;
305 gchar *mailtoCommand = NULL;
306 BYTE editFlags[4] = { 0x02, 0x00, 0x00, 0x00 };
308 static HKEY tmp_subkey = (HKEY) INVALID_HANDLE_VALUE;
310 if ((returnValue = RegSetValueExA (hKey, NULL, 0, REG_SZ, (const BYTE *)"URL:MailTo Protocol", strlen ("URL:MailTo Protocol") + 1)))
311 goto cleanup;
312 if ((returnValue = RegSetValueExA (hKey, "EditFlags", 0, REG_BINARY, editFlags, G_N_ELEMENTS (editFlags))))
313 goto cleanup;
314 if ((returnValue = RegSetValueExA (hKey, "URL Protocol", 0, REG_SZ, (const BYTE *)"", strlen ("") + 1)))
315 goto cleanup;
317 RegFlushKey (hKey);
319 if ((returnValue = RegCreateKeyExA (hKey, "DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
320 goto cleanup;
322 evolutionBinary = _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S, _e_get_bindir (), EVOBINARY, NULL));
323 defaultIcon = g_strconcat (evolutionBinary, ",1", NULL);
325 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)defaultIcon, strlen (defaultIcon) + 1)))
326 goto cleanup;
329 RegFlushKey (tmp_subkey);
331 RegCloseKey (tmp_subkey);
333 if ((returnValue = RegCreateKeyExA (hKey, "shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmp_subkey, &dwDisposition)))
334 goto cleanup;
336 evolutionBinary = _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S, _e_get_bindir (), EVOBINARY, NULL));
337 mailtoCommand = g_strconcat("\"", evolutionBinary, "\" --component=mail mailto:\%1", NULL);
339 if ((returnValue = RegSetValueExA (tmp_subkey, NULL, 0, REG_SZ, (const BYTE *)mailtoCommand, strlen (mailtoCommand) + 1)))
340 goto cleanup;
343 RegFlushKey (tmp_subkey);
345 RegCloseKey (tmp_subkey);
347 cleanup:
348 g_free (defaultIcon);
349 g_free (evolutionBinary);
350 g_free (mailtoCommand);
353 static void
354 _e_win32_register_mailer_impl (gboolean system)
356 LONG returnValue;
357 DWORD i, dwDisposition;
358 gchar *defaultIcon = NULL;
359 gchar *dllPath = NULL;
360 gchar *evolutionBinary = NULL;
361 gchar *openCommand = NULL;
362 gchar *reinstallCommand = NULL;
363 gchar *showIconsCommand = NULL;
364 gchar *hideIconsCommand = NULL;
366 static HKEY reg_key = (HKEY) INVALID_HANDLE_VALUE;
367 static HKEY reg_subkey = (HKEY) INVALID_HANDLE_VALUE;
370 if ((returnValue = RegCreateKeyExA (system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
371 "Software\\Clients\\Mail\\" CANONICALNAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_key, &dwDisposition)))
372 goto cleanup;
374 if ((returnValue = RegSetValueExA (reg_key, NULL, 0, REG_SZ, (const BYTE *)CANONICALNAME, strlen (CANONICALNAME) + 1)))
375 goto cleanup;
377 dllPath = _e_win32_sanitize_path (g_build_path(G_DIR_SEPARATOR_S, _e_get_bindir (), EUTILDLL, NULL));
379 if ((returnValue = RegSetValueExA (reg_key, "DLLPath", 0, REG_SZ, (const BYTE *)dllPath, strlen (dllPath) + 1)))
380 goto cleanup;
382 RegFlushKey (reg_key);
384 if ((returnValue = RegCreateKeyExA (reg_key, "DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_subkey, &dwDisposition)))
385 goto cleanup;
387 evolutionBinary = _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S, _e_get_bindir (), EVOBINARY, NULL));
388 defaultIcon = g_strconcat(evolutionBinary, ",0", NULL);
390 if ((returnValue = RegSetValueExA (reg_subkey, NULL, 0, REG_SZ, (const BYTE *)defaultIcon, strlen (defaultIcon) + 1)))
391 goto cleanup;
394 RegFlushKey (reg_subkey);
396 RegCloseKey (reg_subkey);
398 if ((returnValue = RegCreateKeyExA (reg_key, "shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_subkey, &dwDisposition)))
399 goto cleanup;
401 openCommand = g_strconcat("\"", evolutionBinary, "\" --component=mail", NULL);
402 if ((returnValue = RegSetValueExA (reg_subkey, NULL, 0, REG_SZ, (const BYTE *)openCommand, strlen (openCommand) + 1)))
403 goto cleanup;
405 RegFlushKey (reg_subkey);
407 RegCloseKey (reg_subkey);
409 if ((returnValue = RegCreateKeyExA (reg_key, "InstallInfo", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_subkey, &dwDisposition)))
410 goto cleanup;
412 reinstallCommand = g_strconcat ("\"", evolutionBinary, "\" --reinstall", NULL);
414 if ((returnValue = RegSetValueExA (reg_subkey, "ReinstallCommand", 0, REG_EXPAND_SZ, (const BYTE *)reinstallCommand, strlen (reinstallCommand) + 1)))
415 goto cleanup;
418 showIconsCommand = g_strconcat ("\"", evolutionBinary, "\" --show-icons", NULL);
420 if ((returnValue = RegSetValueExA (reg_subkey, "ShowIconsCommand", 0, REG_EXPAND_SZ, (const BYTE *)showIconsCommand, strlen (showIconsCommand) + 1)))
421 goto cleanup;
424 hideIconsCommand = g_strconcat ("\"", evolutionBinary, "\" --hide-icons", NULL);
426 if ((returnValue = RegSetValueExA (reg_subkey, "HideIconsCommand", 0, REG_EXPAND_SZ, (const BYTE *)hideIconsCommand, strlen (hideIconsCommand) + 1)))
427 goto cleanup;
430 i = 1;
431 if ((returnValue = RegSetValueExA (reg_subkey, "IconsVisible", 0, REG_DWORD, (BYTE*)&i, sizeof (i))))
432 goto cleanup;
434 RegFlushKey (reg_subkey);
436 RegCloseKey (reg_subkey);
438 if ((returnValue = RegCreateKeyExA (reg_key, "Protocols\\mailto", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_subkey, &dwDisposition)))
439 goto cleanup;
441 if ((returnValue = RegSetValueExA (reg_key, NULL, 0, REG_SZ, (const BYTE *)CANONICALNAME, strlen (CANONICALNAME) + 1)))
442 goto cleanup;
444 _e_register_mailto_structure (reg_subkey);
446 RegCloseKey (reg_subkey);
448 RegCloseKey (reg_key);
450 cleanup:
451 g_free (defaultIcon);
452 g_free (dllPath);
453 g_free (evolutionBinary);
454 g_free (openCommand);
455 g_free (reinstallCommand);
456 g_free (showIconsCommand);
457 g_free (hideIconsCommand);
460 void
461 _e_win32_register_mailer (void)
463 _e_win32_register_mailer_impl (TRUE);
464 _e_win32_register_mailer_impl (FALSE);
467 void
468 _e_win32_unregister_mailer (void)
472 static void
473 _e_win32_set_default_mailer_impl (gboolean system)
475 LONG returnValue;
476 DWORD dwDisposition;
478 const char client_message[] = "Software\\Clients\\Mail";
479 const char mailto_message[] = "Software\\Classes\\mailto";
481 static HKEY reg_key = (HKEY) INVALID_HANDLE_VALUE;
483 _e_win32_register_mailer_impl (system);
485 if ((returnValue = RegCreateKeyExA (system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
486 client_message, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_key, &dwDisposition)))
487 return;
489 if ((returnValue = RegSetValueExA (reg_key, NULL, 0, REG_SZ, (const BYTE *)CANONICALNAME, strlen (CANONICALNAME) + 1)))
490 return;
492 RegFlushKey (reg_key);
494 RegCloseKey (reg_key);
496 if ((returnValue = RegCreateKeyExA (system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
497 mailto_message, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg_key, &dwDisposition)))
498 return;
500 _e_register_mailto_structure (reg_key);
502 RegFlushKey (reg_key);
504 RegCloseKey (reg_key);
506 SendMessageA (HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)&client_message);
507 SendMessageA (HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)&mailto_message);
510 void
511 _e_win32_set_default_mailer (void)
513 _e_win32_set_default_mailer_impl (TRUE);
514 _e_win32_set_default_mailer_impl (FALSE);
517 void
518 _e_win32_unset_default_mailer (void)
520 /* TODO: implement */