|
1 /* |
|
2 * ==================================================================== |
|
3 * contactsmodule.h |
|
4 * |
|
5 * Python API to Series 60 contacts database. |
|
6 * |
|
7 * Copyright (c) 2006-2007 Nokia Corporation |
|
8 * |
|
9 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
10 * you may not use this file except in compliance with the License. |
|
11 * You may obtain a copy of the License at |
|
12 * |
|
13 * http://www.apache.org/licenses/LICENSE-2.0 |
|
14 * |
|
15 * Unless required by applicable law or agreed to in writing, software |
|
16 * distributed under the License is distributed on an "AS IS" BASIS, |
|
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 * See the License for the specific language governing permissions and |
|
19 * limitations under the License. |
|
20 * ==================================================================== |
|
21 */ |
|
22 |
|
23 |
|
24 #include "Python.h" |
|
25 #include "symbian_python_ext_util.h" |
|
26 |
|
27 |
|
28 #include <CNTDB.H> |
|
29 #include <CNTITEM.H> |
|
30 #include <CNTFLDST.H> |
|
31 #include <e32cmn.h> |
|
32 #include <CNTFIELD.H> |
|
33 #include <S32MEM.H> |
|
34 |
|
35 |
|
36 #include <CPbkFieldsInfo.h> |
|
37 |
|
38 |
|
39 //////////////CONSTANTS////////////// |
|
40 |
|
41 |
|
42 _LIT8(KKeyStrUniqueId, "uniqueid"); |
|
43 _LIT8(KKeyStrTitle, "title"); |
|
44 _LIT8(KKeyStrLastModified, "lastmodified"); |
|
45 |
|
46 _LIT8(KKeyStrFieldId, "fieldid"); |
|
47 _LIT8(KKeyStrFieldLocation, "fieldlocation"); |
|
48 _LIT8(KKeyStrFieldName, "fieldname"); |
|
49 |
|
50 |
|
51 #define KContactGroupTypeId 268440330 |
|
52 |
|
53 |
|
54 //////////////TYPE DEFINITION////////////// |
|
55 |
|
56 |
|
57 struct Contact_object; |
|
58 |
|
59 |
|
60 /* |
|
61 * Contact database (database = contacts.open()) |
|
62 */ |
|
63 #define ContactsDb_type ((PyTypeObject*)SPyGetGlobalString("ContactsDbType")) |
|
64 struct ContactsDb_object { |
|
65 PyObject_VAR_HEAD |
|
66 CContactDatabase* contactDatabase; |
|
67 }; |
|
68 |
|
69 |
|
70 /* |
|
71 * Contact (contact = database[unique_contact_id]) |
|
72 */ |
|
73 #define CONTACT_NOT_OPEN 0x0 |
|
74 #define CONTACT_READ_ONLY 0x1 |
|
75 #define CONTACT_READ_WRITE 0x2 |
|
76 #define Contact_type ((PyTypeObject*)SPyGetGlobalString("ContactType")) |
|
77 struct Contact_object { |
|
78 PyObject_VAR_HEAD |
|
79 TInt mode; |
|
80 TContactItemId uniqueID; |
|
81 CContactItem* contactItem; |
|
82 ContactsDb_object* contactsDb; |
|
83 }; |
|
84 |
|
85 |
|
86 /* |
|
87 * Contact iterator (for unique_contact_id in database:) |
|
88 */ |
|
89 #define ContactIterator_type ((PyTypeObject*)SPyGetGlobalString("ContactIteratorType")) |
|
90 struct ContactIterator_object { |
|
91 PyObject_VAR_HEAD |
|
92 TContactIter* iterator; |
|
93 bool initialized; |
|
94 ContactsDb_object* contactsDb; |
|
95 }; |
|
96 |
|
97 |
|
98 /* |
|
99 * Field iterator (for field in contact:) |
|
100 */ |
|
101 #define FieldIterator_type ((PyTypeObject*)SPyGetGlobalString("FieldIteratorType")) |
|
102 struct FieldIterator_object { |
|
103 PyObject_VAR_HEAD |
|
104 Contact_object* contact; |
|
105 bool initialized; |
|
106 TInt iterationIndex; |
|
107 }; |
|
108 |
|
109 |
|
110 //////////////MACRO DEFINITION/////////////// |
|
111 |
|
112 |
|
113 #define ASSERT_CONTACTOPEN \ |
|
114 if (self->mode == CONTACT_NOT_OPEN){ \ |
|
115 PyErr_SetString(PyExc_RuntimeError, "contact not open"); \ |
|
116 return NULL; \ |
|
117 } |
|
118 |
|
119 #define ASSERT_CONTACT_READ_WRITE \ |
|
120 if (self->mode != CONTACT_READ_WRITE || \ |
|
121 self->contactsDb->contactDatabase == NULL) { \ |
|
122 PyErr_SetString(PyExc_RuntimeError, "contact not open for writing"); \ |
|
123 return NULL; \ |
|
124 } |
|
125 |
|
126 #define ASSERT_CONTACTOPEN_FI \ |
|
127 if (self->contact->mode == CONTACT_NOT_OPEN){\ |
|
128 PyErr_SetString(PyExc_RuntimeError, "contact not open"); \ |
|
129 return NULL; \ |
|
130 } |
|
131 |
|
132 |
|
133 //////////////METHODS/////////////// |
|
134 |
|
135 |
|
136 /* |
|
137 * Create new Contact object. |
|
138 * - if (uniqueId == KNullContactId) completely new contact entry is created. |
|
139 * Else only new (python) contact object is created (wrapper object to |
|
140 * existing contact entry that the uniqueId identifies). |
|
141 */ |
|
142 extern "C" PyObject * |
|
143 new_Contact_object(ContactsDb_object* self, TContactItemId uniqueId); |
|
144 |
|
145 |
|
146 /* |
|
147 * Create new ContactsDb object. |
|
148 */ |
|
149 extern "C" PyObject * |
|
150 new_ContactsDb_object(CContactDatabase* contactDatabase); |
|
151 |
|
152 |
|
153 /* |
|
154 * Deletes the CPbkContactItem inside the contact object. |
|
155 */ |
|
156 void Contact_delete_entry(Contact_object* self); |