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