1 /*
2  * Nautilus-Actions
3  * A Nautilus extension which offers configurable context menu actions.
4  *
5  * Copyright (C) 2005 The GNOME Foundation
6  * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7  * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8  *
9  * Nautilus-Actions is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * Nautilus-Actions is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Nautilus-Actions; see the file COPYING. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  * Authors:
24  *   Frederic Ruaudel <grumz@grumz.net>
25  *   Rodrigo Moya <rodrigo@gnome-db.org>
26  *   Pierre Wieser <pwieser@trychlos.org>
27  *   ... and many others (see AUTHORS)
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include <glib/gi18n.h>
35 #include <gtk/gtk.h>
36 #include <libintl.h>
37 
38 #include <api/na-iexporter.h>
39 
40 #include "nadp-formats.h"
41 
42 typedef struct {
43 	gchar *format;
44 	gchar *label;
45 	gchar *description;
46 	gchar *image;
47 }
48 	NadpExportFormat;
49 
50 static NadpExportFormat nadp_formats[] = {
51 
52 	/* DESKTOP_V1: the initial desktop format as described in
53 	 * http://www.nautilus-actions.org/?q=node/377
54 	 */
55 	{ NADP_FORMAT_DESKTOP_V1,
56 			N_( "Export as a ._desktop file" ),
57 			N_( "This format has been introduced with v 3.0 serie, " \
58 				"and should be your newly preferred format when exporting items.\n" \
59 				"It let you easily share your actions with the whole world, " \
60 				"including with users of other desktop environments, " \
61 				"as long as their own application implements the DES-EMA specification " \
62 				"which describes this format.\n" \
63 				"The exported .desktop file may later be imported via :\n" \
64 				"- Import assistant of the Nautilus-Actions Configuration Tool,\n" \
65 				"- drag-n-drop into the Nautilus-Actions Configuration Tool,\n" \
66 				"- or by copying it into a XDG_DATA_DIRS/file-manager/actions directory." ),
67 			"export-desktop.png" },
68 
69 	{ NULL }
70 };
71 
72 #if 0
73 static void on_pixbuf_finalized( const NAIExporter* exporter, GObject *pixbuf );
74 #endif
75 
76 /**
77  * nadp_formats_get_formats:
78  * @exporter: this #NAIExporter provider.
79  *
80  * Returns: a #GList of the #NAIExporterFormatv2 supported export formats.
81  *
82  * This list should be nadp_formats_free_formats() by the caller.
83  *
84  * Since: 3.2
85  */
86 GList *
nadp_formats_get_formats(const NAIExporter * exporter)87 nadp_formats_get_formats( const NAIExporter* exporter )
88 {
89 #if 0
90 	static const gchar *thisfn = "nadp_formats_get_formats";
91 #endif
92 	GList *str_list;
93 	NAIExporterFormatv2 *str;
94 	guint i;
95 	gint width, height;
96 	gchar *fname;
97 
98 	str_list = NULL;
99 
100 	if( !gtk_icon_size_lookup( GTK_ICON_SIZE_DIALOG, &width, &height )){
101 		width = height = 48;
102 	}
103 
104 	for( i = 0 ; nadp_formats[i].format ; ++i ){
105 		str = g_new0( NAIExporterFormatv2, 1 );
106 		str->version = 2;
107 		str->provider = NA_IEXPORTER( exporter );
108 		str->format = g_strdup( nadp_formats[i].format );
109 		str->label = g_strdup( gettext( nadp_formats[i].label ));
110 		str->description = g_strdup( gettext( nadp_formats[i].description ));
111 		if( nadp_formats[i].image ){
112 			fname = g_strdup_printf( "%s/%s", PROVIDER_DATADIR, nadp_formats[i].image );
113 			str->pixbuf = gdk_pixbuf_new_from_file_at_size( fname, width, height, NULL );
114 			g_free( fname );
115 #if 0
116 			/* do not set weak reference on a graphical object provided by a plugin
117 			 * if the windows does not have its own builder, it may happens that the
118 			 * graphical object be finalized when destroying toplevels at common
119 			 * builder finalization time, and so after the plugins have been shutdown
120 			 */
121 			if( str->pixbuf ){
122 				g_debug( "%s: allocating pixbuf at %p", thisfn, str->pixbuf );
123 				g_object_weak_ref( G_OBJECT( str->pixbuf ), ( GWeakNotify ) on_pixbuf_finalized, ( gpointer ) exporter );
124 			}
125 #endif
126 		}
127 		str_list = g_list_prepend( str_list, str );
128 	}
129 
130 	return( str_list );
131 }
132 
133 #if 0
134 static void
135 on_pixbuf_finalized( const NAIExporter* exporter, GObject *pixbuf )
136 {
137 	g_debug( "nadp_formats_on_pixbuf_finalized: exporter=%p, pixbuf=%p", ( void * ) exporter, ( void * ) pixbuf );
138 }
139 #endif
140 
141 /**
142  * nadp_formats_free_formats:
143  * @formats: a #GList to be freed.
144  *
145  * Returns: a #GList of the #NAIExporterFormatv2 supported export formats.
146  *
147  * This list should be nadp_format_free_formats() by the caller.
148  *
149  * Since: 3.2
150  */
151 void
nadp_formats_free_formats(GList * formats)152 nadp_formats_free_formats( GList *formats )
153 {
154 	GList *is;
155 	NAIExporterFormatv2 *str;
156 
157 	for( is = formats ; is ; is = is->next ){
158 		str = ( NAIExporterFormatv2 * ) is->data;
159 		g_free( str->format );
160 		g_free( str->label );
161 		g_free( str->description );
162 		if( str->pixbuf ){
163 			g_object_unref( str->pixbuf );
164 		}
165 		g_free( str );
166 	}
167 
168 	g_list_free( formats );
169 }
170