2013-09-04 16 views

답변

2

QContactManager이 3 개 신호가 있습니다

void QContactManager::contactsAdded (const QList<QContactLocalId> & contactIds); 
void QContactManager::contactsChanged (const QList<QContactLocalId> & contactIds); 
void QContactManager::contactsRemoved (const QList<QContactLocalId> & contactIds); 

는 알림을 수신하기 위해 그들에게 당신의 슬롯을 연결합니다.

+0

감사 Sashoalm하지만 실제로 우리가 추가 할 때마다, 팝업을 보여 삭제하거나 업데이트 접촉하고 싶다. 그러면 내가 어떻게 할 수 있니? 이걸 좀 도와 주실 래요? –

+0

사용 [QMessageBox (http://harmattan-dev.nokia.com/docs/library/html/qt4/qmessagebox.html) 팝업을 표시합니다. 내 대답은 효과가 있습니까? 새 연락처가 추가/삭제/업데이트되면 슬롯이 호출됩니까? 나는 분명히 시험 할 수 없을 정도로 블랙 베리가 없다. – sashoalm

+0

무슨 일이 일어 났습니까? 답변이 당신에게 효과가 있습니까? 답변 중 하나를 수락 하시겠습니까? – sashoalm

0

--- HPP 파일 ------

API : BB :: 핌 :: 연락처

BB/PIM/연락처/ContactService에서

BB/PIM/연락처/연락

BB/PIM/연락처/ContactAttributeBuilder

BB/PIM/연락처/ContactBuilder ..

예를

#include <bb/pim/contacts/ContactService> 

#include <QtCore/QObject> 
class ContactEditor : public QObject 
{ 
    Q_OBJECT 

    // The data properties of the contact that is created or updated 
    Q_PROPERTY(QString firstName READ firstName WRITE setFirstName NOTIFY firstNameChanged) 
    Q_PROPERTY(QString lastName READ lastName WRITE setLastName NOTIFY lastNameChanged) 
    Q_PROPERTY(QDateTime birthday READ birthday WRITE setBirthday NOTIFY birthdayChanged) 
    Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged) 

    // Defines whether the editor is in 'create' or 'edit' mode 
    Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged) 

    Q_ENUMS(Mode) 

public: 
    /** 
    * Describes the mode of the contact editor. 
    * The mode information are used to adapt the behavior of the editor and 
    * provide hints to the UI. 
    */ 
    enum Mode { 
     CreateMode, 
     EditMode 
    }; 

    ContactEditor(bb::pim::contacts::ContactService *service, QObject *parent = 0); 

    void setMode(Mode mode); 
    Mode mode() const; 

public Q_SLOTS: 
    /** 
    * Loads the contact with the given ID. 
    */ 
    void loadContact(bb::pim::contacts::ContactId contactId); 

    /** 
    * Save the currently loaded contact if in 'edit' mode or creates a new one 
    * if in 'create' mode. 
    */ 
    void saveContact(); 

    /** 
    * Resets all fields of the contact editor. 
    */ 
    void reset(); 

Q_SIGNALS: 
    // The change notification signals of the properties 
    void firstNameChanged(); 
    void lastNameChanged(); 
    void birthdayChanged(); 
    void emailChanged(); 
    void modeChanged(); 

private: 
    // The accessor methods of the properties 
    void setFirstName(const QString &firstName); 
    QString firstName() const; 

    void setLastName(const QString &lastName); 
    QString lastName() const; 

    void setBirthday(const QDateTime &birthday); 
    QDateTime birthday() const; 

    void setEmail(const QString &email); 
    QString email() const; 

    // The central object to access the contact service 
    bb::pim::contacts::ContactService *m_contactService; 

    // The ID of the currently loaded contact (if in 'edit' mode) 
    bb::pim::contacts::ContactId m_contactId; 

    // The property values 
    QString m_firstName; 
    QString m_lastName; 
    QDateTime m_birthday; 
    QString m_email; 

    Mode m_mode; 
}; 
//! [0] 

#endif 

----- CPP 파일 -----을 folwing 참조 같은

using namespace bb::pim::contacts; 

//! [0] 
/** 
* A helper method to update a single attribute on a Contact object. 
* It first deletes the old attribute (if it exists) and adds the attribute with the 
* new value afterwards. 
*/ 
template <typename T> 
static void updateContactAttribute(ContactBuilder &builder, const Contact &contact, 
             AttributeKind::Type kind, AttributeSubKind::Type subKind, 
             const T &value) 
{ 
    // Delete previous instance of the attribute 
    QList<ContactAttribute> attributes = contact.filteredAttributes(kind); 
    foreach (const ContactAttribute &attribute, attributes) { 
     if (attribute.subKind() == subKind) 
      builder.deleteAttribute(attribute); 
    } 

    // Add new instance of the attribute with new value 
    builder.addAttribute(ContactAttributeBuilder() 
         .setKind(kind) 
         .setSubKind(subKind) 
         .setValue(value)); 
} 
//! [0] 

//! [1] 
ContactEditor::ContactEditor(ContactService *service, QObject *parent) 
    : QObject(parent) 
    , m_contactService(service) 
    , m_contactId(-1) 
    , m_birthday(QDateTime::currentDateTime()) 
    , m_mode(CreateMode) 
{ 
} 
//! [1] 

//! [2] 
void ContactEditor::loadContact(ContactId contactId) 
{ 
    m_contactId = contactId; 

    // Load the contact from the persistent storage 
    const Contact contact = m_contactService->contactDetails(m_contactId); 

    // Update the properties with the data from the contact 
    m_firstName = contact.firstName(); 
    m_lastName = contact.lastName(); 

    m_birthday = QDateTime::currentDateTime(); 
    const QList<ContactAttribute> dateAttributes = contact.filteredAttributes(AttributeKind::Date); 
    foreach (const ContactAttribute &dateAttribute, dateAttributes) { 
     if (dateAttribute.subKind() == AttributeSubKind::DateBirthday) 
      m_birthday = dateAttribute.valueAsDateTime(); 
    } 

    m_email.clear(); 
    const QList<ContactAttribute> emails = contact.emails(); 
    if (!emails.isEmpty()) 
     m_email = emails.first().value(); 

    // Emit the change notifications 
    emit firstNameChanged(); 
    emit lastNameChanged(); 
    emit birthdayChanged(); 
    emit emailChanged(); 
} 
//! [2] 

//! [3] 
void ContactEditor::saveContact() 
{ 
    if (m_mode == CreateMode) { 
     // Create a builder to assemble the new contact 
     ContactBuilder builder; 

     // Set the first name 
     builder.addAttribute(ContactAttributeBuilder() 
          .setKind(AttributeKind::Name) 
          .setSubKind(AttributeSubKind::NameGiven) 
          .setValue(m_firstName)); 

     // Set the last name 
     builder.addAttribute(ContactAttributeBuilder() 
          .setKind(AttributeKind::Name) 
          .setSubKind(AttributeSubKind::NameSurname) 
          .setValue(m_lastName)); 

     // Set the birthday 
     builder.addAttribute(ContactAttributeBuilder() 
          .setKind(AttributeKind::Date) 
          .setSubKind(AttributeSubKind::DateBirthday) 
          .setValue(m_birthday)); 

     // Set the email address 
     builder.addAttribute(ContactAttributeBuilder() 
          .setKind(AttributeKind::Email) 
          .setSubKind(AttributeSubKind::Other) 
          .setValue(m_email)); 

     // Save the contact to persistent storage 
     m_contactService->createContact(builder, false); 

    } else if (m_mode == EditMode) { 
     // Load the contact from persistent storage 
     Contact contact = m_contactService->contactDetails(m_contactId); 
     if (contact.id()) { 
      // Create a builder to modify the contact 
      ContactBuilder builder = contact.edit(); 

      // Update the single attributes 
      updateContactAttribute<QString>(builder, contact, AttributeKind::Name, AttributeSubKind::NameGiven, m_firstName); 
      updateContactAttribute<QString>(builder, contact, AttributeKind::Name, AttributeSubKind::NameSurname, m_lastName); 
      updateContactAttribute<QDateTime>(builder, contact, AttributeKind::Date, AttributeSubKind::DateBirthday, m_birthday); 
      updateContactAttribute<QString>(builder, contact, AttributeKind::Email, AttributeSubKind::Other, m_email); 

      // Save the updated contact back to persistent storage 
      m_contactService->updateContact(builder); 
     } 
    } 
} 
//! [3] 

//! [4] 
void ContactEditor::reset() 
{ 
    // Reset all properties 
    m_firstName.clear(); 
    m_lastName.clear(); 
    m_birthday = QDateTime::currentDateTime(); 
    m_email.clear(); 

    // Emit the change notifications 
    emit firstNameChanged(); 
    emit lastNameChanged(); 
    emit birthdayChanged(); 
    emit emailChanged(); 
} 
//! [4] 

void ContactEditor::setFirstName(const QString &firstName) 
{ 
    if (m_firstName == firstName) 
     return; 

    m_firstName = firstName; 
    emit firstNameChanged(); 
} 

QString ContactEditor::firstName() const 
{ 
    return m_firstName; 
} 

void ContactEditor::setLastName(const QString &lastName) 
{ 
    if (m_lastName == lastName) 
     return; 

    m_lastName = lastName; 
    emit lastNameChanged(); 
} 

QString ContactEditor::lastName() const 
{ 
    return m_lastName; 
} 

void ContactEditor::setBirthday(const QDateTime &birthday) 
{ 
    if (m_birthday.date() == birthday.date()) 
     return; 

    m_birthday = birthday; 
    emit birthdayChanged(); 
} 

QDateTime ContactEditor::birthday() const 
{ 
    return m_birthday; 
} 

void ContactEditor::setEmail(const QString &email) 
{ 
    if (m_email == email) 
     return; 

    m_email = email; 
    emit emailChanged(); 
} 

QString ContactEditor::email() const 
{ 
    return m_email; 
} 

void ContactEditor::setMode(Mode mode) 
{ 
    if (m_mode == mode) 
     return; 

    m_mode = mode; 
    emit modeChanged(); 
} 

ContactEditor::Mode ContactEditor::mode() const 
{ 
    return m_mode; 
} 
+0

Rajesh에게 감사하지만이 코드를 추가했지만 응용 프로그램의 연락처를 업데이트 한 다음 네이티브 연락처에 반영했습니다. 실제로 네이티브에서 연락처를 추가, 삭제 또는 업데이트 할 때 대화 상자 나 다른 것과 비슷한 팝업을 표시하려고합니다. 연락처 신청 .... 그의 생각에 그의 –

+1

사용 경고 알림. 내 다른 대답을 확인 – svmrajesh

+0

안녕하세요 rajesh. 하나의 샘플 앱을 개발 중이며 CallLog 코어 애플리케이션과 통합하고 싶습니다. 신청서에 전화 기록을 보내고 싶습니다. 나 좀 도와 줄래? –

0

사용 경고 ->

경고 (TR ("연락처 저장 됨"));

경고 (TR()는 "접점 첨가"); (() "연락처 삭제"TR)

경고;

샘플은 다음을 참조

----------- QML --------------

버튼 { HorizontalAlignment로 : HorizontalAlignment.Center

 text: qsTr("Update") 

     onClicked: { 
      _app.updateRecord(idUpdateTextField.text, firstNameUpdateTextField.text, lastNameUpdateTextField.text); 
     } 
    } 

----------------- CPP 파일 -------------------

부울 App :: updateRecord (const QString & 고객 ID는 const를 QString & firstName을, const를 QString &과 lastName) {

bool intConversionGood = false; 
const int customerIDKey = customerID.toInt(&intConversionGood); 
if (!intConversionGood) { 
    alert(tr("You must provide valid integer key.")); 
    return false; 
} 


QSqlDatabase database = QSqlDatabase::database(); 

QSqlQuery query(database); 
const QString sqlCommand = "UPDATE customers " 
          " SET firstName = :firstName, lastName = :lastName" 
          " WHERE customerID = :customerID"; 
query.prepare(sqlCommand); 
query.bindValue(":firstName", firstName); 
query.bindValue(":lastName", lastName); 
query.bindValue(":customerID", customerIDKey); 


bool updated = false; 
if (query.exec()) { 

    if (query.numRowsAffected() > 0) { 
     alert(tr("Customer with id=%1 was updated.").arg(customerID)); 
     updated = true; 
    } else { 
     alert(tr("Customer with id=%1 was not found.").arg(customerID)); 
    } 
+0

나는이 해결책이 당신의 질문을 해결할 것이라고 생각한다. – svmrajesh