Top | ![]() |
![]() |
![]() |
![]() |
const gchar * | gwy_resource_get_name () |
gboolean | gwy_resource_get_is_modifiable () |
gboolean | gwy_resource_get_is_preferred () |
void | gwy_resource_set_is_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 () |
GString * | gwy_resource_dump () |
GwyResource * | gwy_resource_parse () |
gboolean | gwy_resource_rename () |
gboolean | gwy_resource_delete () |
void | gwy_resource_class_load () |
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_get_is_modifiable()
), loading resources from
files and saving them.
const gchar *
gwy_resource_get_name (GwyResource *resource
);
Returns resource name.
gboolean
gwy_resource_get_is_modifiable (GwyResource *resource
);
Returns whether a resource is modifiable.
gboolean
gwy_resource_get_is_preferred (GwyResource *resource
);
Returns whether a resource is preferred.
void gwy_resource_set_is_preferred (GwyResource *resource
,gboolean is_preferred
);
Sets preferability of a resource.
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 is_modified
flag on the resource.
Mostly useful in resource implementation.
void
gwy_resource_data_saved (GwyResource *resource
);
Clears is_modified
flag of a resource.
Since: 2.8
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.
GString *
gwy_resource_dump (GwyResource *resource
);
Dumps a resource to a textual (human readable) form.
GwyResource * gwy_resource_parse (const gchar *text
,GType expected_type
);
Reconstructs a resource from human readable form.
text |
Textual resource representation. |
|
expected_type |
Resource object type. If not 0, only resources of give type are allowed. Zero value means any GwyResource is allowed. |
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).
Since: 2.51
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 resources cannot be deleted.
Since: 2.51
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).
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.
Since: 2.8
struct GwyResource;
The GwyResource struct contains private data only and should be accessed using the functions below.
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, gboolean is_const); };
Resource class.
GwyInventory * |
Inventory with resources. |
|
const gchar * |
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. |
||
gwy_resource_dump() virtual method, it only cares about resource data itself, the envelope is handled by GwyResource. |
||
gwy_resource_parse() virtual method, in only cares about resource data itself, the envelope is handled by GwyResource. |
“is-const”
property“is-const” gboolean
Whether a resource is constant (system).
Owner: GwyResource
Flags: Read / Write / Construct Only
Default value: FALSE
“is-preferred”
property“is-preferred” gboolean
Whether a resource is preferred.
Owner: GwyResource
Flags: Read / Write
Default value: FALSE
“name”
property“name” gchar *
Resource name.
Owner: GwyResource
Flags: Read
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