phonebookui/phonebookservices/src/cntservices.cpp
author hgs
Fri, 15 Oct 2010 12:24:46 +0300
changeset 81 640d30f4fb64
parent 72 6abfb1094884
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description:
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "cntservices.h"
hgs
parents:
diff changeset
    19
#include "cntglobal.h"
hgs
parents:
diff changeset
    20
#include "cntdebug.h"
hgs
parents:
diff changeset
    21
#include <cntabstractviewmanager.h>
53
hgs
parents: 50
diff changeset
    22
#include "cntserviceviewmanager.h"
50
hgs
parents:
diff changeset
    23
#include "cntimageutility.h"
hgs
parents:
diff changeset
    24
#include "cntserviceviewparams.h"
53
hgs
parents: 50
diff changeset
    25
#include <cntservicescontact.h>
50
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
#include <hbview.h>
hgs
parents:
diff changeset
    28
#include <hblistview.h>
hgs
parents:
diff changeset
    29
#include <qversitreader.h>
hgs
parents:
diff changeset
    30
#include <qversitcontactimporter.h>
hgs
parents:
diff changeset
    31
#include <qversitdocument.h>
hgs
parents:
diff changeset
    32
#include <xqserviceprovider.h>
61
hgs
parents: 54
diff changeset
    33
#include <cntabstractengine.h>
50
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
#include <QApplication>
hgs
parents:
diff changeset
    36
#include <QPixmap>
hgs
parents:
diff changeset
    37
#include <QFile>
hgs
parents:
diff changeset
    38
#include <QUrl>
hgs
parents:
diff changeset
    39
hgs
parents:
diff changeset
    40
CntServices::CntServices() :
hgs
parents:
diff changeset
    41
mViewManager(NULL),
72
hgs
parents: 66
diff changeset
    42
mCurrentProvider(NULL)
50
hgs
parents:
diff changeset
    43
{
hgs
parents:
diff changeset
    44
    CNT_ENTRY
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
    // Definition names supported in symbian back-end
hgs
parents:
diff changeset
    47
    m_definitionNames << QContactName::DefinitionName;
hgs
parents:
diff changeset
    48
    m_definitionNames << QContactNickname::DefinitionName;
hgs
parents:
diff changeset
    49
    m_definitionNames << QContactPhoneNumber::DefinitionName;
hgs
parents:
diff changeset
    50
    m_definitionNames << QContactEmailAddress::DefinitionName;
hgs
parents:
diff changeset
    51
    m_definitionNames << QContactAddress::DefinitionName;
hgs
parents:
diff changeset
    52
    m_definitionNames << QContactUrl::DefinitionName;
hgs
parents:
diff changeset
    53
    m_definitionNames << QContactBirthday::DefinitionName;
hgs
parents:
diff changeset
    54
    m_definitionNames << QContactOrganization::DefinitionName;
hgs
parents:
diff changeset
    55
    m_definitionNames << QContactSyncTarget::DefinitionName;
hgs
parents:
diff changeset
    56
    m_definitionNames << QContactNote::DefinitionName;
hgs
parents:
diff changeset
    57
    m_definitionNames << QContactFamily::DefinitionName;
hgs
parents:
diff changeset
    58
    m_definitionNames << QContactAvatar::DefinitionName;
hgs
parents:
diff changeset
    59
    m_definitionNames << QContactAnniversary::DefinitionName;
hgs
parents:
diff changeset
    60
    m_definitionNames << QContactGeoLocation::DefinitionName;
hgs
parents:
diff changeset
    61
    m_definitionNames << QContactGender::DefinitionName;
hgs
parents:
diff changeset
    62
    m_definitionNames << QContactOnlineAccount::DefinitionName;
hgs
parents:
diff changeset
    63
    
hgs
parents:
diff changeset
    64
    CNT_EXIT
hgs
parents:
diff changeset
    65
}
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
CntServices::~CntServices()
hgs
parents:
diff changeset
    69
{
hgs
parents:
diff changeset
    70
    CNT_LOG
hgs
parents:
diff changeset
    71
}
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
61
hgs
parents: 54
diff changeset
    74
void CntServices::setEngine( CntAbstractEngine& aEngine )
hgs
parents: 54
diff changeset
    75
{
hgs
parents: 54
diff changeset
    76
    CNT_LOG
hgs
parents: 54
diff changeset
    77
    mEngine = &aEngine;
hgs
parents: 54
diff changeset
    78
    mViewManager = &mEngine->viewManager();
hgs
parents: 54
diff changeset
    79
    CntServiceViewManager* srvMng = static_cast<CntServiceViewManager*>(mViewManager);
hgs
parents: 54
diff changeset
    80
    connect(srvMng, SIGNAL(applicationClosed()), this, SLOT(terminateService()));
hgs
parents: 54
diff changeset
    81
}
50
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
void CntServices::singleFetch(
hgs
parents:
diff changeset
    84
    const QString &title, const QString &action,
hgs
parents:
diff changeset
    85
    CntAbstractServiceProvider& aServiceProvider )
hgs
parents:
diff changeset
    86
{
hgs
parents:
diff changeset
    87
    CNT_ENTRY
hgs
parents:
diff changeset
    88
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
    89
hgs
parents:
diff changeset
    90
    CntViewParameters params;
hgs
parents:
diff changeset
    91
    params.insert(EViewId, serviceContactFetchView);
hgs
parents:
diff changeset
    92
    params.insert(ESelectedAction, action);
hgs
parents:
diff changeset
    93
    params.insert(KCntServiceViewParamTitle, title);
hgs
parents:
diff changeset
    94
    // SINGLE fetch
hgs
parents:
diff changeset
    95
    params.insert(ESelectionMode, HbAbstractItemView::SingleSelection);
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
    mViewManager->changeView(params);
hgs
parents:
diff changeset
    98
    CNT_EXIT
hgs
parents:
diff changeset
    99
}
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
void CntServices::multiFetch(
hgs
parents:
diff changeset
   103
    const QString &title, const QString &action,
hgs
parents:
diff changeset
   104
    CntAbstractServiceProvider& aServiceProvider )
hgs
parents:
diff changeset
   105
{
hgs
parents:
diff changeset
   106
    CNT_ENTRY
hgs
parents:
diff changeset
   107
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   108
hgs
parents:
diff changeset
   109
    CntViewParameters params;
hgs
parents:
diff changeset
   110
    params.insert(EViewId, serviceContactFetchView);
hgs
parents:
diff changeset
   111
    params.insert(ESelectedAction, action);
hgs
parents:
diff changeset
   112
    params.insert(KCntServiceViewParamTitle, title);
hgs
parents:
diff changeset
   113
    // MULTI fetch
hgs
parents:
diff changeset
   114
    params.insert(ESelectionMode, HbAbstractItemView::MultiSelection);
hgs
parents:
diff changeset
   115
    mViewManager->changeView(params);
hgs
parents:
diff changeset
   116
    CNT_EXIT
hgs
parents:
diff changeset
   117
}
hgs
parents:
diff changeset
   118
53
hgs
parents: 50
diff changeset
   119
void CntServices::editCreateNew(const QString &definitionName, const QString &value,
hgs
parents: 50
diff changeset
   120
    CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp )
hgs
parents: 50
diff changeset
   121
{
hgs
parents: 50
diff changeset
   122
    CNT_ENTRY
hgs
parents: 50
diff changeset
   123
    editCreateNew( definitionName, value, QString(), aServiceProvider, defaultForOnlineAccountIsImpp);
hgs
parents: 50
diff changeset
   124
    CNT_EXIT
hgs
parents: 50
diff changeset
   125
}
50
hgs
parents:
diff changeset
   126
53
hgs
parents: 50
diff changeset
   127
void CntServices::editCreateNew(const QString &definitionName, const QString &value, const QString& subType,
hgs
parents: 50
diff changeset
   128
    CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp )
50
hgs
parents:
diff changeset
   129
{
hgs
parents:
diff changeset
   130
    CNT_ENTRY
hgs
parents:
diff changeset
   131
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
    QContact contact;
hgs
parents:
diff changeset
   134
    
hgs
parents:
diff changeset
   135
    if (definitionName == QContactPhoneNumber::DefinitionName)
53
hgs
parents: 50
diff changeset
   136
    {
50
hgs
parents:
diff changeset
   137
        QContactPhoneNumber phoneNumber;
hgs
parents:
diff changeset
   138
        phoneNumber.setNumber(value);
53
hgs
parents: 50
diff changeset
   139
        if (!subType.isEmpty())
hgs
parents: 50
diff changeset
   140
        {
hgs
parents: 50
diff changeset
   141
            phoneNumber.setSubTypes(subType);
50
hgs
parents:
diff changeset
   142
        }
53
hgs
parents: 50
diff changeset
   143
        else
hgs
parents: 50
diff changeset
   144
        {
hgs
parents: 50
diff changeset
   145
            phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile); // Mobile is the default if subtype is not given.
hgs
parents: 50
diff changeset
   146
        }
hgs
parents: 50
diff changeset
   147
         contact.saveDetail(&phoneNumber);
hgs
parents: 50
diff changeset
   148
    }
50
hgs
parents:
diff changeset
   149
    else if (definitionName == QContactEmailAddress::DefinitionName)
53
hgs
parents: 50
diff changeset
   150
    {
50
hgs
parents:
diff changeset
   151
        QContactEmailAddress email;
hgs
parents:
diff changeset
   152
        email.setEmailAddress(value);
53
hgs
parents: 50
diff changeset
   153
        // Email addresses can't have subtypes.
50
hgs
parents:
diff changeset
   154
        contact.saveDetail(&email);
53
hgs
parents: 50
diff changeset
   155
    }
50
hgs
parents:
diff changeset
   156
    else if (definitionName == QContactOnlineAccount::DefinitionName)
53
hgs
parents: 50
diff changeset
   157
    {
50
hgs
parents:
diff changeset
   158
        QContactOnlineAccount account;
53
hgs
parents: 50
diff changeset
   159
        fillOnlineAccount( account, value, subType, defaultForOnlineAccountIsImpp);
50
hgs
parents:
diff changeset
   160
        contact.saveDetail(&account);
53
hgs
parents: 50
diff changeset
   161
    }    
50
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
    // Launch editor now
hgs
parents:
diff changeset
   164
    CntViewParameters params;
hgs
parents:
diff changeset
   165
    params.insert(EViewId, serviceEditView);
hgs
parents:
diff changeset
   166
    QVariant var;
hgs
parents:
diff changeset
   167
    var.setValue(contact);
hgs
parents:
diff changeset
   168
    params.insert(ESelectedContact, var);
hgs
parents:
diff changeset
   169
    mViewManager->changeView(params);
hgs
parents:
diff changeset
   170
    CNT_EXIT
hgs
parents:
diff changeset
   171
}
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
61
hgs
parents: 54
diff changeset
   174
void CntServices::editCreateNewFromVCard(const QString &fileName,
50
hgs
parents:
diff changeset
   175
    CntAbstractServiceProvider& aServiceProvider )
hgs
parents:
diff changeset
   176
{
hgs
parents:
diff changeset
   177
    CNT_ENTRY
hgs
parents:
diff changeset
   178
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   179
hgs
parents:
diff changeset
   180
    CntImageUtility imageUtility;
hgs
parents:
diff changeset
   181
    QContact contact;
hgs
parents:
diff changeset
   182
    QVersitReader reader;
61
hgs
parents: 54
diff changeset
   183
    QFile vCardFile(fileName);
hgs
parents: 54
diff changeset
   184
    if (!vCardFile.open(QIODevice::ReadOnly))
hgs
parents: 54
diff changeset
   185
        return;
hgs
parents: 54
diff changeset
   186
    reader.setDevice(&vCardFile);
50
hgs
parents:
diff changeset
   187
    reader.startReading();
hgs
parents:
diff changeset
   188
    reader.waitForFinished();
hgs
parents:
diff changeset
   189
    // Use the resulting document(s)...
hgs
parents:
diff changeset
   190
    QVersitContactImporter importer;
hgs
parents:
diff changeset
   191
    QList<QVersitDocument> versitDocuments = reader.results();
hgs
parents:
diff changeset
   192
    if(versitDocuments.count() > 0 
hgs
parents:
diff changeset
   193
       && importer.importDocuments(versitDocuments))
hgs
parents:
diff changeset
   194
        {
hgs
parents:
diff changeset
   195
        QList<QContact> contacts = importer.contacts();
hgs
parents:
diff changeset
   196
        if(contacts.count() > 0)
hgs
parents:
diff changeset
   197
            contact = contacts.first();
hgs
parents:
diff changeset
   198
        }
61
hgs
parents: 54
diff changeset
   199
    vCardFile.close();
50
hgs
parents:
diff changeset
   200
    
hgs
parents:
diff changeset
   201
    // Save thumbnail images
hgs
parents:
diff changeset
   202
    QList<QContactThumbnail> details = contact.details<QContactThumbnail>();
hgs
parents:
diff changeset
   203
    for (int i = 0;i < details.count();i++)
hgs
parents:
diff changeset
   204
        {
hgs
parents:
diff changeset
   205
        if (!details.at(i).thumbnail().isNull())
hgs
parents:
diff changeset
   206
            {
hgs
parents:
diff changeset
   207
            QString imagepath;
hgs
parents:
diff changeset
   208
            QPixmap pixmap = QPixmap::fromImage(details.at(i).thumbnail());
hgs
parents:
diff changeset
   209
            if(imageUtility.createImage(pixmap,imagepath))
hgs
parents:
diff changeset
   210
                {
hgs
parents:
diff changeset
   211
                // Update contact detail
hgs
parents:
diff changeset
   212
                QContactAvatar detail=details.at(i);
hgs
parents:
diff changeset
   213
                detail.setImageUrl(imagepath);
hgs
parents:
diff changeset
   214
                contact.saveDetail(&detail);
hgs
parents:
diff changeset
   215
                }
hgs
parents:
diff changeset
   216
            }
hgs
parents:
diff changeset
   217
        }
hgs
parents:
diff changeset
   218
    
hgs
parents:
diff changeset
   219
    removeNotSupportedDetails(contact);
hgs
parents:
diff changeset
   220
    removeNotSupportedFields(contact);
hgs
parents:
diff changeset
   221
hgs
parents:
diff changeset
   222
    // Launch editor now
hgs
parents:
diff changeset
   223
    CntViewParameters params;
hgs
parents:
diff changeset
   224
    params.insert(EViewId, serviceEditView);
hgs
parents:
diff changeset
   225
    QVariant var;
hgs
parents:
diff changeset
   226
    var.setValue(contact);
hgs
parents:
diff changeset
   227
    params.insert(ESelectedContact, var);
hgs
parents:
diff changeset
   228
    mViewManager->changeView(params);
hgs
parents:
diff changeset
   229
    CNT_EXIT
hgs
parents:
diff changeset
   230
}
hgs
parents:
diff changeset
   231
53
hgs
parents: 50
diff changeset
   232
void CntServices::editUpdateExisting(const QString &definitionName, const QString &value,
hgs
parents: 50
diff changeset
   233
    CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp )
hgs
parents: 50
diff changeset
   234
{
hgs
parents: 50
diff changeset
   235
    CNT_ENTRY
hgs
parents: 50
diff changeset
   236
    editUpdateExisting( definitionName, value, QString(), aServiceProvider, defaultForOnlineAccountIsImpp );
hgs
parents: 50
diff changeset
   237
    CNT_EXIT
hgs
parents: 50
diff changeset
   238
}
50
hgs
parents:
diff changeset
   239
53
hgs
parents: 50
diff changeset
   240
void CntServices::editUpdateExisting(const QString &definitionName, const QString &value, const QString& subType,
hgs
parents: 50
diff changeset
   241
    CntAbstractServiceProvider& aServiceProvider, bool defaultForOnlineAccountIsImpp )
50
hgs
parents:
diff changeset
   242
{
hgs
parents:
diff changeset
   243
    CNT_ENTRY
hgs
parents:
diff changeset
   244
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
    QContactDetail detail;
hgs
parents:
diff changeset
   247
    
hgs
parents:
diff changeset
   248
    if (definitionName == QContactPhoneNumber::DefinitionName)
hgs
parents:
diff changeset
   249
    {
hgs
parents:
diff changeset
   250
        QContactPhoneNumber phoneNumber;
hgs
parents:
diff changeset
   251
        phoneNumber.setNumber(value);
53
hgs
parents: 50
diff changeset
   252
        if (!subType.isEmpty())
hgs
parents: 50
diff changeset
   253
        {        
hgs
parents: 50
diff changeset
   254
            phoneNumber.setSubTypes(subType);
hgs
parents: 50
diff changeset
   255
        }
hgs
parents: 50
diff changeset
   256
        else
hgs
parents: 50
diff changeset
   257
        {
hgs
parents: 50
diff changeset
   258
            phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile);    
hgs
parents: 50
diff changeset
   259
        }
50
hgs
parents:
diff changeset
   260
        detail = phoneNumber;
hgs
parents:
diff changeset
   261
    }
hgs
parents:
diff changeset
   262
    else if (definitionName == QContactEmailAddress::DefinitionName)
hgs
parents:
diff changeset
   263
    {
hgs
parents:
diff changeset
   264
        QContactEmailAddress email;
hgs
parents:
diff changeset
   265
        email.setEmailAddress(value);
53
hgs
parents: 50
diff changeset
   266
        // Email addresses can't have subtypes.
50
hgs
parents:
diff changeset
   267
        detail = email;
hgs
parents:
diff changeset
   268
    }
hgs
parents:
diff changeset
   269
    else if (definitionName == QContactOnlineAccount::DefinitionName)
hgs
parents:
diff changeset
   270
    {
hgs
parents:
diff changeset
   271
        QContactOnlineAccount account;
53
hgs
parents: 50
diff changeset
   272
        fillOnlineAccount( account, value, subType, defaultForOnlineAccountIsImpp);
50
hgs
parents:
diff changeset
   273
        detail = account;
hgs
parents:
diff changeset
   274
    }
hgs
parents:
diff changeset
   275
hgs
parents:
diff changeset
   276
    CntViewParameters params;
hgs
parents:
diff changeset
   277
    params.insert(EViewId, serviceContactSelectionView);
hgs
parents:
diff changeset
   278
    QVariant var;
hgs
parents:
diff changeset
   279
    var.setValue(detail);
hgs
parents:
diff changeset
   280
    params.insert(ESelectedDetail, var);
hgs
parents:
diff changeset
   281
    mViewManager->changeView(params);
hgs
parents:
diff changeset
   282
    CNT_EXIT
hgs
parents:
diff changeset
   283
}
hgs
parents:
diff changeset
   284
hgs
parents:
diff changeset
   285
void CntServices::editExisting(int contactId,
hgs
parents:
diff changeset
   286
CntAbstractServiceProvider& aServiceProvider)
hgs
parents:
diff changeset
   287
{
hgs
parents:
diff changeset
   288
    CNT_ENTRY
hgs
parents:
diff changeset
   289
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   290
hgs
parents:
diff changeset
   291
    // Give parameters for launching editor.
hgs
parents:
diff changeset
   292
    CntViewParameters params;
hgs
parents:
diff changeset
   293
    params.insert(EViewId, serviceEditView);
hgs
parents:
diff changeset
   294
54
hgs
parents: 53
diff changeset
   295
    QContact contact = contactManager()->contact(contactId);
50
hgs
parents:
diff changeset
   296
    QVariant varContact;
hgs
parents:
diff changeset
   297
    varContact.setValue(contact);
hgs
parents:
diff changeset
   298
    params.insert(ESelectedContact, varContact);
hgs
parents:
diff changeset
   299
    mViewManager->changeView(params);
hgs
parents:
diff changeset
   300
    CNT_EXIT
hgs
parents:
diff changeset
   301
}
hgs
parents:
diff changeset
   302
hgs
parents:
diff changeset
   303
hgs
parents:
diff changeset
   304
void CntServices::launchContactCard(int aContactId,
hgs
parents:
diff changeset
   305
    CntAbstractServiceProvider& aServiceProvider )
hgs
parents:
diff changeset
   306
{
hgs
parents:
diff changeset
   307
    CNT_ENTRY
hgs
parents:
diff changeset
   308
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   309
54
hgs
parents: 53
diff changeset
   310
    QContact contact = contactManager()->contact(aContactId);
50
hgs
parents:
diff changeset
   311
hgs
parents:
diff changeset
   312
    // Launch Contact Card view
hgs
parents:
diff changeset
   313
    CntViewParameters params;
hgs
parents:
diff changeset
   314
    params.insert(EViewId, serviceContactCardView);
hgs
parents:
diff changeset
   315
    QVariant var;
hgs
parents:
diff changeset
   316
    var.setValue(contact);
hgs
parents:
diff changeset
   317
    params.insert(ESelectedContact, var);
hgs
parents:
diff changeset
   318
    mViewManager->changeView( params );
hgs
parents:
diff changeset
   319
    CNT_EXIT
hgs
parents:
diff changeset
   320
}
hgs
parents:
diff changeset
   321
hgs
parents:
diff changeset
   322
hgs
parents:
diff changeset
   323
void CntServices::launchTemporaryContactCard(const QString &definitionName, const QString &value,
hgs
parents:
diff changeset
   324
    CntAbstractServiceProvider& aServiceProvider )
hgs
parents:
diff changeset
   325
{
hgs
parents:
diff changeset
   326
    CNT_ENTRY
hgs
parents:
diff changeset
   327
    mCurrentProvider = &aServiceProvider;
hgs
parents:
diff changeset
   328
hgs
parents:
diff changeset
   329
    QContact contact;
hgs
parents:
diff changeset
   330
    QContactDetail detail;
hgs
parents:
diff changeset
   331
    
53
hgs
parents: 50
diff changeset
   332
    QContactName name;
hgs
parents: 50
diff changeset
   333
    name.setFirstName(hbTrId("txt_phob_list_unknown"));
hgs
parents: 50
diff changeset
   334
    contact.saveDetail(&name);
hgs
parents: 50
diff changeset
   335
    
50
hgs
parents:
diff changeset
   336
    if (definitionName == QContactPhoneNumber::DefinitionName)
hgs
parents:
diff changeset
   337
    {
hgs
parents:
diff changeset
   338
        QContactPhoneNumber phoneNumber;
hgs
parents:
diff changeset
   339
        phoneNumber.setNumber(value);
hgs
parents:
diff changeset
   340
        phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile);
hgs
parents:
diff changeset
   341
        contact.saveDetail(&phoneNumber);
hgs
parents:
diff changeset
   342
        detail = phoneNumber;
hgs
parents:
diff changeset
   343
    }
hgs
parents:
diff changeset
   344
    else if (definitionName == QContactEmailAddress::DefinitionName)
hgs
parents:
diff changeset
   345
    {
hgs
parents:
diff changeset
   346
        QContactEmailAddress email;
hgs
parents:
diff changeset
   347
        email.setEmailAddress(value);
hgs
parents:
diff changeset
   348
        contact.saveDetail(&email);
hgs
parents:
diff changeset
   349
        detail = email;
hgs
parents:
diff changeset
   350
    }
hgs
parents:
diff changeset
   351
    else if (definitionName == QContactOnlineAccount::DefinitionName)
hgs
parents:
diff changeset
   352
    {
hgs
parents:
diff changeset
   353
        QContactOnlineAccount account;
hgs
parents:
diff changeset
   354
        account.setAccountUri(value);
hgs
parents:
diff changeset
   355
        account.setSubTypes(QContactOnlineAccount::SubTypeSipVoip);
hgs
parents:
diff changeset
   356
        contact.saveDetail(&account);
hgs
parents:
diff changeset
   357
        detail = account;
hgs
parents:
diff changeset
   358
    }
hgs
parents:
diff changeset
   359
hgs
parents:
diff changeset
   360
    // Launch the view
hgs
parents:
diff changeset
   361
    CntViewParameters params;
hgs
parents:
diff changeset
   362
    params.insert(EViewId, serviceAssignContactCardView);
hgs
parents:
diff changeset
   363
    QVariant var;
hgs
parents:
diff changeset
   364
    var.setValue(contact);
hgs
parents:
diff changeset
   365
    params.insert(ESelectedContact, var);
hgs
parents:
diff changeset
   366
    QVariant varDetail;
hgs
parents:
diff changeset
   367
    varDetail.setValue(detail);
hgs
parents:
diff changeset
   368
    params.insert(ESelectedDetail, varDetail);
hgs
parents:
diff changeset
   369
    mViewManager->changeView(params);
hgs
parents:
diff changeset
   370
    CNT_EXIT
hgs
parents:
diff changeset
   371
}
hgs
parents:
diff changeset
   372
54
hgs
parents: 53
diff changeset
   373
void CntServices::launchGroupMemberView(int aContactId,
hgs
parents: 53
diff changeset
   374
    CntAbstractServiceProvider& aServiceProvider )
hgs
parents: 53
diff changeset
   375
{
hgs
parents: 53
diff changeset
   376
    CNT_ENTRY
hgs
parents: 53
diff changeset
   377
    mCurrentProvider = &aServiceProvider;
hgs
parents: 53
diff changeset
   378
hgs
parents: 53
diff changeset
   379
    QContact contact = contactManager()->contact(aContactId);
hgs
parents: 53
diff changeset
   380
hgs
parents: 53
diff changeset
   381
    // Launch Group member view
hgs
parents: 53
diff changeset
   382
    CntViewParameters params;
hgs
parents: 53
diff changeset
   383
    params.insert(EViewId, serviceGroupMemberView);
hgs
parents: 53
diff changeset
   384
    QVariant var;
hgs
parents: 53
diff changeset
   385
    var.setValue(contact);
hgs
parents: 53
diff changeset
   386
    params.insert(ESelectedGroupContact, var);
hgs
parents: 53
diff changeset
   387
    mViewManager->changeView( params );
hgs
parents: 53
diff changeset
   388
    CNT_EXIT
hgs
parents: 53
diff changeset
   389
}
50
hgs
parents:
diff changeset
   390
53
hgs
parents: 50
diff changeset
   391
void CntServices::quitApp()
hgs
parents: 50
diff changeset
   392
{
72
hgs
parents: 66
diff changeset
   393
    CNT_ENTRY   
hgs
parents: 66
diff changeset
   394
    
hgs
parents: 66
diff changeset
   395
    qApp->quit();
hgs
parents: 66
diff changeset
   396
    
53
hgs
parents: 50
diff changeset
   397
    CNT_EXIT
hgs
parents: 50
diff changeset
   398
}
hgs
parents: 50
diff changeset
   399
50
hgs
parents:
diff changeset
   400
void CntServices::removeNotSupportedDetails(QContact& contact)
hgs
parents:
diff changeset
   401
{
hgs
parents:
diff changeset
   402
    CNT_ENTRY
hgs
parents:
diff changeset
   403
    // Check definition map, remove details not supported
hgs
parents:
diff changeset
   404
    for (int i=0; i < contact.details().count(); i++)
hgs
parents:
diff changeset
   405
    {
hgs
parents:
diff changeset
   406
        if (!m_definitionNames.contains(contact.details().at(i).definitionName()))
hgs
parents:
diff changeset
   407
        {
hgs
parents:
diff changeset
   408
            QContactDetail detail= contact.details().at(i);
hgs
parents:
diff changeset
   409
            contact.removeDetail(&detail);
hgs
parents:
diff changeset
   410
        }
hgs
parents:
diff changeset
   411
    }
hgs
parents:
diff changeset
   412
    CNT_EXIT
hgs
parents:
diff changeset
   413
}
hgs
parents:
diff changeset
   414
hgs
parents:
diff changeset
   415
void CntServices::removeNotSupportedFields(QContact& contact)
hgs
parents:
diff changeset
   416
{
hgs
parents:
diff changeset
   417
    CNT_ENTRY
hgs
parents:
diff changeset
   418
    QList<QContactDetail>   removeList;
hgs
parents:
diff changeset
   419
    
hgs
parents:
diff changeset
   420
    // Not all fields are supported in symbian back-end
hgs
parents:
diff changeset
   421
    // Remove not supported fields
hgs
parents:
diff changeset
   422
    for (int i=0; i < contact.details().count(); i++)
hgs
parents:
diff changeset
   423
    {
hgs
parents:
diff changeset
   424
        QContactDetail detail = contact.details().at(i);
hgs
parents:
diff changeset
   425
        if(detail.definitionName() == QContactAddress::DefinitionName)
hgs
parents:
diff changeset
   426
        {
hgs
parents:
diff changeset
   427
            QContactAddress addrDetail = static_cast<QContactAddress>(detail);
hgs
parents:
diff changeset
   428
            
hgs
parents:
diff changeset
   429
            // Sub-types not supported
hgs
parents:
diff changeset
   430
            if(detail.removeValue(QContactAddress::FieldSubTypes))
hgs
parents:
diff changeset
   431
                contact.saveDetail(&detail);
hgs
parents:
diff changeset
   432
        }
hgs
parents:
diff changeset
   433
        else if(detail.definitionName() == QContactAnniversary::DefinitionName)
hgs
parents:
diff changeset
   434
        {
hgs
parents:
diff changeset
   435
            QContactAnniversary annivDetail = static_cast<QContactAnniversary>(detail);
hgs
parents:
diff changeset
   436
            
hgs
parents:
diff changeset
   437
            // Sub-types not supported
hgs
parents:
diff changeset
   438
            if(detail.removeValue(QContactAnniversary::FieldSubType))
hgs
parents:
diff changeset
   439
                contact.saveDetail(&detail);
hgs
parents:
diff changeset
   440
            
hgs
parents:
diff changeset
   441
            // Context not supported
hgs
parents:
diff changeset
   442
            if(detail.removeValue(QContactDetail::FieldContext))
hgs
parents:
diff changeset
   443
                contact.saveDetail(&detail);
hgs
parents:
diff changeset
   444
        }
hgs
parents:
diff changeset
   445
        else if(detail.definitionName() == QContactPhoneNumber::DefinitionName)
hgs
parents:
diff changeset
   446
        {
hgs
parents:
diff changeset
   447
            QContactPhoneNumber phoneDetail = static_cast<QContactPhoneNumber>(detail);
hgs
parents:
diff changeset
   448
            
hgs
parents:
diff changeset
   449
            if(phoneDetail.subTypes().size() > 0 )
hgs
parents:
diff changeset
   450
            {
hgs
parents:
diff changeset
   451
                // Sub-types not supported
hgs
parents:
diff changeset
   452
                if(phoneDetail.subTypes().contains(QContactPhoneNumber::SubTypeVoice)
hgs
parents:
diff changeset
   453
                   || phoneDetail.subTypes().contains(QContactPhoneNumber::SubTypeMessagingCapable))
hgs
parents:
diff changeset
   454
                {
54
hgs
parents: 53
diff changeset
   455
                    // Default to subtype mobile
hgs
parents: 53
diff changeset
   456
                    QStringList l;
hgs
parents: 53
diff changeset
   457
                    l << QLatin1String(QContactPhoneNumber::SubTypeMobile);
hgs
parents: 53
diff changeset
   458
                    detail.setValue(QContactPhoneNumber::FieldSubTypes, l);
50
hgs
parents:
diff changeset
   459
                    contact.saveDetail(&detail);
hgs
parents:
diff changeset
   460
                }
hgs
parents:
diff changeset
   461
            }
hgs
parents:
diff changeset
   462
        }
hgs
parents:
diff changeset
   463
        else if(detail.definitionName() == QContactUrl::DefinitionName)
hgs
parents:
diff changeset
   464
        {
hgs
parents:
diff changeset
   465
            QContactUrl urlDetail = static_cast<QContactUrl>(detail);
hgs
parents:
diff changeset
   466
            
hgs
parents:
diff changeset
   467
            QString stype=QContactUrl::SubTypeHomePage;
hgs
parents:
diff changeset
   468
            if(urlDetail.subType().compare(stype) != 0)
hgs
parents:
diff changeset
   469
            {
hgs
parents:
diff changeset
   470
                detail.removeValue(QContactUrl::FieldSubType);
hgs
parents:
diff changeset
   471
                contact.saveDetail(&detail);
hgs
parents:
diff changeset
   472
            }
hgs
parents:
diff changeset
   473
        }
hgs
parents:
diff changeset
   474
    }
hgs
parents:
diff changeset
   475
    CNT_EXIT
hgs
parents:
diff changeset
   476
}
hgs
parents:
diff changeset
   477
53
hgs
parents: 50
diff changeset
   478
void CntServices::fillOnlineAccount( QContactOnlineAccount& account, const QString& value,
hgs
parents: 50
diff changeset
   479
    const QString& subType, bool defaultForOnlineAccountIsImpp )
81
hgs
parents: 72
diff changeset
   480
{
hgs
parents: 72
diff changeset
   481
    // The value should normally consist of two parts:
hgs
parents: 72
diff changeset
   482
    //    <service provider>:<user ID>
hgs
parents: 72
diff changeset
   483
    // for eg. "serviceprovider:jack@serviceprovider.com"
hgs
parents: 72
diff changeset
   484
    QStringList accountDetails = value.split(":");
hgs
parents: 72
diff changeset
   485
    if (accountDetails.count() == 1)
53
hgs
parents: 50
diff changeset
   486
    {
81
hgs
parents: 72
diff changeset
   487
        // For some reason it only had one part, so we're assuming it's the user ID.
hgs
parents: 72
diff changeset
   488
        account.setAccountUri(accountDetails.at(0));
hgs
parents: 72
diff changeset
   489
    }
hgs
parents: 72
diff changeset
   490
    else if (accountDetails.count() >= 2)
hgs
parents: 72
diff changeset
   491
    {
hgs
parents: 72
diff changeset
   492
        account.setServiceProvider(accountDetails.at(0));        
hgs
parents: 72
diff changeset
   493
        account.setAccountUri(accountDetails.at(1)); // the user ID
hgs
parents: 72
diff changeset
   494
    }
hgs
parents: 72
diff changeset
   495
hgs
parents: 72
diff changeset
   496
    if (!subType.isEmpty())
hgs
parents: 72
diff changeset
   497
    {        
hgs
parents: 72
diff changeset
   498
        account.setSubTypes(subType);
hgs
parents: 72
diff changeset
   499
    }
hgs
parents: 72
diff changeset
   500
    else
hgs
parents: 72
diff changeset
   501
    {
hgs
parents: 72
diff changeset
   502
        if (defaultForOnlineAccountIsImpp)
53
hgs
parents: 50
diff changeset
   503
        {
81
hgs
parents: 72
diff changeset
   504
            account.setSubTypes( QContactOnlineAccount::SubTypeImpp );
53
hgs
parents: 50
diff changeset
   505
        }
hgs
parents: 50
diff changeset
   506
        else
hgs
parents: 50
diff changeset
   507
        {
81
hgs
parents: 72
diff changeset
   508
            account.setSubTypes( QContactOnlineAccount::SubTypeSipVoip );
53
hgs
parents: 50
diff changeset
   509
        }
hgs
parents: 50
diff changeset
   510
    }
81
hgs
parents: 72
diff changeset
   511
}
53
hgs
parents: 50
diff changeset
   512
50
hgs
parents:
diff changeset
   513
// This method is inherited from CntAbstractServiceProvider
hgs
parents:
diff changeset
   514
void CntServices::CompleteServiceAndCloseApp(const QVariant& retValue)
hgs
parents:
diff changeset
   515
{
hgs
parents:
diff changeset
   516
    CNT_ENTRY
hgs
parents:
diff changeset
   517
    if (  mCurrentProvider )
54
hgs
parents: 53
diff changeset
   518
    {
50
hgs
parents:
diff changeset
   519
        mCurrentProvider->CompleteServiceAndCloseApp( retValue );
54
hgs
parents: 53
diff changeset
   520
    }
50
hgs
parents:
diff changeset
   521
    CNT_EXIT
hgs
parents:
diff changeset
   522
}
hgs
parents:
diff changeset
   523
61
hgs
parents: 54
diff changeset
   524
// This method is inherited from CntAbstractServiceProvider
hgs
parents: 54
diff changeset
   525
void CntServices::overrideReturnValue(const QVariant& retValue)
hgs
parents: 54
diff changeset
   526
{
hgs
parents: 54
diff changeset
   527
    CNT_ENTRY
hgs
parents: 54
diff changeset
   528
    if (  mCurrentProvider )
hgs
parents: 54
diff changeset
   529
    {
hgs
parents: 54
diff changeset
   530
        mCurrentProvider->overrideReturnValue( retValue );
hgs
parents: 54
diff changeset
   531
    }
hgs
parents: 54
diff changeset
   532
    CNT_EXIT
hgs
parents: 54
diff changeset
   533
}
hgs
parents: 54
diff changeset
   534
hgs
parents: 54
diff changeset
   535
// This method is inherited from CntAbstractServiceProvider
hgs
parents: 54
diff changeset
   536
bool CntServices::allowSubViewsExit()
hgs
parents: 54
diff changeset
   537
{
hgs
parents: 54
diff changeset
   538
    bool allow = true;
hgs
parents: 54
diff changeset
   539
    if (  mCurrentProvider )
hgs
parents: 54
diff changeset
   540
    {
hgs
parents: 54
diff changeset
   541
        allow = mCurrentProvider->allowSubViewsExit();
hgs
parents: 54
diff changeset
   542
    }
hgs
parents: 54
diff changeset
   543
    
hgs
parents: 54
diff changeset
   544
    return allow;
hgs
parents: 54
diff changeset
   545
}
hgs
parents: 54
diff changeset
   546
53
hgs
parents: 50
diff changeset
   547
void CntServices::terminateService()
50
hgs
parents:
diff changeset
   548
{
hgs
parents:
diff changeset
   549
    CNT_ENTRY
53
hgs
parents: 50
diff changeset
   550
    if (  mCurrentProvider )
54
hgs
parents: 53
diff changeset
   551
    {
53
hgs
parents: 50
diff changeset
   552
        // Complete the service with KCntServicesTerminated return value
hgs
parents: 50
diff changeset
   553
        QVariant var(KCntServicesTerminated);
hgs
parents: 50
diff changeset
   554
        mCurrentProvider->CompleteServiceAndCloseApp( var );
54
hgs
parents: 53
diff changeset
   555
    }
50
hgs
parents:
diff changeset
   556
    CNT_EXIT
hgs
parents:
diff changeset
   557
}
hgs
parents:
diff changeset
   558
54
hgs
parents: 53
diff changeset
   559
QContactManager* CntServices::contactManager()
hgs
parents: 53
diff changeset
   560
{
61
hgs
parents: 54
diff changeset
   561
    if ( mEngine )
hgs
parents: 54
diff changeset
   562
        return &mEngine->contactManager(SYMBIAN_BACKEND);
54
hgs
parents: 53
diff changeset
   563
    return NULL;
hgs
parents: 53
diff changeset
   564
}
hgs
parents: 53
diff changeset
   565
50
hgs
parents:
diff changeset
   566
Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
hgs
parents:
diff changeset
   567
Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)
53
hgs
parents: 50
diff changeset
   568