File: vfs-xfer-progress-info.c

package info (click to toggle)
gnome-python 2.12.4-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,804 kB
  • ctags: 813
  • sloc: sh: 8,593; ansic: 7,747; python: 1,811; makefile: 333; xml: 54
file content (172 lines) | stat: -rw-r--r-- 5,589 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* -*- mode: C; c-basic-offset: 4 -*- */

#include "pygnomevfs-private.h"


PyObject *
pygnome_vfs_xfer_progress_info_getattr(PyGnomeVFSXferProgressInfo *self, char *attr)
{

    if (!self->info) {
	PyErr_SetString(PyExc_RuntimeError, "this XferProgressInfo is no longer valid");
	return NULL;
    }
    
#define add_int_attr(name)				\
    else if (!strcmp(attr, #name)) {			\
	return PyInt_FromLong(self->info->name);	\
    }
#define add_size_attr(name)					\
    else if (!strcmp(attr, #name)) {				\
	return PyLong_FromUnsignedLongLong(self->info->name);	\
    }
#define add_string_attr(name)					\
    else if (!strcmp(attr, #name)) {				\
	if (self->info->name) {					\
	    return PyString_FromString(self->info->name);	\
	} else {						\
	    Py_INCREF(Py_None);					\
	    return Py_None;					\
        }							\
    }
#define add_bool_attr(name)						\
    else if (!strcmp(attr, #name)) {					\
	PyObject *retval = (self->info->name)? Py_True : Py_False;	\
	Py_INCREF(retval);						\
	return retval;							\
    }

    if (!strcmp(attr, "__members__")) {
	return Py_BuildValue("[ssssssssssss]", "status", "vfs_status",
			     "phase", "source_name", "target_name",
			     "file_index", "files_total", "bytes_total",
			     "bytes_copied", "total_bytes_copied", "duplicate_name",
			     "top_level_item");
    }
    add_int_attr(status)
    add_int_attr(vfs_status)
    add_int_attr(phase)
    add_string_attr(source_name)
    add_string_attr(target_name)
    add_int_attr(file_index)
    add_int_attr(files_total)
    add_size_attr(bytes_total)
    add_size_attr(bytes_copied)
    add_size_attr(total_bytes_copied)
    add_string_attr(duplicate_name)
    add_bool_attr(top_level_item)
    else {
	PyObject *name = PyString_FromString(attr);
	PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name);

	Py_DECREF(name);
	return ret;
    }

#undef add_int_attr
#undef add_string_attr
#undef add_size_attr
#undef add_bool_attr
}

int
pygnome_vfs_xfer_progress_info_setattr(PyGnomeVFSXferProgressInfo *self,
				       char *attr, PyObject *value)
{
    if (!self->info) {
	PyErr_SetString(PyExc_RuntimeError, "this XferProgressInfo is no longer valid");
	return -1;
    }

#define add_int_attr(name)									\
    else if (!strcmp(attr, #name)) {								\
	if (!PyInt_Check(value)) {								\
	    PyErr_SetString(PyExc_TypeError, "XferProgressInfo."#name" must be of type 'int'");	\
	    return -1;										\
	}											\
	self->info->name = PyInt_AsLong(value);							\
    }
#define add_size_attr(name)										\
    else if (!strcmp(attr, #name)) {									\
	if (!PyLong_Check(value)) {									\
	    PyErr_SetString(PyExc_TypeError, "XferProgressInfo."#name" must be of type 'long'");	\
	    return -1;											\
	}												\
	self->info->name = PyLong_AsUnsignedLongLong(value);						\
    }
#define add_string_attr(name)							\
    else if (!strcmp(attr, #name)) {						\
	if (value == Py_None) {							\
	    if (self->info->name) g_free(self->info->name);			\
	    self->info->name = NULL;						\
	} else {								\
	    if (!PyString_Check(value)) {					\
		PyErr_SetString(PyExc_TypeError, "XferProgressInfo."#name	\
				" must be of type 'str' or None");		\
		return -1;							\
	    }									\
	    if (self->info->name) g_free(self->info->name);			\
	    self->info->name = g_strdup(PyString_AsString(value));		\
        }									\
    }
#define add_bool_attr(name)				\
    else if (!strcmp(attr, #name)) {			\
	self->info->name = PyObject_IsTrue(value);	\
    }

    if (0) {}
    add_int_attr(status)
    add_int_attr(vfs_status)
    add_int_attr(phase)
    add_string_attr(source_name)
    add_string_attr(target_name)
    add_int_attr(file_index)
    add_int_attr(files_total)
    add_size_attr(bytes_total)
    add_size_attr(bytes_copied)
    add_size_attr(total_bytes_copied)
    add_string_attr(duplicate_name)
    add_bool_attr(top_level_item)
	;
#undef add_int_attr
#undef add_string_attr
#undef add_size_attr
#undef add_bool_attr
    return -1;
}

PyObject *
pygnome_vfs_xfer_progress_info_new(GnomeVFSXferProgressInfo *info)
{
    PyObject *self;
    self = (PyObject *) PyObject_NEW(PyGnomeVFSXferProgressInfo,
				     &PyGnomeVFSXferProgressInfo_Type);
    if (self == NULL) return NULL;
    pygnome_vfs_xfer_progress_info_set(self, info);
    return self;
}

PyTypeObject PyGnomeVFSXferProgressInfo_Type = {
    PyObject_HEAD_INIT(NULL)
    0,                                  /* ob_size */
    "gnomevfs.XferProgressInfo",       /* tp_name */
    sizeof(PyGnomeVFSXferProgressInfo), /* tp_basicsize */
    0,                                  /* tp_itemsize */
    /* methods */
    (destructor)0,                      /* tp_dealloc */
    (printfunc)0,                       /* tp_print */
    (getattrfunc)pygnome_vfs_xfer_progress_info_getattr,  /* tp_getattr */
    (setattrfunc)pygnome_vfs_xfer_progress_info_setattr,  /* tp_setattr */
    (cmpfunc)0,                         /* tp_compare */
    (reprfunc)0,                        /* tp_repr */
    0,                                  /* tp_as_number */
    0,                                  /* tp_as_sequence */
    0,                                  /* tp_as_mapping */
    (hashfunc)0,                        /* tp_hash */
    (ternaryfunc)0,                     /* tp_call */
    (reprfunc)0,                        /* tp_str */
    (getattrofunc)0,                    /* tp_getattro */
    (setattrofunc)0,                    /* tp_setattro */
    0,                                  /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
};