Commit 5455b8bf authored by Michael Natterer's avatar Michael Natterer 😴

app: move some stuff out of app/file/

file-procedure.[ch] is gone and its functions moved to
GimpPlugInManager where they belong (the manager keeps around the
lists of load, save and export procedures).

Utility functions from file-utils.[ch] that have nothing to do with
image files moved to core/gimp-utils.[ch].
parent 87a668a4
......@@ -284,8 +284,9 @@ file_actions_update (GimpActionGroup *group,
show_overwrite =
(source &&
gimp_plug_in_manager_file_has_exporter (gimp->plug_in_manager,
source));
gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_EXPORT,
source, NULL));
#define SET_VISIBLE(action,condition) \
gimp_action_group_set_action_visible (group, action, (condition) != 0)
......
......@@ -36,10 +36,9 @@
#include "core/gimpprogress.h"
#include "core/gimptemplate.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginmanager-file.h"
#include "file/file-open.h"
#include "file/file-procedure.h"
#include "file/file-save.h"
#include "file/gimp-file.h"
......@@ -258,8 +257,9 @@ file_save_cmd_callback (GtkAction *action,
if (file && ! save_proc)
{
save_proc =
file_procedure_find (image->gimp->plug_in_manager->save_procs,
file, NULL);
gimp_plug_in_manager_file_procedure_find (image->gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_SAVE,
file, NULL);
}
if (file && save_proc)
......@@ -357,8 +357,9 @@ file_save_cmd_callback (GtkAction *action,
if (file && ! export_proc)
{
export_proc =
file_procedure_find (image->gimp->plug_in_manager->export_procs,
file, NULL);
gimp_plug_in_manager_file_procedure_find (image->gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_EXPORT,
file, NULL);
}
if (file && export_proc)
......
......@@ -745,6 +745,90 @@ gimp_file_is_executable (GFile *file)
return executable;
}
/**
* gimp_file_get_extension:
* @file: A #GFile
*
* Returns @file's extension (including the .), or NULL if there is no
* extension. Note that this function handles compressed files too,
* e.g. for "file.png.gz" it will return ".png.gz".
*
* Returns: The @file's extension. Free with g_free() when no longer needed.
**/
gchar *
gimp_file_get_extension (GFile *file)
{
gchar *uri;
gint uri_len;
gchar *ext = NULL;
gint search_len;
g_return_val_if_fail (G_IS_FILE (file), NULL);
uri = g_file_get_uri (file);
uri_len = strlen (uri);
if (g_str_has_suffix (uri, ".gz"))
search_len = uri_len - 3;
else if (g_str_has_suffix (uri, ".bz2"))
search_len = uri_len - 4;
else if (g_str_has_suffix (uri, ".xz"))
search_len = uri_len - 3;
else
search_len = uri_len;
ext = g_strrstr_len (uri, search_len, ".");
if (ext)
ext = g_strdup (ext);
g_free (uri);
return ext;
}
GFile *
gimp_file_with_new_extension (GFile *file,
GFile *ext_file)
{
gchar *uri;
gchar *file_ext;
gint file_ext_len = 0;
gchar *ext_file_ext = NULL;
gchar *uri_without_ext;
gchar *new_uri;
GFile *ret;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (ext_file == NULL || G_IS_FILE (ext_file), NULL);
uri = g_file_get_uri (file);
file_ext = gimp_file_get_extension (file);
if (file_ext)
{
file_ext_len = strlen (file_ext);
g_free (file_ext);
}
if (ext_file)
ext_file_ext = gimp_file_get_extension (ext_file);
uri_without_ext = g_strndup (uri, strlen (uri) - file_ext_len);
g_free (uri);
new_uri = g_strconcat (uri_without_ext, ext_file_ext, NULL);
ret = g_file_new_for_uri (new_uri);
g_free (ext_file_ext);
g_free (uri_without_ext);
g_free (new_uri);
return ret;
}
/* debug stuff */
......
......@@ -76,6 +76,9 @@ void gimp_constrain_line (gdouble start_x,
gint gimp_file_compare (GFile *file1,
GFile *file2);
gboolean gimp_file_is_executable (GFile *file);
gchar * gimp_file_get_extension (GFile *file);
GFile * gimp_file_with_new_extension (GFile *file,
GFile *ext_file);
GimpImage * gimp_create_image_from_buffer (Gimp *gimp,
GeglBuffer *buffer,
......
......@@ -39,6 +39,7 @@
#include "gimp.h"
#include "gimp-memsize.h"
#include "gimp-parasites.h"
#include "gimp-utils.h"
#include "gimpcontext.h"
#include "gimpdrawablestack.h"
#include "gimpgrid.h"
......@@ -72,8 +73,6 @@
#include "gimptemplate.h"
#include "gimpundostack.h"
#include "file/file-utils.h"
#include "vectors/gimpvectors.h"
#include "gimp-log.h"
......@@ -2168,7 +2167,7 @@ gimp_image_format_display_uri (GimpImage *image,
}
if (display_file)
display_file = file_utils_file_with_new_ext (display_file, NULL);
display_file = gimp_file_with_new_extension (display_file, NULL);
uri_format = "[%s]";
}
......
......@@ -35,7 +35,6 @@
#include "core/gimpprogress.h"
#include "file/file-open.h"
#include "file/file-utils.h"
#include "file/gimp-file.h"
#include "widgets/gimpfiledialog.h"
......
......@@ -32,10 +32,9 @@
#include "core/gimpimage.h"
#include "core/gimpprogress.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginmanager-file.h"
#include "plug-in/gimppluginprocedure.h"
#include "file/file-procedure.h"
#include "file/file-save.h"
#include "file/gimp-file.h"
......@@ -78,8 +77,9 @@ static CheckUriResult file_save_dialog_check_file (GtkWidget
GimpPlugInProcedure **ret_save_proc);
static gboolean file_save_dialog_no_overwrite_confirmation (GimpFileDialog *dialog,
Gimp *gimp);
static GSList * file_save_dialog_get_procs (GimpFileDialog *dialog,
Gimp *gimp);
static GimpPlugInProcedure *
file_save_dialog_find_procedure (GimpFileDialog *dialog,
GFile *file);
static gboolean file_save_dialog_switch_dialogs (GimpFileDialog *file_dialog,
Gimp *gimp,
const gchar *basename);
......@@ -295,12 +295,8 @@ file_save_dialog_check_file (GtkWidget *dialog,
basename_file = g_file_new_for_uri (basename);
save_proc = file_dialog->file_proc;
uri_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
gimp),
file, NULL);
basename_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
gimp),
basename_file, NULL);
uri_proc = file_save_dialog_find_procedure (file_dialog, file);
basename_proc = file_save_dialog_find_procedure (file_dialog, basename_file);
g_object_unref (basename_file);
......@@ -539,9 +535,7 @@ file_save_dialog_no_overwrite_confirmation (GimpFileDialog *file_dialog,
basename_file = g_file_new_for_uri (basename);
save_proc = file_dialog->file_proc;
basename_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
gimp),
basename_file, NULL);
basename_proc = file_save_dialog_find_procedure (file_dialog, basename_file);
g_object_unref (basename_file);
......@@ -558,13 +552,19 @@ file_save_dialog_no_overwrite_confirmation (GimpFileDialog *file_dialog,
return uri_will_change || unknown_ext;
}
static GSList *
file_save_dialog_get_procs (GimpFileDialog *file_dialog,
Gimp *gimp)
static GimpPlugInProcedure *
file_save_dialog_find_procedure (GimpFileDialog *file_dialog,
GFile *file)
{
return (GIMP_IS_SAVE_DIALOG (file_dialog) ?
gimp->plug_in_manager->save_procs :
gimp->plug_in_manager->export_procs);
GimpPlugInManager *manager = file_dialog->gimp->plug_in_manager;
GimpFileProcedureGroup group;
if (GIMP_IS_SAVE_DIALOG (file_dialog))
group = GIMP_FILE_PROCEDURE_GROUP_SAVE;
else
group = GIMP_FILE_PROCEDURE_GROUP_EXPORT;
return gimp_plug_in_manager_file_procedure_find (manager, group, file, NULL);
}
static gboolean
......@@ -582,17 +582,21 @@ file_save_dialog_switch_dialogs (GimpFileDialog *file_dialog,
Gimp *gimp,
const gchar *basename)
{
GimpPlugInProcedure *proc_in_other_group;
GFile *file;
gboolean switch_dialogs = FALSE;
GimpPlugInProcedure *proc_in_other_group;
GimpFileProcedureGroup other_group;
GFile *file;
gboolean switch_dialogs = FALSE;
file = g_file_new_for_uri (basename);
if (GIMP_IS_EXPORT_DIALOG (file_dialog))
other_group = GIMP_FILE_PROCEDURE_GROUP_SAVE;
else
other_group = GIMP_FILE_PROCEDURE_GROUP_EXPORT;
proc_in_other_group =
file_procedure_find (GIMP_IS_EXPORT_DIALOG (file_dialog) ?
gimp->plug_in_manager->save_procs :
gimp->plug_in_manager->export_procs,
file, NULL);
gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
other_group, file, NULL);
g_object_unref (file);
......
......@@ -13,14 +13,12 @@ AM_CPPFLAGS = \
noinst_LIBRARIES = libappfile.a
libappfile_a_SOURCES = \
file-open.c \
file-open.h \
file-procedure.c \
file-procedure.h \
file-remote.c \
file-remote.h \
file-save.c \
file-save.h \
file-utils.c \
file-utils.h \
file-open.c \
file-open.h \
file-remote.c \
file-remote.h \
file-save.c \
file-save.h \
file-utils.c \
file-utils.h \
gimp-file.h
......@@ -46,27 +46,25 @@
#include "pdb/gimppdb.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginmanager-file.h"
#include "plug-in/gimppluginprocedure.h"
#include "file-open.h"
#include "file-procedure.h"
#include "file-remote.h"
#include "file-utils.h"
#include "gimp-file.h"
#include "gimp-intl.h"
static void file_open_sanitize_image (GimpImage *image,
gboolean as_new);
static void file_open_convert_items (GimpImage *dest_image,
const gchar *basename,
GList *items);
static GList * file_open_get_layers (const GimpImage *image,
gboolean merge_visible,
gint *n_visible);
static gboolean file_open_file_proc_is_import (const GimpPlugInProcedure *file_proc);
static void file_open_sanitize_image (GimpImage *image,
gboolean as_new);
static void file_open_convert_items (GimpImage *dest_image,
const gchar *basename,
GList *items);
static GList * file_open_get_layers (const GimpImage *image,
gboolean merge_visible,
gint *n_visible);
static gboolean file_open_file_proc_is_import (GimpPlugInProcedure *file_proc);
/* public functions */
......@@ -136,8 +134,9 @@ file_open_image (Gimp *gimp,
}
if (! file_proc)
file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, file,
error);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_OPEN,
file, error);
if (! file_proc)
return NULL;
......@@ -320,8 +319,9 @@ file_open_thumbnail (Gimp *gimp,
*format = NULL;
*num_layers = -1;
file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, file,
NULL);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_OPEN,
file, NULL);
if (! file_proc || ! file_proc->thumb_loader)
return NULL;
......@@ -791,7 +791,7 @@ file_open_get_layers (const GimpImage *image,
}
static gboolean
file_open_file_proc_is_import (const GimpPlugInProcedure *file_proc)
file_open_file_proc_is_import (GimpPlugInProcedure *file_proc)
{
return !(file_proc &&
file_proc->mime_type &&
......
......@@ -44,7 +44,6 @@
#include "file-remote.h"
#include "file-save.h"
#include "file-utils.h"
#include "gimp-file.h"
#include "gimp-intl.h"
......
......@@ -35,9 +35,8 @@
#include "core/gimpimage.h"
#include "core/gimpimagefile.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginmanager-file.h"
#include "file-procedure.h"
#include "file-utils.h"
#include "gimp-intl.h"
......@@ -105,8 +104,9 @@ file_utils_filename_to_file (Gimp *gimp,
file = g_file_new_for_uri (filename);
/* check for prefixes like http or ftp */
if (file_procedure_find_by_prefix (gimp->plug_in_manager->load_procs,
file))
if (gimp_plug_in_manager_file_procedure_find_by_prefix (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_OPEN,
file))
{
if (g_utf8_validate (filename, -1, NULL))
{
......@@ -155,90 +155,6 @@ file_utils_filename_to_file (Gimp *gimp,
return file;
}
GFile *
file_utils_file_with_new_ext (GFile *file,
GFile *ext_file)
{
gchar *uri;
gchar *file_ext;
gint file_ext_len = 0;
gchar *ext_file_ext = NULL;
gchar *uri_without_ext;
gchar *new_uri;
GFile *ret;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (ext_file == NULL || G_IS_FILE (ext_file), NULL);
uri = g_file_get_uri (file);
file_ext = file_utils_file_get_ext (file);
if (file_ext)
{
file_ext_len = strlen (file_ext);
g_free (file_ext);
}
if (ext_file)
ext_file_ext = file_utils_file_get_ext (ext_file);
uri_without_ext = g_strndup (uri, strlen (uri) - file_ext_len);
g_free (uri);
new_uri = g_strconcat (uri_without_ext, ext_file_ext, NULL);
ret = g_file_new_for_uri (new_uri);
g_free (ext_file_ext);
g_free (uri_without_ext);
g_free (new_uri);
return ret;
}
/**
* file_utils_file_get_ext:
* @file:
*
* Returns the position of the extension (including the .), or NULL
* if there is no extension.
*
* Returns:
**/
gchar *
file_utils_file_get_ext (GFile *file)
{
gchar *uri;
gint uri_len;
gchar *ext = NULL;
gint search_len;
g_return_val_if_fail (G_IS_FILE (file), NULL);
uri = g_file_get_uri (file);
uri_len = strlen (uri);
if (g_str_has_suffix (uri, ".gz"))
search_len = uri_len - 3;
else if (g_str_has_suffix (uri, ".bz2"))
search_len = uri_len - 4;
else if (g_str_has_suffix (uri, ".xz"))
search_len = uri_len - 3;
else
search_len = uri_len;
ext = g_strrstr_len (uri, search_len, ".");
if (ext)
ext = g_strdup (ext);
g_free (uri);
return ext;
}
GdkPixbuf *
file_utils_load_thumbnail (const gchar *filename)
{
......
......@@ -25,10 +25,6 @@ GFile * file_utils_filename_to_file (Gimp *gimp,
const gchar *filename,
GError **error);
GFile * file_utils_file_with_new_ext (GFile *file,
GFile *ext_file);
gchar * file_utils_file_get_ext (GFile *file);
GdkPixbuf * file_utils_load_thumbnail (const gchar *filename);
gboolean file_utils_save_thumbnail (GimpImage *image,
const gchar *filename);
......
......@@ -47,9 +47,7 @@
#include "text/gimpfont.h"
#include "plug-in/gimppluginmanager.h"
#include "file/file-procedure.h"
#include "plug-in/gimppluginmanager-file.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpbrushselect.h"
......@@ -734,8 +732,9 @@ gui_recent_list_load (Gimp *gimp)
const gchar *mime_type = gtk_recent_info_get_mime_type (info);
if (mime_type &&
file_procedure_find_by_mime_type (gimp->plug_in_manager->load_procs,
mime_type))
gimp_plug_in_manager_file_procedure_find_by_mime_type (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_OPEN,
mime_type))
{
GimpImagefile *imagefile;
GFile *file;
......
......@@ -38,11 +38,9 @@
#include "core/gimplayer.h"
#include "core/gimpparamspecs.h"
#include "file/file-open.h"
#include "file/file-procedure.h"
#include "file/file-save.h"
#include "file/file-utils.h"
#include "plug-in/gimppluginmanager-file.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginprocedure.h"
#include "gimppdb.h"
......@@ -73,8 +71,9 @@ file_load_invoker (GimpProcedure *procedure,
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
file_proc = file_procedure_find (gimp->plug_in_manager->load_procs,
file, error);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_OPEN,
file, error);
if (! file_proc)
{
......@@ -279,12 +278,14 @@ file_save_invoker (GimpProcedure *procedure,
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
file_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
file, NULL);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_SAVE,
file, NULL);
if (! file_proc)
file_proc = file_procedure_find (gimp->plug_in_manager->export_procs,
file, error);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_EXPORT,
file, error);
if (! file_proc)
{
......
......@@ -46,6 +46,8 @@ libappplug_in_a_SOURCES = \
gimppluginmanager-data.h \
gimppluginmanager-file.c \
gimppluginmanager-file.h \
gimppluginmanager-file-procedure.c \
gimppluginmanager-file-procedure.h \
gimppluginmanager-help-domain.c \
gimppluginmanager-help-domain.h \
gimppluginmanager-locale-domain.c \
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
* Copyright (C) 1997 Josh MacDonald
*
* file-procedure.c
* gimppluginmanager-file-procedure.c
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -28,12 +28,12 @@
#include "libgimpbase/gimpbase.h"
#include "core/core-types.h"
#include "plug-in-types.h"
#include "plug-in/gimppluginprocedure.h"
#include "core/gimp-utils.h"
#include "file-procedure.h"
#include "file-utils.h"
#include "gimppluginmanager-file-procedure.h"
#include "gimppluginprocedure.h"
#include "gimp-intl.h"
......@@ -252,40 +252,6 @@ file_procedure_find_by_mime_type (GSList *procs,
return NULL;
}
gboolean
file_procedure_in_group (GimpPlugInProcedure *file_proc,
FileProcedureGroup group)
{
const gchar *name = gimp_object_get_name (file_proc);
gboolean is_xcf_save = FALSE;
gboolean is_filter = FALSE;
is_xcf_save = (strcmp (name, "gimp-xcf-save") == 0);
is_filter = (strcmp (name, "file-gz-save") == 0 ||
strcmp (name, "file-bz2-save") == 0 ||
strcmp (name, "file-xz-save") == 0);
switch (group)
{
case FILE_PROCEDURE_GROUP_SAVE:
/* Only .xcf shall pass */
return is_xcf_save || is_filter;
case FILE_PROCEDURE_GROUP_EXPORT:
/* Anything but .xcf shall pass */
return ! is_xcf_save;
case FILE_PROCEDURE_GROUP_OPEN:
/* No filter applied for Open */
return TRUE;
default:
case FILE_PROCEDURE_GROUP_ANY:
return TRUE;
}
}
/* private functions */
......@@ -328,7 +294,7 @@ file_proc_find_by_extension (GSList *procs,
gboolean skip_magic,
gboolean uri_procs_only)
{
gchar *ext = file_utils_file_get_ext (file);
gchar *ext = gimp_file_get_extension (file);
if (ext)
{
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* file-procedure.h
* gimppluginmanager-file-procedure.h
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -17,32 +17,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __FILE_PROCEDURE_H__
#define __FILE_PROCEDURE_H__
#ifndef __GIMP_PLUG_IN_MANAGER_FILE_PROCEDURE_H__
#define __GIMP_PLUG_IN_MANAGER_FILE_PROCEDURE_H__
typedef enum
{
FILE_PROCEDURE_GROUP_ANY,
FILE_PROCEDURE_GROUP_OPEN,
FILE_PROCEDURE_GROUP_SAVE,
FILE_PROCEDURE_GROUP_EXPORT
} FileProcedureGroup;
GimpPlugInProcedure *file_procedure_find (GSList *procs,
GFile *file,
GError **error);
GimpPlugInProcedure *file_procedure_find_by_prefix (GSList *procs,
GFile *file);
GimpPlugInProcedure *file_procedure_find_by_extension (GSList *procs,
GFile *file);
GimpPlugInProcedure *file_procedure_find (GSList *procs,
GFile *file,
GError **error);
GimpPlugInProcedure *file_procedure_find_by_prefix (GSList *procs,
GFile *file);
GimpPlugInProcedure *file_procedure_find_by_extension (GSList *procs,
GFile *file);
GimpPlugInProcedure *file_procedure_find_by_mime_type (GSList *procs,
const gchar *mime_type);
GimpPlugInProcedure *file_procedure_find_by_mime_type (GSList *procs,
const gchar *mime_type);
gboolean file_procedure_in_group (GimpPlugInProcedure *file_proc,
FileProcedureGroup group);
#endif /* __FILE_PROCEDURE_H__ */
#endif /* __GIMP_PLUG_IN_MANAGER_FILE_PROCEDURE_H__ */
......@@ -19,6 +19,8 @@
#include "config.h"
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
......@@ -27,15 +29,18 @@
#include "core/gimp.h"
#include "core/gimpparamspecs.h"
#include "file/file-procedure.h"
#include "gimpplugin.h"
#include "gimpplugindef.h"
#include "gimppluginmanager.h"
#include "gimppluginmanager-file.h"
#include "gimppluginmanager-file-procedure.h"
#include "gimppluginprocedure.h"
static gboolean file_procedure_in_group (GimpPlugInProcedure *file_proc,
GimpFileProcedureGroup group);