phonebookui/cntcommonui/common/cntactionlauncher.cpp
changeset 81 640d30f4fb64
parent 72 6abfb1094884
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
    17 #include "cntactionlauncher.h"
    17 #include "cntactionlauncher.h"
    18 
    18 
    19 /*!
    19 /*!
    20 Action launcher. Caller should delete the instance.
    20 Action launcher. Caller should delete the instance.
    21 */
    21 */
    22 CntActionLauncher::CntActionLauncher( QContactManager& aContactManager, QString aAction ) : QObject(),
    22 CntActionLauncher::CntActionLauncher( QContactManager& aContactManager, QString aAction ) :
    23 mAction( aAction ),
    23     QObject(),
    24 mContactAction( NULL ),
    24     mAction( aAction ),
    25 mContactManager( &aContactManager )
    25     mContactAction( NULL ),
       
    26     mContactManager( &aContactManager )
       
    27 {
       
    28     
       
    29 }
       
    30 
       
    31 CntActionLauncher::~CntActionLauncher()
       
    32 {
       
    33     delete mContactAction;
       
    34 }
       
    35     
       
    36 bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail )
       
    37 {
       
    38     bool executed = false;
       
    39     QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
       
    40     if ( all.count() )
    26     {
    41     {
       
    42         mContactAction = QContactAction::action( all.first() );
       
    43         
       
    44         if (mContactAction)
       
    45         {
       
    46             if (aContact.preferredDetail(mAction).isEmpty() && (mAction == "call"))
       
    47             {
       
    48                 aContact.setPreferredDetail(mAction, aDetail);
       
    49                 //return value will be ignored because we cannot do anything if it fails.
       
    50                 mContactManager->saveContact(&aContact);
       
    51             }
       
    52 
       
    53             connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
       
    54                     this, SLOT(progress(QContactAction::State)));
       
    55             executed = mContactAction->invokeAction( aContact, aDetail );
       
    56         }
       
    57         else
       
    58         {
       
    59             progress(QContactAction::FinishedWithErrorState);
       
    60         }
       
    61     }
       
    62     else
       
    63     {
       
    64         progress(QContactAction::FinishedWithErrorState);
    27     }
    65     }
    28 
    66 
    29 CntActionLauncher::~CntActionLauncher()
    67     return executed;
    30     {
    68 }
    31     delete mContactAction;
    69 
    32     }
    70 bool CntActionLauncher::execute( QContact aGrpContact, QContactDetail aDetail, QVariantMap aParameters )
    33     
    71 {
    34 bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail )
       
    35     {
       
    36     bool executed = false;
    72     bool executed = false;
    37     QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
    73     QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
    38     mContactAction = QContactAction::action( all.first() );
    74     mContactAction = QContactAction::action( all.first() );
    39     if ( mContactAction )
    75     if ( mContactAction )
    40         {
       
    41         if (aContact.preferredDetail(mAction).isEmpty() && (mAction == "call" || mAction == "message" || mAction == "email"))
       
    42             {
       
    43             aContact.setPreferredDetail(mAction, aDetail);
       
    44             //return value will be ignored because we cannot do anything if it fails.
       
    45             mContactManager->saveContact(&aContact);
       
    46             }
       
    47         
       
    48         connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
       
    49                 this, SLOT(progress(QContactAction::State)));
       
    50         executed = mContactAction->invokeAction( aContact, aDetail );
       
    51         }
       
    52     else
       
    53         {
       
    54         progress(QContactAction::FinishedWithErrorState);
       
    55         }
       
    56     
       
    57     return executed;
       
    58     }
       
    59 
       
    60 bool CntActionLauncher::execute( QContact aGrpContact, QContactDetail aDetail, QVariantMap aParameters )
       
    61     {
    76     {
    62     bool executed = false;
       
    63     QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
       
    64     mContactAction = QContactAction::action( all.first() );
       
    65     if ( mContactAction )
       
    66         {
       
    67         connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
    77         connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
    68                 this, SLOT(progress(QContactAction::State)));
    78                 this, SLOT(progress(QContactAction::State)));
    69         executed = mContactAction->invokeAction( aGrpContact, aDetail, aParameters );
    79         executed = mContactAction->invokeAction( aGrpContact, aDetail, aParameters );
    70         }
    80     }
    71     else
    81     else
    72         {
    82     {
    73         progress(QContactAction::FinishedWithErrorState);
    83         progress(QContactAction::FinishedWithErrorState);
    74         }
    84     }
    75     
    85 
    76     return executed;
    86     return executed;
    77     }
    87 }
    78  
    88 
    79 /*!
    89 /*!
    80 Launch dynamic action
    90 Launch dynamic action
    81 */
    91 */
    82 bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor )
    92 bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor )
    83 {
    93 {
    96     }
   106     }
    97     return executed;
   107     return executed;
    98 }
   108 }
    99 
   109 
   100 void CntActionLauncher::progress( QContactAction::State status )
   110 void CntActionLauncher::progress( QContactAction::State status )
       
   111 {
       
   112     switch(status)
   101     {
   113     {
   102     switch(status)
   114     case QContactAction::FinishedState:
   103        {
   115     case QContactAction::FinishedWithErrorState:
   104        case QContactAction::FinishedState:
   116         emit actionExecuted( this );
   105        case QContactAction::FinishedWithErrorState:
   117         break;
   106            emit actionExecuted( this );
   118     default:
   107            break;
   119         break;
   108        default:
       
   109            break;
       
   110        }
       
   111     }
   120     }
       
   121 }
   112 
   122 
   113 // End of File
   123 // End of File