Commit Graph

119 Commits

Author SHA1 Message Date
Jehan d931098d36 app, libgimp, pdb: new gimp_image_get_palette().
This is meant to replace gimp_image_get_colormap() (see also #9477).

We likely won't need a gimp_image_set_palette() because we can simply edit the
image's colormap/palette with GimpPalette API now and it is directly updated.

For instance, the following code changes the first entry in the image palette to
red, immediately:

```python
i = Gimp.list_images()[0]
p = i.get_palette()
c = Gimp.RGB()
c.r = 1.0
p.entry_set_color(0, c)
```

For this to work fine, I added a new concept to GimpData, which is that they can
be tied to a GimpImage (instead of a GFile). Image palettes are not considered
internals, they are just tied to their image, therefore they can be edited by
scripts/plug-ins.

Additionally with this commit, editing an image's colormap from libgimp API also
generates undo steps now.
2023-10-06 22:04:34 +02:00
Jehan 1a9c470b82 app: fix gimp_data_get_identifier() and add a concept of data collection.
The way we were creating a GimpData identifier was simply wrong, because it was
based on the assumption that the source file uniquely identifies a GimpData (cf.
gimp_tagged_get_identifier() which clearly says that the returned string must
uniquely identify this data). The very simple counter-examples for why this is
a mistake to consider a data file to be a good unique identifier are collection
files. For instance, TTC files (TrueType Collection) contain multiple fonts.

Instead I am adding the concept of "collection" with the assumption that
**within a given collection**, data names are unique (I do hope this to be and
stay true). So I add gimp_data_get_identifiers() and gimp_data_identify() to get
identifiers and check for identity.

The collection will use the old implementation of gimp_data_get_identifier()
because it is quite nice to have paths relative to data and config directories
(it allows some cases of data relocation without losing data identification).

The new implementation to compute a GimpTagged identifier on the other hand will
construct a string from the quality of being internal or not, the data name and
its collection.
2023-07-27 15:29:58 +02:00
Michael Natterer bb7ed43eac app: make the GimpResource dummy class the parent of GimpData
It does absolutely nothing except sitting there, providing an is-a
relation (both ways because GimpData is its only subclass). This will
simplify having more libgimp API on GimpResource, without having to
add different PDB code for app and libgimp.
2023-06-05 14:33:23 +02:00
Michael Natterer 9638102418 Introduce a global ID space for GimpData/GimpResource objects
Much like for images and items. Change the PDB to transmit IDs
instead of names for brush, pattern etc. and refactor a whole
lot of libgimp code to deal with it.

	modified:   libgimp/gimpplugin-private.h
2023-05-31 16:12:04 +02:00
Stanislav Grinkov 619cb91230 Remove unnecessary gimpmarshal.h and gimpwidgetsmarshal.h includes. 2021-08-13 18:01:13 +00:00
Niels De Graef 878804fb01 Cleanup GObject signal marshallers
* Don't generate our own marshallers if they are available in GLib
  already
* Don't set the c_marshaller parameter in `g_signal_new()` if it's a
  default marshaller provided by GLib. See commit message of commit
  39e4aa3c57 on why this is the case.
2020-04-01 21:20:01 +00:00
Niels De Graef 5f92ced1f3 Add (nullable) if applicable
Basically this commit makes sure that all return values that are marked
as "Returns:" also have a `(nullable)` annotation if it is mentioned on
the same line that NULL can also be returned.

This will prevent a few problems in GObject-introspection.
2019-08-03 07:53:47 +00:00
Niels De Graef 1dda60154c Use "Returns:" to annotate return values
To be able to annotate return values through GObject-introspection, you
need to make sure it is tagged with `Returns:` and not something else.
2019-08-03 07:53:47 +00:00
Michael Natterer e72a9d88a5 app: get rid of manual object type registration
and all deprecated use of private instance registration.
2019-06-29 16:41:41 +02:00
Jehan 613bf7c5ab app, libgimpconfig: make various usage of g_file_replace() safer.
When an error occurs, we want to prevent overwriting any previous
version of the file by incomplete contents. So run
g_output_stream_close() with a cancelled GCancellable to do so.
See also discussion in #2565.
2018-11-26 15:50:38 +01:00
Michael Natterer 5f700549e7 Change the license URL from http://www.gnu.org/licenses/ to https:// 2018-07-11 23:29:46 +02:00
Michael Natterer f23958407c app: don't leak the identifier if gimp_data_make_internal() is called again 2018-06-03 22:43:55 +02:00
Michael Natterer 1b7d63cce9 Use g_set_object() in a lot of places, and splrinkle some g_clear_object() 2018-06-01 12:59:52 +02:00
Jehan f6b586237c app: identifier of MyPaint brush GimpData using ${mypaint_brushes_dir}.
Absolute paths not to be used in $XDG_CONFIG/GIMP/{version}/tags.xml.
These are actually only an identifier, and not used as a path at all
anyway. Moreover MyPaint brushes even generate checksum (which allows
to remap the GimpData appropriately even if the paths are changing).
But anyway it's better not to have absolute paths when we can prevent
so.
2018-04-29 00:40:26 +02:00
Ell 2fe6575d7e Bug 789901 - Gimp allows duplicating non-duplicatable data objects ...
... leading to a crash

Add gimp_data_is_copyable() and gimp_data_is_dulicatable().

Use gimp_data_is_duplicatable() when setting the sensitivity of the
various "foo-duplicate" actions, instead of inspecting the object's
GimpDataClass::duplicate pointer directly, since this is no longer
an indication of whether a GimpData object is duplicatable or not
(since commit 33de4d5530).
2017-11-04 22:00:29 -04:00
Ell bccef43049 app, pdb: prevent custom gradient from being renamed
Make internal data objects non-renamable, even if they're writable,
through gimp_data_is_name_editable().  Currently, the only such
object is the custom gradient.

Prevent changing the name of non-renamable data by making the name
entry of GimpDataEditor non-editable whenever
gimp_viewable_is_name_editable() is FALSE, even if the data is
otherwise editable.

Prevent the vairous PDB -rename() functions from renaming non-
renamable data, by adding a GimpPDBDataAccess flags type,
specifying the desired access mode for the data -- any combination
of READ, WRITE, and RENAME -- and replacing the 'writable'
parameter of the gimp_pdb_get_foo() functions with an 'access'
parameter.  Change the various .pdb files to use READ where they'd
used FALSE, and WRITE where they'd used TRUE; use RENAME, isntead
of WRITE, in the -rename() functions.
2017-10-30 17:22:29 -04:00
Ell f36f234fc0 app: add compare() virtual function to GimpData
... which subclasses can override to refine comparison.  Provide a
default implementation that uses the current logic.
2017-10-09 12:48:50 -04:00
Ell 33de4d5530 app: add gimp_data_copy()
... which copies the contents of a GimpData into an existing GimpData,
without creating a new instance.

Add a copy() virtual function to GimpData, which subclasses can
override to implement copying; gimp_data_copy() may only be called
for types that implement copy().  Keep the duplicate() virtual
function around, but provide a default implementation that creates
a new object of the source type, and uses copy() to copy the source
object into it.
2017-10-09 12:48:50 -04:00
Michael Natterer 0cb3e75f79 app: use a lot of g_clear_object() and g_clear_pointer()
More than 2000 lines of code less in app/, instead of

if (instance->member)
  {
    g_object_unref/g_free/g_whatever (instance->member);
    instance->member = NULL;
  }

we now simply use

g_clear_object/pointer (&instance->member);
2017-07-15 18:42:44 +02:00
Jehan 84ee79c71d app: clean out many tabs under app/core/. 2016-11-25 05:51:03 +01:00
Michael Natterer 5129b8519b app: don't g_warning() on filenames that can't be turned into UTF-8
gimp_data_get_identifier(): use g_printerr() instead.
2016-11-16 15:30:44 +01:00
Michael Natterer 82a2754540 Bug 343090 - Most brushes and all patterns appear renameable but aren't
Introduce virtual function GimpViewable::is_name_editable() and class
member "gboolean name_editable" for the default value. Default to
FALSE and only return TRUE if the name can actually be edited by the
user.

When attemting an edit, check the new API and beep instead of starting
the edit.
2016-11-16 15:13:08 +01:00
Michael Natterer 849481a861 Clean up code around calls to g_file_replace()
- use G_FILE_CREATE_NONE instead of 0
- don't put "Could not open <file> for writing: <error>" around the
  returned error, the returned message is already verbose
2014-10-04 02:44:54 +02:00
Michael Natterer 980ba7f85a app: move memsize functions into their own files gimp-memsize.[ch] 2014-08-12 13:57:57 +02:00
Michael Natterer 6821eb298c app: port GimpDataFactory file loading to GFileEnumerator
Also slightly change the semantics of gimp_data_set_folder_tags()
to be less complicated.
2014-08-01 20:30:45 +02:00
Michael Natterer b328bd3087 app: don't leak a GFileInfo in gimp_data_set_file() 2014-07-26 16:52:56 +02:00
Michael Natterer 58c3b7661f app: port gimp_data_create_filename() to GFile
implies also porting gimp_data_factory_get_save_dir().
2014-07-26 16:37:30 +02:00
Michael Natterer 1aa5a85d2a app: don't drop the last reference to "file" in gimp_data_set_file(), argh
also improve precondition check in gimp_data_save().
2014-07-26 16:33:40 +02:00
Michael Natterer 93c19c20d4 app: fix a bunch of valgrind-found leaks 2014-07-20 21:40:57 +02:00
Michael Natterer e6f4252d55 app: simplify GimpData load/save error reporting a lot
Add the filename and general "Foo failed" spam generically in GimpData
and GimpDataFactory, and make the individual loaders/savers much
simpler.
2014-07-04 18:46:02 +02:00
Michael Natterer aab55c34c8 app: add a GOutputStream* parameter to GimpData::save()
Open/close the stream generically in GimpData. Improves error handling
and simplifies the save() functions.
2014-07-03 23:44:38 +02:00
Michael Natterer 32e2aebbe0 app: remove old includes from gimpdata.c too 2014-07-03 15:49:29 +02:00
Michael Natterer 9696e297ac app: turn GimpData's "filename" string into a "file" GFile
One more step, but for now just causes more code in most places to get
to the path inside the GFile.
2014-07-01 01:19:35 +02:00
Michael Natterer 7fca15c27d Bug 722975 - crash when removing tag from palette while filtering by same tag
Each of the following cleans up tag refcounting, fixes access to
released memory, or other small glitches. Not sure which change
actually fixed the bug:

gimp_data_remove_tag(): remove the found tag, not the passed in tag
(which is to be treated only as a value for comparison).

gimp_tagged_remove_tag(): don't continue the loop after the tag to
remove has been found, there can only be one matching tag, and the
list element has become invalid.

gimptagentry.c: keep references around for the members of
entry->common_tags, and make sure the references are always dropped
properly. In assign_tags(), reference the "add" and "remove" lists for
paranoia and safety reasons.
2014-01-26 21:03:28 +01:00
Michael Natterer 697572ccc0 app,libgimp*: fix includes to follow our include policy
- don't include <gdk-pixbuf/gdk-pixbuf.h> in headers in app/
- instead, include it in many .c files instead of <glib-object.h>,
  finally acknowledging the fact that app/ depends on gdk-pixbuf almost
  globally
- fix up includes as if libgimpbase depended in GIO, which it soon will
2013-10-15 01:58:39 +02:00
Michael Natterer e72cf05ccb app: port mtime code in gimp_data_save() to GIO
because it gets its stat() calls right.
2013-08-04 16:51:31 +02:00
Michael Natterer 13614f6182 app: change GimpData:mtime from time_t to gint64 2013-07-12 16:33:12 +02:00
Michael Natterer 5280a02ed8 Bug 700215 - Gradient name changes do not persist across sessions...
if the gradient itself isn't changed.

GimpData: implement GimpObject::name_changed() and set the "dirty"
flag to TRUE. Don't set dirty in GimpData::dirty()'s default impl
because that calls gimp_object_name_changed() anyway.
2013-05-29 22:29:29 +02:00
Michael Natterer 908f727f0a Chain up unconditionally in GObject::constructed()
It's supported since GLib 2.28.
2012-11-12 21:51:22 +01:00
Michael Natterer 5a7b7d9a4b app: add gimp_gegl_buffer_get_tile_manager()
and ust it in some get_memsize() functions instead of having a
FIXME. So many files changed because they need to inlcude <gegl.h>
now.
2012-05-02 17:46:07 +02:00
Nils Philippsen 4ec7def1d0 put operators on end of line in long expressions
This fixes commit 3a151bd1a9, GIMP is
deviating from the GNU coding style here.
2012-02-11 16:50:44 +01:00
Nils Philippsen 3a151bd1a9 app: check top_directory for plausibility 2012-02-10 16:20:15 +01:00
Michael Natterer 0729c25bc0 app: set tags for all subdirectories a data file lives in
GimpData: add gimp_data_set_folder_tags() and remove the tag logic
from gimp_data_set_filename(). The function gets the toplevel data
directory passed so it knows where to stop assigning tags.

GimpDataFactory: when loading data, keep track of the currently
processed data hierachy's toplevel directory, and pass it to above new
function. Also make sure obsolete files don't get folder-tagged.
2012-02-09 10:02:49 +01:00
Alexia Death f7554c299e app: use deletable flag for sorting user data above system data
Previously flag writable was used. This caused ritable and editable
brushes to sort first. This was not clearly understood criteria.
Now user brushes in writable folders are sorted first.
2012-02-01 21:05:16 +02:00
Alexia Death aa9806c687 app: Make resource subfolders elements in the tag cloud
This patch does following things for this purpose:
* Adds intrernal flag to GimpTag api
* Modifies GimpData gimp_data_set_filename to use the last element
  of the path, unless blacklisted, as internal tag for the resource.
* Modify tag cache to not save internal tags
* Removes a check for existing tags when objects are added to tag cache
2011-12-04 20:36:05 +02:00
Michael Natterer ede0d26b91 app: gimp_data_create_filename(): avoid evil characters in the filename
such as forbidden ones on various platforms. List collected on #gimp
with a fair portion of paranoia involved.
2011-04-13 21:25:10 +02:00
Michael Natterer fcfb7cf160 Use the new g_[s]list_free_full() instead of foreach() and free() 2011-03-07 17:11:28 +01:00
Michael Natterer 3873aa5cac app: gimp_data_duplicate() reset name, filename, writable and deletable
to default values on the copy, so the duplicated data behaves as
documented, even if a subclass copied too much. Makes duplicated
dynamics work.
2011-02-07 19:38:23 +01:00
Michael Natterer 5e4eee4653 app: implement GObject::constructed() instead of ::constructor() 2011-01-12 22:53:58 +01:00
Aurimas Juška 73b86bd9c9 app: Fix GimpTag reference handling 2010-03-03 23:35:20 +02:00