Top | ![]() |
![]() |
![]() |
![]() |
const gchar * | gwy_resource_get_name () |
gboolean | gwy_resource_is_modifiable () |
gboolean | gwy_resource_is_managed () |
gboolean | gwy_resource_is_modified () |
gboolean | gwy_resource_get_preferred () |
void | gwy_resource_set_preferred () |
const gchar * | gwy_resource_class_get_name () |
GwyInventory * | gwy_resource_class_get_inventory () |
const GwyInventoryItemType * | gwy_resource_class_get_item_type () |
void | gwy_resource_use () |
void | gwy_resource_release () |
gboolean | gwy_resource_is_used () |
void | gwy_resource_data_changed () |
void | gwy_resource_data_saved () |
gchar * | gwy_resource_build_filename () |
gboolean | gwy_resource_rename () |
gboolean | gwy_resource_delete () |
gboolean | gwy_resource_save () |
void | gwy_resource_class_load () |
void | gwy_resource_class_save_modified () |
gboolean | gwy_resource_class_mkdir () |
void | gwy_resource_classes_finalize () |
GwyResource is a base class for various application resources. It defines common interface: questioning resource
name (gwy_resource_get_name()
), modifiability (gwy_resource_is_modifiable()
), loading resources from files and
saving them.
Resources of one type are typically managed in an inventory which is filled during initialisation. Resource objects
are created, deleted and modified using GwyResource and GwyInventory methods. You can create standalone
(unmanaged) resource objects outside the inventory using g_object_new()
or class-specific means and it is useful
sometimes for private resources, but program-wide resources are handled through the inventory.
const gchar *
gwy_resource_get_name (GwyResource *resource
);
Returns resource name.
gboolean
gwy_resource_is_modifiable (GwyResource *resource
);
Returns whether a resource is modifiable.
Resources loaded from user directories and unmanaged resources are generally modifiable. System resources are not.
gboolean
gwy_resource_is_managed (GwyResource *resource
);
Returns whether a resource is managed.
Managed resources are in the class inventory returned by gwy_resource_class_get_inventory()
(or class-specific
functions). They are usualy backed up by on disk files. New are created using inventory functions.
Unmanaged resources are standalone objects, not in the class inventory and not saved to disk.
gboolean
gwy_resource_is_modified (GwyResource *resource
);
Returns whether a resource has been modified.
Resources loaded from user directories and unmanaged resources are generally modifiable. System resources are not.
gboolean
gwy_resource_get_preferred (GwyResource *resource
);
Returns whether a resource is preferred.
void gwy_resource_set_preferred (GwyResource *resource
,gboolean is_preferred
);
Sets preferability of a resource.
Preferred resources are offered more readily. For instance short lists can offer only preferred resources and the user may have to go to a full list to access the non-preferred.
const gchar *
gwy_resource_class_get_name (GwyResourceClass *klass
);
Gets the name of resource class.
This is an simple identifier usable for example as directory name.
GwyInventory *
gwy_resource_class_get_inventory (GwyResourceClass *klass
);
Gets inventory which holds resources of a resource class.
const GwyInventoryItemType *
gwy_resource_class_get_item_type (GwyResourceClass *klass
);
Gets inventory item type for a resource class.
void
gwy_resource_use (GwyResource *resource
);
Starts using a resource.
Call to this function is necessary to use a resource properly. It makes the resource to create any auxiliary structures that consume considerable amount of memory and perform other initialization to ready-to-use form.
When a resource is no longer used, it should be released with gwy_resource_release()
.
In addition, it calls g_object_ref()
on the resource.
Resources usually exist through almost whole program lifetime from GObject perspective, but from the viewpoint of
use this method is the constructor and gwy_resource_release()
is the destructor.
void
gwy_resource_release (GwyResource *resource
);
Releases a resource.
When the number of resource uses drops to zero, it frees all auxiliary data and returns back to `latent' form. In
addition, it calls g_object_unref()
on it. See gwy_resource_use()
for more.
gboolean
gwy_resource_is_used (GwyResource *resource
);
Tells whether a resource is currently in use.
See gwy_resource_use()
for details.
void
gwy_resource_data_changed (GwyResource *resource
);
Emits signal "data-changed" on a resource.
It can be called only on non-constant resources. The default handler sets the modified flag on the resource which
can be queried with gwy_resource_is_modified()
.
Mostly useful in resource implementation.
void
gwy_resource_data_saved (GwyResource *resource
);
Clears the modified flag of a resource.
gchar *
gwy_resource_build_filename (GwyResource *resource
);
Builds file name a resource should be saved to.
If the resource has not been newly created, renamed, or system it was probably loaded from file of the same name.
gboolean gwy_resource_rename (GwyResource *resource
,const gchar *newname
);
Renames a resource, including renaming it on disk.
The method renames the resource both in the inventory and on disk. The renaming must not conflict with an existing resource, constant resources cannot be renamed, etc. It is OK to rename a resource to the same name (nothing happens then).
Constant (system) resources cannot be renamed. Unmanaged resources can be renamed using this function; it just does not change anything on disk in such case.
gboolean
gwy_resource_delete (GwyResource *resource
);
Deletes a resource, including removal from disk.
The method deletes the resource both in the inventory and on disk. Constant and unmanaged resources cannot be removed (simply unref unmananged resources as any other object to destroy them).
gboolean gwy_resource_save (GwyResource *resource
,GError **error
);
Saves a resource to disk.
Constant resources cannot be saved. Unmanaged resources cannot be saved using this function because they have no associated on-disk location.
The file name is determined by gwy_resource_build_filename()
. The resource data are saved even if the modified flag
is not set. Upon successful save, the modified flag is cleared.
Instead of saving individual resources, consider also using gwy_resource_class_save_modified()
.
void
gwy_resource_class_load (GwyResourceClass *klass
);
Loads resources of a resources class from disk.
Resources are loaded from system directory (and marked constant) and from user directory (marked modifiable).
void
gwy_resource_class_save_modified (GwyResourceClass *klass
);
Saves all modified resource of given class to disk.
gboolean
gwy_resource_class_mkdir (GwyResourceClass *klass
);
Creates directory for user resources if it does not exist.
void
gwy_resource_classes_finalize (void
);
Destroys the inventories of all resource classes.
This function makes the affected resource classes unusable. Its purpose is to faciliate reference leak debugging by destroying a large number of objects that normally live forever.
Note static resource classes that never called gwy_resource_class_load()
are excluded.
struct GwyResourceClass { GwyInventory *inventory; const gchar *name; /* Traits */ GwyInventoryItemType item_type; /* Signals */ void (*data_changed)(GwyResource *resource); /* Virtual table */ void (*use)(GwyResource *resource); void (*release)(GwyResource *resource); void (*dump)(GwyResource *resource, GString *string); GwyResource* (*parse)(const gchar *text); GwyResource* (*parse_with_type)(GType type, const gchar *text); };
Resource class.
GwyInventory * |
Inventory with resources. |
|
Resource class name, usable as resource directory name for on-disk resources. |
||
GwyInventoryItemType |
Inventory item type. Most fields are pre-filled, but namely |
|
"data-changed" signal method. |
||
gwy_resource_use() virtual method. |
||
gwy_resource_release() virtual method. |
||
Format resource data to text. Only the data itself is formatted; the envelope is handled by GwyResource. |
||
Fill resource data from a string. The function only gets the resource data itself, the envelope is handled by GwyResource. This is the usual method as the parser normally knows its type. |
||
Alternative construction from a string, with the type to construct explicitly passed. It takes
precedence over |
“const”
property “const” gboolean
Whether a resource is constant (system).
Owner: GwyResource
Flags: Read / Write / Construct Only
Default value: FALSE
“managed”
property “managed” gboolean
Whether a resource is managed in the inventory.
Owner: GwyResource
Flags: Read
Default value: FALSE
“name”
property “name” char *
Resource name.
Owner: GwyResource
Flags: Read / Write / Construct Only
Default value: NULL
“data-changed”
signalvoid user_function (GwyResource *gwyresource, gpointer user_data)
The ::data-changed signal is emitted when resource data changes.
gwyresource |
The GwyResource which received the signal. |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First