contactengine/contactsengine.cpp
author John Kern <johnk@symbian.org>
Thu, 16 Sep 2010 10:59:11 -0700
changeset 49 d9d4ea56179a
parent 41 b56d7e268634
permissions -rwxr-xr-x
added a listview to support orange lab fw
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
}
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
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   136
void ContactsEngine::setManager(const QString & aMgrName)
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   137
{
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   138
   // noop
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   139
}
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
void ContactsEngine::populateAddresses()
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   142
{
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   143
    QContact *contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   144
    QContactOrganization *dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   145
    QStringList departmentName;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   146
    QContactPhoneNumber *number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   147
    QContactAddress *address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   148
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   149
    // 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
   150
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   151
    // emergency numbers
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   152
    // fire Foster City
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   153
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   154
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   155
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   156
    departmentName << "Foster City Fire department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   157
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   158
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   159
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   160
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   161
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   162
    number->setNumber("+1-650-286-3350");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   163
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   164
    //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
   165
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   166
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   167
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   168
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   169
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   170
    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
   171
    address->setStreet("1040 East Hillsdale Boulevard");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   172
    address->setPostcode("94404");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   173
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   174
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   175
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   176
    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
   177
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   178
    // Note that the caller retains ownership of the detail.
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   179
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   180
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   181
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   182
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   183
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   184
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   185
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   186
    // police - foster city
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   187
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   188
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   189
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   190
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   191
    departmentName << "Foster City Police department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   192
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   193
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   194
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   195
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   196
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   197
    number->setNumber("+1(650)286-3300");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   198
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   199
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   200
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   201
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   202
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   203
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   204
    address->setLocality("Foster City");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   205
    address->setStreet("1030 East Hillsdale Boulevard");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   206
    address->setPostcode("94404");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   207
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   208
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   209
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   210
    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
   211
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   212
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   213
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   214
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   215
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   216
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   217
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   218
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   219
    // taxi - Foster City
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   220
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   221
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   222
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   223
    departmentName << "Foster City Yellow Cab";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   224
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   225
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   226
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   227
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   228
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   229
    number->setNumber("+1(650)367-9999");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   230
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   231
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   232
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   233
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   234
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   235
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   236
    address->setLocality("Foster City");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   237
    address->setStreet("1055 foster city blvd");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   238
    address->setPostcode("94404");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   239
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   240
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   241
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   242
    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
   243
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   244
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   245
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   246
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   247
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   248
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   249
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   250
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   251
    // fire  - Menlo Park
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   252
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   253
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   254
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   255
    departmentName << "Menlo Park fire department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   256
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   257
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   258
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   259
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   260
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   261
    number->setNumber("+1(650)688-8400");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   262
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   263
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   264
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   265
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   266
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   267
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   268
    address->setLocality("Menlo Park");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   269
    address->setStreet("170 Middlefield Road");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   270
    address->setPostcode("94025");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   271
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   272
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   273
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   274
    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
   275
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   276
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   277
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   278
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   279
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   280
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   281
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   282
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   283
    //701 Laurel Street, Menlo Park, CA? -
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   284
    // police  - Menlo Park
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   285
    contact = new QContact();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   286
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   287
    dept = new QContactOrganization();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   288
    departmentName << "Menlo Park police department";
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   289
    dept->setDepartment(departmentName);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   290
    contact->saveDetail(dept);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   291
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   292
    number = new QContactPhoneNumber();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   293
    number->setContexts(QContactDetail::ContextWork);
29
a9f1d0e21384 fixed typo
John Kern <johnk@symbian.org>
parents: 25
diff changeset
   294
    number->setNumber("+1(650)858-3328");
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   295
    contact->saveDetail(number);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   296
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   297
    // create address detail
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   298
    address = new QContactAddress();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   299
    address->setCountry("USA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   300
    address->setRegion("CA");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   301
    address->setLocality("Menlo Park");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   302
    address->setStreet("701 Laurel Street");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   303
    address->setPostcode("94025");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   304
    contact->saveDetail(address);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   305
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   306
    this->m_manager_sf->saveContact(contact);
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   307
    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
   308
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   309
    delete dept;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   310
    while (!departmentName.isEmpty())
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   311
        departmentName.takeFirst();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   312
    delete number;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   313
    delete address;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   314
    delete contact;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   315
}
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
QStringList ContactsEngine::dataSources()
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   320
{
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   321
     QStringList availableManagers = QContactManager::availableManagers();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   322
     availableManagers.removeAll("invalid");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   323
     foreach(QString managerName, availableManagers) {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   324
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   325
         QMap<QString, QString> params;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   326
         QString managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   327
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   328
         // 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
   329
         // all the stores.
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   330
         if (managerName == "symbiansim") {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   331
             availableManagers.removeAll("symbiansim");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   332
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   333
             availableManagers.append("symbiansim:adn");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   334
             params.insert("store", "ADN");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   335
             managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   336
             m_availableManagers.insert(availableManagers.last(), managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   337
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   338
             availableManagers.append("symbiansim:fdn");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   339
             params.clear();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   340
             params.insert("store", "FDN");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   341
             managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   342
             m_availableManagers.insert(availableManagers.last(), managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   343
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   344
             availableManagers.append("symbiansim:sdn");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   345
             params.clear();
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   346
             params.insert("store", "SDN");
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   347
             managerUri = QContactManager::buildUri(managerName, params);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   348
             m_availableManagers.insert(availableManagers.last(), managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   349
         }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   350
         else {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   351
             m_availableManagers.insert(managerName, managerUri);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   352
         }
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
     return (availableManagers);
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   355
}
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
int ContactsEngine::rowCount(const QModelIndex &parent) const
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   358
 {
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   359
    return this->m_allContacts.count();
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   360
 }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   361
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   362
void ContactsEngine::enumerateMgrs()
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   363
{
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   364
    QStringList mgrs = QContactManager::availableManagers();
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   365
    qDebug() << "Enumerate available Contact Managers:" << endl;
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   366
    foreach(QString m, mgrs)
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   367
    {
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   368
        qDebug() << "\tmgr: " << m << endl;
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   369
    }
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   370
    qDebug() << endl;
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   371
}
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
// dump the current contact manager.
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   374
void  ContactsEngine::dumpContactMgr()
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   375
{
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   376
    qDebug() << "Dump Contact Manager(default):" << endl;
25
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   377
    if (this->m_manager) {
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   378
        qDebug() << "\tname: " << this->m_manager->managerName() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   379
        qDebug() << "\tURI: "  << this->m_manager->managerUri() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   380
        qDebug() << "\tVersion: "  << this->m_manager->managerVersion() << endl;
adbe71832e2b runs on-device now; testing on 5800
John Kern <johnk@symbian.org>
parents: 23
diff changeset
   381
        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
   382
    } else {
31
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   383
        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
   384
    }
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   385
    qDebug() << endl;
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   386
    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
   387
    if (this->m_manager_sf) {
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   388
        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
   389
        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
   390
        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
   391
        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
   392
    } else {
7140311376c0 created in memory contact mgr; populateAddress populates it
John Kern <johnk@symbian.org>
parents: 29
diff changeset
   393
        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
   394
    }
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   395
    qDebug() << endl;
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   396
}
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   397
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   398
QVariant ContactsEngine::data(const QModelIndex &index, int role) const
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   399
 {
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   400
    QVariant rc;
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   401
    QContact c;
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   402
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   403
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   404
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   405
    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
   406
         return rc;
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   407
    }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   408
    if (role == Qt::DisplayRole) {
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   409
        //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
   410
        c = this->m_allContacts.at(index.row());
23
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   411
        // 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
   412
        QContactDetail cd = c.detail(QContactName::DefinitionName);
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   413
        if (cd.isEmpty()) {
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   414
            rc = QVariant (c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldDepartment) );
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   415
        } else {
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   416
            rc = QVariant ( c.displayLabel());
51fcdd1558d8 clean up
John Kern <johnk@symbian.org>
parents: 19
diff changeset
   417
        }
19
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   418
    }
e4b6ee329501 WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff changeset
   419
    return rc;
40
edc0144719a1 removed invariant from data() and rowCount(). Performance should be ok now.
John Kern <johnk@symbian.org>
parents: 38
diff changeset
   420
}