⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contactsmodule.cpp

📁 python s60 1.4.5版本的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

  TRAP(error, titleBuf = self->contactItem->GetContactTitleL());

  if(error != KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);  
  }

  PyObject* ret = Py_BuildValue("u#", titleBuf->Ptr(), titleBuf->Length()); 

  delete titleBuf;
 
  return ret;
}


/*
 * Contact iterator methods.
 */



/*
 * Creates CPbkContactIter object.
 */
CPbkContactIter*
ContactIterator_create_CPbkContactIterL(ContactsDb_object* self)
{
  CPbkContactIter* iter = NULL;
  iter = self->contactEngine->CreateContactIteratorLC();
  CleanupStack::Pop(iter);
  return iter;
}


/*
 * Create new ContactIterator object.
 */
extern "C" PyObject *
new_ContactIterator_object(ContactsDb_object* self, PyObject /**args*/)
{
  ASSERT_DBOPEN

  ContactIterator_object* ci = 
    PyObject_New(ContactIterator_object, ContactIterator_type);

  if (ci == NULL){
    return PyErr_NoMemory();
  }

  // Initialize the struct.
  ci->iterator = NULL;
  ci->initialized = false;
  ci->contactsDb = NULL;
   
  TRAPD(error, {
    ci->iterator = ContactIterator_create_CPbkContactIterL(self);
  });

  if(error != KErrNone){
    PyObject_Del(ci);   
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  ci->contactsDb = self;
  Py_INCREF(ci->contactsDb);
  return (PyObject*)ci;
}


/*
 * Get the uniqueId of the next contact entry object.
 */
extern "C" PyObject *
ContactIterator_next(ContactIterator_object* self, PyObject /**args*/)
{
  ASSERT_DBOPEN_FI

  TContactItemId uniqueId = KNullContactId;
  TInt error = KErrNone;

  if ( self->initialized ){
    TRAP(error, uniqueId = self->iterator->NextL());   
  }else{
    TRAP(error, uniqueId = self->iterator->FirstL());
    self->initialized = true;
  }

  if(error != KErrNone){   
    return SPyErr_SetFromSymbianOSErr(error);
  }

  // Check if the iteration ended.
  if(uniqueId == KNullContactId){
    PyErr_SetObject(PyExc_StopIteration, Py_None);
    return NULL;
  }
  return Py_BuildValue("i", uniqueId);
}


/*
 * Deallocate ContactIterator_object.
 */
extern "C" {
  static void ContactIterator_dealloc(ContactIterator_object *contactIterator)
  {  
    delete contactIterator->iterator;
    contactIterator->iterator = NULL;
  
    Py_DECREF(contactIterator->contactsDb);
    PyObject_Del(contactIterator);
  }
}


/*
 * Field iterator methods.
 */


/*
 * Create new FieldIterator object.
 */
extern "C" PyObject *
new_FieldIterator_object(Contact_object* self, PyObject /**args*/)
{ 
  ASSERT_CONTACTOPEN

  FieldIterator_object* fi = 
    PyObject_New(FieldIterator_object, FieldIterator_type);
  if (fi == NULL){
    return PyErr_NoMemory();
  }

  fi->contact = self;
  fi->initialized = false;
  fi->iterationIndex = 0;
  Py_INCREF(fi->contact);
  return (PyObject*)fi; 
}


/*
 * Deallocate FieldIterator_object.
 */
extern "C" {
  static void FieldIterator_dealloc(FieldIterator_object *fieldIterator)
  {
    Py_DECREF(fieldIterator->contact);
    fieldIterator->contact = NULL;
    PyObject_Del(fieldIterator);  
  }
}


/*
 * Returns data of the next field of the contact.
 */
extern "C" PyObject *
FieldIterator_next_field(FieldIterator_object* self, PyObject /**args*/)
{  
  ASSERT_CONTACTOPEN_FI

  if (!self->initialized) {
    self->iterationIndex = 0;
    self->initialized = true;   
  }

  CPbkFieldArray& fieldArray = self->contact->contactItem->CardFields();

  if(self->iterationIndex < fieldArray.Count()){
    PyObject* ret = 
      Contact_build_field_data_object(self->contact, self->iterationIndex);
    self->iterationIndex++;
    return ret;
  }

  PyErr_SetObject(PyExc_StopIteration, Py_None);
  return NULL;
}



//////////////TYPE SET//////////////


extern "C" {


/*
 * Just return self. Used as a helper function in the iterator
 * protocol.
 */

  PyObject *
  return_self(PyObject* self, PyObject /* *args */)
  {
    Py_INCREF(self);
    return self;
  }

  const static PyMethodDef ContactsDb_methods[] = {
    {"field_types", (PyCFunction)ContactsDb_field_types, METH_NOARGS},
    {"field_info", (PyCFunction)ContactsDb_field_info, METH_VARARGS},
    {"add_contact", (PyCFunction)ContactsDb_add_contact, METH_NOARGS},
    {"find", (PyCFunction)ContactsDb_find, METH_VARARGS},
    {"export_vcards", (PyCFunction)ContactsDb_export_vcards, METH_VARARGS},
    {"import_vcards", (PyCFunction)ContactsDb_import_vcards, METH_VARARGS},
    {"contact_groups", (PyCFunction)ContactsDb_contact_groups, METH_NOARGS},    
    {"contact_group_label", (PyCFunction)ContactsDb_contact_group_label, METH_VARARGS},   
    {"contact_group_set_label", (PyCFunction)ContactsDb_contact_group_set_label, METH_VARARGS},     
    {"contact_group_ids", (PyCFunction)ContactsDb_contact_group_ids, METH_VARARGS},  
    {"add_contact_to_group", (PyCFunction)ContactsDb_add_contact_to_group, METH_VARARGS},   
    {"remove_contact_from_group", (PyCFunction)ContactsDb_remove_contact_from_group, METH_VARARGS}, 
    {"create_contact_group", (PyCFunction)ContactsDb_create_contact_group, METH_NOARGS},   
    {"contact_group_count", (PyCFunction)ContactsDb_contact_group_count, METH_NOARGS}, 
    {"compact", (PyCFunction)ContactsDb_compact, METH_NOARGS},
    {"compact_recommended", (PyCFunction)ContactsDb_compact_recommended, METH_NOARGS},
    {NULL, NULL}  
  };


  const static PyMethodDef ContactIterator_methods[] = {
    {"next", (PyCFunction)ContactIterator_next, METH_NOARGS},
    {NULL, NULL}  
  };


  const static PyMethodDef Contact_methods[] = {
    {"begin", (PyCFunction)Contact_begin, METH_NOARGS, NULL}, 
    {"commit", (PyCFunction)Contact_commit, METH_NOARGS, NULL}, 
    {"rollback", (PyCFunction)Contact_rollback, METH_NOARGS, NULL}, 
    {"add_field", (PyCFunction)Contact_add_field, METH_VARARGS | METH_KEYWORDS, NULL},
    {"modify_field", (PyCFunction)Contact_modify_field, METH_VARARGS | METH_KEYWORDS, NULL}, 
    {"field_info_index", (PyCFunction)Contact_field_info_index, METH_VARARGS, NULL}, 
    {"entry_data", (PyCFunction)Contact_entry_data, METH_NOARGS, NULL},
    {"find_field_indexes", (PyCFunction)Contact_find_field_indexes, METH_VARARGS, NULL},
    {"is_contact_group", (PyCFunction)Contact_is_contact_group, METH_NOARGS}, 
    {NULL, NULL, 0 , NULL}  
  };


  const static PyMethodDef FieldIterator_methods[] = {
    {"next", (PyCFunction)FieldIterator_next_field, METH_NOARGS},
    {NULL, NULL}  
  };


  static PyObject *
  ContactsDb_getattr(ContactsDb_object *op, char *name)
  {
    return Py_FindMethod((PyMethodDef*)ContactsDb_methods, (PyObject *)op, name);
  }


  static PyObject *
  ContactIterator_getattr(ContactIterator_object *op, char *name)
  {
    return Py_FindMethod((PyMethodDef*)ContactIterator_methods, (PyObject *)op, name);
  }


  static PyObject *
  Contact_getattr(Contact_object *op, char *name)
  {
    return Py_FindMethod((PyMethodDef*)Contact_methods, (PyObject *)op, name);
  }


  static PyObject *
  FieldIterator_getattr(FieldIterator_object *op, char *name)
  {
    return Py_FindMethod((PyMethodDef*)FieldIterator_methods, (PyObject *)op, name);
  }


  #ifdef __WINS__
  static PyMappingMethods contactsDb_as_mapping = {
  #else
  static const PyMappingMethods contactsDb_as_mapping = {
  #endif  
    (inquiry)ContactsDb_len,                  /*mp_length*/
    (binaryfunc)ContactsDb_getitem,           /*mp_subscript*/
    (objobjargproc)ContactsDb_ass_sub,        /*mp_ass_subscript*/
  };


  #ifndef SYMBIAN
  PyTypeObject c_ContactsDb_type = {
    PyObject_HEAD_INIT(&PyType_Type)
  #else
  const PyTypeObject c_ContactsDb_type = {
    PyObject_HEAD_INIT(NULL)
  #endif
    0,                                        /*ob_size*/
    "_contacts.ContactsDb",                   /*tp_name*/
    sizeof(ContactsDb_object),                /*tp_basicsize*/
    0,                                        /*tp_itemsize*/
    (destructor)ContactsDb_dealloc,           /*tp_dealloc*/
    0,                                        /*tp_print*/
    (getattrfunc)ContactsDb_getattr,          /*tp_getattr*/
    0,                                        /*tp_setattr*/
    0,                                        /*tp_compare*/
    0,                                        /*tp_repr*/
    0,                                        /*tp_as_number*/
    0,                                        /*tp_as_sequence*/
    &contactsDb_as_mapping,                   /*tp_as_mapping*/
    0,                                        /*tp_hash */
    0,                                        /*tp_call*/
    0,                                        /*tp_str*/
    0,                                        /*tp_getattro*/
    0,                                        /*tp_setattro*/
    0,                                        /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT,                       /*tp_flags*/
    "",                                       /*tp_doc */
    0,                                        /*tp_traverse */
    0,                                        /*tp_clear */
    0,                                        /*tp_richcompare */
    0,                                        /*tp_weaklistoffset */
    (getiterfunc)new_ContactIterator_object,  /*tp_iter */
  };


  static const PyTypeObject c_ContactIterator_type = {
    PyObject_HEAD_INIT(NULL)
    0,                                        /*ob_size*/
    "_contacts.ContactIterator",               /*tp_name*/
    sizeof(ContactIterator_object),           /*tp_basicsize*/
    0,                                        /*tp_itemsize*/
    (destructor)ContactIterator_dealloc,      /*tp_dealloc*/
    0,                                        /*tp_print*/
    (getattrfunc)ContactIterator_getattr,     /*tp_getattr*/
    0,                                        /*tp_setattr*/
    0,                                        /*tp_compare*/
    0,                                        /*tp_repr*/
    0,                                        /*tp_as_number*/
    0,                                        /*tp_as_sequence*/
    0,                                        /*tp_as_mapping*/
    0,                                        /*tp_hash */
    0,                                        /*tp_call*/
    0,                                        /*tp_str*/
    0,                                        /*tp_getattro*/
    0,                                        /*tp_setattro*/
    0,                                        /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT,                       /*tp_flags*/
    "",                                       /*tp_doc */
    0,                                        /*tp_traverse */
    0,                                        /*tp_clear */
    0,                                        /*tp_richcompare */
    0,                                        /*tp_weaklistoffset */
    (getiterfunc)return_self,                 /*tp_iter */
    (iternextfunc)ContactIterator_next,       /*tp_iternext */
  };


  #ifdef __WINS__
  static PyMappingMethods contact_as_mapping = {
  #else
  static const PyMappingMethods contact_as_mapping = {
  #endif
    (inquiry)Contact_len,                     /*mp_length*/
    (binaryfunc)Contact_getitem,              /*mp_subscript*/
    (objobjargproc)Contact_ass_sub,           /*mp_ass_subscript*/
  };


  #ifndef SYMBIAN
  PyTypeObject c_Contact_type = {
    PyObject_HEAD_INIT(&PyType_Type)
  #else
  const PyTypeObject c_Contact_type = {
    PyObject_HEAD_INIT(NULL)
  #endif
    0,                                        /*ob_size*/
    "_contacts.Contact",                       /*tp_name*/
    sizeof(Contact_object),                   /*tp_basicsize*/
    0,                                        /*tp_itemsize*/
    (destructor)Contact_dealloc,              /*tp_dealloc*/
    0,                                        /*tp_print*/
    (getattrfunc)Contact_getattr,             /*tp_getattr*/
    0,                                        /*tp_setattr*/
    0,                                        /*tp_compare*/
    0,                                        /*tp_repr*/
    0,                                        /*tp_as_number*/
    0,                                        /*tp_as_sequence*/
    &contact_as_mapping,                      /*tp_as_mapping*/
    0,                                        /*tp_hash */
    0,                                        /*tp_call*/
    (reprfunc)Contact_repr_str,               /*tp_str*/
    0,                                        /*tp_getattro*/
    0,                                        /*tp_setattro*/
    0,                                        /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT,                       /*tp_flags*/
    "",                                       /*tp_doc */
    0,                                        /*tp_traverse */
    0,                                        /*tp_clear */
    0,                                        /*tp_richcompare */
    0,                                        /*tp_weaklistoffset */
    (getiterfunc)new_FieldIterator_object,    /*tp_iter */
  };


  static const PyTypeObject c_FieldIterator_type = {
    PyObject_HEAD_INIT(NULL)
    0,                                        /*ob_size*/
    "_contacts.FieldIterator",                 /*tp_name*/
    sizeof(FieldIterator_object),             /*tp_basicsize*/
    0,                                        /*tp_itemsize*/
    (destructor)FieldIterator_dealloc,        /*tp_dealloc*/
    0,                                        /*tp_print*/
    (getattrfunc)FieldIterator_getattr,       /*tp_getattr*/
    0,                                        /*tp_setattr*/
    0,                                        /*tp_compare*/
    0,                                        /*tp_repr*/
    0,                                        /*tp_as_number*/
    0,                                        /*tp_as_sequence*/
    0,                                        /*tp_as_mapping*/
    0,                                        /*tp_hash */
    0,                                        /*tp_call*/
    0,                                        /*tp_str*/
    0,                                        /*tp_getattro*/
    0,                                        /*tp_setattro*/
    0,                                        /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT,                       /*tp_flags*/
    "",                                       /*tp_doc */
    0,                                        /*tp_traverse */
    0,                                        /*tp_clear */
    0,                                        /*tp_richcompare */
    0,                                        /*tp_weaklistoffset */
    (getiterfunc)return_self,                 /*tp_iter */
    (iternextfunc)FieldIterator_next_field,   /*tp_iternext */
  };


} //extern C


//////////////INIT//////////////


extern "C" {
  static const PyMethodDef contacts_methods[] = {
    {"open", (PyCFunction)open_db, METH_VARARGS, NULL},
    {NULL,              NULL}           /* sentinel */
  };

  DL_EXPORT(void) initcontacts(void)
  {
    PyTypeObject* contacts_db_type = PyObject_New(PyTypeObject, &PyType_Type);
    *contacts_db_type = c_ContactsDb_type;
    contacts_db_type->ob_type = &PyType_Type;
    SPyAddGlobalString("ContactsDbType", (PyObject*)contacts_db_type);

    PyTypeObject* contact_iterator_type = PyObject_New(PyTypeObject, &PyType_Type);
    *contact_iterator_type = c_ContactIterator_type;
    contact_iterator_type->ob_type = &PyType_Type;
    SPyAddGlobalString("ContactIteratorType", (PyObject*)contact_iterator_type);

    PyTypeObject* contact_type = PyObject_New(PyTypeObject, &PyType_Type);
    *contact_type = c_Contact_type;
    contact_type->ob_type = &PyType_Type;
    SPyAddGlobalString("ContactType", (PyObject*)contact_type);

    P

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -