Split the playlist in a generic songlist and playlist.
[python-gnt.git] / gnttree.override
blob48f68368d74b9808310ee3d579f2b20ac0b253a1
1 /**
2  * pygnt- Python bindings for the GNT toolkit.
3  * Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@pidgin.im>
4  *
5  *   gnttree.override: overrides for the tree widget.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301
20  * USA
21  */
23 headers
24 #include "common.h"
26 ignore 
27 gnt_tree_create_row
28 gnt_tree_create_row_from_list
29 gnt_tree_new_with_columns
30 gnt_tree_add_row_last
32 override gnt_tree_new
33 static void
34 deref_key(gpointer data)
36         Py_DECREF((PyGObject*)data);
39 static int
40 _wrap_gnt_tree_new(PyGObject *self, PyObject *args, PyObject *kwargs)
42         static char* kwlist[] = { NULL };
44         if (!PyArg_ParseTupleAndKeywords(args, kwargs,
45                                 ":gnt.Tree.__init__",
46                                 kwlist))
47                 return -1;
49         pygobject_constructv(self, 0, NULL);
50         if (!self->obj) {
51                 PyErr_SetString(
52                                 PyExc_RuntimeError, 
53                                 "could not create gnt.Tree object");
54                 return -1;
55         }
56         g_object_set(G_OBJECT(self->obj), "columns", 1, NULL);
57         gnt_tree_set_hash_fns(GNT_TREE(self->obj), g_direct_hash, g_direct_equal, deref_key);
58         return 0;
61 override gnt_tree_get_selection_text_list noargs
62 static PyObject *
63 _wrap_gnt_tree_get_selection_text_list(PyGObject *self)
65         GList *list = gnt_tree_get_selection_text_list(GNT_TREE(self->obj));
66         return create_pyobject_from_string_list(list);
69 override gnt_tree_get_rows noargs
70 static PyObject *
71 _wrap_gnt_tree_get_rows(PyGObject *self)
73         GList *list = gnt_tree_get_rows(GNT_TREE(self->obj));
74         PyObject *py_list;
75         if (list == NULL) {
76                 Py_INCREF(Py_None);
77                 return Py_None;
78         }
79         if ((py_list = PyList_New(0)) == NULL) {
80                 return NULL;
81         }
82         while (list) {
83                 PyObject *obj = list->data;
84                 PyList_Append(py_list, obj);
85                 list = list->next;
86         }
87         return py_list;
90 override gnt_tree_add_row_after
91 static PyObject *
92 _wrap_gnt_tree_add_row_after(PyGObject *self, PyObject *args)
94         static char *kwlist[] = {"key", "row", "parent", "bigbro", NULL};
95         PyObject *py_list;
96         gpointer key, parent, bigbro = NULL;
97         int len, i;
98         GList *list = NULL;
99         GntTreeRow *row;
100         gboolean insert_last = FALSE;
102         if (!PyArg_ParseTuple(args,
103                                 "O!OO|O:GntTree.add_row_after",
104                                 &PyGObject_Type, &key,
105                                 &py_list,
106                                 &parent,
107                                 &bigbro))
108                 return NULL;
110         len = PySequence_Length(py_list);
111         for (i = 0; i < len; i++) {
112                 PyObject *item = PySequence_GetItem(py_list, i);
113                 if (!pygobject_check(item, &PyString_Type)) {
114                         PyErr_SetString(PyExc_TypeError,
115                                         "column_list members must be strings");
116                         Py_DECREF(item);
117                         return NULL;
118                 }
119                 list = g_list_prepend(list, PyString_AsString(item));
120                 Py_DECREF(item);
121         }
123         if (parent == Py_None)
124                 parent = NULL;
125         if (bigbro == Py_None)
126                 bigbro = NULL;
127         else if (bigbro == NULL)
128                 insert_last = TRUE;
130         list = g_list_reverse(list);
131         row = gnt_tree_create_row_from_list(GNT_TREE(self->obj), list);
132         if (insert_last)
133                 gnt_tree_add_row_last(GNT_TREE(self->obj),
134                                 key, row, parent);
135         else
136                 gnt_tree_add_row_after(GNT_TREE(self->obj),
137                                 key, row,
138                                 parent, bigbro);
139         Py_INCREF((PyGObject*)key);
140         g_list_free(list);
142         Py_INCREF(Py_None);
143         return Py_None;
146 override gnt_tree_get_selection_data noargs
147 static PyObject *
148 _wrap_gnt_tree_get_selection_data(PyGObject *self)
150         PyObject *ret = gnt_tree_get_selection_data(GNT_TREE(self->obj));
151         if (!ret)
152                 ret = Py_None;
153         Py_INCREF(ret);
154         return ret;
157 override gnt_tree_change_text kwargs
158 static PyObject *
159 _wrap_gnt_tree_change_text(PyGObject *self, PyObject *args, PyObject *kwargs)
161         static char *kwlist[] = { "key", "colno", "text", NULL };
162         char *text;
163         int colno;
164         gpointer key;
166         if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!is:GntTree.change_text", kwlist, &PyGObject_Type, &key, &colno, &text))
167                 return NULL;
169         gnt_tree_change_text(GNT_TREE(self->obj), key, colno, text);
171         Py_INCREF(Py_None);
172         return Py_None;
175 override gnt_tree_set_row_flags
176 static PyObject *
177 _wrap_gnt_tree_set_row_flags(PyGObject *self, PyObject *args, PyObject *kwargs)
179         static char *kwlist[] = { "key", "flag", NULL };
180         int flag;
181         gpointer key;
183         if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!i:GntTree.set_row_flags", kwlist, &PyGObject_Type, &key, &flag))
184                 return NULL;
186         gnt_tree_set_row_flags(GNT_TREE(self->obj), key, flag);
188         Py_INCREF(Py_None);
189         return Py_None;
192 override gnt_tree_remove
193 static PyObject *
194 _wrap_gnt_tree_remove(PyGObject *self, PyObject *args, PyObject *kwargs)
196         static char *kwlist[] = { "key", NULL };
197         gpointer key;
199         if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:GntTree.remove", kwlist, &PyGObject_Type, &key))
200                 return NULL;
202         gnt_tree_remove(GNT_TREE(self->obj), key);
204         Py_INCREF(Py_None);
205         return Py_None;
208 override gnt_tree_set_selected
209 static PyObject *
210 _wrap_gnt_tree_set_selected(PyGObject *self, PyObject *args)
212         gpointer key;
213         if (!PyArg_ParseTuple(args, "O!:GntTree.set_selected", &PyGObject_Type, &key)) {
214                 return NULL;
215         }
216         gnt_tree_set_selected(GNT_TREE(self->obj), key);
217         Py_INCREF(Py_None);
218         return Py_None;
221 ignore gnt_tree_set_compare_func
223 define GntTree.enable_sort noargs
226   Both p1 and p2 are expected to be GObjects, with a 'compare_func' property.
227  */
228 static int
229 custom_compare_func(gconstpointer p1, gconstpointer p2)
231         PyObject *compare_func;
232         PyObject *ret, *params;
233         const PyGObject *o1, *o2;
234         int retval;
235         PyTypeObject *class;
237         o1 = p1;
238         o2 = p2;
240         g_return_val_if_fail(G_IS_OBJECT(o1->obj), -1);
241         g_return_val_if_fail(G_IS_OBJECT(o2->obj), -1);
243         class = pygobject_lookup_class(G_TYPE_FROM_INSTANCE(o1->obj));
244         compare_func = PyDict_GetItemString(class->tp_dict, "COMPARE_FUNC");
245         g_return_val_if_fail(compare_func && PyCallable_Check(compare_func), -1);
247         params = PyTuple_New(2);
248         Py_INCREF((PyObject*)o1);
249         PyTuple_SetItem(params, 0, (PyObject*)o1);
250         Py_INCREF((PyObject*)o2);
251         PyTuple_SetItem(params, 1, (PyObject*)o2);
252         ret = PyObject_CallObject(compare_func, params);
253         retval = (int)PyInt_AsLong(ret);
255         Py_DECREF(params);
256         Py_DECREF(ret);
257         return retval;
260 static PyObject *
261 _wrap_gnt_tree_enable_sort(PyGObject *self)
263         gnt_tree_set_compare_func(GNT_TREE(self->obj), custom_compare_func);
265         Py_INCREF(Py_None);
266         return Py_None;