2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-02-11 09:39:24 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-04-22 08:38:56 +08:00
|
|
|
* gimpdata.c
|
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-02-11 09:39:24 +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
|
2001-02-11 09:39:24 +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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-02-11 09:39:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2012-03-22 04:58:40 +08:00
|
|
|
#include <gegl.h>
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2004-07-19 21:22:44 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-08-12 19:57:57 +08:00
|
|
|
#include "gimp-memsize.h"
|
2001-02-11 09:39:24 +08:00
|
|
|
#include "gimpdata.h"
|
2001-02-14 03:53:07 +08:00
|
|
|
#include "gimpmarshal.h"
|
2008-12-12 06:04:05 +08:00
|
|
|
#include "gimptag.h"
|
2008-01-17 18:51:31 +08:00
|
|
|
#include "gimptagged.h"
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-10-31 02:46:29 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DIRTY,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-07-01 07:19:35 +08:00
|
|
|
PROP_FILE,
|
2005-05-26 07:47:42 +08:00
|
|
|
PROP_WRITABLE,
|
|
|
|
PROP_DELETABLE,
|
2005-05-26 07:25:45 +08:00
|
|
|
PROP_MIME_TYPE
|
|
|
|
};
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
typedef struct _GimpDataPrivate GimpDataPrivate;
|
|
|
|
|
|
|
|
struct _GimpDataPrivate
|
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
GFile *file;
|
2009-11-01 01:48:38 +08:00
|
|
|
GQuark mime_type;
|
|
|
|
guint writable : 1;
|
|
|
|
guint deletable : 1;
|
|
|
|
guint dirty : 1;
|
|
|
|
guint internal : 1;
|
|
|
|
gint freeze_count;
|
2013-07-12 22:33:12 +08:00
|
|
|
gint64 mtime;
|
2009-11-01 01:48:38 +08:00
|
|
|
|
|
|
|
/* Identifies the GimpData object across sessions. Used when there
|
|
|
|
* is not a filename associated with the object.
|
|
|
|
*/
|
|
|
|
gchar *identifier;
|
|
|
|
|
|
|
|
GList *tags;
|
2009-10-31 22:24:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GIMP_DATA_GET_PRIVATE(data) \
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (data, GIMP_TYPE_DATA, GimpDataPrivate)
|
|
|
|
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_data_class_init (GimpDataClass *klass);
|
|
|
|
static void gimp_data_tagged_iface_init (GimpTaggedInterface *iface);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_data_init (GimpData *data,
|
|
|
|
GimpDataClass *data_class);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_data_constructed (GObject *object);
|
|
|
|
static void gimp_data_finalize (GObject *object);
|
|
|
|
static void gimp_data_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_data_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2013-05-30 04:23:38 +08:00
|
|
|
static void gimp_data_name_changed (GimpObject *object);
|
2011-01-13 05:53:58 +08:00
|
|
|
static gint64 gimp_data_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
2005-11-01 21:04:09 +08:00
|
|
|
|
2016-11-16 22:13:08 +08:00
|
|
|
static gboolean gimp_data_is_name_editable (GimpViewable *viewable);
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_data_real_dirty (GimpData *data);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static gboolean gimp_data_add_tag (GimpTagged *tagged,
|
|
|
|
GimpTag *tag);
|
|
|
|
static gboolean gimp_data_remove_tag (GimpTagged *tagged,
|
|
|
|
GimpTag *tag);
|
|
|
|
static GList * gimp_data_get_tags (GimpTagged *tagged);
|
|
|
|
static gchar * gimp_data_get_identifier (GimpTagged *tagged);
|
|
|
|
static gchar * gimp_data_get_checksum (GimpTagged *tagged);
|
2008-01-17 18:51:31 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
static guint data_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GimpViewableClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
GType
|
2001-02-11 09:39:24 +08:00
|
|
|
gimp_data_get_type (void)
|
|
|
|
{
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
static GType data_type = 0;
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
if (! data_type)
|
|
|
|
{
|
2006-10-18 21:17:50 +08:00
|
|
|
const GTypeInfo data_info =
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpDataClass),
|
2004-01-30 00:19:57 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_data_class_init,
|
2004-07-16 03:01:57 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2004-01-30 00:19:57 +08:00
|
|
|
sizeof (GimpData),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_data_init,
|
2001-02-11 09:39:24 +08:00
|
|
|
};
|
|
|
|
|
2008-01-17 18:51:31 +08:00
|
|
|
const GInterfaceInfo tagged_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gimp_data_tagged_iface_init,
|
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
|
|
|
};
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
data_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
|
2004-01-30 00:19:57 +08:00
|
|
|
"GimpData",
|
|
|
|
&data_info, 0);
|
2008-01-17 18:51:31 +08:00
|
|
|
|
|
|
|
g_type_add_interface_static (data_type, GIMP_TYPE_TAGGED, &tagged_info);
|
2008-04-19 22:48:50 +08:00
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
return data_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_class_init (GimpDataClass *klass)
|
|
|
|
{
|
2016-11-16 22:13:08 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
data_signals[DIRTY] =
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_new ("dirty",
|
2004-07-16 03:01:57 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpDataClass, dirty),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2016-11-16 22:13:08 +08:00
|
|
|
object_class->constructed = gimp_data_constructed;
|
|
|
|
object_class->finalize = gimp_data_finalize;
|
|
|
|
object_class->set_property = gimp_data_set_property;
|
|
|
|
object_class->get_property = gimp_data_get_property;
|
|
|
|
|
|
|
|
gimp_object_class->name_changed = gimp_data_name_changed;
|
|
|
|
gimp_object_class->get_memsize = gimp_data_get_memsize;
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2016-11-16 22:13:08 +08:00
|
|
|
viewable_class->name_editable = TRUE;
|
|
|
|
viewable_class->is_name_editable = gimp_data_is_name_editable;
|
2001-02-12 11:27:28 +08:00
|
|
|
|
2016-11-16 22:13:08 +08:00
|
|
|
klass->dirty = gimp_data_real_dirty;
|
|
|
|
klass->save = NULL;
|
|
|
|
klass->get_extension = NULL;
|
|
|
|
klass->duplicate = NULL;
|
2005-05-26 07:25:45 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_FILE,
|
|
|
|
g_param_spec_object ("file", NULL, NULL,
|
|
|
|
G_TYPE_FILE,
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2005-05-27 18:56:33 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_WRITABLE,
|
2006-04-12 20:49:29 +08:00
|
|
|
g_param_spec_boolean ("writable", NULL, NULL,
|
2005-05-27 18:56:33 +08:00
|
|
|
FALSE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2005-05-27 18:56:33 +08:00
|
|
|
|
2006-10-28 02:11:46 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_DELETABLE,
|
2006-04-12 20:49:29 +08:00
|
|
|
g_param_spec_boolean ("deletable", NULL, NULL,
|
2005-05-27 18:56:33 +08:00
|
|
|
FALSE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2005-05-27 18:56:33 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_MIME_TYPE,
|
2006-04-12 20:49:29 +08:00
|
|
|
g_param_spec_string ("mime-type", NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_READWRITE |
|
2005-05-27 18:56:33 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2009-10-31 22:24:57 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpDataPrivate));
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2008-01-17 18:51:31 +08:00
|
|
|
static void
|
|
|
|
gimp_data_tagged_iface_init (GimpTaggedInterface *iface)
|
|
|
|
{
|
2008-12-13 19:58:24 +08:00
|
|
|
iface->add_tag = gimp_data_add_tag;
|
|
|
|
iface->remove_tag = gimp_data_remove_tag;
|
|
|
|
iface->get_tags = gimp_data_get_tags;
|
|
|
|
iface->get_identifier = gimp_data_get_identifier;
|
|
|
|
iface->get_checksum = gimp_data_get_checksum;
|
2008-01-17 18:51:31 +08:00
|
|
|
}
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static void
|
2004-02-15 19:23:32 +08:00
|
|
|
gimp_data_init (GimpData *data,
|
|
|
|
GimpDataClass *data_class)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
private->writable = TRUE;
|
|
|
|
private->deletable = TRUE;
|
|
|
|
private->dirty = TRUE;
|
2004-02-13 19:53:22 +08:00
|
|
|
|
2004-02-15 19:23:32 +08:00
|
|
|
/* look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data)
|
|
|
|
* here, because the latter is always GimpDataClass itself
|
|
|
|
*/
|
|
|
|
if (! data_class->save)
|
2009-11-01 01:48:38 +08:00
|
|
|
private->writable = FALSE;
|
2005-11-01 21:04:09 +08:00
|
|
|
|
|
|
|
/* freeze the data object during construction */
|
|
|
|
gimp_data_freeze (data);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void
|
|
|
|
gimp_data_constructed (GObject *object)
|
2008-04-19 22:48:50 +08:00
|
|
|
{
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2008-04-19 22:48:50 +08:00
|
|
|
|
|
|
|
gimp_data_thaw (GIMP_DATA (object));
|
|
|
|
}
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_data_finalize (GObject *object)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (private->file)
|
2001-08-11 22:39:19 +08:00
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
g_object_unref (private->file);
|
|
|
|
private->file = NULL;
|
2001-08-11 22:39:19 +08:00
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
if (private->tags)
|
2008-01-17 18:51:31 +08:00
|
|
|
{
|
2011-03-08 00:10:18 +08:00
|
|
|
g_list_free_full (private->tags, (GDestroyNotify) g_object_unref);
|
2009-11-01 01:48:38 +08:00
|
|
|
private->tags = NULL;
|
2008-01-17 18:51:31 +08:00
|
|
|
}
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
if (private->identifier)
|
2008-12-12 15:03:42 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
g_free (private->identifier);
|
|
|
|
private->identifier = NULL;
|
2008-12-12 15:03:42 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
static void
|
|
|
|
gimp_data_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpData *data = GIMP_DATA (object);
|
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data);
|
2005-05-26 07:25:45 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
case PROP_FILE:
|
|
|
|
gimp_data_set_file (data,
|
|
|
|
g_value_get_object (value),
|
|
|
|
private->writable,
|
|
|
|
private->deletable);
|
2005-05-26 07:47:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_WRITABLE:
|
2009-11-01 01:48:38 +08:00
|
|
|
private->writable = g_value_get_boolean (value);
|
2005-05-26 07:47:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_DELETABLE:
|
2009-11-01 01:48:38 +08:00
|
|
|
private->deletable = g_value_get_boolean (value);
|
2005-05-26 07:47:42 +08:00
|
|
|
break;
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
case PROP_MIME_TYPE:
|
|
|
|
if (g_value_get_string (value))
|
2009-11-01 01:48:38 +08:00
|
|
|
private->mime_type = g_quark_from_string (g_value_get_string (value));
|
2005-05-26 07:25:45 +08:00
|
|
|
else
|
2009-11-01 01:48:38 +08:00
|
|
|
private->mime_type = 0;
|
2005-05-26 07:25:45 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
|
2005-05-26 07:25:45 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
case PROP_FILE:
|
|
|
|
g_value_set_object (value, private->file);
|
2005-05-26 07:47:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_WRITABLE:
|
2009-11-01 01:48:38 +08:00
|
|
|
g_value_set_boolean (value, private->writable);
|
2005-05-26 07:47:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_DELETABLE:
|
2009-11-01 01:48:38 +08:00
|
|
|
g_value_set_boolean (value, private->deletable);
|
2005-05-26 07:47:42 +08:00
|
|
|
break;
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
case PROP_MIME_TYPE:
|
2009-11-01 01:48:38 +08:00
|
|
|
g_value_set_string (value, g_quark_to_string (private->mime_type));
|
2005-05-26 07:25:45 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 04:23:38 +08:00
|
|
|
static void
|
|
|
|
gimp_data_name_changed (GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
private->dirty = TRUE;
|
|
|
|
|
|
|
|
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
|
|
|
|
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
|
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_data_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
|
2009-10-31 22:24:57 +08:00
|
|
|
gint64 memsize = 0;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
memsize += gimp_g_object_get_memsize (G_OBJECT (private->file));
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 22:13:08 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_data_is_name_editable (GimpViewable *viewable)
|
|
|
|
{
|
|
|
|
return gimp_data_is_writable (GIMP_DATA (viewable));
|
|
|
|
}
|
|
|
|
|
2004-06-13 06:13:31 +08:00
|
|
|
static void
|
|
|
|
gimp_data_real_dirty (GimpData *data)
|
|
|
|
{
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (data));
|
2006-05-23 23:39:45 +08:00
|
|
|
|
2013-05-30 04:23:38 +08:00
|
|
|
/* Emit the "name-changed" to signal general dirtiness, our name
|
|
|
|
* changed implementation will also set the "dirty" flag to TRUE.
|
|
|
|
*/
|
2006-05-23 23:39:45 +08:00
|
|
|
gimp_object_name_changed (GIMP_OBJECT (data));
|
2004-06-13 06:13:31 +08:00
|
|
|
}
|
|
|
|
|
2008-01-17 18:51:31 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_data_add_tag (GimpTagged *tagged,
|
2008-12-12 06:04:05 +08:00
|
|
|
GimpTag *tag)
|
2008-01-17 18:51:31 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged);
|
|
|
|
GList *list;
|
2008-01-17 18:51:31 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
for (list = private->tags; list; list = g_list_next (list))
|
2008-01-17 18:51:31 +08:00
|
|
|
{
|
2008-12-12 06:04:05 +08:00
|
|
|
GimpTag *this = GIMP_TAG (list->data);
|
2008-01-17 18:51:31 +08:00
|
|
|
|
2008-12-12 06:04:05 +08:00
|
|
|
if (gimp_tag_equals (tag, this))
|
2008-01-17 18:51:31 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private->tags = g_list_prepend (private->tags, g_object_ref (tag));
|
2008-01-17 18:51:31 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_data_remove_tag (GimpTagged *tagged,
|
2008-12-12 06:04:05 +08:00
|
|
|
GimpTag *tag)
|
2008-01-17 18:51:31 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged);
|
|
|
|
GList *list;
|
2008-01-17 18:51:31 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
for (list = private->tags; list; list = g_list_next (list))
|
2008-01-17 18:51:31 +08:00
|
|
|
{
|
2008-12-12 06:04:05 +08:00
|
|
|
GimpTag *this = GIMP_TAG (list->data);
|
2008-01-17 18:51:31 +08:00
|
|
|
|
2008-12-12 06:04:05 +08:00
|
|
|
if (gimp_tag_equals (tag, this))
|
2008-01-17 18:51:31 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
private->tags = g_list_delete_link (private->tags, list);
|
2014-01-27 04:03:28 +08:00
|
|
|
g_object_unref (this);
|
2008-01-17 18:51:31 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
gimp_data_get_tags (GimpTagged *tagged)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged);
|
|
|
|
|
|
|
|
return private->tags;
|
2008-01-17 18:51:31 +08:00
|
|
|
}
|
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
static gchar *
|
2008-12-13 19:58:24 +08:00
|
|
|
gimp_data_get_identifier (GimpTagged *tagged)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged);
|
2009-10-31 22:24:57 +08:00
|
|
|
gchar *identifier = NULL;
|
2008-12-13 19:58:24 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (private->file)
|
2008-12-13 19:58:24 +08:00
|
|
|
{
|
2009-11-08 04:14:56 +08:00
|
|
|
const gchar *data_dir = gimp_data_directory ();
|
|
|
|
const gchar *gimp_dir = gimp_directory ();
|
2014-07-01 07:19:35 +08:00
|
|
|
gchar *path = g_file_get_path (private->file);
|
2009-11-08 04:14:56 +08:00
|
|
|
gchar *tmp;
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (g_str_has_prefix (path, data_dir))
|
2009-11-08 04:14:56 +08:00
|
|
|
{
|
|
|
|
tmp = g_strconcat ("${gimp_data_dir}",
|
2014-07-01 07:19:35 +08:00
|
|
|
path + strlen (data_dir),
|
2009-11-08 04:14:56 +08:00
|
|
|
NULL);
|
|
|
|
identifier = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
2014-07-01 07:19:35 +08:00
|
|
|
else if (g_str_has_prefix (path, gimp_dir))
|
2009-11-08 04:14:56 +08:00
|
|
|
{
|
|
|
|
tmp = g_strconcat ("${gimp_dir}",
|
2014-07-01 07:19:35 +08:00
|
|
|
path + strlen (gimp_dir),
|
2009-11-08 04:14:56 +08:00
|
|
|
NULL);
|
|
|
|
identifier = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
identifier = g_filename_to_utf8 (path, -1,
|
2009-11-08 04:14:56 +08:00
|
|
|
NULL, NULL, NULL);
|
|
|
|
}
|
2008-12-13 19:58:24 +08:00
|
|
|
|
|
|
|
if (! identifier)
|
|
|
|
{
|
2016-11-16 22:30:44 +08:00
|
|
|
g_printerr ("%s: failed to convert '%s' to utf8.\n",
|
|
|
|
G_STRFUNC, path);
|
2014-07-01 07:19:35 +08:00
|
|
|
identifier = g_strdup (path);
|
2008-12-13 19:58:24 +08:00
|
|
|
}
|
2014-07-01 07:19:35 +08:00
|
|
|
|
|
|
|
g_free (path);
|
2008-12-13 19:58:24 +08:00
|
|
|
}
|
2009-11-01 01:48:38 +08:00
|
|
|
else if (private->internal)
|
2008-12-13 19:58:24 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
identifier = g_strdup (private->identifier);
|
2008-12-13 19:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gimp_data_get_checksum (GimpTagged *tagged)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_save:
|
|
|
|
* @data: object whose contents are to be saved.
|
2004-07-16 18:07:30 +08:00
|
|
|
* @error: return location for errors or %NULL
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
2014-07-01 07:19:35 +08:00
|
|
|
* Save the object. If the object is marked as "internal", nothing
|
|
|
|
* happens. Otherwise, it is saved to disk, using the file name set
|
|
|
|
* by gimp_data_set_file(). If the save is successful, the object is
|
|
|
|
* marked as not dirty. If not, an error message is returned using
|
|
|
|
* the @error argument.
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
2004-07-16 18:07:30 +08:00
|
|
|
* Returns: %TRUE if the object is internal or the save is successful.
|
2004-07-16 03:01:57 +08:00
|
|
|
**/
|
2001-02-11 09:39:24 +08:00
|
|
|
gboolean
|
2002-12-02 21:39:09 +08:00
|
|
|
gimp_data_save (GimpData *data,
|
|
|
|
GError **error)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
gboolean success = FALSE;
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
2002-12-02 21:39:09 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
g_return_val_if_fail (private->writable == TRUE, FALSE);
|
|
|
|
|
|
|
|
if (private->internal)
|
2002-06-12 21:48:47 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
private->dirty = FALSE;
|
2002-06-12 21:48:47 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-07-26 22:33:40 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (private->file), FALSE);
|
2002-12-03 06:41:44 +08:00
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
if (GIMP_DATA_GET_CLASS (data)->save)
|
2014-07-04 05:44:38 +08:00
|
|
|
{
|
|
|
|
GOutputStream *output;
|
|
|
|
|
|
|
|
output = G_OUTPUT_STREAM (g_file_replace (private->file,
|
|
|
|
NULL, FALSE, G_FILE_CREATE_NONE,
|
|
|
|
NULL, error));
|
|
|
|
|
|
|
|
if (output)
|
|
|
|
{
|
|
|
|
success = GIMP_DATA_GET_CLASS (data)->save (data, output, error);
|
|
|
|
|
2014-07-05 00:46:02 +08:00
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
if (! g_output_stream_close (output, NULL, error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error,
|
|
|
|
_("Error saving '%s': "),
|
|
|
|
gimp_file_get_utf8_name (private->file));
|
|
|
|
success = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (error && *error)
|
2014-07-04 05:44:38 +08:00
|
|
|
{
|
|
|
|
g_prefix_error (error,
|
2014-07-05 00:46:02 +08:00
|
|
|
_("Error saving '%s': "),
|
2014-07-04 05:44:38 +08:00
|
|
|
gimp_file_get_utf8_name (private->file));
|
2014-07-05 00:46:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
|
|
|
|
_("Error saving '%s'"),
|
|
|
|
gimp_file_get_utf8_name (private->file));
|
2014-07-04 05:44:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (output);
|
|
|
|
}
|
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
if (success)
|
2005-10-31 19:29:01 +08:00
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
GFileInfo *info = g_file_query_info (private->file,
|
|
|
|
G_FILE_ATTRIBUTE_TIME_MODIFIED,
|
2013-08-04 22:51:31 +08:00
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
private->mtime =
|
|
|
|
g_file_info_get_attribute_uint64 (info,
|
|
|
|
G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
2005-10-31 19:29:01 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private->dirty = FALSE;
|
2005-10-31 19:29:01 +08:00
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_dirty:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @data: a #GimpData object.
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
2004-07-16 18:07:30 +08:00
|
|
|
* Marks @data as dirty. Unless the object is frozen, this causes
|
|
|
|
* its preview to be invalidated, and emits a "dirty" signal. If the
|
|
|
|
* object is frozen, the function has no effect.
|
2004-07-16 03:01:57 +08:00
|
|
|
**/
|
2001-02-11 09:39:24 +08:00
|
|
|
void
|
|
|
|
gimp_data_dirty (GimpData *data)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
if (private->freeze_count == 0)
|
2004-06-13 06:13:31 +08:00
|
|
|
g_signal_emit (data, data_signals[DIRTY], 0);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
void
|
|
|
|
gimp_data_clean (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
private->dirty = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_data_is_dirty (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->dirty;
|
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_freeze:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @data: a #GimpData object.
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
|
|
|
* Increments the freeze count for the object. A positive freeze count
|
|
|
|
* prevents the object from being treated as dirty. Any call to this
|
|
|
|
* function must be followed eventually by a call to gimp_data_thaw().
|
|
|
|
**/
|
2004-06-13 06:13:31 +08:00
|
|
|
void
|
|
|
|
gimp_data_freeze (GimpData *data)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
2004-06-13 06:13:31 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
2001-02-12 11:27:28 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
private->freeze_count++;
|
2004-06-13 06:13:31 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_thaw:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @data: a #GimpData object.
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
|
|
|
* Decrements the freeze count for the object. If the freeze count
|
|
|
|
* drops to zero, the object is marked as dirty, and the "dirty"
|
|
|
|
* signal is emitted. It is an error to call this function without
|
|
|
|
* having previously called gimp_data_freeze().
|
|
|
|
**/
|
2004-06-13 06:13:31 +08:00
|
|
|
void
|
|
|
|
gimp_data_thaw (GimpData *data)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
2004-06-13 06:13:31 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
2004-06-13 06:13:31 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
g_return_if_fail (private->freeze_count > 0);
|
|
|
|
|
|
|
|
private->freeze_count--;
|
|
|
|
|
|
|
|
if (private->freeze_count == 0)
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_dirty (data);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
gboolean
|
|
|
|
gimp_data_is_frozen (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->freeze_count > 0;
|
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_delete_from_disk:
|
|
|
|
* @data: a #GimpData object.
|
2004-07-16 18:07:30 +08:00
|
|
|
* @error: return location for errors or %NULL
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
|
|
|
* Deletes the object from disk. If the object is marked as "internal",
|
|
|
|
* nothing happens. Otherwise, if the file exists whose name has been
|
2014-07-01 07:19:35 +08:00
|
|
|
* set by gimp_data_set_file(), it is deleted. Obviously this is
|
2004-07-16 03:01:57 +08:00
|
|
|
* a potentially dangerous function, which should be used with care.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the object is internal to Gimp, or the deletion is
|
|
|
|
* successful.
|
|
|
|
**/
|
2001-02-11 09:39:24 +08:00
|
|
|
gboolean
|
2002-10-31 02:46:29 +08:00
|
|
|
gimp_data_delete_from_disk (GimpData *data,
|
|
|
|
GError **error)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
2002-10-31 02:46:29 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
g_return_val_if_fail (private->file != NULL, FALSE);
|
2009-11-01 01:48:38 +08:00
|
|
|
g_return_val_if_fail (private->deletable == TRUE, FALSE);
|
2009-10-31 22:24:57 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
if (private->internal)
|
2002-06-12 21:48:47 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
return g_file_delete (private->file, NULL, error);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_data_get_extension (GimpData *data)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
if (GIMP_DATA_GET_CLASS (data)->get_extension)
|
|
|
|
return GIMP_DATA_GET_CLASS (data)->get_extension (data);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
return NULL;
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
2014-07-01 07:19:35 +08:00
|
|
|
* gimp_data_set_file:
|
2004-07-16 03:01:57 +08:00
|
|
|
* @data: A #GimpData object
|
2014-07-01 07:19:35 +08:00
|
|
|
* @file: File to assign to @data.
|
2004-07-16 03:01:57 +08:00
|
|
|
* @writable: %TRUE if we want to be able to write to this file.
|
2004-10-04 17:39:27 +08:00
|
|
|
* @deletable: %TRUE if we want to be able to delete this file.
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
2014-07-01 07:19:35 +08:00
|
|
|
* This function assigns a file to @data, and sets some flags
|
2004-07-16 03:01:57 +08:00
|
|
|
* according to the properties of the file. If @writable is %TRUE,
|
2014-07-01 07:19:35 +08:00
|
|
|
* and the user has permission to write or overwrite the requested
|
|
|
|
* file name, and a "save" method exists for @data's object type, then
|
2004-07-16 18:07:30 +08:00
|
|
|
* @data is marked as writable.
|
2004-07-16 03:01:57 +08:00
|
|
|
**/
|
2001-02-11 09:39:24 +08:00
|
|
|
void
|
2014-07-01 07:19:35 +08:00
|
|
|
gimp_data_set_file (GimpData *data,
|
|
|
|
GFile *file,
|
|
|
|
gboolean writable,
|
|
|
|
gboolean deletable)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
GimpDataPrivate *private;
|
2014-07-01 07:19:35 +08:00
|
|
|
gchar *path;
|
2009-10-31 22:24:57 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
2014-07-01 07:19:35 +08:00
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
path = g_file_get_path (file);
|
|
|
|
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
g_return_if_fail (g_path_is_absolute (path));
|
|
|
|
|
|
|
|
g_free (path);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
if (private->internal)
|
2002-06-12 21:48:47 +08:00
|
|
|
return;
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (private->file)
|
|
|
|
g_object_unref (private->file);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
private->file = g_object_ref (file);
|
2009-11-01 01:48:38 +08:00
|
|
|
private->writable = FALSE;
|
|
|
|
private->deletable = FALSE;
|
2003-02-27 02:08:26 +08:00
|
|
|
|
2004-10-04 17:39:27 +08:00
|
|
|
/* if the data is supposed to be writable or deletable,
|
|
|
|
* still check if it really is
|
|
|
|
*/
|
|
|
|
if (writable || deletable)
|
2003-02-27 02:08:26 +08:00
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
GFileInfo *info;
|
2003-02-27 02:08:26 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (g_file_query_exists (private->file, NULL)) /* check if it exists */
|
2003-02-27 02:08:26 +08:00
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
info = g_file_query_info (private->file,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
/* and we can write it */
|
2014-07-21 03:40:57 +08:00
|
|
|
if (info)
|
2014-07-01 07:19:35 +08:00
|
|
|
{
|
2014-07-21 03:40:57 +08:00
|
|
|
if (g_file_info_get_attribute_boolean (info,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
|
|
|
|
{
|
|
|
|
private->writable = writable ? TRUE : FALSE;
|
|
|
|
private->deletable = deletable ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
2014-07-01 07:19:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* OR it doesn't exist */
|
|
|
|
{
|
|
|
|
GFile *parent = g_file_get_parent (private->file);
|
|
|
|
|
|
|
|
info = g_file_query_info (parent,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
/* and we can write to its parent directory */
|
2014-07-21 03:40:57 +08:00
|
|
|
if (info)
|
2014-07-01 07:19:35 +08:00
|
|
|
{
|
2014-07-21 03:40:57 +08:00
|
|
|
if (g_file_info_get_attribute_boolean (info,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
|
|
|
|
{
|
|
|
|
private->writable = writable ? TRUE : FALSE;
|
|
|
|
private->deletable = deletable ? TRUE : FALSE;
|
|
|
|
}
|
2014-07-26 22:52:56 +08:00
|
|
|
|
|
|
|
g_object_unref (info);
|
2014-07-01 07:19:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (parent);
|
2003-02-27 02:08:26 +08:00
|
|
|
}
|
2004-02-06 06:17:14 +08:00
|
|
|
|
|
|
|
/* if we can't save, we are not writable */
|
|
|
|
if (! GIMP_DATA_GET_CLASS (data)->save)
|
2009-11-01 01:48:38 +08:00
|
|
|
private->writable = FALSE;
|
2003-02-27 02:08:26 +08:00
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
GFile *
|
|
|
|
gimp_data_get_file (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->file;
|
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_create_filename:
|
|
|
|
* @data: a #Gimpdata object.
|
|
|
|
* @dest_dir: directory in which to create a file name.
|
|
|
|
*
|
|
|
|
* This function creates a unique file name to be used for saving
|
|
|
|
* a representation of @data in the directory @dest_dir. If the
|
|
|
|
* user does not have write permission in @dest_dir, then @data
|
|
|
|
* is marked as "not writable", so you should check on this before
|
|
|
|
* assuming that @data can be saved.
|
|
|
|
**/
|
2001-02-11 09:39:24 +08:00
|
|
|
void
|
2014-07-26 22:37:30 +08:00
|
|
|
gimp_data_create_filename (GimpData *data,
|
|
|
|
GFile *dest_dir)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
gchar *safename;
|
2014-07-01 07:19:35 +08:00
|
|
|
gchar *basename;
|
|
|
|
GFile *file;
|
2009-11-01 01:48:38 +08:00
|
|
|
gint i;
|
|
|
|
gint unum = 1;
|
|
|
|
GError *error = NULL;
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
2014-07-26 22:37:30 +08:00
|
|
|
g_return_if_fail (G_IS_FILE (dest_dir));
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
if (private->internal)
|
2005-04-04 23:14:50 +08:00
|
|
|
return;
|
|
|
|
|
2014-07-26 22:37:30 +08:00
|
|
|
safename = g_strstrip (g_strdup (gimp_object_get_name (data)));
|
2011-04-14 03:25:10 +08:00
|
|
|
|
2004-07-06 02:10:05 +08:00
|
|
|
if (safename[0] == '.')
|
|
|
|
safename[0] = '-';
|
|
|
|
|
|
|
|
for (i = 0; safename[i]; i++)
|
2011-04-14 03:25:10 +08:00
|
|
|
if (strchr ("\\/*?\"`'<>{}|\n\t ;:$^&", safename[i]))
|
2004-07-06 02:10:05 +08:00
|
|
|
safename[i] = '-';
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
basename = g_strconcat (safename, gimp_data_get_extension (data), NULL);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-26 22:37:30 +08:00
|
|
|
file = g_file_get_child_for_display_name (dest_dir, basename, &error);
|
2014-07-01 07:19:35 +08:00
|
|
|
g_free (basename);
|
2001-10-24 23:56:33 +08:00
|
|
|
|
2014-07-26 22:37:30 +08:00
|
|
|
if (! file)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2014-07-26 22:37:30 +08:00
|
|
|
g_warning ("gimp_data_create_filename:\n"
|
|
|
|
"g_file_get_child_for_display_name() failed for '%s': %s",
|
|
|
|
gimp_object_get_name (data), error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_free (safename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (g_file_query_exists (file, NULL))
|
|
|
|
{
|
|
|
|
g_object_unref (file);
|
2001-10-24 23:56:33 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
basename = g_strdup_printf ("%s-%d%s",
|
2004-07-16 03:01:57 +08:00
|
|
|
safename,
|
2002-12-02 21:39:09 +08:00
|
|
|
unum++,
|
2004-07-16 03:01:57 +08:00
|
|
|
gimp_data_get_extension (data));
|
2001-10-24 23:56:33 +08:00
|
|
|
|
2014-07-26 22:37:30 +08:00
|
|
|
file = g_file_get_child_for_display_name (dest_dir, basename, NULL);
|
2014-07-01 07:19:35 +08:00
|
|
|
g_free (basename);
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|
|
|
|
|
2004-07-06 02:10:05 +08:00
|
|
|
g_free (safename);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
gimp_data_set_file (data, file, TRUE, TRUE);
|
2009-10-31 22:24:57 +08:00
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
g_object_unref (file);
|
2009-10-31 22:24:57 +08:00
|
|
|
}
|
|
|
|
|
2012-02-09 17:02:49 +08:00
|
|
|
static const gchar *tag_blacklist[] = { "brushes",
|
|
|
|
"dynamics",
|
|
|
|
"patterns",
|
|
|
|
"palettes",
|
|
|
|
"gradients",
|
|
|
|
"tool-presets" };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_data_set_folder_tags:
|
|
|
|
* @data: a #Gimpdata object.
|
|
|
|
* @top_directory: the top directory of the currently processed data
|
2014-08-02 02:30:45 +08:00
|
|
|
* hierarchy.
|
2012-02-09 17:02:49 +08:00
|
|
|
*
|
|
|
|
* Sets tags based on all folder names below top_directory. So if the
|
2014-08-02 02:30:45 +08:00
|
|
|
* data's filename is e.g.
|
|
|
|
* /home/foo/.config/GIMP/X.Y/brushes/Flowers/Roses/rose.gbr, it will
|
|
|
|
* add "Flowers" and "Roses" tags.
|
2012-02-09 17:02:49 +08:00
|
|
|
*
|
|
|
|
* if the top directory (as passed, or as derived from the data's
|
|
|
|
* filename) does not end with one of the default data directory names
|
|
|
|
* (brushes, patterns etc), its name will be added as tag too.
|
|
|
|
**/
|
|
|
|
void
|
2014-08-02 02:30:45 +08:00
|
|
|
gimp_data_set_folder_tags (GimpData *data,
|
|
|
|
GFile *top_directory)
|
2012-02-09 17:02:49 +08:00
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
2014-08-02 02:30:45 +08:00
|
|
|
gchar *tmp;
|
2012-02-09 17:02:49 +08:00
|
|
|
gchar *dirname;
|
2014-08-02 02:30:45 +08:00
|
|
|
gchar *top_path;
|
2012-02-09 17:02:49 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
2014-08-02 02:30:45 +08:00
|
|
|
g_return_if_fail (G_IS_FILE (top_directory));
|
2012-02-09 17:02:49 +08:00
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
if (private->internal)
|
|
|
|
return;
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
g_return_if_fail (private->file != NULL);
|
2012-02-09 17:02:49 +08:00
|
|
|
|
2014-08-02 02:30:45 +08:00
|
|
|
tmp = g_file_get_path (private->file);
|
|
|
|
dirname = g_path_get_dirname (tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
top_path = g_file_get_path (top_directory);
|
|
|
|
|
|
|
|
g_return_if_fail (g_str_has_prefix (dirname, top_path));
|
2012-02-09 17:02:49 +08:00
|
|
|
|
2014-08-02 02:30:45 +08:00
|
|
|
/* walk up the hierarchy and set each folder on the way as tag,
|
|
|
|
* except the top_directory
|
2012-02-09 17:02:49 +08:00
|
|
|
*/
|
2014-08-02 02:30:45 +08:00
|
|
|
while (strcmp (dirname, top_path))
|
2012-02-09 17:02:49 +08:00
|
|
|
{
|
2014-08-02 02:30:45 +08:00
|
|
|
gchar *basename = g_path_get_basename (dirname);
|
|
|
|
GimpTag *tag = gimp_tag_new (basename);
|
2012-02-10 22:17:09 +08:00
|
|
|
|
2014-08-02 02:30:45 +08:00
|
|
|
gimp_tag_set_internal (tag, TRUE);
|
|
|
|
gimp_tagged_add_tag (GIMP_TAGGED (data), tag);
|
|
|
|
g_object_unref (tag);
|
|
|
|
g_free (basename);
|
2012-02-10 22:17:09 +08:00
|
|
|
|
2014-08-02 02:30:45 +08:00
|
|
|
tmp = g_path_get_dirname (dirname);
|
|
|
|
g_free (dirname);
|
|
|
|
dirname = tmp;
|
2012-02-09 17:02:49 +08:00
|
|
|
}
|
|
|
|
|
2014-08-02 02:30:45 +08:00
|
|
|
g_free (top_path);
|
|
|
|
|
2012-02-09 17:02:49 +08:00
|
|
|
if (dirname)
|
|
|
|
{
|
|
|
|
gchar *basename = g_path_get_basename (dirname);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (tag_blacklist); i++)
|
|
|
|
{
|
|
|
|
if (! strcmp (basename, tag_blacklist[i]))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == G_N_ELEMENTS (tag_blacklist))
|
|
|
|
{
|
|
|
|
GimpTag *tag = gimp_tag_new (basename);
|
|
|
|
|
|
|
|
gimp_tag_set_internal (tag, TRUE);
|
|
|
|
gimp_tagged_add_tag (GIMP_TAGGED (data), tag);
|
|
|
|
g_object_unref (tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (basename);
|
|
|
|
g_free (dirname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_data_get_mime_type (GimpData *data)
|
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return g_quark_to_string (private->mime_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_data_is_writable (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->writable;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_data_is_deletable (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->deletable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_set_mtime (GimpData *data,
|
2013-07-12 22:33:12 +08:00
|
|
|
gint64 mtime)
|
2009-11-01 01:48:38 +08:00
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
private->mtime = mtime;
|
|
|
|
}
|
|
|
|
|
2013-07-12 22:33:12 +08:00
|
|
|
gint64
|
2009-11-01 01:48:38 +08:00
|
|
|
gimp_data_get_mtime (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), 0);
|
|
|
|
|
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->mtime;
|
2005-05-26 07:25:45 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_duplicate:
|
2005-06-08 19:27:31 +08:00
|
|
|
* @data: a #GimpData object
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
|
|
|
* Creates a copy of @data, if possible. Only the object data is
|
2004-07-16 18:07:30 +08:00
|
|
|
* copied: the newly created object is not automatically given an
|
2004-07-16 03:01:57 +08:00
|
|
|
* object name, file name, preview, etc.
|
|
|
|
*
|
|
|
|
* Returns: the newly created copy, or %NULL if @data cannot be copied.
|
|
|
|
**/
|
2001-02-14 22:57:14 +08:00
|
|
|
GimpData *
|
2005-06-08 19:27:31 +08:00
|
|
|
gimp_data_duplicate (GimpData *data)
|
2001-02-14 22:57:14 +08:00
|
|
|
{
|
2002-12-02 21:39:09 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
|
|
|
|
|
|
|
|
if (GIMP_DATA_GET_CLASS (data)->duplicate)
|
2011-02-08 02:38:23 +08:00
|
|
|
{
|
|
|
|
GimpData *new = GIMP_DATA_GET_CLASS (data)->duplicate (data);
|
|
|
|
GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (new);
|
|
|
|
|
|
|
|
g_object_set (new,
|
|
|
|
"name", NULL,
|
|
|
|
"writable", GIMP_DATA_GET_CLASS (new)->save != NULL,
|
|
|
|
"deletable", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (private->file)
|
2011-02-08 02:38:23 +08:00
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
g_object_unref (private->file);
|
|
|
|
private->file = NULL;
|
2011-02-08 02:38:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
2004-02-13 19:53:22 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-14 22:57:14 +08:00
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_make_internal:
|
|
|
|
* @data: a #GimpData object.
|
|
|
|
*
|
2004-07-16 18:07:30 +08:00
|
|
|
* Mark @data as "internal" to Gimp, which means that it will not be
|
|
|
|
* saved to disk. Note that if you do this, later calls to
|
|
|
|
* gimp_data_save() and gimp_data_delete_from_disk() will
|
|
|
|
* automatically return successfully without giving any warning.
|
2008-12-12 15:03:42 +08:00
|
|
|
*
|
|
|
|
* The identifier name shall be an untranslated globally unique string
|
|
|
|
* that identifies the internal object across sessions.
|
2004-07-16 03:01:57 +08:00
|
|
|
**/
|
2004-02-13 19:53:22 +08:00
|
|
|
void
|
2009-11-01 01:48:38 +08:00
|
|
|
gimp_data_make_internal (GimpData *data,
|
|
|
|
const gchar *identifier)
|
2004-02-13 19:53:22 +08:00
|
|
|
{
|
2009-10-31 22:24:57 +08:00
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
2004-02-13 19:53:22 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA (data));
|
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
2014-07-01 07:19:35 +08:00
|
|
|
if (private->file)
|
2004-02-13 19:53:22 +08:00
|
|
|
{
|
2014-07-01 07:19:35 +08:00
|
|
|
g_object_unref (private->file);
|
|
|
|
private->file = NULL;
|
2004-01-29 05:53:50 +08:00
|
|
|
}
|
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private->identifier = g_strdup (identifier);
|
|
|
|
private->writable = FALSE;
|
|
|
|
private->deletable = FALSE;
|
|
|
|
private->internal = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_data_is_internal (GimpData *data)
|
|
|
|
{
|
|
|
|
GimpDataPrivate *private;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
2008-12-12 15:03:42 +08:00
|
|
|
|
2009-11-01 01:48:38 +08:00
|
|
|
private = GIMP_DATA_GET_PRIVATE (data);
|
|
|
|
|
|
|
|
return private->internal;
|
2002-12-02 21:39:09 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
2008-07-10 17:08:54 +08:00
|
|
|
* gimp_data_compare:
|
2004-07-16 03:01:57 +08:00
|
|
|
* @data1: a #GimpData object.
|
|
|
|
* @data2: another #GimpData object.
|
|
|
|
*
|
2008-07-10 17:08:54 +08:00
|
|
|
* Compares two data objects for use in sorting. Objects marked as
|
|
|
|
* "internal" come first, then user-writable objects, then system data
|
|
|
|
* files. In these three groups, the objects are sorted alphabetically
|
|
|
|
* by name, using gimp_object_name_collate().
|
2004-07-16 03:01:57 +08:00
|
|
|
*
|
|
|
|
* Return value: -1 if @data1 compares before @data2,
|
|
|
|
* 0 if they compare equal,
|
|
|
|
* 1 if @data1 compares after @data2.
|
|
|
|
**/
|
2004-05-24 18:49:34 +08:00
|
|
|
gint
|
2008-07-10 17:08:54 +08:00
|
|
|
gimp_data_compare (GimpData *data1,
|
2016-11-25 12:51:03 +08:00
|
|
|
GimpData *data2)
|
2004-05-24 18:49:34 +08:00
|
|
|
{
|
2009-11-01 01:48:38 +08:00
|
|
|
GimpDataPrivate *private1 = GIMP_DATA_GET_PRIVATE (data1);
|
|
|
|
GimpDataPrivate *private2 = GIMP_DATA_GET_PRIVATE (data2);
|
|
|
|
|
2004-05-24 18:49:34 +08:00
|
|
|
/* move the internal objects (like the FG -> BG) gradient) to the top */
|
2009-11-01 01:48:38 +08:00
|
|
|
if (private1->internal != private2->internal)
|
|
|
|
return private1->internal ? -1 : 1;
|
2004-05-24 18:49:34 +08:00
|
|
|
|
2012-02-02 03:04:41 +08:00
|
|
|
/* keep user-deletable objects above system resource files */
|
|
|
|
if (private1->deletable != private2->deletable)
|
|
|
|
return private1->deletable ? -1 : 1;
|
2008-07-10 17:08:54 +08:00
|
|
|
|
2004-05-24 18:49:34 +08:00
|
|
|
return gimp_object_name_collate ((GimpObject *) data1,
|
|
|
|
(GimpObject *) data2);
|
|
|
|
}
|
|
|
|
|
2004-07-16 03:01:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_error_quark:
|
|
|
|
*
|
2004-07-16 18:07:30 +08:00
|
|
|
* This function is used to implement the GIMP_DATA_ERROR macro. It
|
|
|
|
* shouldn't be called directly.
|
|
|
|
*
|
|
|
|
* Return value: the #GQuark to identify error in the GimpData error domain.
|
2004-07-16 03:01:57 +08:00
|
|
|
**/
|
2002-12-02 21:39:09 +08:00
|
|
|
GQuark
|
|
|
|
gimp_data_error_quark (void)
|
|
|
|
{
|
2006-04-06 20:07:18 +08:00
|
|
|
return g_quark_from_static_string ("gimp-data-error-quark");
|
2001-02-14 22:57:14 +08:00
|
|
|
}
|