summaryrefslogtreecommitdiff
path: root/properties/ev-properties-main.c
blob: 9235c86a8351b138bfe99124aa7ba5f850acd2ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Copyright (C) 2000, 2001 Eazel Inc.
 * Copyright (C) 2003  Andrew Sobala <aes@gnome.org>
 * Copyright (C) 2005  Bastien Nocera <hadess@hadess.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Ev project hereby grant permission for non-gpl compatible GStreamer
 * plugins to be used and distributed together with GStreamer and Ev. This
 * permission are above and beyond the permissions granted by the GPL license
 * Ev is covered by.
 *
 * Monday 7th February 2005: Christian Schaller: Add excemption clause.
 * See license_change file for details.
 *
 */

#include <config.h>

#include <string.h>

#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>

#include <libcaja-extension/caja-extension-types.h>
#include <libcaja-extension/caja-property-page-provider.h>

#include <atril-document.h>
#include "ev-properties-view.h"

static GType epp_type = 0;
static void property_page_provider_iface_init
	(CajaPropertyPageProviderIface *iface);
static GList *ev_properties_get_pages
	(CajaPropertyPageProvider *provider, GList *files);

static void
ev_properties_plugin_register_type (GTypeModule *module)
{
	const GTypeInfo info = {
		sizeof (GObjectClass),
		(GBaseInitFunc) NULL,
		(GBaseFinalizeFunc) NULL,
		(GClassInitFunc) NULL,
		NULL,
		NULL,
		sizeof (GObject),
		0,
		(GInstanceInitFunc) NULL
	};
	const GInterfaceInfo property_page_provider_iface_info = {
		(GInterfaceInitFunc)property_page_provider_iface_init,
		NULL,
		NULL
	};

	epp_type = g_type_module_register_type (module, G_TYPE_OBJECT,
			"EvPropertiesPlugin",
			&info, 0);
	g_type_module_add_interface (module,
			epp_type,
			CAJA_TYPE_PROPERTY_PAGE_PROVIDER,
			&property_page_provider_iface_info);
}

static void
property_page_provider_iface_init (CajaPropertyPageProviderIface *iface)
{
	iface->get_pages = ev_properties_get_pages;
}

static GList *
ev_properties_get_pages (CajaPropertyPageProvider *provider,
			 GList *files)
{
	GError *error = NULL;
	EvDocument *document;
	GList *pages = NULL;
	CajaFileInfo *file;
	gchar *uri = NULL;
	gchar *mime_type = NULL;
	GtkWidget *page, *label;
	CajaPropertyPage *property_page;

	/* only add properties page if a single file is selected */
	if (files == NULL || files->next != NULL)
		goto end;
	file = files->data;

	/* okay, make the page */
	uri = caja_file_info_get_uri (file);
	mime_type = caja_file_info_get_mime_type (file);
	
	document = ev_backends_manager_get_document (mime_type);
	if (!document)
		goto end;

	ev_document_load (document, uri, &error);
	if (error) {
		g_error_free (error);
		goto end;
	}
	
	label = gtk_label_new (_("Document"));
	page = ev_properties_view_new (uri);
	ev_properties_view_set_info (EV_PROPERTIES_VIEW (page),
				     ev_document_get_info (document));
	gtk_widget_show (page);
	property_page = caja_property_page_new ("document-properties",
			label, page);
	g_object_unref (document);

	pages = g_list_prepend (pages, property_page);

end:
	g_free (uri);
	g_free (mime_type);
	
	return pages;
}

/* --- extension interface --- */
void
caja_module_initialize (GTypeModule *module)
{
	ev_properties_plugin_register_type (module);
	ev_properties_view_register_type (module);

        ev_init ();
}

void
caja_module_shutdown (void)
{
        ev_shutdown ();
}

void
caja_module_list_types (const GType **types,
                            int          *num_types)
{
	static GType type_list[1];

	type_list[0] = epp_type;
	*types = type_list;
	*num_types = G_N_ELEMENTS (type_list);
}