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