phonebookui/pbkcommonui/src/cntactionlauncher.cpp
author hgs
Wed, 21 Jul 2010 11:21:49 +0300
changeset 50 77bc263e1626
parent 47 7cbcb2896f0e
child 53 e6aff7b69165
permissions -rw-r--r--
201027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b46a585f6909 Revision: 201021
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".
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
#include "cntactionlauncher.h"
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    19
/*!
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    20
Action launcher. Caller should delete the instance.
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    21
*/
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    22
CntActionLauncher::CntActionLauncher( QContactManager& aContactManager, QString aAction ) : QObject(),
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
mAction( aAction ),
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    24
mContactAction( NULL ),
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    25
mContactManager( &aContactManager )
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
    {
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
    }
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
CntActionLauncher::~CntActionLauncher()
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
    {
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
    delete mContactAction;
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
    }
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
    
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    34
bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail )
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
    {
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    36
    bool executed = false;
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
    QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
    mContactAction = QContactAction::action( all.first() );
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    if ( mContactAction )
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
        {
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    41
        if (aContact.preferredDetail(mAction).isEmpty() && (mAction == "call" || mAction == "message" || mAction == "email"))
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    42
            {
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    43
            aContact.setPreferredDetail(mAction, aDetail);
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    44
            //return value will be ignored because we cannot do anything if it fails.
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    45
            mContactManager->saveContact(&aContact);
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    46
            }
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    47
        
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
        connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
                this, SLOT(progress(QContactAction::State)));
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    50
        executed = mContactAction->invokeAction( aContact, aDetail );
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
        }
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    52
    
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    53
    return executed;
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
    }
50
hgs
parents: 47
diff changeset
    55
hgs
parents: 47
diff changeset
    56
bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail, QVariantMap aParameters )
hgs
parents: 47
diff changeset
    57
    {
hgs
parents: 47
diff changeset
    58
    bool executed = false;
hgs
parents: 47
diff changeset
    59
    QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
hgs
parents: 47
diff changeset
    60
    mContactAction = QContactAction::action( all.first() );
hgs
parents: 47
diff changeset
    61
    if ( mContactAction )
hgs
parents: 47
diff changeset
    62
        {
hgs
parents: 47
diff changeset
    63
        if (aContact.preferredDetail(mAction).isEmpty() && (mAction == "call" || mAction == "message" || mAction == "email"))
hgs
parents: 47
diff changeset
    64
            {
hgs
parents: 47
diff changeset
    65
            aContact.setPreferredDetail(mAction, aDetail);
hgs
parents: 47
diff changeset
    66
            //return value will be ignored because we cannot do anything if it fails.
hgs
parents: 47
diff changeset
    67
            mContactManager->saveContact(&aContact);
hgs
parents: 47
diff changeset
    68
            }
hgs
parents: 47
diff changeset
    69
        
hgs
parents: 47
diff changeset
    70
        connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
hgs
parents: 47
diff changeset
    71
                this, SLOT(progress(QContactAction::State)));
hgs
parents: 47
diff changeset
    72
        executed = mContactAction->invokeAction( aContact, aDetail, aParameters );
hgs
parents: 47
diff changeset
    73
        }
hgs
parents: 47
diff changeset
    74
    
hgs
parents: 47
diff changeset
    75
    return executed;
hgs
parents: 47
diff changeset
    76
    }
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
 
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
/*!
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
Launch dynamic action
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
*/
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    81
bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor )
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
{
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    83
    bool executed = false;
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
    // detail might be empty -> in that case engine uses the preferred detail for the selected action
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
    mContactAction = QContactAction::action( aActionDescriptor );
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    86
    if ( mContactAction )
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    87
    {
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    88
        connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
                this, SLOT(progress(QContactAction::State)));
47
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    90
        executed = mContactAction->invokeAction( aContact, aDetail );
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    91
    }
7cbcb2896f0e Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 40
diff changeset
    92
    return executed;
40
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
}
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
void CntActionLauncher::progress( QContactAction::State status )
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
    {
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
    switch(status)
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
       {
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
       case QContactAction::FinishedState:
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
       case QContactAction::FinishedWithErrorState:
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
           emit actionExecuted( this );
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
           break;
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
       default:
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
           break;
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
       }
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
    }
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
b46a585f6909 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
// End of File