contactengine/contactsengine.cpp
author John Kern <johnk@symbian.org>
Thu, 26 Aug 2010 14:34:34 -0700
changeset 40 edc0144719a1
parent 38 6dfc2ca6334b
child 41 b56d7e268634
permissions -rwxr-xr-x
removed invariant from data() and rowCount(). Performance should be ok now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     1
#include <QContact>
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     2
#include <QContactAddress>
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
     3
#include <QContactName>
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     4
#include <QContactOrganization>
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     5
#include <QContactPhoneNumber>
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     6
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
     7
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     8
#include "contactsengine.h"
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
    10
#include <QDebug>
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
    11
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
using namespace QtMobility;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
ContactsEngine::ContactsEngine(QObject *parent) :
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    15
    QAbstractListModel(parent)
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    16
{
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    17
    this->m_manager = 0;
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    18
}
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
    19
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    20
ContactsEngine::~ContactsEngine()
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    21
{
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
    22
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    23
}
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
    24
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    25
void ContactsEngine::createManagerSF()
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    26
{
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    27
    // let's try the default.
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    28
    this->m_manager_sf = new QContactManager("memory");
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    29
    // Debugger confirms this is hit, Qt Simulator doesn't display QMessageBox but
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    30
    // the associated control window shows it is the top level window.
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    31
    // emit this->errorOccurred(this->errorString(this->m_manager_sf->error()));
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    32
}
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    33
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    34
QString ContactsEngine::errorString(QContactManager::Error aErr)
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    35
{
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    36
    QString err;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    37
    switch(aErr)
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    38
    {
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    39
    case QContactManager::NoError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    40
        err = "No Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    41
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    42
    case QContactManager::DoesNotExistError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    43
        err = "Does Not Exist Error ";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    44
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    45
    case QContactManager::AlreadyExistsError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    46
        err = "Already Exists Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    47
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    48
    case QContactManager::InvalidDetailError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    49
        err = "Invalid Detail Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    50
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    51
    case QContactManager::InvalidRelationshipError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    52
        err = "Invalid Relationship Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    53
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    54
    case QContactManager::LockedError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    55
        err = "Locked Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    56
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    57
    case QContactManager::DetailAccessError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    58
        err = "Detail Access Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    59
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    60
    case QContactManager::PermissionsError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    61
        err = "Permissions Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    62
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    63
    case QContactManager::OutOfMemoryError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    64
        err = "Out Of Memory Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    65
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    66
    case QContactManager::NotSupportedError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    67
        err = "Not Supported Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    68
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    69
    case QContactManager::BadArgumentError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    70
        err = "Bad Argument Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    71
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    72
    case QContactManager::UnspecifiedError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    73
        err = "Unspecified Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    74
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    75
    case QContactManager::VersionMismatchError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    76
        err = "Version Mismatch Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    77
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    78
    case QContactManager::LimitReachedError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    79
        err = "Limit Reached Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    80
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    81
    case QContactManager::InvalidContactTypeError:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    82
        err = "Invalid Contact Type Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    83
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    84
    default:
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    85
        err = "Unknown Error";
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    86
        break;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    87
    }
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    88
    return err;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
    89
}
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    90
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    91
void ContactsEngine::createManager()
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    92
{
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    93
    // adapted from http://wiki.forum.nokia.com/index.php/Finding_contact_manager_in_Qt
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    94
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    95
    // Get list of different contact back-ends
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    96
    QStringList availableManagers = QContactManager::availableManagers();
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    97
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    98
    QList<QContactLocalId> contactIds;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
    99
    // Try to find contacts from some back-end
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   100
    while (!availableManagers.isEmpty()) {
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   101
        // Get some manager
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   102
        m_manager = new QContactManager(availableManagers.first());
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   103
        availableManagers.removeFirst();
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   104
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   105
        // Contacts exists?
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   106
        contactIds = m_manager->contactIds();
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   107
        if (!contactIds.isEmpty()) {
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   108
            // Contact found
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   109
            availableManagers.clear();
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   110
            break;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   111
        }
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   112
        else {
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   113
            // Not found, try the next manager
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   114
            delete m_manager;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   115
            m_manager = 0;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   116
        }
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   117
    }
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   118
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   119
    // Use default if no contact found from any back-end
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   120
    if (!m_manager) {
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   121
        m_manager = new QContactManager();
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   122
    }
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   123
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   124
    if(this->m_manager && (this->m_manager->error() == QContactManager::NoError ))
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   125
    {
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   126
        this->m_allContacts = this->m_manager->contacts();
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   127
    }
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   128
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   129
    // Show message to the user
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   130
    QString msg = QString("Manager %1 created, that has %2 contacts")
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   131
                  .arg(m_manager->managerName()).arg(contactIds.count());
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   132
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   133
   // emit errorOccurred(msg);
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   134
}
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   135
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   136
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   137
void ContactsEngine::setManager(const QString & aMgrName)
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   138
{
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   139
   // noop
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   140
}
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   141
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   142
void ContactsEngine::populateAddresses()
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   143
{
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   144
    QContact *contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   145
    QContactOrganization *dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   146
    QStringList departmentName;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   147
    QContactPhoneNumber *number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   148
    QContactAddress *address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   149
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   150
    // this source is open source. Do not put private numbers in here.
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   151
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   152
    // emergency numbers
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   153
    // fire Foster City
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   154
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   155
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   156
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   157
    departmentName << "Foster City Fire department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   158
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   159
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   160
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   161
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   162
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   163
    number->setNumber("+1-650-286-3350");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   164
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   165
    //fire.setPreferredDetail("DialAction",number); //doesn't compile. Has it been depreciated?
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   166
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   167
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   168
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   169
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   170
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   171
    address->setLocality("Foster City"); // RFC 2426 - defines the difference locality and region.
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   172
    address->setStreet("1040 East Hillsdale Boulevard");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   173
    address->setPostcode("94404");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   174
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   175
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   176
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   177
    qDebug() << "cm sf status: " << this->errorString(this->m_manager_sf->error());
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   178
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   179
    // Note that the caller retains ownership of the detail.
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   180
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   181
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   182
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   183
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   184
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   185
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   186
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   187
    // police - foster city
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   188
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   189
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   190
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   191
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   192
    departmentName << "Foster City Police department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   193
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   194
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   195
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   196
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   197
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   198
    number->setNumber("+1(650)286-3300");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   199
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   200
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   201
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   202
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   203
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   204
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   205
    address->setLocality("Foster City");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   206
    address->setStreet("1030 East Hillsdale Boulevard");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   207
    address->setPostcode("94404");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   208
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   209
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   210
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   211
    qDebug() << "cm sf status: " << this->errorString(this->m_manager_sf->error());
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   212
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   213
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   214
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   215
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   216
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   217
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   218
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   219
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   220
    // taxi - Foster City
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   221
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   222
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   223
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   224
    departmentName << "Foster City Yellow Cab";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   225
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   226
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   227
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   228
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   229
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   230
    number->setNumber("+1(650)367-9999");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   231
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   232
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   233
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   234
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   235
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   236
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   237
    address->setLocality("Foster City");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   238
    address->setStreet("1055 foster city blvd");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   239
    address->setPostcode("94404");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   240
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   241
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   242
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   243
    qDebug() << "cm sf status: " << this->errorString(this->m_manager_sf->error());
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   244
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   245
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   246
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   247
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   248
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   249
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   250
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   251
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   252
    // fire  - Menlo Park
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   253
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   254
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   255
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   256
    departmentName << "Menlo Park fire department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   257
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   258
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   259
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   260
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   261
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   262
    number->setNumber("+1(650)688-8400");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   263
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   264
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   265
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   266
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   267
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   268
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   269
    address->setLocality("Menlo Park");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   270
    address->setStreet("170 Middlefield Road");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   271
    address->setPostcode("94025");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   272
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   273
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   274
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   275
    qDebug() << "cm sf status: " << this->errorString(this->m_manager_sf->error());
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   276
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   277
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   278
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   279
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   280
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   281
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   282
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   283
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   284
    //701 Laurel Street, Menlo Park, CA? -
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   285
    // police  - Menlo Park
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   286
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   287
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   288
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   289
    departmentName << "Menlo Park police department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   290
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   291
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   292
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   293
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   294
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   295
    number->setNumber("+1(650)858-3328");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   296
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   297
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   298
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   299
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   300
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   301
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   302
    address->setLocality("Menlo Park");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   303
    address->setStreet("701 Laurel Street");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   304
    address->setPostcode("94025");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   305
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   306
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   307
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   308
    qDebug() << "cm sf status: " << this->errorString(this->m_manager_sf->error());
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   309
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   310
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   311
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   312
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   313
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   314
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   315
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   316
}
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   317
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   318
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   319
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   320
QStringList ContactsEngine::dataSources()
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   321
{
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   322
     QStringList availableManagers = QContactManager::availableManagers();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   323
     availableManagers.removeAll("invalid");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   324
     foreach(QString managerName, availableManagers) {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   325
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   326
         QMap<QString, QString> params;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   327
         QString managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   328
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   329
         // Add some parameters to SIM backend so that we can use
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   330
         // all the stores.
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   331
         if (managerName == "symbiansim") {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   332
             availableManagers.removeAll("symbiansim");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   333
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   334
             availableManagers.append("symbiansim:adn");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   335
             params.insert("store", "ADN");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   336
             managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   337
             m_availableManagers.insert(availableManagers.last(), managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   338
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   339
             availableManagers.append("symbiansim:fdn");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   340
             params.clear();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   341
             params.insert("store", "FDN");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   342
             managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   343
             m_availableManagers.insert(availableManagers.last(), managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   344
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   345
             availableManagers.append("symbiansim:sdn");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   346
             params.clear();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   347
             params.insert("store", "SDN");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   348
             managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   349
             m_availableManagers.insert(availableManagers.last(), managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   350
         }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   351
         else {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   352
             m_availableManagers.insert(managerName, managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   353
         }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   354
     }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   355
     return (availableManagers);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   356
}
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   357
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   358
int ContactsEngine::rowCount(const QModelIndex &parent) const
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   359
 {
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   360
    return this->m_allContacts.count();
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   361
 }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   362
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   363
void ContactsEngine::enumerateMgrs()
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   364
{
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   365
    QStringList mgrs = QContactManager::availableManagers();
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   366
    qDebug() << "Enumerate available Contact Managers:" << endl;
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   367
    foreach(QString m, mgrs)
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   368
    {
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   369
        qDebug() << "\tmgr: " << m << endl;
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   370
    }
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   371
    qDebug() << endl;
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   372
}
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   373
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   374
// dump the current contact manager.
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   375
void  ContactsEngine::dumpContactMgr()
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   376
{
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   377
    qDebug() << "Dump Contact Manager(default):" << endl;
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   378
    if (this->m_manager) {
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   379
        qDebug() << "\tname: " << this->m_manager->managerName() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   380
        qDebug() << "\tURI: "  << this->m_manager->managerUri() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   381
        qDebug() << "\tVersion: "  << this->m_manager->managerVersion() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   382
        qDebug() << "\tCount:" << this->m_manager->contacts().count() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   383
    } else {
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   384
        qDebug() << "\t Contact Manager(default) set to zero." << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   385
    }
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   386
    qDebug() << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   387
    qDebug() << "Dump Contact Manager(SF Staff):" << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   388
    if (this->m_manager_sf) {
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   389
        qDebug() << "\tname: " << this->m_manager_sf->managerName() << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   390
        qDebug() << "\tURI: "  << this->m_manager_sf->managerUri() << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   391
        qDebug() << "\tVersion: "  << this->m_manager_sf->managerVersion() << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   392
        qDebug() << "\tCount:" << this->m_manager_sf->contacts().count() << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   393
    } else {
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   394
        qDebug() << "\t Contact Manager(SF Staff) set to zero." << endl;
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   395
    }
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   396
    qDebug() << endl;
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   397
}
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   398
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   399
QVariant ContactsEngine::data(const QModelIndex &index, int role) const
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   400
 {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   401
    QVariant rc;
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   402
    QContact c;
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   403
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   404
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   405
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   406
    if (!index.isValid() || index.row() >= this->m_allContacts.size()) {
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   407
         return rc;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   408
    }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   409
    if (role == Qt::DisplayRole) {
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   410
        //rc = QVariant(allContacts.at(index.row()).displayLabel());
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   411
        c = this->m_allContacts.at(index.row());
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   412
        // organizations do not have first and last names.  So the displayLabel() is empty.
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   413
        QContactDetail cd = c.detail(QContactName::DefinitionName);
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   414
        if (cd.isEmpty()) {
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   415
            rc = QVariant (c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldDepartment) );
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   416
        } else {
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   417
            rc = QVariant ( c.displayLabel());
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   418
        }
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   419
    }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   420
    return rc;
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   421
}