phonebookui/phonebookservices/src/cntservicecontactfetchview.cpp
author hgs
Thu, 05 Aug 2010 14:31:09 +0300
changeset 54 47627ab5d7a4
parent 50 77bc263e1626
child 61 d30183af6ca6
permissions -rw-r--r--
201031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "cntservicecontactfetchview.h"
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    20
#include <cntservicescontact.h>
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    21
#include <cntlistmodel.h>
50
hgs
parents: 46
diff changeset
    22
#include "cntserviceviewparams.h"
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include <hbmenu.h>
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    25
#include <hbview.h>
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    26
#include <hblistview.h>
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    27
#include <hbdocumentloader.h>
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    28
#include <hbaction.h>
54
hgs
parents: 50
diff changeset
    29
#include "cntactionpopup.h"
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    31
#include <QCoreApplication>
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    32
50
hgs
parents: 46
diff changeset
    33
CntServiceContactFetchView::CntServiceContactFetchView( CntAbstractServiceProvider& aServiceProvider ):
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    34
CntBaseSelectionView(),
50
hgs
parents: 46
diff changeset
    35
mProvider( aServiceProvider )
hgs
parents: 46
diff changeset
    36
    {
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    37
    HbAction* cancel = static_cast<HbAction*>( mDocument->findObject( "cnt:cancel" ) );
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    38
    mView->menu()->addAction( cancel );
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    39
    connect(cancel,  SIGNAL(triggered()), this, SLOT(cancelFetch()) );
50
hgs
parents: 46
diff changeset
    40
    connect( this, SIGNAL(viewClosed()), this, SLOT(closeFetchView()) );
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    41
    connect( this, SIGNAL(viewOpened(CntAbstractViewManager*, const CntViewParameters)), this, SLOT(aboutToOpenView(CntAbstractViewManager*, const CntViewParameters)) );
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
}
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
CntServiceContactFetchView::~CntServiceContactFetchView()
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
{
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
}
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
void CntServiceContactFetchView::cancelFetch()
50
hgs
parents: 46
diff changeset
    50
    {
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
    CntServicesContactList serviceList;
50
hgs
parents: 46
diff changeset
    52
    QVariant variant;
hgs
parents: 46
diff changeset
    53
    variant.setValue(serviceList);
hgs
parents: 46
diff changeset
    54
    mProvider.CompleteServiceAndCloseApp(variant);
hgs
parents: 46
diff changeset
    55
    }
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
50
hgs
parents: 46
diff changeset
    57
hgs
parents: 46
diff changeset
    58
hgs
parents: 46
diff changeset
    59
void CntServiceContactFetchView::closeFetchView()
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
{
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    61
    QContactManager* mgr = mMgr->contactManager(SYMBIAN_BACKEND);
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    62
    QModelIndexList temp = mListView->selectionModel()->selection().indexes();
54
hgs
parents: 50
diff changeset
    63
    mIndex = 0;
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
    for(int i = 0; i < temp.count(); i++ )
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
    {
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
    66
        QContact contact = mListModel->contact(temp.at(i));
54
hgs
parents: 50
diff changeset
    67
        if (mAction == KCntActionCall)
hgs
parents: 50
diff changeset
    68
        {
hgs
parents: 50
diff changeset
    69
            serviceCallMessageAction(contact, KCntActionCall);
hgs
parents: 50
diff changeset
    70
        }
hgs
parents: 50
diff changeset
    71
        else if (mAction == KCntActionSms )
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
        {
54
hgs
parents: 50
diff changeset
    73
            serviceCallMessageAction(contact, "message");
hgs
parents: 50
diff changeset
    74
        }
hgs
parents: 50
diff changeset
    75
        else if (mAction == KCntActionEmail)
hgs
parents: 50
diff changeset
    76
        {
hgs
parents: 50
diff changeset
    77
            serviceEmailAction(contact);
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
        }
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
        else
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
        {
54
hgs
parents: 50
diff changeset
    81
            serviceAllAction(contact);
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
        }
54
hgs
parents: 50
diff changeset
    83
    }
hgs
parents: 50
diff changeset
    84
    showPreviousView();
hgs
parents: 50
diff changeset
    85
}
hgs
parents: 50
diff changeset
    86
hgs
parents: 50
diff changeset
    87
void CntServiceContactFetchView::serviceCallMessageAction(QContact& aContact, QString aAction)
hgs
parents: 50
diff changeset
    88
{
hgs
parents: 50
diff changeset
    89
    CntServicesContact servicesContact;
hgs
parents: 50
diff changeset
    90
    //get the phonenumber
hgs
parents: 50
diff changeset
    91
    QList<QContactPhoneNumber> phonenumbers = aContact.details<QContactPhoneNumber>();
hgs
parents: 50
diff changeset
    92
    
hgs
parents: 50
diff changeset
    93
    Q_ASSERT_X( phonenumbers.count() > 0, "serviceCallMessageAction", "Number count is zero");
hgs
parents: 50
diff changeset
    94
    
hgs
parents: 50
diff changeset
    95
    QContactDetail detail = aContact.preferredDetail(aAction);
hgs
parents: 50
diff changeset
    96
    if (!detail.isEmpty())
hgs
parents: 50
diff changeset
    97
    {
hgs
parents: 50
diff changeset
    98
        //Set preferred detail for services
hgs
parents: 50
diff changeset
    99
        QContactPhoneNumber number = detail;
hgs
parents: 50
diff changeset
   100
        servicesContact.mDisplayName = aContact.displayLabel();
hgs
parents: 50
diff changeset
   101
        servicesContact.mPhoneNumber = number.number();
hgs
parents: 50
diff changeset
   102
        servicesContact.mEmailAddress = "";
hgs
parents: 50
diff changeset
   103
        servicesContact.mContactId = aContact.localId();
hgs
parents: 50
diff changeset
   104
        mServiceList.append(servicesContact);
hgs
parents: 50
diff changeset
   105
    }
hgs
parents: 50
diff changeset
   106
    else 
hgs
parents: 50
diff changeset
   107
    {
hgs
parents: 50
diff changeset
   108
        // show popup for call numbers
hgs
parents: 50
diff changeset
   109
        CntActionPopup *actionPopup = new CntActionPopup(&aContact);
hgs
parents: 50
diff changeset
   110
        bool popup = actionPopup->showActionPopup(aAction);
hgs
parents: 50
diff changeset
   111
        if(popup)
hgs
parents: 50
diff changeset
   112
        {
hgs
parents: 50
diff changeset
   113
            //if call numbers are present wait for signals
hgs
parents: 50
diff changeset
   114
            mIndex++;
hgs
parents: 50
diff changeset
   115
            connect( actionPopup, SIGNAL(executeContactAction(QContact&,QContactDetail, QString)), this, 
hgs
parents: 50
diff changeset
   116
                    SLOT(popupContactAction(QContact&, QContactDetail, QString)));
hgs
parents: 50
diff changeset
   117
            connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this, 
hgs
parents: 50
diff changeset
   118
                                SLOT(actionPopupCancelSlot()));
hgs
parents: 50
diff changeset
   119
        }
hgs
parents: 50
diff changeset
   120
        else 
hgs
parents: 50
diff changeset
   121
        {
hgs
parents: 50
diff changeset
   122
            //else delete popup if no call number present
hgs
parents: 50
diff changeset
   123
            delete actionPopup;
hgs
parents: 50
diff changeset
   124
        }
hgs
parents: 50
diff changeset
   125
    }
hgs
parents: 50
diff changeset
   126
}
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
54
hgs
parents: 50
diff changeset
   128
void CntServiceContactFetchView::serviceEmailAction(QContact& aContact)
hgs
parents: 50
diff changeset
   129
{
hgs
parents: 50
diff changeset
   130
    CntServicesContact servicesContact;
hgs
parents: 50
diff changeset
   131
    //get the email address
hgs
parents: 50
diff changeset
   132
    QList<QContactEmailAddress> emailAddresses = aContact.details<QContactEmailAddress>();
hgs
parents: 50
diff changeset
   133
    
hgs
parents: 50
diff changeset
   134
    Q_ASSERT_X( emailAddresses.count() > 0, "serviceEmailAction", "email address count is zero");
hgs
parents: 50
diff changeset
   135
    
hgs
parents: 50
diff changeset
   136
    QContactDetail detail = aContact.preferredDetail("email");
hgs
parents: 50
diff changeset
   137
    if (!detail.isEmpty())
hgs
parents: 50
diff changeset
   138
    {
hgs
parents: 50
diff changeset
   139
        //Set preferred detail for services
hgs
parents: 50
diff changeset
   140
        QContactEmailAddress email = detail;
hgs
parents: 50
diff changeset
   141
        servicesContact.mDisplayName = aContact.displayLabel();
hgs
parents: 50
diff changeset
   142
        servicesContact.mPhoneNumber = "";
hgs
parents: 50
diff changeset
   143
        servicesContact.mEmailAddress = email.emailAddress();
hgs
parents: 50
diff changeset
   144
        servicesContact.mContactId = aContact.localId();
hgs
parents: 50
diff changeset
   145
        mServiceList.append(servicesContact);
hgs
parents: 50
diff changeset
   146
        
hgs
parents: 50
diff changeset
   147
    }
hgs
parents: 50
diff changeset
   148
    else 
hgs
parents: 50
diff changeset
   149
    {
hgs
parents: 50
diff changeset
   150
        // show popup for email id's 
hgs
parents: 50
diff changeset
   151
        CntActionPopup *actionPopup = new CntActionPopup(&aContact);
hgs
parents: 50
diff changeset
   152
        bool popup = actionPopup->showActionPopup("email");
hgs
parents: 50
diff changeset
   153
        if(popup)
hgs
parents: 50
diff changeset
   154
        {
hgs
parents: 50
diff changeset
   155
            //if email id's are present wait for signals
hgs
parents: 50
diff changeset
   156
            mIndex++;
hgs
parents: 50
diff changeset
   157
            connect( actionPopup, SIGNAL(executeContactAction(QContact&,QContactDetail, QString)), this, 
hgs
parents: 50
diff changeset
   158
                    SLOT(popupContactAction(QContact&, QContactDetail, QString)));
hgs
parents: 50
diff changeset
   159
            connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this, 
hgs
parents: 50
diff changeset
   160
                                SLOT(actionPopupCancelSlot()));
hgs
parents: 50
diff changeset
   161
        }
hgs
parents: 50
diff changeset
   162
        else 
hgs
parents: 50
diff changeset
   163
        {
hgs
parents: 50
diff changeset
   164
            //else delete popup if no email present
hgs
parents: 50
diff changeset
   165
            delete actionPopup;
hgs
parents: 50
diff changeset
   166
        }
hgs
parents: 50
diff changeset
   167
    }
hgs
parents: 50
diff changeset
   168
}
hgs
parents: 50
diff changeset
   169
hgs
parents: 50
diff changeset
   170
void CntServiceContactFetchView::serviceAllAction(QContact& aContact)
hgs
parents: 50
diff changeset
   171
{
hgs
parents: 50
diff changeset
   172
    CntServicesContact servicesContact;
hgs
parents: 50
diff changeset
   173
    servicesContact.mDisplayName = aContact.displayLabel();
hgs
parents: 50
diff changeset
   174
    QContactDetail callDetail = aContact.preferredDetail("call");
hgs
parents: 50
diff changeset
   175
    //Check for preferredDetail from call
hgs
parents: 50
diff changeset
   176
    // if not present check for preferredDetail for message
hgs
parents: 50
diff changeset
   177
    // if not present pick first phone number
hgs
parents: 50
diff changeset
   178
    if (!callDetail.isEmpty())
hgs
parents: 50
diff changeset
   179
    {
hgs
parents: 50
diff changeset
   180
        QContactPhoneNumber number = callDetail;
hgs
parents: 50
diff changeset
   181
        servicesContact.mPhoneNumber = number.number();
hgs
parents: 50
diff changeset
   182
    }
hgs
parents: 50
diff changeset
   183
    else
hgs
parents: 50
diff changeset
   184
    {
hgs
parents: 50
diff changeset
   185
        QContactDetail smsDetail = aContact.preferredDetail("message");
hgs
parents: 50
diff changeset
   186
        if (!callDetail.isEmpty())
hgs
parents: 50
diff changeset
   187
        {
hgs
parents: 50
diff changeset
   188
            QContactPhoneNumber number = smsDetail;
hgs
parents: 50
diff changeset
   189
            servicesContact.mPhoneNumber = number.number();
hgs
parents: 50
diff changeset
   190
        }
hgs
parents: 50
diff changeset
   191
        else 
hgs
parents: 50
diff changeset
   192
        {
hgs
parents: 50
diff changeset
   193
            QList<QContactPhoneNumber> phonenumbers = aContact.details<QContactPhoneNumber>();
hgs
parents: 50
diff changeset
   194
            if(phonenumbers.count() > 0)
hgs
parents: 50
diff changeset
   195
            {
hgs
parents: 50
diff changeset
   196
            servicesContact.mPhoneNumber = phonenumbers.first().number();
hgs
parents: 50
diff changeset
   197
            }
hgs
parents: 50
diff changeset
   198
            else
hgs
parents: 50
diff changeset
   199
            {
hgs
parents: 50
diff changeset
   200
            servicesContact.mPhoneNumber = "";
hgs
parents: 50
diff changeset
   201
            }
hgs
parents: 50
diff changeset
   202
        }
hgs
parents: 50
diff changeset
   203
    }
hgs
parents: 50
diff changeset
   204
    
hgs
parents: 50
diff changeset
   205
    QContactDetail emailDetail = aContact.preferredDetail("email");
hgs
parents: 50
diff changeset
   206
    if (!emailDetail.isEmpty())
hgs
parents: 50
diff changeset
   207
    {
hgs
parents: 50
diff changeset
   208
        QContactEmailAddress email = emailDetail;
hgs
parents: 50
diff changeset
   209
        servicesContact.mEmailAddress = email.emailAddress();
hgs
parents: 50
diff changeset
   210
    }
hgs
parents: 50
diff changeset
   211
    else
hgs
parents: 50
diff changeset
   212
    {
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
        //get first email address
54
hgs
parents: 50
diff changeset
   214
        QList<QContactEmailAddress> emailAddresses = aContact.details<QContactEmailAddress>();
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
        if(emailAddresses.count() > 0)
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
        {
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
            servicesContact.mEmailAddress = emailAddresses.first().emailAddress();
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
        }
54
hgs
parents: 50
diff changeset
   219
        else 
hgs
parents: 50
diff changeset
   220
        {
hgs
parents: 50
diff changeset
   221
            servicesContact.mEmailAddress = "";
hgs
parents: 50
diff changeset
   222
        }
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
    }
54
hgs
parents: 50
diff changeset
   224
    servicesContact.mContactId = aContact.localId();
hgs
parents: 50
diff changeset
   225
    mServiceList.append(servicesContact);
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
}
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   228
void CntServiceContactFetchView::aboutToOpenView(CntAbstractViewManager* aMgr, const CntViewParameters aArgs)
25
76a2435edfd4 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   229
{
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   230
    mMgr = aMgr;
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   231
    
25
76a2435edfd4 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   232
    // Set title of the view.
50
hgs
parents: 46
diff changeset
   233
    QString title = aArgs.value(KCntServiceViewParamTitle).toString();
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   234
    mView->setTitle(title);
25
76a2435edfd4 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   235
    
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   236
    // Set action filter
54
hgs
parents: 50
diff changeset
   237
    mAction = aArgs.value(ESelectedAction).toString();
50
hgs
parents: 46
diff changeset
   238
    // ESelectedAction is defined in cntviewparams.h
hgs
parents: 46
diff changeset
   239
hgs
parents: 46
diff changeset
   240
    // Has never been implemented.
hgs
parents: 46
diff changeset
   241
    //QString filterStr = aArgs.value(KCntServiceViewParamFilter).toString();
hgs
parents: 46
diff changeset
   242
    // KCntServiceViewParamFilter is defined in cntserviceviewparams.h
hgs
parents: 46
diff changeset
   243
54
hgs
parents: 50
diff changeset
   244
    if (mAction == KCntActionSms)
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   245
        {
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   246
            QContactActionFilter actionFilter;
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   247
            actionFilter.setActionName("message");
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   248
            mListModel->setFilter(actionFilter);
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   249
        }
54
hgs
parents: 50
diff changeset
   250
        else if (mAction == KCntActionCall)
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   251
        {
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   252
            QContactActionFilter actionFilter;
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   253
            actionFilter.setActionName("call");
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   254
            mListModel->setFilter(actionFilter);
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   255
        }
54
hgs
parents: 50
diff changeset
   256
        else if (mAction == KCntActionEmail)
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   257
        {
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   258
            QContactActionFilter actionFilter;
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   259
            actionFilter.setActionName("email");
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   260
            mListModel->setFilter(actionFilter);
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   261
        }
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   262
        else
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   263
        {
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   264
            QContactDetailFilter filter;
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   265
            filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   266
            QString typeContact = QContactType::TypeContact;
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   267
            filter.setValue(typeContact);
46
efe85016a067 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
   268
            mListModel->setFilter(filter);
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   269
        }
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   270
27
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   271
        // hide my card if it's not set
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   272
        if ( mListModel->myCardId() == 0 )
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   273
        {
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   274
            mListModel->showMyCard( false );
de1630741fbe Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 25
diff changeset
   275
        }
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   276
}
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   277
54
hgs
parents: 50
diff changeset
   278
void CntServiceContactFetchView::popupContactAction(QContact& aContact,QContactDetail contactDetail, QString aAction)
hgs
parents: 50
diff changeset
   279
{
hgs
parents: 50
diff changeset
   280
    if (aAction.compare("call", Qt::CaseInsensitive) == 0 
hgs
parents: 50
diff changeset
   281
           || aAction.compare("message", Qt::CaseInsensitive) == 0 )
hgs
parents: 50
diff changeset
   282
       {       
hgs
parents: 50
diff changeset
   283
           CntServicesContact servicesContact;
hgs
parents: 50
diff changeset
   284
           QContactPhoneNumber number = static_cast<QContactPhoneNumber>(contactDetail);
hgs
parents: 50
diff changeset
   285
           QString name = aContact.displayLabel();
hgs
parents: 50
diff changeset
   286
           servicesContact.mDisplayName = aContact.displayLabel();
hgs
parents: 50
diff changeset
   287
           servicesContact.mPhoneNumber = number.number();
hgs
parents: 50
diff changeset
   288
           servicesContact.mEmailAddress = "";
hgs
parents: 50
diff changeset
   289
           servicesContact.mContactId = aContact.localId();
hgs
parents: 50
diff changeset
   290
           mServiceList.append(servicesContact);
hgs
parents: 50
diff changeset
   291
           mIndex--;
hgs
parents: 50
diff changeset
   292
       }
hgs
parents: 50
diff changeset
   293
       else if (aAction.compare("email", Qt::CaseInsensitive) == 0 )
hgs
parents: 50
diff changeset
   294
       {
hgs
parents: 50
diff changeset
   295
           CntServicesContact servicesContact;
hgs
parents: 50
diff changeset
   296
           QContactEmailAddress email = static_cast<QContactEmailAddress>(contactDetail);
hgs
parents: 50
diff changeset
   297
           servicesContact.mDisplayName = aContact.displayLabel();
hgs
parents: 50
diff changeset
   298
           servicesContact.mPhoneNumber = "";
hgs
parents: 50
diff changeset
   299
           servicesContact.mEmailAddress = email.emailAddress();
hgs
parents: 50
diff changeset
   300
           servicesContact.mContactId = aContact.localId();
hgs
parents: 50
diff changeset
   301
           mServiceList.append(servicesContact);
hgs
parents: 50
diff changeset
   302
           mIndex--;
hgs
parents: 50
diff changeset
   303
       }
hgs
parents: 50
diff changeset
   304
    
hgs
parents: 50
diff changeset
   305
    if (aContact.preferredDetail(aAction).isEmpty() && (aAction == "call" || aAction == "message" || aAction == "email"))
hgs
parents: 50
diff changeset
   306
    {
hgs
parents: 50
diff changeset
   307
        aContact.setPreferredDetail(aAction, contactDetail);
hgs
parents: 50
diff changeset
   308
        //return value will be ignored because we cannot do anything if it fails.
hgs
parents: 50
diff changeset
   309
        mMgr->contactManager(SYMBIAN_BACKEND)->saveContact(&aContact);
hgs
parents: 50
diff changeset
   310
    }
hgs
parents: 50
diff changeset
   311
    
hgs
parents: 50
diff changeset
   312
    showPreviousView();
hgs
parents: 50
diff changeset
   313
}
hgs
parents: 50
diff changeset
   314
hgs
parents: 50
diff changeset
   315
void CntServiceContactFetchView::actionPopupCancelSlot()
hgs
parents: 50
diff changeset
   316
{
hgs
parents: 50
diff changeset
   317
    mIndex--;
hgs
parents: 50
diff changeset
   318
    showPreviousView();
hgs
parents: 50
diff changeset
   319
}
hgs
parents: 50
diff changeset
   320
hgs
parents: 50
diff changeset
   321
void CntServiceContactFetchView::showPreviousView()
hgs
parents: 50
diff changeset
   322
{
hgs
parents: 50
diff changeset
   323
    if(mIndex==0)
hgs
parents: 50
diff changeset
   324
    {
hgs
parents: 50
diff changeset
   325
        QVariant variant;
hgs
parents: 50
diff changeset
   326
        variant.setValue(mServiceList);
hgs
parents: 50
diff changeset
   327
        mProvider.CompleteServiceAndCloseApp(variant);
hgs
parents: 50
diff changeset
   328
        
hgs
parents: 50
diff changeset
   329
        CntViewParameters args;
hgs
parents: 50
diff changeset
   330
        mMgr->back( args );
hgs
parents: 50
diff changeset
   331
    }
hgs
parents: 50
diff changeset
   332
}
24
0ba2181d7c28 Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
// EOF