[evince/gnome-2-30] Remove some code duplication



commit bb5e5eed05809e2988f2c3db07002338c01a4a9f
Author: Hib Eris <hib hiberis nl>
Date:   Tue May 25 17:44:01 2010 +0200

    Remove some code duplication

 libdocument/ev-init.c    |   45 +++++++++++++++++++++++++++------------------
 libdocument/ev-init.h    |    2 ++
 previewer/Makefile.am    |    1 -
 previewer/ev-previewer.c |   31 +------------------------------
 shell/Makefile.am        |    1 -
 shell/main.c             |   31 +------------------------------
 6 files changed, 31 insertions(+), 80 deletions(-)
---
diff --git a/libdocument/ev-init.c b/libdocument/ev-init.c
index fb10ac5..9e8e105 100644
--- a/libdocument/ev-init.c
+++ b/libdocument/ev-init.c
@@ -35,6 +35,7 @@ static int ev_init_count;
 #ifdef G_OS_WIN32
 
 static HMODULE evdocument_dll = NULL;
+static gchar *locale_dir = NULL;
 
 #ifdef DLL_EXPORT
 BOOL WINAPI
@@ -49,34 +50,39 @@ DllMain (HINSTANCE hinstDLL,
 }
 #endif
 
-#endif
-
-static gchar *
-_ev_get_locale_dir (void)
+static const gchar *
+_ev_win32_get_locale_dir (HMODULE module)
 {
-#ifdef G_OS_WIN32
-	gchar *install_dir = NULL, *locale_dir;
+	gchar *install_dir = NULL, *utf8_locale_dir;
 	gchar *retval = NULL;
 
 	if (evdocument_dll != NULL)
-		install_dir = g_win32_get_package_installation_directory_of_module (evdocument_dll);
+		install_dir =
+		g_win32_get_package_installation_directory_of_module (module);
 
 	if (install_dir) {
-		locale_dir = g_build_filename (install_dir,
+		utf8_locale_dir = g_build_filename (install_dir,
 			"share", "locale", NULL);
 
-		retval = g_win32_locale_filename_from_utf8 (locale_dir);
+		locale_dir = g_win32_locale_filename_from_utf8 (utf8_locale_dir);
 
 		g_free (install_dir);
-		g_free (locale_dir);
+		g_free (utf8_locale_dir);
 	}
 
-	if (retval)
-		return retval;
-	else
-		return g_strdup ("");
+	if (!locale_dir)
+		locale_dir = g_strdup ("");
+}
+
+#endif
+
+const gchar *
+ev_get_locale_dir (void)
+{
+#ifdef G_OS_WIN32
+	return _ev_win32_get_locale_dir (evdocument_dll);
 #else
-	return g_strdup (GNOMELOCALEDIR);
+	return GNOMELOCALEDIR;
 #endif
 }
 
@@ -100,9 +106,7 @@ ev_init (void)
                 return have_backends;
 
 	/* set up translation catalog */
-	gchar *tmp = _ev_get_locale_dir ();
-	bindtextdomain (GETTEXT_PACKAGE, tmp);
-	g_free (tmp);
+	bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir ());
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
         _ev_debug_init ();
@@ -125,6 +129,11 @@ ev_shutdown (void)
         if (--ev_init_count > 0)
                 return;
 
+#ifdef G_OS_WIN32
+	if (locale_dir != NULL)
+		g_free(locale_dir);
+#endif
+
         _ev_backends_manager_shutdown ();
         _ev_file_helpers_shutdown ();
         _ev_debug_shutdown ();
diff --git a/libdocument/ev-init.h b/libdocument/ev-init.h
index 00560a4..046ee9b 100644
--- a/libdocument/ev-init.h
+++ b/libdocument/ev-init.h
@@ -28,6 +28,8 @@
 
 G_BEGIN_DECLS
 
+const gchar* ev_get_locale_dir (void);
+
 gboolean    ev_init           (void);
 
 void        ev_shutdown       (void);
diff --git a/previewer/Makefile.am b/previewer/Makefile.am
index ea5296e..da0706c 100644
--- a/previewer/Makefile.am
+++ b/previewer/Makefile.am
@@ -13,7 +13,6 @@ evince_previewer_CPPFLAGS = \
         -I$(top_srcdir)/libdocument             \
         -I$(top_srcdir)/libview                 \
 	-I$(top_srcdir)/libmisc			\
-	-DGNOMELOCALEDIR=\"$(datadir)/locale\"	\
 	$(AM_CPPFLAGS)
 
 evince_previewer_CFLAGS = \
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index 14d4f2f..2b8dea3 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -100,33 +100,6 @@ ev_previewer_load_document (const gchar     *filename,
 	g_free (uri);
 }
 
-static gchar*
-ev_previewer_get_locale_dir ()
-{
-#ifdef G_OS_WIN32
-	gchar *install_dir = NULL, *locale_dir;
-	gchar *retval = NULL;
-
-	install_dir =
-	    g_win32_get_package_installation_directory_of_module (NULL);
-
-	if (install_dir) {
-		locale_dir = g_build_filename (install_dir,
-					"share", "locale", NULL);
-		retval = g_win32_locale_filename_from_utf8 (locale_dir);
-		g_free (install_dir);
-		g_free (locale_dir);
-	}
-
-	if (retval)
-		return retval;
-	else
-		return g_strdup ("");
-#else
-	return g_strdup (GNOMELOCALEDIR);
-#endif
-}
-
 gint
 main (gint argc, gchar **argv)
 {
@@ -166,9 +139,7 @@ main (gint argc, gchar **argv)
 
 #ifdef ENABLE_NLS
 	/* Initialize the i18n stuff */
-	gchar *tmp = ev_previewer_get_locale_dir ();
-	bindtextdomain (GETTEXT_PACKAGE, tmp);
-	g_free (tmp);
+	bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir());
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 #endif
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 16f3034..392e91c 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -15,7 +15,6 @@ INCLUDES=							\
 	-I$(top_builddir)/libview				\
 	-I$(top_srcdir)/libmisc					\
 	-I$(top_srcdir)/properties				\
-	-DGNOMELOCALEDIR=\"$(datadir)/locale\"			\
 	-DGNOMEICONDIR=\""$(datadir)/pixmaps"\" 		\
 	-DBINDIR=\""$(bindir)"\"				\
 	-DLIBEXECDIR=\""$(libexecdir)"\"			\
diff --git a/shell/main.c b/shell/main.c
index 54507ee..77732a9 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -227,33 +227,6 @@ load_files (const char **files)
         }
 }
 
-static gchar*
-ev_get_locale_dir ()
-{
-#ifdef G_OS_WIN32
-	gchar *install_dir = NULL, *locale_dir;
-	gchar *retval = NULL;
-
-	install_dir =
-	    g_win32_get_package_installation_directory_of_module (NULL);
-
-	if (install_dir) {
-		locale_dir = g_build_filename (install_dir,
-					"share", "locale", NULL);
-		retval = g_win32_locale_filename_from_utf8 (locale_dir);
-		g_free (install_dir);
-		g_free (locale_dir);
-	}
-
-	if (retval)
-		return retval;
-	else
-		return g_strdup ("");
-#else
-	return g_strdup (GNOMELOCALEDIR);
-#endif
-}
-
 int
 main (int argc, char *argv[])
 {
@@ -291,9 +264,7 @@ main (int argc, char *argv[])
 
 #ifdef ENABLE_NLS
 	/* Initialize the i18n stuff */
-	gchar *tmp = ev_get_locale_dir ();
-	bindtextdomain (GETTEXT_PACKAGE, tmp);
-	g_free (tmp);
+	bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir());
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]