]> www.fi.muni.cz Git - evince.git/commitdiff
A libdocument/ev-init.[ch]: Add single init/shutdown method. Bug #569117.
authorChristian Persch <chpe@src.gnome.org>
Fri, 30 Jan 2009 18:40:17 +0000 (18:40 +0000)
committerChristian Persch <chpe@src.gnome.org>
Fri, 30 Jan 2009 18:40:17 +0000 (18:40 +0000)
* evince-document.h:
* libdocument/Makefile.am:
A libdocument/ev-init.[ch]: Add single init/shutdown method. Bug
#569117.

* libdocument/ev-backends-manager.c: (_ev_backends_manager_init):
* libdocument/ev-backends-manager.h:
* libdocument/ev-debug.c: (_ev_debug_init), (_ev_debug_shutdown):
* libdocument/ev-debug.h:
* libdocument/ev-file-helpers.c: (_ev_file_helpers_init),
(_ev_file_helpers_shutdown):
* libdocument/ev-file-helpers.h: Make these init/shutdown methods
private.

* properties/ev-properties-main.c: (nautilus_module_initialize),
(nautilus_module_shutdown):
* shell/main.c: (main):
* thumbnailer/evince-thumbnailer.c: (main): Use the new single
init/shutdown method.

svn path=/trunk/; revision=3391

14 files changed:
ChangeLog
evince-document.h
libdocument/Makefile.am
libdocument/ev-backends-manager.c
libdocument/ev-backends-manager.h
libdocument/ev-debug.c
libdocument/ev-debug.h
libdocument/ev-file-helpers.c
libdocument/ev-file-helpers.h
libdocument/ev-init.c [new file with mode: 0644]
libdocument/ev-init.h [new file with mode: 0644]
properties/ev-properties-main.c
shell/main.c
thumbnailer/evince-thumbnailer.c

index b7798041b074756be7d12b88e5cc06a2b2298490..d9f6925ce66a0e8c57c63fb8925c7f2c47278ec0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2009-01-30  Christian Persch  <chpe@gnome.org>
+
+       * evince-document.h:
+       * libdocument/Makefile.am:
+       A libdocument/ev-init.[ch]: Add single init/shutdown method. Bug
+       #569117.
+
+       * libdocument/ev-backends-manager.c: (_ev_backends_manager_init):
+       * libdocument/ev-backends-manager.h:
+       * libdocument/ev-debug.c: (_ev_debug_init), (_ev_debug_shutdown):
+       * libdocument/ev-debug.h:
+       * libdocument/ev-file-helpers.c: (_ev_file_helpers_init),
+       (_ev_file_helpers_shutdown):
+       * libdocument/ev-file-helpers.h: Make these init/shutdown methods
+       private.
+
+       * properties/ev-properties-main.c: (nautilus_module_initialize),
+       (nautilus_module_shutdown):
+       * shell/main.c: (main):
+       * thumbnailer/evince-thumbnailer.c: (main): Use the new single
+       init/shutdown method.
+
 2009-01-29  Christian Persch  <chpe@gnome.org>
 
        * shell/main.c: (option_version_cb): Add --version which was lost in
index 0f1c13f7e0c8a40a673571ca1848234c83752c47..b35525f2648f0791e95c015d5fcb2ecbbe5553ea 100644 (file)
@@ -42,6 +42,7 @@
 #include <libdocument/ev-file-helpers.h>
 #include <libdocument/ev-form-field.h>
 #include <libdocument/ev-image.h>
+#include <libdocument/ev-init.h>
 #include <libdocument/ev-layer.h>
 #include <libdocument/ev-link-action.h>
 #include <libdocument/ev-link-dest.h>
index 94b049f561d3557352b8912fdce1176c7e0acb27..6eab5854498386df3699aa64b498e1396760f000 100644 (file)
@@ -26,6 +26,7 @@ INST_H_FILES =                                        \
        ev-file-helpers.h                       \
        ev-form-field.h                         \
        ev-image.h                              \
+       ev-init.h                               \
        ev-layer.h                              \
        ev-link-action.h                        \
        ev-link-dest.h                          \
@@ -48,6 +49,7 @@ libevdocument_la_SOURCES=                     \
        ev-link-action.c                        \
        ev-link-dest.c                          \
        ev-image.c                              \
+       ev-init.c                               \
        ev-document.c                           \
        ev-document-factory.c                   \
        ev-document-thumbnails.c                \
index 505d5c4d102f0adfbdf9bf048d39aeba648e4143..e92ecb5c2845865ec32cbc870486e22e1d60d290 100644 (file)
@@ -146,17 +146,29 @@ ev_backends_manager_load (void)
        return TRUE;
 }
 
+/*
+ * _ev_backends_manager_init:
+ *
+ * Initializes the evince backends manager.
+ *
+ * Returns: %TRUE if there were any backends found; %FALSE otherwise
+ */
 gboolean
-ev_backends_manager_init (void)
+_ev_backends_manager_init (void)
 {
        if (ev_backends_list)
-               return FALSE;
+               return TRUE;
 
        return ev_backends_manager_load ();
 }
 
+/*
+ * _ev_backends_manager_shutdown:
+ *
+ * Shuts the evince backends manager down.
+ */
 void
-ev_backends_manager_shutdown (void)
+_ev_backends_manager_shutdown (void)
 {
        g_list_foreach (ev_backends_list, (GFunc)ev_backend_info_free, NULL);
        g_list_free (ev_backends_list);
index 4fb165643dedd858ae497ef3edc3db3ed55273ae..4bb54f23fc92d381a07f92842e201b95f8ec3cb6 100644 (file)
@@ -35,8 +35,8 @@ typedef struct _EvTypeInfo {
        const gchar **mime_types;
 } EvTypeInfo;
 
-gboolean   ev_backends_manager_init                       (void);
-void       ev_backends_manager_shutdown                   (void);
+gboolean    _ev_backends_manager_init                     (void);
+void        _ev_backends_manager_shutdown                 (void);
 
 EvDocument  *ev_backends_manager_get_document             (const gchar *mime_type);
 const gchar *ev_backends_manager_get_document_module_name (EvDocument  *document);
index 48cbf5dda5418b6232e99d6c744ea075014aa7f3..c6918e7be6494730ff1bf83e3efd18feea7c88bc 100644 (file)
@@ -79,14 +79,14 @@ profile_init ()
 }
 
 void
-ev_debug_init ()
+_ev_debug_init ()
 {
        debug_init ();
        profile_init ();
 }
 
 void
-ev_debug_shutdown ()
+_ev_debug_shutdown ()
 {
        if (timers) {
                g_hash_table_destroy (timers);
index 7acb41f03721c707ad6bf41a12f87304c854468e..e97cdf4682fd1cc4e0e01954cfa295b5d77a425b 100644 (file)
@@ -87,8 +87,8 @@ typedef enum {
        EV_PROFILE_JOBS = 1 << 0
 } EvProfileSection;
 
-void ev_debug_init     (void);
-void ev_debug_shutdown (void);
+void _ev_debug_init     (void);
+void _ev_debug_shutdown (void);
 
 void ev_debug_message  (EvDebugSection   section,
                        const gchar     *file,
index 9c65aa5e9e445d37e0ccd20a900082254b7035bb..e48ce9d081bc42bc8a95116b7200ac09ebf6a181 100644 (file)
@@ -75,12 +75,12 @@ ev_tmp_dir (void)
 }
 
 void
-ev_file_helpers_init (void)
+_ev_file_helpers_init (void)
 {
 }
 
 void
-ev_file_helpers_shutdown (void)
+_ev_file_helpers_shutdown (void)
 {      
        if (tmp_dir != NULL)    
                g_rmdir (tmp_dir);
index 51d763db75b5ff2917eccd7d6259ee9786102dd4..adec69c35b23b4d1004eedb5c801966bfd0840c1 100644 (file)
@@ -38,9 +38,9 @@ typedef enum {
 
 const gchar *ev_tmp_dir               (void);
 
-void         ev_file_helpers_init     (void);
+void        _ev_file_helpers_init     (void);
 
-void         ev_file_helpers_shutdown (void);
+void        _ev_file_helpers_shutdown (void);
 
 gboolean     ev_dir_ensure_exists     (const gchar       *dir,
                                        int                mode);
diff --git a/libdocument/ev-init.c b/libdocument/ev-init.c
new file mode 100644 (file)
index 0000000..34b323c
--- /dev/null
@@ -0,0 +1,83 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright © 2009 Christian Persch
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+
+#include "ev-init.h"
+#include "ev-backends-manager.h"
+#include "ev-debug.h"
+#include "ev-file-helpers.h"
+
+static int ev_init_count;
+
+/**
+ * ev_init:
+ *
+ * Initializes the evince document library.
+ *
+ * You must call this before calling any other function in the evince
+ * document library.
+ *
+ * Returns: %TRUE if any backends were found; %FALSE otherwise
+ */
+gboolean
+ev_init (void)
+{
+        static gboolean have_backends;
+
+        if (ev_init_count++ > 0)
+                return have_backends;
+
+        _ev_debug_init ();
+        _ev_file_helpers_init ();
+        have_backends = _ev_backends_manager_init ();
+
+        return have_backends;
+}
+
+/**
+ * ev_shutdown:
+ *
+ * Shuts the evince document library down.
+ */
+void
+ev_shutdown (void)
+{
+        g_assert (_ev_is_initialized ());
+
+        if (--ev_init_count > 0)
+                return;
+
+        _ev_backends_manager_shutdown ();
+        _ev_file_helpers_shutdown ();
+        _ev_debug_shutdown ();
+}
+
+/*
+ * _ev_is_initialized:
+ *
+ * Returns: %TRUE if the evince document library has been initialized
+ */
+gboolean
+_ev_is_initialized (void)
+{
+        return ev_init_count > 0;
+}
diff --git a/libdocument/ev-init.h b/libdocument/ev-init.h
new file mode 100644 (file)
index 0000000..976429c
--- /dev/null
@@ -0,0 +1,39 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright © 2009 Christian Persch
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION)
+#error "Only <evince-document.h> can be included directly."
+#endif
+
+#ifndef EV_INIT_H
+#define EV_INIT_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean    ev_init           (void);
+
+void        ev_shutdown       (void);
+
+gboolean   _ev_is_initialized (void);
+
+G_END_DECLS
+
+#endif /* EV_INIT_H */
index a3c045b43ff8df8323fdcec646d029efcd0216a8..27b80c31c47c057a63694a6abdefdbded9d3c322 100644 (file)
@@ -137,13 +137,13 @@ nautilus_module_initialize (GTypeModule *module)
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-       ev_backends_manager_init ();
+        ev_init ();
 }
 
 void
 nautilus_module_shutdown (void)
 {
-       ev_backends_manager_shutdown ();
+        ev_shutdown ();
 }
 
 void
@@ -156,4 +156,3 @@ nautilus_module_list_types (const GType **types,
        *types = type_list;
        *num_types = G_N_ELEMENTS (type_list);
 }
-
index c10ac853752e4bab36da169b9b76df414fc39dfb..5348469fce27c9c9b13b1a0654eb252cb9af6bae 100644 (file)
@@ -33,6 +33,7 @@
 #include "ev-application.h"
 #include "ev-backends-manager.h"
 #include "ev-debug.h"
+#include "ev-init.h"
 #include "ev-file-helpers.h"
 #include "ev-stock-icons.h"
 #include "eggsmclient.h"
@@ -369,10 +370,9 @@ main (int argc, char *argv[])
        }
 #endif /* ENABLE_DBUS */
 
-       ev_debug_init ();
-       ev_backends_manager_init ();
-       
-       ev_file_helpers_init ();
+        if (!ev_init ())
+                return 1;
+
        ev_stock_icons_init ();
        
        egg_set_desktop_file (GNOMEDATADIR "/applications/evince.desktop");
@@ -383,11 +383,7 @@ main (int argc, char *argv[])
 
        gtk_main ();
 
-       ev_file_helpers_shutdown ();
-
-       ev_backends_manager_shutdown ();
-
-       ev_debug_shutdown ();
+       ev_shutdown ();
 
        return 0;
 }
index ec72f16eea86d5ff09f14c916e5105397ab01a7c..217210b651167fc4a10daf1129d97a066583ae2d 100644 (file)
@@ -163,7 +163,8 @@ main (int argc, char *argv[])
        if (!g_thread_supported ())
                g_thread_init (NULL);
 
-       ev_backends_manager_init ();
+        if (!ev_init ())
+                return -1;
 
        file = g_file_new_for_commandline_arg (input);
        uri = g_file_get_uri (file);
@@ -173,13 +174,13 @@ main (int argc, char *argv[])
        g_free (uri);
 
        if (!document) {
-               ev_backends_manager_shutdown ();
+               ev_shutdown ();
                return -2;
        }
 
        if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
                g_object_unref (document);
-               ev_backends_manager_shutdown ();
+               ev_shutdown ();
                return -2;
        }
 
@@ -198,19 +199,19 @@ main (int argc, char *argv[])
                gtk_main ();
 
                g_object_unref (document);
-               ev_backends_manager_shutdown ();
+               ev_shutdown ();
 
                return data.success ? 0 : -2;
        }
 
        if (!evince_thumbnail_pngenc_get (document, output, size)) {
                g_object_unref (document);
-               ev_backends_manager_shutdown ();
+               ev_shutdown ();
                return -2;
        }
 
        g_object_unref (document);
-       ev_backends_manager_shutdown ();
+        ev_shutdown ();
 
        return 0;
 }