]> www.fi.muni.cz Git - evince.git/blob - properties/ev-properties-main.c
Use g_type_module_add_interface instead of g_type_add_interface_static.
[evince.git] / properties / ev-properties-main.c
1 /*
2  * Copyright (C) 2000, 2001 Eazel Inc.
3  * Copyright (C) 2003  Andrew Sobala <aes@gnome.org>
4  * Copyright (C) 2005  Bastien Nocera <hadess@hadess.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * The Ev project hereby grant permission for non-gpl compatible GStreamer
21  * plugins to be used and distributed together with GStreamer and Ev. This
22  * permission are above and beyond the permissions granted by the GPL license
23  * Ev is covered by.
24  *
25  * Monday 7th February 2005: Christian Schaller: Add excemption clause.
26  * See license_change file for details.
27  *
28  */
29
30 #include "ev-properties-view.h"
31 #include "ev-backends-manager.h"
32 #include "ev-document-factory.h"
33
34 #include <config.h>
35 #include <string.h>
36 #include <glib/gi18n-lib.h>
37 #include <gtk/gtklabel.h>
38 #include <libnautilus-extension/nautilus-extension-types.h>
39 #include <libnautilus-extension/nautilus-property-page-provider.h>
40
41 static GType epp_type = 0;
42 static void property_page_provider_iface_init
43         (NautilusPropertyPageProviderIface *iface);
44 static GList *ev_properties_get_pages
45         (NautilusPropertyPageProvider *provider, GList *files);
46
47 static void
48 ev_properties_plugin_register_type (GTypeModule *module)
49 {
50         const GTypeInfo info = {
51                 sizeof (GObjectClass),
52                 (GBaseInitFunc) NULL,
53                 (GBaseFinalizeFunc) NULL,
54                 (GClassInitFunc) NULL,
55                 NULL,
56                 NULL,
57                 sizeof (GObject),
58                 0,
59                 (GInstanceInitFunc) NULL
60         };
61         const GInterfaceInfo property_page_provider_iface_info = {
62                 (GInterfaceInitFunc)property_page_provider_iface_init,
63                 NULL,
64                 NULL
65         };
66
67         epp_type = g_type_module_register_type (module, G_TYPE_OBJECT,
68                         "EvPropertiesPlugin",
69                         &info, 0);
70         g_type_module_add_interface (module,
71                         epp_type,
72                         NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
73                         &property_page_provider_iface_info);
74 }
75
76 static void
77 property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface)
78 {
79         iface->get_pages = ev_properties_get_pages;
80 }
81
82 static GList *
83 ev_properties_get_pages (NautilusPropertyPageProvider *provider,
84                          GList *files)
85 {
86         GError *error = NULL;
87         EvDocument *document;
88         GList *pages = NULL;
89         NautilusFileInfo *file;
90         char *uri = NULL;
91         GtkWidget *page, *label;
92         NautilusPropertyPage *property_page;
93
94         /* only add properties page if a single file is selected */
95         if (files == NULL || files->next != NULL)
96                 goto end;
97         file = files->data;
98
99         /* okay, make the page */
100         uri = nautilus_file_info_get_uri (file);
101         document = ev_document_factory_get_document (uri, &error);
102
103         if (error) {
104                 g_error_free (error);
105                 goto end;
106         }
107         
108         if (!document)
109                 goto end;
110
111         label = gtk_label_new (_("Document"));
112         page = ev_properties_view_new ();
113         ev_properties_view_set_info (EV_PROPERTIES_VIEW (page),
114                                      ev_document_get_info (document));
115         gtk_widget_show (page);
116         property_page = nautilus_property_page_new ("document-properties",
117                         label, page);
118         g_object_unref (document);
119
120         pages = g_list_prepend (pages, property_page);
121
122 end:
123         g_free (uri);
124         return pages;
125 }
126
127 /* --- extension interface --- */
128 void
129 nautilus_module_initialize (GTypeModule *module)
130 {
131         ev_properties_plugin_register_type (module);
132         ev_properties_view_register_type (module);
133
134         /* set up translation catalog */
135         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
136         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
137
138         ev_backends_manager_init ();
139 }
140
141 void
142 nautilus_module_shutdown (void)
143 {
144         ev_backends_manager_shutdown ();
145 }
146
147 void
148 nautilus_module_list_types (const GType **types,
149                             int          *num_types)
150 {
151         static GType type_list[1];
152
153         type_list[0] = epp_type;
154         *types = type_list;
155         *num_types = G_N_ELEMENTS (type_list);
156 }
157