~snaggen/rhythmbox/bpm

« back to all changes in this revision

Viewing changes to bindings/python/rhythmdb.override

  • Committer: James Livingston
  • Author(s): James Livingston
  • Date: 2007-02-12 13:17:35 UTC
  • Revision ID: git-v1:1573e175fae7a73ca3c53bc5f66705f3a6b57db2
add new function which appends a single criteria to the query. Mostly for

2007-02-13  James Livingston  <doclivingston@gmail.com>

        * rhythmdb/rhythmdb-query.c: (rhythmdb_query_append_params): add new
        function which appends a single criteria to the query. Mostly for use
        by bindings.

        * rhythmdb/rhythmdb.h: The above, and replace GPtrArray with
        RhythmDBQuery in the header.

        * bindings/python/rhythmdb.defs:
        * bindings/python/rhythmdb.override: bind the new function, and fix up
        some other bits.

svn path=/trunk/; revision=4813

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        PyObject *ret;
104
104
 
105
105
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:RhythmDB.entry_get", kwlist, &entry, &py_propid))
106
 
            return NULL;
 
106
                return NULL;
107
107
        if (pyg_enum_get_value(RHYTHMDB_TYPE_PROP_TYPE, py_propid, (gint *)&propid))
108
 
            return NULL;
 
108
                return NULL;
109
109
 
110
110
        db = RHYTHMDB (self->obj);
111
111
        g_value_init (&value, rhythmdb_get_property_type (db, propid));
113
113
        ret = pyg_value_as_pyobject (&value, TRUE);
114
114
        g_value_unset (&value);
115
115
        if (ret)
116
 
            return ret;
 
116
                return ret;
117
117
        Py_INCREF(Py_None);
118
118
        return Py_None;
119
119
}
132
132
        GType prop_type;
133
133
 
134
134
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO:RhythmDBEntry.set", kwlist, &py_entry, &py_propid, &py_value))
135
 
            return NULL;
 
135
                return NULL;
136
136
        if (pyg_boxed_check(py_entry, RHYTHMDB_TYPE_ENTRY))
137
 
            entry = pyg_boxed_get(py_entry, RhythmDBEntry);
 
137
                entry = pyg_boxed_get(py_entry, RhythmDBEntry);
138
138
        else {
139
 
            PyErr_SetString(PyExc_TypeError, "entry should be a RhythmDBEntry");
140
 
            return NULL;
 
139
                PyErr_SetString(PyExc_TypeError, "entry should be a RhythmDBEntry");
 
140
                return NULL;
141
141
        }
142
142
        if (pyg_enum_get_value(RHYTHMDB_TYPE_PROP_TYPE, py_propid, (gint *)&propid))
143
 
            return NULL;
 
143
                return NULL;
144
144
 
145
145
        prop_type = rhythmdb_get_property_type (RHYTHMDB(self->obj), propid);
146
146
        g_value_init(&value, prop_type);
148
148
                char *s;
149
149
 
150
150
                s = g_strdup_printf ("could not convert argument from type '%s' (%d) to correct type '%s'",
151
 
                                     g_type_name (pyg_type_from_object (py_value)),
152
 
                                     pyg_type_from_object (py_value),
153
 
                                     g_type_name (prop_type));
 
151
                                         g_type_name (pyg_type_from_object (py_value)),
 
152
                                         (int)pyg_type_from_object (py_value),
 
153
                                         g_type_name (prop_type));
154
154
                PyErr_SetString(PyExc_TypeError, s);
155
155
                g_free (s);
156
156
                return NULL;
171
171
        GPtrArray *array;
172
172
 
173
173
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:RhythmDBQueryResults.add_results", kwlist, &py_entries))
174
 
            return NULL;
 
174
                return NULL;
175
175
 
176
176
        array = g_ptr_array_new();
177
177
        size = PyList_Size(py_entries);
178
178
        for (i = 0; i < size; i++) {
179
 
            PyObject *py_entry;
180
 
            RhythmDBEntry *entry;
 
179
                PyObject *py_entry;
 
180
                RhythmDBEntry *entry;
181
181
 
182
 
            py_entry = PyList_GetItem(py_entries, i);
183
 
            if (!pyg_boxed_check(py_entry, RHYTHMDB_TYPE_ENTRY)) {
184
 
                g_ptr_array_free(array, FALSE);
185
 
                return NULL;
186
 
            }
 
182
                py_entry = PyList_GetItem(py_entries, i);
 
183
                if (!pyg_boxed_check(py_entry, RHYTHMDB_TYPE_ENTRY)) {
 
184
                        g_ptr_array_free(array, FALSE);
 
185
                        return NULL;
 
186
                }
187
187
 
188
188
        entry = pyg_boxed_get(py_entry, RhythmDBEntry);
189
 
            g_ptr_array_add(array, entry);
 
189
                g_ptr_array_add(array, entry);
190
190
        }
191
191
 
192
192
        rhythmdb_query_results_add_results (RHYTHMDB_QUERY_RESULTS(self->obj), array);
212
212
        PyObject *py_entry;
213
213
 
214
214
        py_entry = pyg_boxed_new (RHYTHMDB_TYPE_ENTRY, entry, TRUE, TRUE);
215
 
        if (data->data)
 
215
        if (data->data) {
216
216
                args = Py_BuildValue ("(OO)", py_entry, data->data);
217
 
        else
 
217
        } else {
218
218
                args = Py_BuildValue ("(O)", py_entry);
 
219
        }
219
220
 
220
221
        result = PyEval_CallObject (data->func, args);
221
222
        Py_DECREF (py_entry);
222
223
        Py_DECREF (args);
223
 
        if (result != NULL)
 
224
        if (result != NULL) {
224
225
                Py_DECREF (result);
 
226
        }
225
227
}
226
228
 
227
229
static PyObject*
251
253
static PyObject*
252
254
_wrap_rhythmdb_query_model_new (PyGObject *self, PyObject *args, PyObject *kwargs)
253
255
{
254
 
        static char *kwlist[] = {"query", "func", "reverse", NULL};
 
256
        static char *kwlist[] = {"query", "func", "reverse", "data", NULL};
255
257
        PyObject *py_query;
256
258
        int reverse = 0;
257
259
        PyRhythmDBQueryModelSortData *data;
266
268
        }
267
269
 
268
270
        /* verify arguments' integrity */
269
 
        if (!PyCallable_Check (data->func)) {
270
 
                PyErr_SetString (PyExc_TypeError, "func must be callable");
271
 
                g_free (data);
272
 
                return NULL;
273
 
        }
274
 
 
275
271
        if (!pyg_boxed_check(py_query, RHYTHMDB_TYPE_QUERY)) {
276
272
                PyErr_SetString(PyExc_TypeError, "query should be a RhythmDBQuery");
277
273
                g_free (data);
278
274
                return NULL;
279
275
        }
280
276
 
281
 
        Py_INCREF (data->func);
282
 
        Py_INCREF (data->data);
 
277
        if (data->func != NULL && !PyCallable_Check (data->func)) {
 
278
                PyErr_SetString (PyExc_TypeError, "func must be callable");
 
279
                g_free (data);
 
280
                return NULL;
 
281
        }
 
282
 
 
283
        Py_XINCREF (data->func);
 
284
        Py_XINCREF (data->data);
283
285
 
284
286
        if (data->func) {
285
287
                query_model = rhythmdb_query_model_new (RHYTHMDB (self->obj), pyg_boxed_get (py_query, RhythmDBQuery),
322
324
        Py_INCREF (data->data);
323
325
 
324
326
        rhythmdb_query_model_set_sort_order (RHYTHMDB_QUERY_MODEL (self->obj),
325
 
                                             (GCompareDataFunc) _rhythmdb_query_model_sort_func,
326
 
                                             data, (GDestroyNotify) _rhythmdb_query_model_sort_data_free,
327
 
                                             (reverse != 0));
 
327
                                                 (GCompareDataFunc) _rhythmdb_query_model_sort_func,
 
328
                                                 data, (GDestroyNotify) _rhythmdb_query_model_sort_data_free,
 
329
                                                 (reverse != 0));
328
330
 
329
331
        Py_INCREF(Py_None);
330
332
        return Py_None;
424
426
 
425
427
static gboolean
426
428
_wrap_py_entry_type_can_sync_metadata (RhythmDB *db, RhythmDBEntry *entry,
427
 
                                      PyObject *py_call)
 
429
                                          PyObject *py_call)
428
430
{
429
431
        gboolean retval = FALSE;
430
432
 
545
547
        RhythmDBEntry *entry = NULL;
546
548
 
547
549
        if (!PyArg_ParseTupleAndKeywords(args, kwargs,"Os:RhythmDB.entry_request_extra_metadata", kwlist, &py_entry, &property_name))
548
 
            return NULL;
 
550
                return NULL;
549
551
        if (pyg_boxed_check(py_entry, RHYTHMDB_TYPE_ENTRY))
550
 
            entry = pyg_boxed_get(py_entry, RhythmDBEntry);
 
552
                entry = pyg_boxed_get(py_entry, RhythmDBEntry);
551
553
        else {
552
 
            PyErr_SetString(PyExc_TypeError, "entry should be a RhythmDBEntry");
553
 
            return NULL;
 
554
                PyErr_SetString(PyExc_TypeError, "entry should be a RhythmDBEntry");
 
555
                return NULL;
554
556
        }
555
557
        
556
558
        ret = rhythmdb_entry_request_extra_metadata(RHYTHMDB_RHYTHMDB(self->obj), entry, property_name);
595
597
        }
596
598
 
597
599
        ret = rhythmdb_entry_gather_metadata(RHYTHMDB_RHYTHMDB(self->obj), entry);
598
 
    
 
600
        
599
601
        if (ret) {
600
602
                PyObject *py_ret = PyDict_New();
601
603
 
643
645
        }
644
646
        rhythmdb_emit_entry_extra_metadata_notify(RHYTHMDB_RHYTHMDB(self->obj), entry, property_name, &val);
645
647
        g_value_unset (&val);
646
 
    
 
648
        
647
649
        Py_INCREF(Py_None);
648
650
        return Py_None;
649
651
}
650
 
 
 
652
%%
 
653
override rhythmdb_query_new noargs
 
654
 
 
655
static PyObject *
 
656
_wrap_rhythmdb_query_new(PyGObject *self)
 
657
{
 
658
    RhythmDBQuery *ret;
 
659
    
 
660
    ret = rhythmdb_query_parse(RHYTHMDB_RHYTHMDB(self->obj), RHYTHMDB_QUERY_END);
 
661
    
 
662
    /* pyg_boxed_new handles NULL checking */
 
663
    return pyg_boxed_new(RHYTHMDB_TYPE_QUERY, ret, TRUE, TRUE);
 
664
}
 
665
%%
 
666
override rhythmdb_query_append kwargs
 
667
 
 
668
static PyObject *
 
669
_wrap_rhythmdb_query_append (PyGObject *self, PyObject *args, PyObject *kwargs)
 
670
{
 
671
        PyObject *obj;
 
672
        RhythmDBQuery *query;
 
673
        int i;
 
674
 
 
675
        if (PyTuple_Size (args) < 2) {
 
676
                PyErr_SetString (PyExc_TypeError, "must have at least two arguments");
 
677
                return NULL;
 
678
        }
 
679
 
 
680
        obj = PyTuple_GetItem (args, 0);
 
681
        if (obj != NULL && pyg_boxed_check (obj, RHYTHMDB_TYPE_QUERY))
 
682
                query = pyg_boxed_get (obj, RhythmDBQuery);
 
683
        else {
 
684
                PyErr_SetString (PyExc_TypeError, "query should be a RhythmDBQuery");
 
685
                return NULL;
 
686
        }
 
687
 
 
688
        for (i = 1; i < PyTuple_Size (args); i++) {
 
689
                PyObject *criteria, *py_type, *obj;
 
690
                RhythmDBQueryType type;
 
691
                RhythmDBPropType propid = -1;
 
692
                GType gtype;
 
693
                GValue value = {0,};
 
694
 
 
695
                criteria = PyTuple_GetItem (args, i);
 
696
                if (!PySequence_Check (criteria)) {
 
697
                        PyErr_SetString (PyExc_TypeError, "criteria object is not a sequence");
 
698
                        return NULL;
 
699
                }
 
700
 
 
701
                py_type = PySequence_GetItem (criteria, 0);
 
702
                if (py_type == NULL) {
 
703
                        PyErr_SetString (PyExc_TypeError, "criteria sequence has no elements");
 
704
                        return NULL;
 
705
                }
 
706
                if (pyg_enum_get_value (RHYTHMDB_TYPE_QUERY_TYPE, py_type, (gpointer)&type)) {
 
707
                        PyErr_SetString (PyExc_TypeError, "criteria operator is invalid");
 
708
                        return NULL;
 
709
                }
 
710
 
 
711
                switch (type) {
 
712
                case RHYTHMDB_QUERY_END:
 
713
                case RHYTHMDB_QUERY_DISJUNCTION:
 
714
                        break;
 
715
                case RHYTHMDB_QUERY_SUBQUERY:
 
716
                        if (PySequence_Size (args) != 2) {
 
717
                                PyErr_SetString (PyExc_TypeError, "wrong number arguments for criteria");
 
718
                        }
 
719
                        g_value_init (&value, G_TYPE_POINTER);
 
720
                        obj = PySequence_GetItem (criteria, 1);
 
721
                        if (obj && pyg_boxed_check (obj, RHYTHMDB_TYPE_QUERY)) {
 
722
                                g_value_set_pointer (&value, pyg_boxed_get ( obj, RhythmDBQuery));
 
723
                        } else {
 
724
                                Py_XDECREF (obj);
 
725
                                g_value_unset (&value);
 
726
                                PyErr_SetString (PyExc_TypeError, "query should be a RhythmDBQuery");
 
727
                                return NULL;
 
728
                        }
 
729
                        Py_DECREF (obj);
 
730
                        break;
 
731
                default:
 
732
                        if (PySequence_Size (criteria) != 3) {
 
733
                                PyErr_SetString (PyExc_TypeError, "wrong number arguments for criteria");
 
734
                                return NULL;
 
735
                        }
 
736
 
 
737
                        obj = PySequence_GetItem (criteria, 1);
 
738
                        if (obj == NULL || pyg_enum_get_value (RHYTHMDB_TYPE_PROP_TYPE, obj, (gpointer)&propid)) {
 
739
                                Py_XDECREF (obj);
 
740
                                PyErr_SetString (PyExc_TypeError, "criteria propid is of wrong type");
 
741
                                return NULL;
 
742
                        }
 
743
                        Py_DECREF (obj);
 
744
 
 
745
                        obj = PySequence_GetItem (criteria, 2);
 
746
                        gtype = pyg_type_from_object ((PyObject *)obj->ob_type);
 
747
                        if (!gtype) {
 
748
                                PyErr_SetString (PyExc_TypeError, "can't map metadata to GType system");
 
749
                                return NULL;
 
750
                        }
 
751
                        g_value_init (&value, gtype);
 
752
                        if (pyg_value_from_pyobject  (&value, obj) < 0) {
 
753
                                Py_XDECREF (obj);
 
754
                                PyErr_SetString (PyExc_TypeError, "could not access value for criteria");
 
755
                                return NULL;
 
756
                        }
 
757
                        Py_DECREF (obj);
 
758
                        break;
 
759
                }
 
760
 
 
761
                rhythmdb_query_append_params (RHYTHMDB_RHYTHMDB (self->obj), query, type, propid, &value);
 
762
                if (G_IS_VALUE (&value))
 
763
                        g_value_unset (&value);
 
764
                Py_DECREF (py_type);
 
765
        }
 
766
        
 
767
        Py_INCREF (Py_None);
 
768
        return Py_None;
 
769
}