]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-init.c
[windows] Fix localization on Windows
[evince.git] / libdocument / ev-init.c
1 /* this file is part of evince, a gnome document viewer
2  *
3  * Copyright © 2009 Christian Persch
4  *
5  * Evince is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License, or
8  * (at your option) any later version.
9  *
10  * Evince is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser 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.
18  */
19
20 #include <config.h>
21
22 #include <glib.h>
23 #include <glib/gi18n-lib.h>
24 #ifdef G_OS_WIN32
25 #include <windows.h>
26 #endif
27
28 #include "ev-init.h"
29 #include "ev-backends-manager.h"
30 #include "ev-debug.h"
31 #include "ev-file-helpers.h"
32
33 static int ev_init_count;
34
35 #ifdef G_OS_WIN32
36
37 static HMODULE evdocument_dll = NULL;
38
39 #ifdef DLL_EXPORT
40 BOOL WINAPI
41 DllMain (HINSTANCE hinstDLL,
42          DWORD     fdwReason,
43          LPVOID    lpvReserved)
44 {
45         if (fdwReason == DLL_PROCESS_ATTACH)
46                 evdocument_dll = hinstDLL;
47
48         return TRUE;
49 }
50 #endif
51
52 #endif
53
54 static gchar *
55 _ev_get_locale_dir (void)
56 {
57 #ifdef G_OS_WIN32
58         gchar *install_dir = NULL, *locale_dir;
59         gchar *retval = NULL;
60
61         if (evdocument_dll != NULL)
62                 install_dir = g_win32_get_package_installation_directory_of_module (evdocument_dll);
63
64         if (install_dir) {
65                 locale_dir = g_build_filename (install_dir,
66                         "share", "locale", NULL);
67
68                 retval = g_win32_locale_filename_from_utf8 (locale_dir);
69
70                 g_free (install_dir);
71                 g_free (locale_dir);
72         }
73
74         if (retval)
75                 return retval;
76         else
77                 return g_strdup ("");
78 #else
79         return g_strdup (GNOMELOCALEDIR);
80 #endif
81 }
82
83 /**
84  * ev_init:
85  *
86  * Initializes the evince document library, and binds the evince
87  * gettext domain.
88  *
89  * You must call this before calling any other function in the evince
90  * document library.
91  *
92  * Returns: %TRUE if any backends were found; %FALSE otherwise
93  */
94 gboolean
95 ev_init (void)
96 {
97         static gboolean have_backends;
98
99         if (ev_init_count++ > 0)
100                 return have_backends;
101
102         /* set up translation catalog */
103         gchar *tmp = _ev_get_locale_dir ();
104         bindtextdomain (GETTEXT_PACKAGE, tmp);
105         g_free (tmp);
106         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
107
108         _ev_debug_init ();
109         _ev_file_helpers_init ();
110         have_backends = _ev_backends_manager_init ();
111
112         return have_backends;
113 }
114
115 /**
116  * ev_shutdown:
117  *
118  * Shuts the evince document library down.
119  */
120 void
121 ev_shutdown (void)
122 {
123         g_assert (_ev_is_initialized ());
124
125         if (--ev_init_count > 0)
126                 return;
127
128         _ev_backends_manager_shutdown ();
129         _ev_file_helpers_shutdown ();
130         _ev_debug_shutdown ();
131 }
132
133 /*
134  * _ev_is_initialized:
135  *
136  * Returns: %TRUE if the evince document library has been initialized
137  */
138 gboolean
139 _ev_is_initialized (void)
140 {
141         return ev_init_count > 0;
142 }