2013-09-04 6 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/PIM/контакты/ContactService

бб/ПИМ/контакты/Контактная информация

бб/ПИМ/контакты/ContactAttributeBuilder

бб/ПИМ/контакты/ContactBuilder ..

см folwing пример

#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 файл -----

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, но я просмотрел этот код, но добавил, обновлял контакты в нашем приложении, а затем отражал его в основном контакте. На самом деле я хочу показать всплывающее диалоговое окно или что-нибудь еще, когда мы добавляем, удаляем или обновляем контакт в Native свяжитесь с нами .... у вас есть идея для его –

+1

использовать оповещение уведомления .. проверьте мой другой ответ – svmrajesh

+0

эй rajesh. Я разрабатываю одно примерное приложение и в нем хочу интегрироваться с основным приложением CallLog. Я хочу получить историю звонков в своем приложении. Вы, пожалуйста, поможете мне? –

0

использовать оповещения, как этот ->

оповещения (Tr («контакт сохранен»));

alert (tr ("contact added"));

предупреждение (tr («контакт удален»));

см Следующий образец

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

Кнопка { HorizontalAlignment: HorizontalAlignment.Center

 text: qsTr("Update") 

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

----------------- CPP файл -------------------

BOOL App :: updateRecord (const QString & клиент ID, Const QString & ПгвЬЫате, 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

Смежные вопросы