~ubuntu-branches/ubuntu/saucy/gimp/saucy-security

« back to all changes in this revision

Viewing changes to app/file/file-utils.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * file-utils.c
6
6
 *
7
 
 * This program is free software; you can redistribute it and/or modify
 
7
 * This program is free software: you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * the Free Software Foundation; either version 3 of the License, or
10
10
 * (at your option) any later version.
11
11
 *
12
12
 * This program is distributed in the hope that it will be useful,
15
15
 * GNU General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
19
 */
21
20
 
22
21
#include "config.h"
23
22
 
24
23
#include <string.h>
25
24
 
26
 
#include <glib-object.h>
27
 
 
 
25
#include <gegl.h>
28
26
#include <gdk-pixbuf/gdk-pixbuf.h>
29
27
 
30
28
#include "libgimpbase/gimpbase.h"
45
43
#include "gimp-intl.h"
46
44
 
47
45
 
48
 
static gchar * file_utils_unescape_uri (const gchar  *escaped,
49
 
                                        gint          len,
50
 
                                        const gchar  *illegal_escaped_characters,
51
 
                                        gboolean      ascii_must_not_be_escaped);
 
46
static gchar *      file_utils_unescape_uri  (const gchar *escaped,
 
47
                                              gint         len,
 
48
                                              const gchar *illegal_escaped_characters,
 
49
                                              gboolean     ascii_must_not_be_escaped);
 
50
static const gchar *file_utils_get_ext_start (const gchar *uri);
 
51
 
52
52
 
53
53
 
54
54
gboolean
84
84
 
85
85
      if (! g_utf8_validate (filename, -1, NULL))
86
86
        {
87
 
          g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
88
 
                       _("Invalid character sequence in URI"));
 
87
          g_set_error_literal (error,
 
88
                               G_CONVERT_ERROR,
 
89
                               G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
 
90
                               _("Invalid character sequence in URI"));
89
91
          return FALSE;
90
92
        }
91
93
 
118
120
        }
119
121
      else
120
122
        {
121
 
          g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
122
 
                       _("Invalid character sequence in URI"));
 
123
          g_set_error_literal (error,
 
124
                               G_CONVERT_ERROR,
 
125
                               G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
 
126
                               _("Invalid character sequence in URI"));
123
127
          return NULL;
124
128
        }
125
129
    }
230
234
}
231
235
 
232
236
gchar *
 
237
file_utils_uri_with_new_ext (const gchar *uri,
 
238
                             const gchar *ext_uri)
 
239
{
 
240
  const gchar *uri_ext      = file_utils_get_ext_start (uri);
 
241
  const gchar *ext_uri_ext  = ext_uri ? file_utils_get_ext_start (ext_uri) : NULL;
 
242
  gchar *uri_without_ext    = g_strndup (uri, uri_ext - uri);
 
243
  gchar *ret                = g_strconcat (uri_without_ext, ext_uri_ext, NULL);
 
244
  g_free (uri_without_ext);
 
245
  return ret;
 
246
}
 
247
 
 
248
 
 
249
/**
 
250
 * file_utils_get_ext_start:
 
251
 * @uri:
 
252
 *
 
253
 * Returns the position of the extension (after the .) for an URI. If
 
254
 * there is no extension the returned position is right after the
 
255
 * string, at the terminating NULL character.
 
256
 *
 
257
 * Returns:
 
258
 **/
 
259
static const gchar *
 
260
file_utils_get_ext_start (const gchar *uri)
 
261
{
 
262
  const gchar *ext        = NULL;
 
263
  int          uri_len    = strlen (uri);
 
264
  int          search_len = 0;
 
265
 
 
266
  if (g_strrstr (uri, ".gz"))
 
267
    search_len = uri_len - 3;
 
268
  else if (g_strrstr (uri, ".bz2"))
 
269
    search_len = uri_len - 4;
 
270
  else
 
271
    search_len = uri_len;
 
272
 
 
273
  ext = g_strrstr_len (uri, search_len, ".");
 
274
 
 
275
  if (! ext)
 
276
    ext = uri + uri_len;
 
277
 
 
278
  return ext;
 
279
}
 
280
 
 
281
gchar *
233
282
file_utils_uri_to_utf8_filename (const gchar *uri)
234
283
{
235
284
  g_return_val_if_fail (uri != NULL, NULL);
402
451
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
403
452
  g_return_val_if_fail (filename != NULL, FALSE);
404
453
 
405
 
  image_uri = gimp_object_get_name (GIMP_OBJECT (image));
 
454
  image_uri = gimp_image_get_uri (image);
406
455
 
407
456
  if (image_uri)
408
457
    {