1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* Desktop Entry Specification
21
* http://standards.freedesktop.org/desktop-entry-spec/latest/
28
#include <glib/gstdio.h>
30
#include <libgimp/gimp.h>
32
#include "libgimp/stdplugins-intl.h"
35
#define LOAD_PROC "file-desktop-link-load"
36
#define PLUG_IN_BINARY "desktop-link"
39
static void query (void);
40
static void run (const gchar *name,
42
const GimpParam *param,
44
GimpParam **return_vals);
46
static gint32 load_image (const gchar *filename,
47
GimpRunMode run_mode);
50
const GimpPlugInInfo PLUG_IN_INFO =
54
query, /* query_proc */
63
static const GimpParamDef load_args[] =
65
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
66
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
67
{ GIMP_PDB_STRING, "raw-filename", "The name entered" }
70
static const GimpParamDef load_return_vals[] =
72
{ GIMP_PDB_IMAGE, "image", "Output image" }
75
gimp_install_procedure (LOAD_PROC,
76
"Follows a link to an image in a .desktop file",
77
"Opens a .desktop file and if it is a link, it "
78
"asks GIMP to open the file the link points to.",
85
G_N_ELEMENTS (load_args),
86
G_N_ELEMENTS (load_return_vals),
87
load_args, load_return_vals);
89
gimp_register_load_handler (LOAD_PROC, "desktop", "");
93
run (const gchar *name,
95
const GimpParam *param,
97
GimpParam **return_vals)
99
static GimpParam values[2];
100
GimpRunMode run_mode;
101
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
104
run_mode = param[0].data.d_int32;
107
*return_vals = values;
109
values[0].type = GIMP_PDB_STATUS;
110
values[0].data.d_status = status;
112
if (strcmp (name, LOAD_PROC) == 0)
114
image_ID = load_image (param[1].data.d_string, run_mode);
118
status = GIMP_PDB_SUCCESS;
121
values[1].type = GIMP_PDB_IMAGE;
122
values[1].data.d_image = image_ID;
127
status = GIMP_PDB_CALLING_ERROR;
130
values[0].data.d_status = status;
134
load_image (const gchar *filename,
135
GimpRunMode run_mode)
137
GKeyFile *file = g_key_file_new ();
140
gint32 image_ID = -1;
141
GError *error = NULL;
143
if (! g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error))
146
group = g_key_file_get_start_group (file);
147
if (! group || strcmp (group, "Desktop Entry") != 0)
150
value = g_key_file_get_value (file, group, "Type", &error);
151
if (! value || strcmp (value, "Link") != 0)
156
value = g_key_file_get_value (file, group, "URL", &error);
158
image_ID = gimp_file_load (run_mode, value, value);
163
g_message (_("Error loading desktop file '%s': %s"),
164
gimp_filename_to_utf8 (filename), error->message);
165
g_error_free (error);
170
g_key_file_free (file);