]> www.fi.muni.cz Git - evince.git/blob - properties/ev-properties-main.c
d7f88e2de1aa08fc198629ad6c20cbaefef51836
[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 <config.h>
31
32 #include <string.h>
33
34 #include <glib/gi18n-lib.h>
35 #include <gtk/gtk.h>
36
37 #include <libnautilus-extension/nautilus-extension-types.h>
38 #include <libnautilus-extension/nautilus-property-page-provider.h>
39
40 #include "ev-properties-view.h"
41 #include "ev-backends-manager.h"
42 #include "ev-document-factory.h"
43
44 static GType epp_type = 0;
45 static void property_page_provider_iface_init
46         (NautilusPropertyPageProviderIface *iface);
47 static GList *ev_properties_get_pages
48         (NautilusPropertyPageProvider *provider, GList *files);
49
50 static void
51 ev_properties_plugin_register_type (GTypeModule *module)
52 {
53         const GTypeInfo info = {
54                 sizeof (GObjectClass),
55                 (GBaseInitFunc) NULL,
56                 (GBaseFinalizeFunc) NULL,
57                 (GClassInitFunc) NULL,
58                 NULL,
59                 NULL,
60                 sizeof (GObject),
61                 0,
62                 (GInstanceInitFunc) NULL
63         };
64         const GInterfaceInfo property_page_provider_iface_info = {
65                 (GInterfaceInitFunc)property_page_provider_iface_init,
66                 NULL,
67                 NULL
68         };
69
70         epp_type = g_type_module_register_type (module, G_TYPE_OBJECT,
71                         "EvPropertiesPlugin",
72                         &info, 0);
73         g_type_module_add_interface (module,
74                         epp_type,
75                         NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
76                         &property_page_provider_iface_info);
77 }
78
79 static void
80 property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface)
81 {
82         iface->get_pages = ev_properties_get_pages;
83 }
84
85 static GList *
86 ev_properties_get_pages (NautilusPropertyPageProvider *provider,
87                          GList *files)
88 {
89         GError *error = NULL;
90         EvDocument *document;
91         GList *pages = NULL;
92         NautilusFileInfo *file;
93         char *uri = NULL;
94         GtkWidget *page, *label;
95         NautilusPropertyPage *property_page;
96
97         /* only add properties page if a single file is selected */
98         if (files == NULL || files->next != NULL)
99                 goto end;
100         file = files->data;
101
102         /* okay, make the page */
103         uri = nautilus_file_info_get_uri (file);
104         document = ev_document_factory_get_document (uri, &error);
105
106         if (error) {
107                 g_error_free (error);
108                 goto end;
109         }
110         
111         if (!document)
112                 goto end;
113
114         label = gtk_label_new (_("Document"));
115         page = ev_properties_view_new (uri);
116         ev_properties_view_set_info (EV_PROPERTIES_VIEW (page),
117                                      ev_document_get_info (document));
118         gtk_widget_show (page);
119         property_page = nautilus_property_page_new ("document-properties",
120                         label, page);
121         g_object_unref (document);
122
123         pages = g_list_prepend (pages, property_page);
124
125 end:
126         g_free (uri);
127         return pages;
128 }
129
130 /* --- extension interface --- */
131 void
132 nautilus_module_initialize (GTypeModule *module)
133 {
134         ev_properties_plugin_register_type (module);
135         ev_properties_view_register_type (module);
136
137         /* set up translation catalog */
138         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
139         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
140
141         ev_backends_manager_init ();
142 }
143
144 void
145 nautilus_module_shutdown (void)
146 {
147         ev_backends_manager_shutdown ();
148 }
149
150 void
151 nautilus_module_list_types (const GType **types,
152                             int          *num_types)
153 {
154         static GType type_list[1];
155
156         type_list[0] = epp_type;
157         *types = type_list;
158         *num_types = G_N_ELEMENTS (type_list);
159 }
160