File: fma-desktop-formats.c

package info (click to toggle)
filemanager-actions 3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,428 kB
  • sloc: ansic: 48,857; xml: 17,767; sh: 4,662; makefile: 1,375; lisp: 9
file content (169 lines) | stat: -rw-r--r-- 5,134 bytes parent folder | download
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
160
161
162
163
164
165
166
167
168
169
/*
 * FileManager-Actions
 * A file-manager extension which offers configurable context menu actions.
 *
 * Copyright (C) 2005 The GNOME Foundation
 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
 *
 * FileManager-Actions 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.
 *
 * FileManager-Actions 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 FileManager-Actions; see the file COPYING. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *   Frederic Ruaudel <grumz@grumz.net>
 *   Rodrigo Moya <rodrigo@gnome-db.org>
 *   Pierre Wieser <pwieser@trychlos.org>
 *   ... and many others (see AUTHORS)
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libintl.h>

#include <api/fma-iexporter.h>

#include "fma-desktop-formats.h"

typedef struct {
	gchar *format;
	gchar *label;
	gchar *description;
	gchar *image;
}
	sExportFormat;

static sExportFormat st_desktop_formats[] = {

	/* DESKTOP_V1: the initial desktop format as described in
	 * http://www.filemanager-actions.org/?q=node/377
	 */
	{ FMA_DESKTOP_FORMAT_V1,
			N_( "Export as a ._desktop file" ),
			N_( "This format has been introduced with v 3.0 series, " \
				"and should be your newly preferred format when exporting items.\n" \
				"It let you easily share your actions with the whole world, " \
				"including with users of other desktop environments, " \
				"as long as their own application implements the DES-EMA specification " \
				"which describes this format.\n" \
				"The exported .desktop file may later be imported via :\n" \
				"- Import assistant of the FileManager-Actions Configuration Tool,\n" \
				"- drag-n-drop into the FileManager-Actions Configuration Tool,\n" \
				"- or by copying it into a XDG_DATA_DIRS/file-manager/actions directory." ),
			"fma-desktop-export.png" },

	{ NULL }
};

#if 0
static void on_pixbuf_finalized( const FMAIExporter* exporter, GObject *pixbuf );
#endif

/**
 * fma_desktop_formats_get_formats:
 * @exporter: this #FMAIExporter provider.
 *
 * Returns: a #GList of the #FMAIExporterFormatv2 supported export formats.
 *
 * This list should be fma_desktop_formats_free_formats() by the caller.
 *
 * Since: 3.2
 */
GList *
fma_desktop_formats_get_formats( const FMAIExporter* exporter )
{
#if 0
	static const gchar *thisfn = "fma_desktop_formats_get_formats";
#endif
	GList *str_list;
	FMAIExporterFormatv2 *str;
	guint i;
	gint width, height;
	gchar *fname;

	str_list = NULL;

	if( !gtk_icon_size_lookup( GTK_ICON_SIZE_DIALOG, &width, &height )){
		width = height = 48;
	}

	for( i = 0 ; st_desktop_formats[i].format ; ++i ){
		str = g_new0( FMAIExporterFormatv2, 1 );
		str->version = 2;
		str->provider = FMA_IEXPORTER( exporter );
		str->format = g_strdup( st_desktop_formats[i].format );
		str->label = g_strdup( gettext( st_desktop_formats[i].label ));
		str->description = g_strdup( gettext( st_desktop_formats[i].description ));
		if( st_desktop_formats[i].image ){
			fname = g_strdup_printf( "%s/%s", PROVIDER_DATADIR, st_desktop_formats[i].image );
			str->pixbuf = gdk_pixbuf_new_from_file_at_size( fname, width, height, NULL );
			g_free( fname );
#if 0
			/* do not set weak reference on a graphical object provided by a plugin
			 * if the windows does not have its own builder, it may happens that the
			 * graphical object be finalized when destroying toplevels at common
			 * builder finalization time, and so after the plugins have been shutdown
			 */
			if( str->pixbuf ){
				g_debug( "%s: allocating pixbuf at %p", thisfn, str->pixbuf );
				g_object_weak_ref( G_OBJECT( str->pixbuf ), ( GWeakNotify ) on_pixbuf_finalized, ( gpointer ) exporter );
			}
#endif
		}
		str_list = g_list_prepend( str_list, str );
	}

	return( str_list );
}

#if 0
static void
on_pixbuf_finalized( const FMAIExporter* exporter, GObject *pixbuf )
{
	g_debug( "fma_desktop_formats_on_pixbuf_finalized: exporter=%p, pixbuf=%p", ( void * ) exporter, ( void * ) pixbuf );
}
#endif

/**
 * fma_desktop_formats_free_formats:
 * @formats: a #GList to be freed.
 *
 * Returns: a #GList of the #FMAIExporterFormatv2 supported export formats.
 *
 * This list should be nadp_format_free_formats() by the caller.
 *
 * Since: 3.2
 */
void
fma_desktop_formats_free_formats( GList *formats )
{
	GList *is;
	FMAIExporterFormatv2 *str;

	for( is = formats ; is ; is = is->next ){
		str = ( FMAIExporterFormatv2 * ) is->data;
		g_free( str->format );
		g_free( str->label );
		g_free( str->description );
		if( str->pixbuf ){
			g_object_unref( str->pixbuf );
		}
		g_free( str );
	}

	g_list_free( formats );
}