Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-init.c
Go to the documentation of this file.
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-document-factory.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 static gchar *locale_dir = NULL;
39 
40 #ifdef DLL_EXPORT
41 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
42 BOOL WINAPI
43 DllMain (HINSTANCE hinstDLL,
44  DWORD fdwReason,
45  LPVOID lpvReserved)
46 {
47  if (fdwReason == DLL_PROCESS_ATTACH)
48  evdocument_dll = hinstDLL;
49 
50  return TRUE;
51 }
52 #endif
53 
54 static const gchar *
55 _ev_win32_get_locale_dir (HMODULE module)
56 {
57  if (locale_dir)
58  return locale_dir;
59 
60  gchar *install_dir = NULL, *utf8_locale_dir;
61 
62  if (evdocument_dll != NULL)
63  install_dir =
64  g_win32_get_package_installation_directory_of_module (module);
65 
66  if (install_dir) {
67  utf8_locale_dir = g_build_filename (install_dir,
68  "share", "locale", NULL);
69 
70  locale_dir = g_win32_locale_filename_from_utf8 (utf8_locale_dir);
71 
72  g_free (install_dir);
73  g_free (utf8_locale_dir);
74  }
75 
76  if (!locale_dir)
77  locale_dir = g_strdup ("");
78 
79  return locale_dir;
80 }
81 
82 #endif
83 
84 const gchar *
86 {
87 #ifdef G_OS_WIN32
88  return _ev_win32_get_locale_dir (evdocument_dll);
89 #else
90  return GNOMELOCALEDIR;
91 #endif
92 }
93 
105 gboolean
106 ev_init (void)
107 {
108  static gboolean have_backends;
109 
110  if (ev_init_count++ > 0)
111  return have_backends;
112 
113  /* set up translation catalog */
114  bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir ());
115  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
116 
117  _ev_debug_init ();
119  have_backends = _ev_document_factory_init ();
120 
121  return have_backends;
122 }
123 
129 void
131 {
132  g_assert (_ev_is_initialized ());
133 
134  if (--ev_init_count > 0)
135  return;
136 
137 #ifdef G_OS_WIN32
138  if (locale_dir != NULL)
139  g_free(locale_dir);
140 #endif
141 
145 }
146 
147 /*
148  * _ev_is_initialized:
149  *
150  * Returns: %TRUE if the evince document library has been initialized
151  */
152 gboolean
154 {
155  return ev_init_count > 0;
156 }