3
* A Nautilus extension which offers configurable context menu actions.
5
* Copyright (C) 2005 The GNOME Foundation
6
* Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7
* Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
9
* This Program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License as
11
* published by the Free Software Foundation; either version 2 of
12
* the License, or (at your option) any later version.
14
* This Program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public
20
* License along with this Library; see the file COPYING. If not,
21
* write to the Free Software Foundation, Inc., 59 Temple Place,
22
* Suite 330, Boston, MA 02111-1307, USA.
25
* Frederic Ruaudel <grumz@grumz.net>
26
* Rodrigo Moya <rodrigo@gnome-db.org>
27
* Pierre Wieser <pwieser@trychlos.org>
28
* ... and many others (see AUTHORS)
36
#include <uuid/uuid.h>
38
#include "na-action.h"
39
#include "na-action-profile.h"
44
struct NAActionClassPrivate {
47
/* private instance data
49
struct NAActionPrivate {
50
gboolean dispose_has_run;
59
/* list of action's profiles as NAActionProfile objects
60
* (thanks, Frederic ;-))
64
/* dynamically set when reading the actions from the I/O storage
66
* defaults to FALSE unless a write has already returned an error
70
/* the original provider
71
* required to be able to edit/delete the action
73
NAIIOProvider *provider;
79
PROP_NAACTION_UUID = 1,
81
PROP_NAACTION_VERSION,
82
PROP_NAACTION_TOOLTIP,
84
PROP_NAACTION_ENABLED,
85
PROP_NAACTION_READONLY,
86
PROP_NAACTION_PROVIDER
89
#define PROP_NAACTION_UUID_STR "na-action-uuid"
90
#define PROP_NAACTION_LABEL_STR "na-action-label"
91
#define PROP_NAACTION_VERSION_STR "na-action-version"
92
#define PROP_NAACTION_TOOLTIP_STR "na-action-tooltip"
93
#define PROP_NAACTION_ICON_STR "na-action-icon"
94
#define PROP_NAACTION_ENABLED_STR "na-action-enabled"
95
#define PROP_NAACTION_READONLY_STR "na-action-read-only"
96
#define PROP_NAACTION_PROVIDER_STR "na-action-provider"
98
#define NA_ACTION_LATEST_VERSION "2.0"
100
static NAObjectClass *st_parent_class = NULL;
102
static GType register_type( void );
103
static void class_init( NAActionClass *klass );
104
static void instance_init( GTypeInstance *instance, gpointer klass );
105
static void instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
106
static void instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
107
static void instance_dispose( GObject *object );
108
static void instance_finalize( GObject *object );
110
static void object_check_edited_status( const NAObject *action );
111
static void object_dump( const NAObject *action );
112
static NAObject *object_duplicate( const NAObject *action );
113
static void object_copy( NAObject *target, const NAObject *source );
114
static gboolean object_are_equal( const NAObject *a, const NAObject *b );
115
static gboolean object_is_valid( const NAObject *action );
117
static void free_profiles( NAAction *action );
120
na_action_get_type( void )
122
static GType action_type = 0;
125
action_type = register_type();
128
return( action_type );
132
register_type( void )
134
static const gchar *thisfn = "na_action_register_type";
135
g_debug( "%s", thisfn );
137
static GTypeInfo info = {
138
sizeof( NAActionClass ),
139
( GBaseInitFunc ) NULL,
140
( GBaseFinalizeFunc ) NULL,
141
( GClassInitFunc ) class_init,
146
( GInstanceInitFunc ) instance_init
149
return( g_type_register_static( NA_OBJECT_TYPE, "NAAction", &info, 0 ));
153
class_init( NAActionClass *klass )
155
static const gchar *thisfn = "na_action_class_init";
156
g_debug( "%s: klass=%p", thisfn, klass );
158
st_parent_class = g_type_class_peek_parent( klass );
160
GObjectClass *object_class = G_OBJECT_CLASS( klass );
161
object_class->dispose = instance_dispose;
162
object_class->finalize = instance_finalize;
163
object_class->set_property = instance_set_property;
164
object_class->get_property = instance_get_property;
167
spec = g_param_spec_string(
168
PROP_NAACTION_UUID_STR,
170
"Globally unique identifier (UUID) of the action", "",
171
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
172
g_object_class_install_property( object_class, PROP_NAACTION_UUID, spec );
174
spec = g_param_spec_string(
175
PROP_NAACTION_LABEL_STR,
177
"Context menu displayable label", "",
178
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
179
g_object_class_install_property( object_class, PROP_NAACTION_LABEL, spec );
181
spec = g_param_spec_string(
182
PROP_NAACTION_VERSION_STR,
184
"Version of the schema", "",
185
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
186
g_object_class_install_property( object_class, PROP_NAACTION_VERSION, spec );
188
spec = g_param_spec_string(
189
PROP_NAACTION_TOOLTIP_STR,
191
"Context menu tooltip", "",
192
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
193
g_object_class_install_property( object_class, PROP_NAACTION_TOOLTIP, spec );
195
spec = g_param_spec_string(
196
PROP_NAACTION_ICON_STR,
198
"Context menu displayable icon", "",
199
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
200
g_object_class_install_property( object_class, PROP_NAACTION_ICON, spec );
202
spec = g_param_spec_boolean(
203
PROP_NAACTION_ENABLED_STR,
205
"Whether this action is enabled", TRUE,
206
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
207
g_object_class_install_property( object_class, PROP_NAACTION_ENABLED, spec );
209
spec = g_param_spec_boolean(
210
PROP_NAACTION_READONLY_STR,
212
"Is this action only readable", FALSE,
213
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
214
g_object_class_install_property( object_class, PROP_NAACTION_READONLY, spec );
216
spec = g_param_spec_pointer(
217
PROP_NAACTION_PROVIDER_STR,
220
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
221
g_object_class_install_property( object_class, PROP_NAACTION_PROVIDER, spec );
223
klass->private = g_new0( NAActionClassPrivate, 1 );
225
NA_OBJECT_CLASS( klass )->dump = object_dump;
226
NA_OBJECT_CLASS( klass )->check_edited_status = object_check_edited_status;
227
NA_OBJECT_CLASS( klass )->duplicate = object_duplicate;
228
NA_OBJECT_CLASS( klass )->copy = object_copy;
229
NA_OBJECT_CLASS( klass )->are_equal = object_are_equal;
230
NA_OBJECT_CLASS( klass )->is_valid = object_is_valid;
234
instance_init( GTypeInstance *instance, gpointer klass )
236
/*static const gchar *thisfn = "na_action_instance_init";
237
g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );*/
239
g_assert( NA_IS_ACTION( instance ));
240
NAAction* self = NA_ACTION( instance );
242
self->private = g_new0( NAActionPrivate, 1 );
244
self->private->dispose_has_run = FALSE;
246
/* initialize suitable default values
248
self->private->version = g_strdup( NA_ACTION_LATEST_VERSION );
249
self->private->tooltip = g_strdup( "" );
250
self->private->icon = g_strdup( "" );
251
self->private->enabled = TRUE;
252
self->private->read_only = FALSE;
253
self->private->provider = NULL;
257
instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
259
g_assert( NA_IS_ACTION( object ));
260
NAAction *self = NA_ACTION( object );
262
switch( property_id ){
263
case PROP_NAACTION_UUID:
264
G_OBJECT_CLASS( st_parent_class )->get_property( object, PROP_NAOBJECT_ID, value, spec );
267
case PROP_NAACTION_LABEL:
268
G_OBJECT_CLASS( st_parent_class )->get_property( object, PROP_NAOBJECT_LABEL, value, spec );
271
case PROP_NAACTION_VERSION:
272
g_value_set_string( value, self->private->version );
275
case PROP_NAACTION_TOOLTIP:
276
g_value_set_string( value, self->private->tooltip );
279
case PROP_NAACTION_ICON:
280
g_value_set_string( value, self->private->icon );
283
case PROP_NAACTION_ENABLED:
284
g_value_set_boolean( value, self->private->enabled );
287
case PROP_NAACTION_READONLY:
288
g_value_set_boolean( value, self->private->read_only );
291
case PROP_NAACTION_PROVIDER:
292
g_value_set_pointer( value, self->private->provider );
296
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
302
instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec )
304
g_assert( NA_IS_ACTION( object ));
305
NAAction *self = NA_ACTION( object );
307
switch( property_id ){
308
case PROP_NAACTION_UUID:
309
G_OBJECT_CLASS( st_parent_class )->set_property( object, PROP_NAOBJECT_ID, value, spec );
312
case PROP_NAACTION_LABEL:
313
G_OBJECT_CLASS( st_parent_class )->set_property( object, PROP_NAOBJECT_LABEL, value, spec );
316
case PROP_NAACTION_VERSION:
317
g_free( self->private->version );
318
self->private->version = g_value_dup_string( value );
321
case PROP_NAACTION_TOOLTIP:
322
g_free( self->private->tooltip );
323
self->private->tooltip = g_value_dup_string( value );
326
case PROP_NAACTION_ICON:
327
g_free( self->private->icon );
328
self->private->icon = g_value_dup_string( value );
331
case PROP_NAACTION_ENABLED:
332
self->private->enabled = g_value_get_boolean( value );
335
case PROP_NAACTION_READONLY:
336
self->private->read_only = g_value_get_boolean( value );
339
case PROP_NAACTION_PROVIDER:
340
self->private->provider = g_value_get_pointer( value );
344
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
350
instance_dispose( GObject *object )
352
static const gchar *thisfn = "na_action_instance_dispose";
353
g_debug( "%s: object=%p", thisfn, object );
355
g_assert( NA_IS_ACTION( object ));
356
NAAction *self = NA_ACTION( object );
358
if( !self->private->dispose_has_run ){
360
self->private->dispose_has_run = TRUE;
362
/* release the profiles */
363
free_profiles( self );
365
/* chain up to the parent class */
366
G_OBJECT_CLASS( st_parent_class )->dispose( object );
371
instance_finalize( GObject *object )
373
static const gchar *thisfn = "na_action_instance_finalize";
374
g_debug( "%s: object=%p", thisfn, object );
376
g_assert( NA_IS_ACTION( object ));
377
NAAction *self = ( NAAction * ) object;
379
g_free( self->private->version );
380
g_free( self->private->tooltip );
381
g_free( self->private->icon );
383
g_free( self->private );
385
/* chain call to parent class */
386
if((( GObjectClass * ) st_parent_class )->finalize ){
387
G_OBJECT_CLASS( st_parent_class )->finalize( object );
394
* Allocates a new #NAAction object.
396
* The new #NAAction object is initialized with suitable default values,
397
* but without any profile.
399
* Returns: the newly allocated #NAAction object.
402
na_action_new( void )
404
NAAction *action = g_object_new( NA_ACTION_TYPE, NULL );
406
na_action_set_new_uuid( action );
408
/* i18n: default label for a new action */
409
na_action_set_label( action, NA_ACTION_DEFAULT_LABEL );
415
* na_action_new_with_profile:
417
* Allocates a new #NAAction object along with a default profile.
419
* Return: the newly allocated #NAAction action.
422
na_action_new_with_profile( void )
424
NAAction *action = na_action_new();
426
NAActionProfile *profile = na_action_profile_new();
428
na_action_attach_profile( action, profile );
434
* na_action_get_uuid:
435
* @action: the #NAAction object to be requested.
437
* Returns the globally unique identifier (UUID) of the action.
439
* Returns: the uuid of the action as a newly allocated string. This
440
* returned string must be g_free() by the caller.
442
* See na_action_set_uuid() for some rationale about uuid.
445
na_action_get_uuid( const NAAction *action )
447
g_assert( NA_IS_ACTION( action ));
450
g_object_get( G_OBJECT( action ), PROP_NAACTION_UUID_STR, &id, NULL );
456
* na_action_get_label:
457
* @action: the #NAAction object to be requested.
459
* Returns the label of the action.
461
* Returns: the label of the action as a newly allocated string. This
462
* returned string must be g_free() by the caller.
464
* See na_action_set_label() for some rationale about label.
467
na_action_get_label( const NAAction *action )
469
g_assert( NA_IS_ACTION( action ));
472
g_object_get( G_OBJECT( action ), PROP_NAACTION_LABEL_STR, &label, NULL );
478
* na_action_get_version:
479
* @action: the #NAAction object to be requested.
481
* Returns the version of the description of the action, as found when
482
* reading it from the I/O storage subsystem.
484
* Returns: the version of the action as a newly allocated string. This
485
* returned string must be g_free() by the caller.
487
* See na_action_set_version() for some rationale about version.
490
na_action_get_version( const NAAction *action )
492
g_assert( NA_IS_ACTION( action ));
495
g_object_get( G_OBJECT( action ), PROP_NAACTION_VERSION_STR, &version, NULL );
501
* na_action_get_tooltip:
502
* @action: the #NAAction object to be requested.
504
* Returns the tooltip which will be display in the Nautilus context
505
* menu item for this action.
507
* Returns: the tooltip of the action as a newly allocated string. This
508
* returned string must be g_free() by the caller.
511
na_action_get_tooltip( const NAAction *action )
513
g_assert( NA_IS_ACTION( action ));
516
g_object_get( G_OBJECT( action ), PROP_NAACTION_TOOLTIP_STR, &tooltip, NULL );
522
* na_action_get_icon:
523
* @action: the #NAAction object to be requested.
525
* Returns the name of the icon attached to the Nautilus context menu
526
* item for this action.
528
* Returns: the icon name as a newly allocated string. This returned
529
* string must be g_free() by the caller.
532
na_action_get_icon( const NAAction *action )
534
g_assert( NA_IS_ACTION( action ));
537
g_object_get( G_OBJECT( action ), PROP_NAACTION_ICON_STR, &icon, NULL );
543
* TODO: remove this function
546
na_action_get_verified_icon_name( const NAAction *action )
548
g_assert( NA_IS_ACTION( action ));
551
g_object_get( G_OBJECT( action ), PROP_NAACTION_ICON_STR, &icon_name, NULL );
553
if( icon_name[0] == '/' ){
554
if( !g_file_test( icon_name, G_FILE_TEST_IS_REGULAR )){
558
} else if( strlen( icon_name ) == 0 ){
567
* na_action_is_enabled:
568
* @action: the #NAAction object to be requested.
570
* Is the specified action enabled ?
571
* When disabled, the action is never candidate to any selection
573
* Returns: %TRUE if the action is enabled, %FALSE else.
576
na_action_is_enabled( const NAAction *action )
578
g_assert( NA_IS_ACTION( action ));
581
g_object_get( G_OBJECT( action ), PROP_NAACTION_ENABLED_STR, &enabled, NULL );
587
* na_action_is_readonly:
588
* @action: the #NAAction object to be requested.
590
* Is the specified action only readable ?
591
* Or, in other words, may this action be edited and then saved to the
592
* original I/O storage subsystem ?
594
* Returns: %TRUE if the action is editable, %FALSE else.
597
na_action_is_readonly( const NAAction *action )
599
g_assert( NA_IS_ACTION( action ));
602
g_object_get( G_OBJECT( action ), PROP_NAACTION_READONLY_STR, &readonly, NULL );
608
* na_action_get_provider:
609
* @action: the #NAAction object to be requested.
611
* Returns the initial provider of the action (or the last which has
612
* accepted a write operation). At the time of this request, this is
613
* the most probable provider willing to accept a next writing
616
* Returns: a #NAIIOProvider object. The reference is
617
* owned by #NAPivot pivot and should be g_object_unref() by the
621
na_action_get_provider( const NAAction *action )
623
g_assert( NA_IS_ACTION( action ));
625
NAIIOProvider *provider;
626
g_object_get( G_OBJECT( action ), PROP_NAACTION_PROVIDER_STR, &provider, NULL );
632
* na_action_set_new_uuid:
633
* @action: the #NAAction object to be updated.
635
* Set a new UUID for the action.
638
na_action_set_new_uuid( NAAction *action )
640
g_assert( NA_IS_ACTION( action ));
644
uuid_generate( uuid );
645
uuid_unparse_lower( uuid, uuid_str );
647
g_object_set( G_OBJECT( action ), PROP_NAACTION_UUID_STR, uuid_str, NULL );
651
* na_action_set_uuid:
652
* @action: the #NAAction object to be updated.
653
* @uuid: the uuid to be set.
655
* Sets a new uuid for the action.
657
* #NAAction takes a copy of the provided UUID. This later may so be
658
* g_free() by the caller after this function returns.
660
* This uuid is only required when writing the action to GConf in order
661
* easily have unique subdirectories.
663
* This is an ASCII, case insensitive, string.
665
* UUID is transfered through import/export operations.
667
* Note that a user may import an action, translate it and then
668
* reexport it : we so may have two different actions with the same
672
na_action_set_uuid( NAAction *action, const gchar *uuid )
674
g_assert( NA_IS_ACTION( action ));
676
g_object_set( G_OBJECT( action ), PROP_NAACTION_UUID_STR, uuid, NULL );
680
* na_action_set_label:
681
* @action: the #NAAction object to be updated.
682
* @label: the label to be set.
684
* Sets a new label for the action.
686
* #NAAction takes a copy of the provided label. This later may so be
687
* g_free() by the caller after this function returns.
689
* The user knows its actions through their labels, as this is the main
690
* visible part (with the icon) in Nautilus context menu and in the
694
na_action_set_label( NAAction *action, const gchar *label )
696
g_assert( NA_IS_ACTION( action ));
698
g_object_set( G_OBJECT( action ), PROP_NAACTION_LABEL_STR, label, NULL );
702
* na_action_set_version:
703
* @action: the #NAAction object to be updated.
704
* @label: the label to be set.
706
* Sets a new version for the action.
708
* #NAAction takes a copy of the provided version. This later may so be
709
* g_free() by the caller after this function returns.
711
* The version describes the schema of the informations in the I/O
714
* Version is stored in the #NAAction object as readen from the I/O
715
* storage subsystem, even if the #NAAction object itself only reflects
716
* the lastest known version. Conversion is made at load time (cf.
717
* na_gconf_load_action()).
720
na_action_set_version( NAAction *action, const gchar *version )
722
g_assert( NA_IS_ACTION( action ));
724
g_object_set( G_OBJECT( action ), PROP_NAACTION_VERSION_STR, version, NULL );
728
* na_action_set_tooltip:
729
* @action: the #NAAction object to be updated.
730
* @tooltip: the tooltip to be set.
732
* Sets a new tooltip for the action. Tooltip will be displayed by
733
* Nautilus when the user move its mouse over the Nautilus context menu
736
* #NAAction takes a copy of the provided tooltip. This later may so be
737
* g_free() by the caller after this function returns.
740
na_action_set_tooltip( NAAction *action, const gchar *tooltip )
742
g_assert( NA_IS_ACTION( action ));
744
g_object_set( G_OBJECT( action ), PROP_NAACTION_TOOLTIP_STR, tooltip, NULL );
748
* na_action_set_icon:
749
* @action: the #NAAction object to be updated.
750
* @icon: the icon name to be set.
752
* Sets a new icon name for the action.
754
* #NAAction takes a copy of the provided icon name. This later may so
755
* be g_free() by the caller after this function returns.
758
na_action_set_icon( NAAction *action, const gchar *icon )
760
g_assert( NA_IS_ACTION( action ));
762
g_object_set( G_OBJECT( action ), PROP_NAACTION_ICON_STR, icon, NULL );
766
* na_action_set_enabled:
767
* @action: the #NAAction object to be updated.
768
* @enabled: the indicator to be set.
770
* Sets whether the action is enabled or not.
773
na_action_set_enabled( NAAction *action, gboolean enabled )
775
g_assert( NA_IS_ACTION( action ));
777
g_object_set( G_OBJECT( action ), PROP_NAACTION_ENABLED_STR, enabled, NULL );
781
* na_action_set_readonly:
782
* @action: the #NAAction object to be updated.
783
* @readonly: the indicator to be set.
785
* Sets whether the action is readonly.
788
na_action_set_readonly( NAAction *action, gboolean readonly )
790
g_assert( NA_IS_ACTION( action ));
792
g_object_set( G_OBJECT( action ), PROP_NAACTION_READONLY_STR, readonly, NULL );
796
* na_action_set_provider:
797
* @action: the #NAAction object to be updated.
798
* @provider: the #NAIIOProvider to be set.
800
* Sets the I/O provider for this #NAAction.
803
na_action_set_provider( NAAction *action, const NAIIOProvider *provider )
805
g_assert( NA_IS_ACTION( action ));
807
g_object_set( G_OBJECT( action ), PROP_NAACTION_PROVIDER_STR, provider, NULL );
811
* na_action_get_new_profile_name:
812
* @action: the #NAAction object which will receive a new profile.
814
* Returns a name suitable as a new profile name.
816
* The search is made by iterating over the standard profile name
817
* prefix : basically, we increment a counter until finding a unique
818
* name. The provided name is so only suitable for the specified
821
* Returns: a newly allocated profile name, which should be g_free() by
825
na_action_get_new_profile_name( const NAAction *action )
827
g_assert( NA_IS_ACTION( action ));
830
gchar *candidate = NULL;
832
for( i=1 ; !ok ; ++i ){
834
candidate = g_strdup_printf( "%s%d", ACTION_PROFILE_PREFIX, i );
835
if( !na_action_get_profile( action, candidate )){
847
* na_action_get_profile:
848
* @action: the #NAAction object which is to be requested.
849
* @name: the name of the searched profile.
851
* Returns the required profile.
853
* Returns: a pointer to the #NAActionProfile profile with the required
856
* The returned #NAActionProfile is owned by the @action object ; the
857
* caller should not try to g_free() nor g_object_unref() it.
860
na_action_get_profile( const NAAction *action, const gchar *name )
862
g_assert( NA_IS_ACTION( action ));
863
NAActionProfile *found = NULL;
866
for( ip = action->private->profiles ; ip && !found ; ip = ip->next ){
867
NAActionProfile *iprofile = NA_ACTION_PROFILE( ip->data );
868
gchar *iname = na_action_profile_get_name( iprofile );
869
if( !strcmp( name, iname )){
879
* na_action_attach_profile:
880
* @action: the #NAAction action to which the profile will be attached.
881
* @profile: the #NAActionProfile profile to be attached to @action.
883
* Adds a profile at the end of the list of profiles.
886
na_action_attach_profile( NAAction *action, NAActionProfile *profile )
888
g_assert( NA_IS_ACTION( action ));
889
g_assert( NA_IS_ACTION_PROFILE( profile ));
891
action->private->profiles = g_slist_append( action->private->profiles, ( gpointer ) profile );
893
na_action_profile_set_action( profile, action );
897
* na_action_remove_profile:
898
* @action: the #NAAction action from which the profile will be removed.
899
* @profile: the #NAActionProfile profile to be removed from @action.
901
* Removes a profile from the list of profiles.
904
na_action_remove_profile( NAAction *action, NAActionProfile *profile )
906
g_assert( NA_IS_ACTION( action ));
907
g_assert( NA_IS_ACTION_PROFILE( profile ));
909
action->private->profiles = g_slist_remove( action->private->profiles, ( gconstpointer ) profile );
913
* na_action_get_profiles:
914
* @action: the #NAAction action whose profiles has to be retrieved.
916
* Returns the list of profiles of the action.
918
* Returns: a #GSList of #NAActionProfile objects. The returned pointer
919
* is owned by the @action object ; the caller should not try to
920
* g_free() nor g_object_unref() it.
923
na_action_get_profiles( const NAAction *action )
925
g_assert( NA_IS_ACTION( action ));
927
return( action->private->profiles );
931
* na_action_set_profiles:
932
* @action: the #NAAction action whose profiles has to be set.
933
* @list: a #GSList list of #NAActionProfile objects to be installed in
936
* Sets the list of the profiles for the action.
938
* The provided list removes and replaces the previous profiles list.
939
* This list is then copied to the action, and thus can then be safely
940
* na_action_free_profiles() by the caller.
943
na_action_set_profiles( NAAction *action, GSList *list )
945
g_assert( NA_IS_ACTION( action ));
947
free_profiles( action );
950
for( ip = list ; ip ; ip = ip->next ){
951
NAObject *new_profile = na_object_duplicate( NA_OBJECT( ip->data ));
952
na_action_attach_profile( action, NA_ACTION_PROFILE( new_profile ));
957
* na_action_free_profiles:
958
* @list: a #GSList list of #NAActionProfile objects.
960
* Frees a profiles list.
963
na_action_free_profiles( GSList *list )
966
for( ip = list ; ip ; ip = ip->next ){
967
g_object_unref( NA_ACTION_PROFILE( ip->data ));
969
g_slist_free( list );
973
* na_action_get_profiles_count:
974
* @action: the #NAAction action whose profiles has to be counted.
976
* Returns the number of profiles which are defined for the action.
978
* Returns: the number of profiles defined for @action.
981
na_action_get_profiles_count( const NAAction *action )
983
g_assert( NA_IS_ACTION( action ));
985
return( g_slist_length( action->private->profiles ));
989
object_check_edited_status( const NAObject *action )
991
if( st_parent_class->check_edited_status ){
992
st_parent_class->check_edited_status( action );
996
for( ip = NA_ACTION( action )->private->profiles ; ip ; ip = ip->next ){
997
na_object_check_edited_status( NA_OBJECT( ip->data ));
1002
object_dump( const NAObject *action )
1004
static const gchar *thisfn = "na_action_object_dump";
1006
g_assert( NA_IS_ACTION( action ));
1007
NAAction *self = NA_ACTION( action );
1009
if( st_parent_class->dump ){
1010
st_parent_class->dump( action );
1013
g_debug( "%s: version='%s'", thisfn, self->private->version );
1014
g_debug( "%s: tooltip='%s'", thisfn, self->private->tooltip );
1015
g_debug( "%s: icon='%s'", thisfn, self->private->icon );
1016
g_debug( "%s: enabled='%s'", thisfn, self->private->enabled ? "True" : "False" );
1017
g_debug( "%s: read-only='%s'", thisfn, self->private->read_only ? "True" : "False" );
1018
g_debug( "%s: provider=%p", thisfn, self->private->provider );
1021
g_debug( "%s: %d profile(s) at %p", thisfn, na_action_get_profiles_count( self ), self->private->profiles );
1023
for( item = self->private->profiles ; item != NULL ; item = item->next ){
1024
na_object_dump(( const NAObject * ) item->data );
1029
object_duplicate( const NAObject *action )
1031
g_assert( NA_IS_ACTION( action ));
1033
NAObject *duplicate = NA_OBJECT( na_action_new());
1035
na_object_copy( duplicate, action );
1037
return( duplicate );
1041
object_copy( NAObject *target, const NAObject *source )
1043
g_assert( NA_IS_ACTION( source ));
1044
g_assert( NA_IS_ACTION( target ));
1046
gchar *version, *tooltip, *icon;
1047
gboolean enabled, readonly;
1050
g_object_get( G_OBJECT( source ),
1051
PROP_NAACTION_VERSION_STR, &version,
1052
PROP_NAACTION_TOOLTIP_STR, &tooltip,
1053
PROP_NAACTION_ICON_STR, &icon,
1054
PROP_NAACTION_ENABLED_STR, &enabled,
1055
PROP_NAACTION_READONLY_STR, &readonly,
1056
PROP_NAACTION_PROVIDER_STR, &provider,
1059
g_object_set( G_OBJECT( target ),
1060
PROP_NAACTION_VERSION_STR, version,
1061
PROP_NAACTION_TOOLTIP_STR, tooltip,
1062
PROP_NAACTION_ICON_STR, icon,
1063
PROP_NAACTION_ENABLED_STR, enabled,
1064
PROP_NAACTION_READONLY_STR, readonly,
1065
PROP_NAACTION_PROVIDER_STR, provider,
1072
for( ip = NA_ACTION( source )->private->profiles ; ip ; ip = ip->next ){
1073
NAActionProfile *profile = NA_ACTION_PROFILE( na_object_duplicate( NA_OBJECT( ip->data )));
1074
na_action_attach_profile( NA_ACTION( target ), profile );
1077
if( st_parent_class->copy ){
1078
st_parent_class->copy( target, source );
1083
object_are_equal( const NAObject *a, const NAObject *b )
1085
g_assert( NA_IS_ACTION( a ));
1086
g_assert( NA_IS_ACTION( b ));
1088
NAAction *first = NA_ACTION( a );
1089
NAAction *second = NA_ACTION( b );
1092
( g_utf8_collate( first->private->version, second->private->version ) == 0 ) &&
1093
( g_utf8_collate( first->private->tooltip, second->private->tooltip ) == 0 ) &&
1094
( g_utf8_collate( first->private->icon, second->private->icon ) == 0 );
1097
equal = ( first->private->enabled && second->private->enabled ) ||
1098
( !first->private->enabled && !second->private->enabled );
1101
equal = ( g_slist_length( first->private->profiles ) == g_slist_length( second->private->profiles ));
1105
for( ip = first->private->profiles ; ip && equal ; ip = ip->next ){
1106
NAActionProfile *first_profile = NA_ACTION_PROFILE( ip->data );
1107
gchar *first_name = na_action_profile_get_name( first_profile );
1108
NAActionProfile *second_profile = NA_ACTION_PROFILE( na_action_get_profile( second, first_name ));
1109
if( second_profile ){
1110
equal = na_object_are_equal( NA_OBJECT( first_profile ), NA_OBJECT( second_profile ));
1114
g_free( first_name );
1119
for( ip = second->private->profiles ; ip && equal ; ip = ip->next ){
1120
NAActionProfile *second_profile = NA_ACTION_PROFILE( ip->data );
1121
gchar *second_name = na_action_profile_get_name( second_profile );
1122
NAActionProfile *first_profile = NA_ACTION_PROFILE( na_action_get_profile( first, second_name ));
1123
if( first_profile ){
1124
equal = na_object_are_equal( NA_OBJECT( first_profile ), NA_OBJECT( second_profile ));
1128
g_free( second_name );
1132
if( st_parent_class->are_equal ){
1133
equal = st_parent_class->are_equal( a, b );
1141
object_is_valid( const NAObject *action )
1143
g_assert( NA_IS_ACTION( action ));
1146
g_object_get( G_OBJECT( action ), PROP_NAACTION_LABEL_STR, &label, NULL );
1147
gboolean is_valid = ( label && g_utf8_strlen( label, -1 ) > 0 );
1151
for( ip = NA_ACTION( action )->private->profiles ; ip && is_valid ; ip = ip->next ){
1152
is_valid = na_object_is_valid( NA_OBJECT( ip->data ));
1156
if( st_parent_class->is_valid ){
1157
is_valid = st_parent_class->is_valid( action );
1165
free_profiles( NAAction *action )
1167
na_action_free_profiles( action->private->profiles );
1169
action->private->profiles = NULL;