No issues found
1 /*
2 * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include <glib.h>
26
27 #include <libtracker-common/tracker-ontologies.h>
28
29 #include "tracker-namespace.h"
30 #include "tracker-ontologies.h"
31 #include "tracker-property.h"
32
33 #define XSD_BOOLEAN TRACKER_XSD_PREFIX "boolean"
34 #define XSD_DATE TRACKER_XSD_PREFIX "date"
35 #define XSD_DATETIME TRACKER_XSD_PREFIX "dateTime"
36 #define XSD_DOUBLE TRACKER_XSD_PREFIX "double"
37 #define XSD_INTEGER TRACKER_XSD_PREFIX "integer"
38 #define XSD_STRING TRACKER_XSD_PREFIX "string"
39
40 #define GET_PRIV(obj) (((TrackerProperty*) obj)->priv)
41 #define TRACKER_PROPERTY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_PROPERTY, TrackerPropertyPrivate))
42
43 struct _TrackerPropertyPrivate {
44 gchar *uri;
45 gchar *name;
46 gchar *table_name;
47
48 gboolean use_gvdb;
49
50 TrackerPropertyType data_type;
51 TrackerClass *domain;
52 TrackerClass *domain_index;
53 TrackerClass *range;
54 gint weight;
55 gint id;
56 gboolean indexed;
57 TrackerProperty *secondary_index;
58 gboolean fulltext_indexed;
59 gboolean multiple_values;
60 gboolean last_multiple_values;
61 gboolean transient;
62 gboolean is_inverse_functional_property;
63 gboolean is_new;
64 gboolean db_schema_changed;
65 gboolean writeback;
66 gchar *default_value;
67 GPtrArray *is_new_domain_index;
68 gboolean force_journal;
69
70 GArray *super_properties;
71 GArray *domain_indexes;
72 GArray *last_super_properties;
73 };
74
75 static void property_finalize (GObject *object);
76
77 GType
78 tracker_property_type_get_type (void)
79 {
80 static GType etype = 0;
81
82 if (etype == 0) {
83 static const GEnumValue values[] = {
84 { TRACKER_PROPERTY_TYPE_UNKNOWN,
85 "TRACKER_PROPERTY_TYPE_UNKNOWN",
86 "unknown" },
87 { TRACKER_PROPERTY_TYPE_STRING,
88 "TRACKER_PROPERTY_TYPE_STRING",
89 "string" },
90 { TRACKER_PROPERTY_TYPE_BOOLEAN,
91 "TRACKER_PROPERTY_TYPE_BOOLEAN",
92 "boolean" },
93 { TRACKER_PROPERTY_TYPE_INTEGER,
94 "TRACKER_PROPERTY_TYPE_INTEGER",
95 "integer" },
96 { TRACKER_PROPERTY_TYPE_DOUBLE,
97 "TRACKER_PROPERTY_TYPE_DOUBLE",
98 "double" },
99 { TRACKER_PROPERTY_TYPE_DATE,
100 "TRACKER_PROPERTY_TYPE_DATE",
101 "date" },
102 { TRACKER_PROPERTY_TYPE_DATETIME,
103 "TRACKER_PROPERTY_TYPE_DATETIME",
104 "datetime" },
105 { TRACKER_PROPERTY_TYPE_RESOURCE,
106 "TRACKER_PROPERTY_TYPE_RESOURCE",
107 "resource" },
108 { 0, NULL, NULL }
109 };
110
111 etype = g_enum_register_static ("TrackerPropertyType", values);
112 }
113
114 return etype;
115 }
116
117 G_DEFINE_TYPE (TrackerProperty, tracker_property, G_TYPE_OBJECT);
118
119 static void
120 tracker_property_class_init (TrackerPropertyClass *klass)
121 {
122 GObjectClass *object_class = G_OBJECT_CLASS (klass);
123
124 object_class->finalize = property_finalize;
125
126 g_type_class_add_private (object_class, sizeof (TrackerPropertyPrivate));
127 }
128
129 static void
130 tracker_property_init (TrackerProperty *property)
131 {
132 TrackerPropertyPrivate *priv;
133
134 priv = TRACKER_PROPERTY_GET_PRIVATE (property);
135
136 priv->id = 0;
137 priv->weight = 1;
138 priv->transient = FALSE;
139 priv->multiple_values = TRUE;
140 priv->force_journal = TRUE;
141 priv->super_properties = g_array_new (TRUE, TRUE, sizeof (TrackerProperty *));
142 priv->domain_indexes = g_array_new (TRUE, TRUE, sizeof (TrackerClass *));
143 priv->last_super_properties = NULL;
144
145 /* Make GET_PRIV working */
146 property->priv = priv;
147 }
148
149 static void
150 property_finalize (GObject *object)
151 {
152 TrackerPropertyPrivate *priv;
153
154 priv = GET_PRIV (object);
155
156 g_free (priv->uri);
157 g_free (priv->name);
158 g_free (priv->table_name);
159
160 if (priv->is_new_domain_index) {
161 g_ptr_array_unref (priv->is_new_domain_index);
162 }
163
164 if (priv->domain) {
165 g_object_unref (priv->domain);
166 }
167
168 if (priv->range) {
169 g_object_unref (priv->range);
170 }
171
172 if (priv->secondary_index) {
173 g_object_unref (priv->secondary_index);
174 }
175
176 if (priv->last_super_properties) {
177 g_array_free (priv->last_super_properties, TRUE);
178 }
179
180 g_array_free (priv->super_properties, TRUE);
181 g_array_free (priv->domain_indexes, TRUE);
182
183 g_free (priv->default_value);
184
185 (G_OBJECT_CLASS (tracker_property_parent_class)->finalize) (object);
186 }
187
188 /**
189 * tracker_property_new:
190 *
191 * Creates a new #TrackerProperty instance.
192 *
193 * Returns: The newly created #TrackerProperty
194 **/
195 TrackerProperty *
196 tracker_property_new (gboolean use_gvdb)
197 {
198 TrackerProperty *property;
199 TrackerPropertyPrivate *priv;
200
201 property = g_object_new (TRACKER_TYPE_PROPERTY, NULL);
202
203 if (use_gvdb) {
204 priv = GET_PRIV (property);
205 priv->use_gvdb = use_gvdb;
206 }
207
208 return property;
209 }
210
211 const gchar *
212 tracker_property_get_uri (TrackerProperty *property)
213 {
214 TrackerPropertyPrivate *priv;
215
216 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
217
218 priv = GET_PRIV (property);
219
220 return priv->uri;
221 }
222
223 gboolean
224 tracker_property_get_transient (TrackerProperty *property)
225 {
226 TrackerPropertyPrivate *priv;
227
228 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
229
230 priv = GET_PRIV (property);
231
232 return priv->transient;
233 }
234
235
236 const gchar *
237 tracker_property_get_name (TrackerProperty *property)
238 {
239 TrackerPropertyPrivate *priv;
240
241 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
242
243 priv = GET_PRIV (property);
244
245 return priv->name;
246 }
247
248 const gchar *
249 tracker_property_get_table_name (TrackerProperty *property)
250 {
251 TrackerPropertyPrivate *priv;
252
253 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
254
255 priv = GET_PRIV (property);
256
257 if (!priv->table_name) {
258 if (tracker_property_get_multiple_values (property)) {
259 priv->table_name = g_strdup_printf ("%s_%s",
260 tracker_class_get_name (tracker_property_get_domain (property)),
261 tracker_property_get_name (property));
262 } else {
263 priv->table_name = g_strdup (tracker_class_get_name (tracker_property_get_domain (property)));
264 }
265 }
266
267 return priv->table_name;
268 }
269
270 TrackerPropertyType
271 tracker_property_get_data_type (TrackerProperty *property)
272 {
273 TrackerPropertyPrivate *priv;
274
275 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), TRACKER_PROPERTY_TYPE_STRING); //FIXME
276
277 priv = GET_PRIV (property);
278
279 if (priv->use_gvdb) {
280 const gchar *range_uri;
281
282 range_uri = tracker_ontologies_get_property_string_gvdb (priv->uri, "range");
283 if (strcmp (range_uri, XSD_STRING) == 0) {
284 priv->data_type = TRACKER_PROPERTY_TYPE_STRING;
285 } else if (strcmp (range_uri, XSD_BOOLEAN) == 0) {
286 priv->data_type = TRACKER_PROPERTY_TYPE_BOOLEAN;
287 } else if (strcmp (range_uri, XSD_INTEGER) == 0) {
288 priv->data_type = TRACKER_PROPERTY_TYPE_INTEGER;
289 } else if (strcmp (range_uri, XSD_DOUBLE) == 0) {
290 priv->data_type = TRACKER_PROPERTY_TYPE_DOUBLE;
291 } else if (strcmp (range_uri, XSD_DATE) == 0) {
292 priv->data_type = TRACKER_PROPERTY_TYPE_DATE;
293 } else if (strcmp (range_uri, XSD_DATETIME) == 0) {
294 priv->data_type = TRACKER_PROPERTY_TYPE_DATETIME;
295 } else {
296 priv->data_type = TRACKER_PROPERTY_TYPE_RESOURCE;
297 }
298 }
299
300 return priv->data_type;
301 }
302
303 TrackerClass *
304 tracker_property_get_domain (TrackerProperty *property)
305 {
306 TrackerPropertyPrivate *priv;
307
308 /* Removed for performance:
309 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL); */
310
311 g_return_val_if_fail (property != NULL, NULL);
312
313 priv = GET_PRIV (property);
314
315 if (!priv->domain && priv->use_gvdb) {
316 const gchar *domain_uri;
317
318 domain_uri = tracker_ontologies_get_property_string_gvdb (priv->uri, "domain");
319 priv->domain = g_object_ref (tracker_ontologies_get_class_by_uri (domain_uri));
320 }
321
322 return priv->domain;
323 }
324
325 TrackerClass **
326 tracker_property_get_domain_indexes (TrackerProperty *property)
327 {
328 TrackerPropertyPrivate *priv;
329
330 /* Removed for performance:
331 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL); */
332
333 g_return_val_if_fail (property != NULL, NULL);
334
335 priv = GET_PRIV (property);
336
337 if (priv->use_gvdb) {
338 TrackerClass *domain_index;
339 GVariant *variant;
340
341 tracker_property_reset_domain_indexes (property);
342
343 variant = tracker_ontologies_get_property_value_gvdb (priv->uri, "domain-indexes");
344 if (variant) {
345 GVariantIter iter;
346 const gchar *uri;
347
348 g_variant_iter_init (&iter, variant);
349 while (g_variant_iter_loop (&iter, "&s", &uri)) {
350 domain_index = tracker_ontologies_get_class_by_uri (uri);
351
352 tracker_property_add_domain_index (property, domain_index);
353 }
354
355 g_variant_unref (variant);
356 }
357 }
358
359 return (TrackerClass ** ) priv->domain_indexes->data;
360 }
361
362 TrackerProperty **
363 tracker_property_get_last_super_properties (TrackerProperty *property)
364 {
365 TrackerPropertyPrivate *priv;
366
367 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
368 g_return_val_if_fail (property != NULL, NULL);
369
370 priv = GET_PRIV (property);
371
372 return (TrackerProperty **) (priv->last_super_properties ? priv->last_super_properties->data : NULL);
373 }
374
375 void
376 tracker_property_reset_super_properties (TrackerProperty *property)
377 {
378 TrackerPropertyPrivate *priv;
379
380 g_return_if_fail (TRACKER_IS_PROPERTY (property));
381
382 priv = GET_PRIV (property);
383
384 if (priv->last_super_properties) {
385 g_array_free (priv->last_super_properties, TRUE);
386 }
387
388 priv->last_super_properties = priv->super_properties;
389 priv->super_properties = g_array_new (TRUE, TRUE, sizeof (TrackerProperty *));
390 }
391
392
393 TrackerClass *
394 tracker_property_get_range (TrackerProperty *property)
395 {
396 TrackerPropertyPrivate *priv;
397
398 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
399
400 priv = GET_PRIV (property);
401
402 if (!priv->range && priv->use_gvdb) {
403 const gchar *range_uri;
404
405 range_uri = tracker_ontologies_get_property_string_gvdb (priv->uri, "range");
406 priv->range = g_object_ref (tracker_ontologies_get_class_by_uri (range_uri));
407 }
408
409 return priv->range;
410 }
411
412 gint
413 tracker_property_get_weight (TrackerProperty *property)
414 {
415 TrackerPropertyPrivate *priv;
416
417 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), -1);
418
419 priv = GET_PRIV (property);
420
421 return priv->weight;
422 }
423
424 gint
425 tracker_property_get_id (TrackerProperty *property)
426 {
427 TrackerPropertyPrivate *priv;
428
429 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), 0);
430
431 priv = GET_PRIV (property);
432
433 return priv->id;
434 }
435
436 gboolean
437 tracker_property_get_indexed (TrackerProperty *property)
438 {
439 TrackerPropertyPrivate *priv;
440
441 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
442
443 priv = GET_PRIV (property);
444
445 return priv->indexed;
446 }
447
448 TrackerProperty *
449 tracker_property_get_secondary_index (TrackerProperty *property)
450 {
451 TrackerPropertyPrivate *priv;
452
453 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
454
455 priv = GET_PRIV (property);
456
457 return priv->secondary_index;
458 }
459
460 gboolean
461 tracker_property_get_fulltext_indexed (TrackerProperty *property)
462 {
463 TrackerPropertyPrivate *priv;
464
465 /* Removed for performance:
466 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL); */
467
468 g_return_val_if_fail (property != NULL, FALSE);
469
470 priv = GET_PRIV (property);
471
472 return priv->fulltext_indexed;
473 }
474
475 gboolean
476 tracker_property_get_is_new (TrackerProperty *property)
477 {
478 TrackerPropertyPrivate *priv;
479
480 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
481
482 priv = GET_PRIV (property);
483
484 return priv->is_new;
485 }
486
487 gboolean
488 tracker_property_get_is_new_domain_index (TrackerProperty *property,
489 TrackerClass *class)
490 {
491 TrackerPropertyPrivate *priv;
492 guint i;
493
494 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
495 g_return_val_if_fail (TRACKER_IS_CLASS (class), FALSE);
496
497 priv = GET_PRIV (property);
498
499 if (!priv->is_new_domain_index) {
500 return FALSE;
501 }
502
503 for (i = 0; i < priv->is_new_domain_index->len; i++) {
504 if (g_ptr_array_index (priv->is_new_domain_index, i) == class) {
505 return TRUE;
506 }
507 }
508
509 return FALSE;
510 }
511
512 gboolean
513 tracker_property_get_writeback (TrackerProperty *property)
514 {
515 TrackerPropertyPrivate *priv;
516
517 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
518
519 priv = GET_PRIV (property);
520
521 return priv->writeback;
522 }
523
524 gboolean
525 tracker_property_get_db_schema_changed (TrackerProperty *property)
526 {
527 TrackerPropertyPrivate *priv;
528
529 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
530
531 priv = GET_PRIV (property);
532
533 return priv->db_schema_changed;
534 }
535
536 gboolean
537 tracker_property_get_multiple_values (TrackerProperty *property)
538 {
539 TrackerPropertyPrivate *priv;
540
541 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
542
543 priv = GET_PRIV (property);
544
545 if (priv->use_gvdb) {
546 GVariant *value;
547 gboolean result;
548
549 value = tracker_ontologies_get_property_value_gvdb (priv->uri, "max-cardinality");
550 if (value != NULL) {
551 result = FALSE;
552 g_variant_unref (value);
553 } else {
554 result = TRUE;
555 }
556
557 return result;
558 }
559
560 return priv->multiple_values;
561 }
562
563 gboolean
564 tracker_property_get_last_multiple_values (TrackerProperty *property)
565 {
566 TrackerPropertyPrivate *priv;
567
568 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
569
570 priv = GET_PRIV (property);
571
572 return priv->last_multiple_values;
573 }
574
575 gboolean
576 tracker_property_get_is_inverse_functional_property (TrackerProperty *property)
577 {
578 TrackerPropertyPrivate *priv;
579
580 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
581
582 priv = GET_PRIV (property);
583
584 if (priv->use_gvdb) {
585 GVariant *value;
586 gboolean result;
587
588 value = tracker_ontologies_get_property_value_gvdb (priv->uri, "inverse-functional");
589 if (value != NULL) {
590 result = g_variant_get_boolean (value);
591 g_variant_unref (value);
592 } else {
593 result = FALSE;
594 }
595
596 return result;
597 }
598
599 return priv->is_inverse_functional_property;
600 }
601
602 gboolean
603 tracker_property_get_force_journal (TrackerProperty *property)
604 {
605 TrackerPropertyPrivate *priv;
606
607 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
608
609 priv = GET_PRIV (property);
610
611 return priv->force_journal;
612 }
613
614 TrackerProperty **
615 tracker_property_get_super_properties (TrackerProperty *property)
616 {
617 TrackerPropertyPrivate *priv;
618
619 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
620
621 priv = GET_PRIV (property);
622
623 return (TrackerProperty **) priv->super_properties->data;
624 }
625
626 const gchar *
627 tracker_property_get_default_value (TrackerProperty *property)
628 {
629 TrackerPropertyPrivate *priv;
630
631 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
632
633 priv = GET_PRIV (property);
634
635 return priv->default_value;
636 }
637
638 void
639 tracker_property_set_uri (TrackerProperty *property,
640 const gchar *value)
641 {
642 TrackerPropertyPrivate *priv;
643
644 g_return_if_fail (TRACKER_IS_PROPERTY (property));
645
646 priv = GET_PRIV (property);
647
648 g_free (priv->uri);
649 g_free (priv->name);
650 priv->uri = NULL;
651 priv->name = NULL;
652
653 if (value) {
654 TrackerNamespace *namespace;
655 gchar *namespace_uri, *hash;
656
657 priv->uri = g_strdup (value);
658
659 hash = strrchr (priv->uri, '#');
660 if (hash == NULL) {
661 /* support ontologies whose namespace uri does not end in a hash, e.g. dc */
662 hash = strrchr (priv->uri, '/');
663 }
664 if (hash == NULL) {
665 g_critical ("Unknown namespace of property %s", priv->uri);
666 } else {
667 namespace_uri = g_strndup (priv->uri, hash - priv->uri + 1);
668 namespace = tracker_ontologies_get_namespace_by_uri (namespace_uri);
669 if (namespace == NULL) {
670 g_critical ("Unknown namespace %s of property %s", namespace_uri, priv->uri);
671 } else {
672 priv->name = g_strdup_printf ("%s:%s", tracker_namespace_get_prefix (namespace), hash + 1);
673 }
674 g_free (namespace_uri);
675 }
676 }
677 }
678
679 void
680 tracker_property_set_transient (TrackerProperty *property,
681 gboolean value)
682 {
683 TrackerPropertyPrivate *priv;
684
685 g_return_if_fail (TRACKER_IS_PROPERTY (property));
686
687 priv = GET_PRIV (property);
688
689 priv->transient = value;
690 }
691
692 void
693 tracker_property_set_domain (TrackerProperty *property,
694 TrackerClass *value)
695 {
696 TrackerPropertyPrivate *priv;
697
698 g_return_if_fail (TRACKER_IS_PROPERTY (property));
699
700 priv = GET_PRIV (property);
701
702 if (priv->domain) {
703 g_object_unref (priv->domain);
704 priv->domain = NULL;
705 }
706
707 if (value) {
708 priv->domain = g_object_ref (value);
709 }
710 }
711
712 void
713 tracker_property_add_domain_index (TrackerProperty *property,
714 TrackerClass *value)
715 {
716 TrackerPropertyPrivate *priv;
717
718 g_return_if_fail (TRACKER_IS_PROPERTY (property));
719 g_return_if_fail (TRACKER_IS_CLASS (value));
720
721 priv = GET_PRIV (property);
722
723 g_array_append_val (priv->domain_indexes, value);
724 }
725
726 void
727 tracker_property_del_domain_index (TrackerProperty *property,
728 TrackerClass *value)
729 {
730 TrackerClass **classes;
731 TrackerPropertyPrivate *priv;
732 gint i = 0, found = -1;
733
734 g_return_if_fail (TRACKER_IS_PROPERTY (property));
735 g_return_if_fail (TRACKER_IS_CLASS (value));
736
737 priv = GET_PRIV (property);
738
739 classes = (TrackerClass **) priv->domain_indexes->data;
740 while (*classes) {
741 if (*classes == value) {
742 found = i;
743 break;
744 }
745 i++;
746 classes++;
747 }
748
749 if (found != -1) {
750 g_array_remove_index (priv->domain_indexes, found);
751 }
752 }
753
754 void
755 tracker_property_reset_domain_indexes (TrackerProperty *property)
756 {
757 TrackerPropertyPrivate *priv;
758
759 g_return_if_fail (TRACKER_IS_PROPERTY (property));
760
761 priv = GET_PRIV (property);
762 g_array_free (priv->domain_indexes, TRUE);
763 priv->domain_indexes = g_array_new (TRUE, TRUE, sizeof (TrackerClass *));
764 }
765
766 void
767 tracker_property_set_secondary_index (TrackerProperty *property,
768 TrackerProperty *value)
769 {
770 TrackerPropertyPrivate *priv;
771
772 g_return_if_fail (TRACKER_IS_PROPERTY (property));
773
774 priv = GET_PRIV (property);
775
776 if (priv->secondary_index) {
777 g_object_unref (priv->secondary_index);
778 priv->secondary_index = NULL;
779 }
780
781 if (value) {
782 priv->secondary_index = g_object_ref (value);
783 }
784 }
785
786 void
787 tracker_property_set_range (TrackerProperty *property,
788 TrackerClass *value)
789 {
790 TrackerPropertyPrivate *priv;
791 const gchar *range_uri;
792
793 g_return_if_fail (TRACKER_IS_PROPERTY (property));
794 g_return_if_fail (TRACKER_IS_CLASS (value));
795
796 priv = GET_PRIV (property);
797
798 if (priv->range) {
799 g_object_unref (priv->range);
800 }
801
802 priv->range = g_object_ref (value);
803
804 range_uri = tracker_class_get_uri (priv->range);
805 if (strcmp (range_uri, XSD_STRING) == 0) {
806 priv->data_type = TRACKER_PROPERTY_TYPE_STRING;
807 } else if (strcmp (range_uri, XSD_BOOLEAN) == 0) {
808 priv->data_type = TRACKER_PROPERTY_TYPE_BOOLEAN;
809 } else if (strcmp (range_uri, XSD_INTEGER) == 0) {
810 priv->data_type = TRACKER_PROPERTY_TYPE_INTEGER;
811 } else if (strcmp (range_uri, XSD_DOUBLE) == 0) {
812 priv->data_type = TRACKER_PROPERTY_TYPE_DOUBLE;
813 } else if (strcmp (range_uri, XSD_DATE) == 0) {
814 priv->data_type = TRACKER_PROPERTY_TYPE_DATE;
815 } else if (strcmp (range_uri, XSD_DATETIME) == 0) {
816 priv->data_type = TRACKER_PROPERTY_TYPE_DATETIME;
817 } else {
818 priv->data_type = TRACKER_PROPERTY_TYPE_RESOURCE;
819 }
820 }
821
822 void
823 tracker_property_set_weight (TrackerProperty *property,
824 gint value)
825 {
826 TrackerPropertyPrivate *priv;
827 g_return_if_fail (TRACKER_IS_PROPERTY (property));
828
829 priv = GET_PRIV (property);
830
831 priv->weight = value;
832 }
833
834
835 void
836 tracker_property_set_id (TrackerProperty *property,
837 gint value)
838 {
839 TrackerPropertyPrivate *priv;
840 g_return_if_fail (TRACKER_IS_PROPERTY (property));
841
842 priv = GET_PRIV (property);
843
844 priv->id = value;
845 }
846
847 void
848 tracker_property_set_indexed (TrackerProperty *property,
849 gboolean value)
850 {
851 TrackerPropertyPrivate *priv;
852
853 g_return_if_fail (TRACKER_IS_PROPERTY (property));
854
855 priv = GET_PRIV (property);
856
857 priv->indexed = value;
858 }
859
860 void
861 tracker_property_set_is_new (TrackerProperty *property,
862 gboolean value)
863 {
864 TrackerPropertyPrivate *priv;
865
866 g_return_if_fail (TRACKER_IS_PROPERTY (property));
867
868 priv = GET_PRIV (property);
869
870 priv->is_new = value;
871 }
872
873 void
874 tracker_property_set_is_new_domain_index (TrackerProperty *property,
875 TrackerClass *class,
876 gboolean value)
877 {
878 TrackerPropertyPrivate *priv;
879
880 g_return_if_fail (TRACKER_IS_PROPERTY (property));
881
882 if (class) {
883 g_return_if_fail (TRACKER_IS_CLASS (class));
884 }
885
886 priv = GET_PRIV (property);
887
888 if (value) {
889 if (!priv->is_new_domain_index) {
890 priv->is_new_domain_index = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
891 }
892 g_ptr_array_add (priv->is_new_domain_index, g_object_ref (class));
893 } else {
894 guint i;
895 gboolean found = FALSE;
896
897 if (!priv->is_new_domain_index) {
898 return;
899 }
900
901 if (!class) {
902 g_ptr_array_unref (priv->is_new_domain_index);
903 priv->is_new_domain_index = NULL;
904 return;
905 }
906
907 for (i = 0; i < priv->is_new_domain_index->len; i++) {
908 if (g_ptr_array_index (priv->is_new_domain_index, i) == class) {
909 found = TRUE;
910 break;
911 }
912 }
913
914 if (found) {
915 g_ptr_array_remove_index (priv->is_new_domain_index, i);
916 }
917 }
918 }
919
920 void
921 tracker_property_set_writeback (TrackerProperty *property,
922 gboolean value)
923 {
924 TrackerPropertyPrivate *priv;
925
926 g_return_if_fail (TRACKER_IS_PROPERTY (property));
927
928 priv = GET_PRIV (property);
929
930 priv->writeback = value;
931 }
932
933 void
934 tracker_property_set_db_schema_changed (TrackerProperty *property,
935 gboolean value)
936 {
937 TrackerPropertyPrivate *priv;
938
939 g_return_if_fail (TRACKER_IS_PROPERTY (property));
940
941 priv = GET_PRIV (property);
942
943 priv->db_schema_changed = value;
944 }
945
946 void
947 tracker_property_set_fulltext_indexed (TrackerProperty *property,
948 gboolean value)
949 {
950 TrackerPropertyPrivate *priv;
951
952 g_return_if_fail (TRACKER_IS_PROPERTY (property));
953
954 priv = GET_PRIV (property);
955
956 priv->fulltext_indexed = value;
957 }
958
959 void
960 tracker_property_set_multiple_values (TrackerProperty *property,
961 gboolean value)
962 {
963 TrackerPropertyPrivate *priv;
964
965 g_return_if_fail (TRACKER_IS_PROPERTY (property));
966
967 priv = GET_PRIV (property);
968
969 priv->multiple_values = value;
970 }
971
972 void
973 tracker_property_set_last_multiple_values (TrackerProperty *property,
974 gboolean value)
975 {
976 TrackerPropertyPrivate *priv;
977
978 g_return_if_fail (TRACKER_IS_PROPERTY (property));
979
980 priv = GET_PRIV (property);
981
982 priv->last_multiple_values = value;
983 }
984
985 void
986 tracker_property_set_is_inverse_functional_property (TrackerProperty *property,
987 gboolean value)
988 {
989 TrackerPropertyPrivate *priv;
990
991 g_return_if_fail (TRACKER_IS_PROPERTY (property));
992
993 priv = GET_PRIV (property);
994
995 priv->is_inverse_functional_property = value;
996 }
997
998 void
999 tracker_property_set_force_journal (TrackerProperty *property,
1000 gboolean value)
1001 {
1002 TrackerPropertyPrivate *priv;
1003
1004 g_return_if_fail (TRACKER_IS_PROPERTY (property));
1005
1006 priv = GET_PRIV (property);
1007
1008 priv->force_journal = value;
1009 }
1010
1011 void
1012 tracker_property_add_super_property (TrackerProperty *property,
1013 TrackerProperty *value)
1014 {
1015 TrackerPropertyPrivate *priv;
1016
1017 g_return_if_fail (TRACKER_IS_PROPERTY (property));
1018 g_return_if_fail (TRACKER_IS_PROPERTY (value));
1019
1020 priv = GET_PRIV (property);
1021
1022 g_array_append_val (priv->super_properties, value);
1023 }
1024
1025 void
1026 tracker_property_del_super_property (TrackerProperty *property,
1027 TrackerProperty *value)
1028 {
1029 TrackerPropertyPrivate *priv;
1030 guint i;
1031
1032 g_return_if_fail (TRACKER_IS_PROPERTY (property));
1033 g_return_if_fail (TRACKER_IS_PROPERTY (value));
1034
1035 priv = GET_PRIV (property);
1036
1037 for (i = 0; priv->super_properties->len; i++) {
1038 TrackerProperty *c_value = g_array_index (priv->super_properties, TrackerProperty*, i);
1039
1040 if (c_value == value) {
1041 priv->super_properties = g_array_remove_index (priv->super_properties, i);
1042 return;
1043 }
1044 }
1045 }
1046
1047 void
1048 tracker_property_set_default_value (TrackerProperty *property,
1049 const gchar *value)
1050 {
1051 TrackerPropertyPrivate *priv;
1052
1053 g_return_if_fail (TRACKER_IS_PROPERTY (property));
1054
1055 priv = GET_PRIV (property);
1056
1057 g_free (priv->default_value);
1058 priv->default_value = g_strdup (value);
1059 }