~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/desktop-link.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
/*
 
20
 * Desktop Entry Specification
 
21
 * http://standards.freedesktop.org/desktop-entry-spec/latest/
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include <string.h>
 
27
 
 
28
#include <glib/gstdio.h>
 
29
 
 
30
#include <libgimp/gimp.h>
 
31
 
 
32
#include "libgimp/stdplugins-intl.h"
 
33
 
 
34
 
 
35
#define LOAD_PROC      "file-desktop-link-load"
 
36
#define PLUG_IN_BINARY "desktop-link"
 
37
 
 
38
 
 
39
static void    query      (void);
 
40
static void    run        (const gchar      *name,
 
41
                           gint              nparams,
 
42
                           const GimpParam  *param,
 
43
                           gint             *nreturn_vals,
 
44
                           GimpParam       **return_vals);
 
45
 
 
46
static gint32  load_image (const gchar      *filename,
 
47
                           GimpRunMode       run_mode);
 
48
 
 
49
 
 
50
const GimpPlugInInfo PLUG_IN_INFO =
 
51
{
 
52
  NULL,  /* init_proc  */
 
53
  NULL,  /* quit_proc  */
 
54
  query, /* query_proc */
 
55
  run,   /* run_proc   */
 
56
};
 
57
 
 
58
MAIN ()
 
59
 
 
60
static void
 
61
query (void)
 
62
{
 
63
  static const GimpParamDef load_args[] =
 
64
  {
 
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"             }
 
68
  };
 
69
 
 
70
  static const GimpParamDef load_return_vals[] =
 
71
  {
 
72
    { GIMP_PDB_IMAGE,  "image",        "Output image"                 }
 
73
  };
 
74
 
 
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.",
 
79
                          "Sven Neumann",
 
80
                          "Sven Neumann",
 
81
                          "2006",
 
82
                          N_("Desktop Link"),
 
83
                          NULL,
 
84
                          GIMP_PLUGIN,
 
85
                          G_N_ELEMENTS (load_args),
 
86
                          G_N_ELEMENTS (load_return_vals),
 
87
                          load_args, load_return_vals);
 
88
 
 
89
  gimp_register_load_handler (LOAD_PROC, "desktop", "");
 
90
}
 
91
 
 
92
static void
 
93
run (const gchar      *name,
 
94
     gint              nparams,
 
95
     const GimpParam  *param,
 
96
     gint             *nreturn_vals,
 
97
     GimpParam       **return_vals)
 
98
{
 
99
  static GimpParam   values[2];
 
100
  GimpRunMode        run_mode;
 
101
  GimpPDBStatusType  status = GIMP_PDB_EXECUTION_ERROR;
 
102
  gint32             image_ID;
 
103
 
 
104
  run_mode = param[0].data.d_int32;
 
105
 
 
106
  *nreturn_vals = 1;
 
107
  *return_vals  = values;
 
108
 
 
109
  values[0].type          = GIMP_PDB_STATUS;
 
110
  values[0].data.d_status = status;
 
111
 
 
112
  if (strcmp (name, LOAD_PROC) == 0)
 
113
    {
 
114
      image_ID = load_image (param[1].data.d_string, run_mode);
 
115
 
 
116
      if (image_ID != -1)
 
117
        {
 
118
          status = GIMP_PDB_SUCCESS;
 
119
 
 
120
          *nreturn_vals = 2;
 
121
          values[1].type         = GIMP_PDB_IMAGE;
 
122
          values[1].data.d_image = image_ID;
 
123
        }
 
124
    }
 
125
  else
 
126
    {
 
127
      status = GIMP_PDB_CALLING_ERROR;
 
128
    }
 
129
 
 
130
  values[0].data.d_status = status;
 
131
}
 
132
 
 
133
static gint32
 
134
load_image (const gchar *filename,
 
135
            GimpRunMode  run_mode)
 
136
{
 
137
  GKeyFile *file     = g_key_file_new ();
 
138
  gchar    *group    = NULL;
 
139
  gchar    *value    = NULL;
 
140
  gint32    image_ID = -1;
 
141
  GError   *error    = NULL;
 
142
 
 
143
  if (! g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error))
 
144
    goto out;
 
145
 
 
146
  group = g_key_file_get_start_group (file);
 
147
  if (! group || strcmp (group, "Desktop Entry") != 0)
 
148
    goto out;
 
149
 
 
150
  value = g_key_file_get_value (file, group, "Type", &error);
 
151
  if (! value || strcmp (value, "Link") != 0)
 
152
    goto out;
 
153
 
 
154
  g_free (value);
 
155
 
 
156
  value = g_key_file_get_value (file, group, "URL", &error);
 
157
  if (value)
 
158
    image_ID = gimp_file_load (run_mode, value, value);
 
159
 
 
160
 out:
 
161
  if (error)
 
162
    {
 
163
      g_message (_("Error loading desktop file '%s': %s"),
 
164
                 gimp_filename_to_utf8 (filename), error->message);
 
165
      g_error_free (error);
 
166
    }
 
167
 
 
168
  g_free (value);
 
169
  g_free (group);
 
170
  g_key_file_free (file);
 
171
 
 
172
  return image_ID;
 
173
}