2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-06-20 20:40:51 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-06-20 20:40:51 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-06-20 20:40:51 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2006-06-20 20:40:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Desktop Entry Specification
|
|
|
|
* http://standards.freedesktop.org/desktop-entry-spec/latest/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define LOAD_PROC "file-desktop-link-load"
|
2008-08-11 18:06:13 +08:00
|
|
|
#define PLUG_IN_BINARY "file-desktop-link"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-file-desktop-link"
|
2006-06-20 20:40:51 +08:00
|
|
|
|
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
typedef struct _Desktop Desktop;
|
|
|
|
typedef struct _DesktopClass DesktopClass;
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
struct _Desktop
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
struct _DesktopClass
|
2006-06-20 20:40:51 +08:00
|
|
|
{
|
2019-08-11 18:31:41 +08:00
|
|
|
GimpPlugInClass parent_class;
|
2006-06-20 20:40:51 +08:00
|
|
|
};
|
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
|
|
|
|
#define DESKTOP_TYPE (desktop_get_type ())
|
2023-10-19 00:29:37 +08:00
|
|
|
#define DESKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DESKTOP_TYPE, Desktop))
|
2019-08-11 18:31:41 +08:00
|
|
|
|
|
|
|
GType desktop_get_type (void) G_GNUC_CONST;
|
|
|
|
|
2023-08-06 08:56:44 +08:00
|
|
|
static GList * desktop_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * desktop_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
2019-08-11 18:31:41 +08:00
|
|
|
|
2023-08-06 08:56:44 +08:00
|
|
|
static GimpValueArray * desktop_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
2019-08-11 18:31:41 +08:00
|
|
|
|
2023-08-06 08:56:44 +08:00
|
|
|
static GimpImage * load_image (GFile *file,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GError **error);
|
2019-08-11 18:31:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Desktop, desktop, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (DESKTOP_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-11 18:31:41 +08:00
|
|
|
|
2006-06-20 20:40:51 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-11 18:31:41 +08:00
|
|
|
desktop_class_init (DesktopClass *klass)
|
2006-06-20 20:40:51 +08:00
|
|
|
{
|
2019-08-11 18:31:41 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = desktop_query_procedures;
|
|
|
|
plug_in_class->create_procedure = desktop_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2006-06-20 20:40:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 18:31:41 +08:00
|
|
|
desktop_init (Desktop *desktop)
|
2006-06-20 20:40:51 +08:00
|
|
|
{
|
2019-08-11 18:31:41 +08:00
|
|
|
}
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
static GList *
|
|
|
|
desktop_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
return g_list_append (NULL, g_strdup (LOAD_PROC));
|
|
|
|
}
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
desktop_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
if (! strcmp (name, LOAD_PROC))
|
|
|
|
{
|
2023-08-06 09:21:27 +08:00
|
|
|
procedure = gimp_load_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
desktop_load, NULL, NULL);
|
2019-08-11 18:31:41 +08:00
|
|
|
|
2022-07-05 04:50:53 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Desktop Link"));
|
2019-08-11 18:31:41 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Follows a link to an image in a "
|
|
|
|
".desktop file",
|
|
|
|
"Opens a .desktop file and if it is "
|
|
|
|
"a link, it asks GIMP to open the "
|
|
|
|
"file the link points to.",
|
|
|
|
LOAD_PROC);
|
|
|
|
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Sven Neumann",
|
|
|
|
"Sven Neumann",
|
|
|
|
"2006");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"desktop");
|
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
static GimpValueArray *
|
2023-08-06 08:56:44 +08:00
|
|
|
desktop_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2019-08-11 18:31:41 +08:00
|
|
|
{
|
|
|
|
GimpValueArray *return_values;
|
2019-08-14 22:23:53 +08:00
|
|
|
GimpImage *image;
|
2019-08-11 18:31:41 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2019-08-14 22:23:53 +08:00
|
|
|
image = load_image (file, run_mode, &error);
|
2019-08-11 18:31:41 +08:00
|
|
|
|
2019-08-14 22:23:53 +08:00
|
|
|
if (! image)
|
2019-08-20 07:03:38 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
2019-08-11 18:31:41 +08:00
|
|
|
|
2019-08-20 07:03:38 +08:00
|
|
|
return_values = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
2019-08-14 22:23:53 +08:00
|
|
|
GIMP_VALUES_SET_IMAGE (return_values, 1, image);
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
return return_values;
|
2006-06-20 20:40:51 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 22:23:53 +08:00
|
|
|
static GimpImage *
|
2019-08-11 18:31:41 +08:00
|
|
|
load_image (GFile *file,
|
2008-08-18 02:28:55 +08:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GError **load_error)
|
2006-06-20 20:40:51 +08:00
|
|
|
{
|
2019-08-14 22:23:53 +08:00
|
|
|
GKeyFile *key_file = g_key_file_new ();
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
gchar *filename = NULL;
|
|
|
|
gchar *group = NULL;
|
|
|
|
gchar *value = NULL;
|
|
|
|
GError *error = NULL;
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
filename = g_file_get_path (file);
|
|
|
|
|
|
|
|
if (! g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &error))
|
2006-06-20 20:40:51 +08:00
|
|
|
goto out;
|
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
group = g_key_file_get_start_group (key_file);
|
2008-12-02 22:18:53 +08:00
|
|
|
if (! group || strcmp (group, G_KEY_FILE_DESKTOP_GROUP) != 0)
|
2006-06-20 20:40:51 +08:00
|
|
|
goto out;
|
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
value = g_key_file_get_value (key_file,
|
2008-12-02 22:18:53 +08:00
|
|
|
group, G_KEY_FILE_DESKTOP_KEY_TYPE, &error);
|
|
|
|
if (! value || strcmp (value, G_KEY_FILE_DESKTOP_TYPE_LINK) != 0)
|
2006-06-20 20:40:51 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
|
2019-08-11 18:31:41 +08:00
|
|
|
value = g_key_file_get_value (key_file,
|
2008-12-02 22:18:53 +08:00
|
|
|
group, G_KEY_FILE_DESKTOP_KEY_URL, &error);
|
2006-06-20 20:40:51 +08:00
|
|
|
if (value)
|
2019-09-12 03:48:34 +08:00
|
|
|
image = gimp_file_load (run_mode, g_file_new_for_uri (value));
|
2006-06-20 20:40:51 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (error)
|
|
|
|
{
|
2008-08-18 02:28:55 +08:00
|
|
|
g_set_error (load_error, error->domain, error->code,
|
|
|
|
_("Error loading desktop file '%s': %s"),
|
|
|
|
gimp_filename_to_utf8 (filename), error->message);
|
2006-06-20 20:40:51 +08:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (value);
|
|
|
|
g_free (group);
|
2019-08-11 18:31:41 +08:00
|
|
|
g_free (filename);
|
|
|
|
g_key_file_free (key_file);
|
2006-06-20 20:40:51 +08:00
|
|
|
|
2019-08-14 22:23:53 +08:00
|
|
|
return image;
|
2006-06-20 20:40:51 +08:00
|
|
|
}
|