locationsystemui/locationsysui/privacyverifiernotifierui/locverifier/src/lpdglobalplugindialog.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  List query dialog suitable for verifier plug-in use.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "lpdglobalplugindialog.h"
       
    21 #include "lpddlgobserver.h"
       
    22 #include "lpdrequestorprocessor.h"
       
    23 #include "locverifierdlgdebug.h"
       
    24 
       
    25 #include <lbs/EPos_CPosContactRequestor.h>
       
    26 #include <lbs/EPos_CPosServiceRequestor.h>
       
    27 #include <lbs/EPos_CPosRequestor.h>
       
    28 #include <hbsymbianvariant.h>
       
    29 #include <hbtextresolversymbian.h>
       
    30 #include <systemtoneservice.h>
       
    31 #include <e32des16.h>
       
    32 
       
    33 _LIT(KNotifReqSeperator,",");
       
    34 _LIT(KHeadingKey, "heading");
       
    35 _LIT(KQueryTextKey, "queryText");
       
    36 _LIT(KQueryText2Key, "queryText2");
       
    37 _LIT(KRequestorKey, "requestor");
       
    38 _LIT(KVerificationDlgType, "hb.posverifiction.dialog/1.0");
       
    39 _LIT(KLocTsFileName, "lilocationmw_");
       
    40 _LIT(KLocTsFilePath, "z://resource/qt/translations/");
       
    41 _LIT(KLocTsAFileAltPath, "c://resource/");
       
    42 //Translation String Ids
       
    43 //Verification Dialog
       
    44 _LIT(KRequestHeading, "txt_loe_title_location_request");
       
    45 _LIT(KSingleshotDecisionRejected, "txt_loe_info_your_location_will_not_be_shared_by_d");
       
    46 _LIT(KSingleshotDecisionAccepted, "txt_loe_info_your_location_will_be_shared_by_defau");
       
    47 _LIT(KSingleshotDecisionNotAvailable, "txt_loe_info_your_location_will_be_shared_with");
       
    48 _LIT(KPeriodicDecisionRejected, "txt_loe_info_your_location_will_not_be_shared_peri");
       
    49 _LIT(KPeriodicDecisionAccepted, "txt_loe_info_your_location_will_be_shared_periodic");
       
    50 _LIT(KPeriodicDecisionNotAvailable, "txt_loe_info_you_location_will_be_shared_periodica");
       
    51 _LIT(KRequestorText, "txt_loe_info_location_was_requested_by");
       
    52 _LIT(KUnknownRequestor, "txt_loe_info_unknown_requestor");
       
    53 //Notification
       
    54 _LIT(KNotificationNotSent, "txt_loe_dpophead_your_location_not_sent_to");
       
    55 _LIT(KNotificationSent, "txt_loe_dpophead_your_location_sent_to");
       
    56 
       
    57 const TInt KNotificationTimeout = 15000;
       
    58 const TInt KMaxSize = 1024;
       
    59 const TInt KVariantMaxSize = 256;
       
    60 // ============================ MEMBER FUNCTIONS ===============================
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CLpdGlobalPluginDialog::CLpdGlobalPluginDialog
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CLpdGlobalPluginDialog::CLpdGlobalPluginDialog(                    
       
    69     MLpdDlgObserver& aCallBack
       
    70     )
       
    71     : iCallBack( aCallBack ),
       
    72       iMsgBox(NULL),
       
    73       iNotification(NULL),
       
    74       iRequestInfo(NULL)
       
    75     {
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CLpdGlobalPluginDialog::ConstructL
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CLpdGlobalPluginDialog::ConstructL()
       
    84     {
       
    85     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::ConstructL" );
       
    86     iMsgBox = CHbDeviceDialogSymbian::NewL();
       
    87     iNotification = CHbDeviceNotificationDialogSymbian::NewL(this);
       
    88     TBool result =
       
    89             HbTextResolverSymbian::Init(KLocTsFileName, KLocTsFilePath);
       
    90     if (!result)
       
    91         {
       
    92         HbTextResolverSymbian::Init(KLocTsFileName, KLocTsAFileAltPath);
       
    93         }
       
    94     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::ConstructL" );
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CLpdGlobalPluginDialog::NewL
       
    99 // Two-phased constructor.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CLpdGlobalPluginDialog* CLpdGlobalPluginDialog::NewL(                    
       
   103     MLpdDlgObserver& aCallBack)
       
   104     {
       
   105     CLpdGlobalPluginDialog* self =
       
   106         new( ELeave ) CLpdGlobalPluginDialog( aCallBack);
       
   107 	CleanupStack::PushL(self);
       
   108 	self->ConstructL();
       
   109 	CleanupStack::Pop(self);  
       
   110     return self;
       
   111     }
       
   112 
       
   113 // Destructor
       
   114 CLpdGlobalPluginDialog::~CLpdGlobalPluginDialog()
       
   115 	{
       
   116    	 LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::~CLpdGlobalPluginDialog" );
       
   117    	delete iMsgBox;
       
   118 	iMsgBox = NULL;
       
   119 	
       
   120 	delete iNotification;
       
   121 	iNotification = NULL;
       
   122 	
       
   123 	 delete iRequestInfo;
       
   124 	 iRequestInfo=NULL;
       
   125 	 LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::~CLpdGlobalPluginDialog" );
       
   126 	}
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CLpdGlobalPluginDialog::RunLD
       
   131 // (other items were commented in a header).
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CLpdGlobalPluginDialog::RunVerificationQueryL()
       
   135     {
       
   136     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::RunVerificationQueryL" );
       
   137     mSymbianVariantMap = CHbSymbianVariantMap::NewL();
       
   138     CleanupStack::PushL(mSymbianVariantMap);
       
   139     
       
   140     AddVerDlgHeadingParamL();
       
   141     AddQueryTextParamL();
       
   142     AddRequestorsParamL();
       
   143     CSystemToneService* sts = CSystemToneService::Create();
       
   144     iMsgBox->Show(KVerificationDlgType, *mSymbianVariantMap, this);
       
   145     if( sts )
       
   146         {
       
   147         sts->PlayTone(CSystemToneService::ELocationRequest);
       
   148         }
       
   149     CSystemToneService::Delete(sts);
       
   150     CleanupStack::Pop(mSymbianVariantMap);
       
   151     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::RunVerificationQueryL" );
       
   152     }
       
   153 
       
   154 void CLpdGlobalPluginDialog::RunNotificationL()
       
   155     {
       
   156     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::RunNotificationL" );
       
   157     if( EPosDecisionByRequestSource == iRequestInfo->iNotifReason ||
       
   158         EPosVerificationTimeout == iRequestInfo->iNotifReason    )
       
   159         {
       
   160         if ( EPosDecisionAccepted == iRequestInfo->iRequestDecision )
       
   161             {
       
   162             HBufC* title = HbTextResolverSymbian::LoadL(KNotificationSent);
       
   163             CleanupStack::PushL(title);
       
   164             iNotification->SetTitleL(title->Des());
       
   165             CleanupStack::PopAndDestroy(title);
       
   166             }
       
   167         if( EPosDecisionRejected == iRequestInfo->iRequestDecision )
       
   168             {
       
   169             HBufC* title = HbTextResolverSymbian::LoadL(KNotificationNotSent);
       
   170             CleanupStack::PushL(title);
       
   171             iNotification->SetTitleL(title->Des());
       
   172             CleanupStack::PopAndDestroy(title);
       
   173             }
       
   174         }
       
   175     else
       
   176         {
       
   177         // Not supported   
       
   178         User::Leave(KErrNotSupported);
       
   179         }
       
   180     TBuf<KMaxSize> buf;
       
   181     
       
   182     TInt count= iRequestInfo->iRequestors.Count();
       
   183     if( count == 0 )
       
   184         {
       
   185         HBufC* requestor = HbTextResolverSymbian::LoadL(KUnknownRequestor);
       
   186         CleanupStack::PushL(requestor);
       
   187         buf.Append(requestor->Des());
       
   188         CleanupStack::PopAndDestroy(requestor);
       
   189         }
       
   190     else
       
   191         {
       
   192         for(TInt i=0;i< count;i++ )
       
   193             {
       
   194             if(i!=0)
       
   195                 {
       
   196                 buf.Append(KNotifReqSeperator);
       
   197                 }
       
   198             buf.Append(iRequestInfo->iRequestors[i]->RequestorIdString());
       
   199             }
       
   200         }
       
   201     iNotification->SetTextL(buf);
       
   202     iNotification->SetTimeout(KNotificationTimeout);
       
   203     iNotification->EnableTouchActivation(ETrue);
       
   204     iNotification->ShowL();
       
   205     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::RunNotificationL" );
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CLpdGlobalPluginDialog::SetMessageTextL
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CLpdGlobalPluginDialog::SetRequestInfoL( CLpdRequestorProcessor* aRequestInfo )
       
   214     {
       
   215     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::SetRequestInfoL" );
       
   216     if(iRequestInfo)
       
   217         {
       
   218         // clear and create again if already has been set before
       
   219         delete iRequestInfo;
       
   220         iRequestInfo=NULL;
       
   221         }
       
   222     iRequestInfo=CLpdRequestorProcessor::NewL();
       
   223     
       
   224     iRequestInfo->iDialogType=aRequestInfo->iDialogType;
       
   225     iRequestInfo->iNotifReason=aRequestInfo->iNotifReason;
       
   226     iRequestInfo->iRequestDecision=aRequestInfo->iRequestDecision;
       
   227     iRequestInfo->iRequestType=aRequestInfo->iRequestType;
       
   228     
       
   229     const RPointerArray<CPosRequestor>& requestors = aRequestInfo->iRequestors;
       
   230     
       
   231     TInt count = requestors.Count();
       
   232     for(TInt i=0; i< count; i++ )
       
   233         {
       
   234         CPosRequestor::TRequestorIdFormat idFormat;
       
   235         TPtrC idString;
       
   236         idFormat=requestors[i]->RequestorIdFormat();
       
   237         idString.Set(requestors[i]->RequestorIdString());
       
   238         
       
   239         if( CPosRequestor::ERequestorService==requestors[i]->RequestType())
       
   240             {
       
   241             CPosServiceRequestor* service = CPosServiceRequestor::NewL(idFormat,idString);
       
   242             CleanupStack::PushL(service);
       
   243             // Ownership transferred
       
   244             iRequestInfo->iRequestors.Append(service);
       
   245             CleanupStack::Pop(service);
       
   246             }
       
   247         else
       
   248             {
       
   249             CPosContactRequestor* contact = CPosContactRequestor::NewL(idFormat,idString);
       
   250             CleanupStack::PushL(contact);
       
   251             // Ownership transferred
       
   252             iRequestInfo->iRequestors.Append(contact);
       
   253             CleanupStack::Pop(contact);
       
   254             }
       
   255         
       
   256         }
       
   257     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::SetRequestInfoL" );
       
   258     }
       
   259 
       
   260 
       
   261 
       
   262 void CLpdGlobalPluginDialog::Cancel()
       
   263     {
       
   264     // Close any running dialogs if any.Close() doesnt have any effect if dialog is not running
       
   265     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::Cancel" );
       
   266     isCancelled = ETrue;
       
   267     iMsgBox->Cancel();
       
   268     iNotification->Close();
       
   269     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::Cancel" );
       
   270     }
       
   271 
       
   272 void CLpdGlobalPluginDialog::NotificationDialogActivated(
       
   273         const CHbDeviceNotificationDialogSymbian */*aDialog*/)        
       
   274     {
       
   275     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::NotificationDialogActivated" );
       
   276     // Complete with KErrNone now 
       
   277     TRAP_IGNORE(iCallBack.HandleDlgDismissedL( KErrNone ));
       
   278     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::NotificationDialogActivated" );
       
   279     }
       
   280 
       
   281 void CLpdGlobalPluginDialog::NotificationDialogClosed(
       
   282         const CHbDeviceNotificationDialogSymbian */*aDialog*/,
       
   283         TInt aCompletionCode)
       
   284     {
       
   285     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::NotificationDialogClosed" );
       
   286     TRAP_IGNORE(iCallBack.HandleDlgDismissedL( aCompletionCode ));
       
   287     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::NotificationDialogClosed" );
       
   288     }
       
   289 
       
   290 void CLpdGlobalPluginDialog::DataReceived(CHbSymbianVariantMap& /*aData*/)
       
   291     {
       
   292     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::DataReceived" );
       
   293     mDissmissed = ETrue;
       
   294     TRAP_IGNORE(iCallBack.HandleDlgDismissedL( KErrAccessDenied ));
       
   295     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::DataReceived" );
       
   296     }
       
   297 
       
   298 void CLpdGlobalPluginDialog::DeviceDialogClosed(TInt /*aCompletionCode*/)
       
   299     {
       
   300      LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::DeviceDialogClosed" );
       
   301     if (!mDissmissed && !isCancelled)
       
   302         {
       
   303         TRAP_IGNORE(iCallBack.HandleDlgDismissedL( KErrNone ));
       
   304         }
       
   305      LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::DeviceDialogClosed" );
       
   306     }
       
   307 
       
   308 void CLpdGlobalPluginDialog::AddVerDlgHeadingParamL()
       
   309     {
       
   310     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::AddVerDlgHeadingParamL" );
       
   311     HBufC* headingText = HbTextResolverSymbian::LoadL(KRequestHeading);
       
   312     CleanupStack::PushL(headingText);
       
   313     CHbSymbianVariant* heading = CHbSymbianVariant::NewL(headingText,
       
   314             CHbSymbianVariant::EDes);
       
   315     CleanupStack::PushL(heading);
       
   316     mSymbianVariantMap->Add(KHeadingKey, heading );
       
   317     CleanupStack::Pop(heading);
       
   318     CleanupStack::PopAndDestroy(headingText);
       
   319     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::AddVerDlgHeadingParamL" );
       
   320     }
       
   321 
       
   322 void CLpdGlobalPluginDialog::AddQueryTextParamL()
       
   323     {
       
   324      LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::AddQueryTextParamL" );
       
   325     HBufC * value = HBufC::NewL(KVariantMaxSize);
       
   326     CleanupStack::PushL(value);
       
   327     HBufC * value2 = HBufC::NewL(KVariantMaxSize);
       
   328     CleanupStack::PushL(value2);
       
   329     HBufC* requestorText = HbTextResolverSymbian::LoadL(KRequestorText);
       
   330     CleanupStack::PushL(requestorText);
       
   331 
       
   332     if (CPosRequestor::ERequestSingleShot == iRequestInfo->iRequestType)
       
   333         {
       
   334         if (EPosDecisionNotAvailable == iRequestInfo->iRequestDecision)
       
   335             {
       
   336             HBufC* queryText = HbTextResolverSymbian::LoadL(
       
   337                     KSingleshotDecisionNotAvailable);
       
   338             CleanupStack::PushL(queryText);
       
   339             value->Des().Copy(queryText->Des());
       
   340             CleanupStack::PopAndDestroy(queryText);
       
   341             }
       
   342         else if (EPosDecisionAccepted == iRequestInfo->iRequestDecision)
       
   343             {
       
   344             HBufC* queryText = HbTextResolverSymbian::LoadL(
       
   345                     KSingleshotDecisionAccepted);
       
   346             CleanupStack::PushL(queryText);
       
   347             value->Des().Copy(queryText->Des());
       
   348             value2->Des().Copy(requestorText->Des());
       
   349             CleanupStack::PopAndDestroy(queryText);
       
   350             }
       
   351         else if (EPosDecisionRejected == iRequestInfo->iRequestDecision)
       
   352             {
       
   353             HBufC* queryText = HbTextResolverSymbian::LoadL(
       
   354                     KSingleshotDecisionRejected);
       
   355             CleanupStack::PushL(queryText);
       
   356             value->Des().Copy(queryText->Des());
       
   357             value2->Des().Copy(requestorText->Des());
       
   358             CleanupStack::PopAndDestroy(queryText);
       
   359             }
       
   360         }
       
   361 
       
   362     else if (CPosRequestor::ERequestPeriodic == iRequestInfo->iRequestType)
       
   363         {
       
   364         if (EPosDecisionNotAvailable == iRequestInfo->iRequestDecision)
       
   365             {
       
   366             HBufC* queryText = HbTextResolverSymbian::LoadL(
       
   367                     KPeriodicDecisionNotAvailable);
       
   368             CleanupStack::PushL(queryText);
       
   369             value->Des().Copy(queryText->Des());
       
   370             CleanupStack::PopAndDestroy(queryText);
       
   371             }
       
   372         else if (EPosDecisionAccepted == iRequestInfo->iRequestDecision)
       
   373             {
       
   374             HBufC* queryText = HbTextResolverSymbian::LoadL(
       
   375                     KPeriodicDecisionAccepted);
       
   376             CleanupStack::PushL(queryText);
       
   377             value->Des().Copy(queryText->Des());
       
   378             value2->Des().Copy(requestorText->Des());
       
   379             CleanupStack::PopAndDestroy(queryText);
       
   380             }
       
   381         else if (EPosDecisionRejected == iRequestInfo->iRequestDecision)
       
   382             {
       
   383             HBufC* queryText = HbTextResolverSymbian::LoadL(
       
   384                     KPeriodicDecisionRejected);
       
   385             CleanupStack::PushL(queryText);
       
   386             value->Des().Copy(queryText->Des());
       
   387             value2->Des().Copy(requestorText->Des());
       
   388             CleanupStack::PopAndDestroy(queryText);
       
   389             }
       
   390         }
       
   391     else
       
   392         {
       
   393         // Not supported   
       
   394         User::Leave(KErrNotSupported);
       
   395         }
       
   396 
       
   397     CHbSymbianVariant* queryText = CHbSymbianVariant::NewL(value,
       
   398             CHbSymbianVariant::EDes);
       
   399     CleanupStack::PushL(queryText);
       
   400 
       
   401     CHbSymbianVariant* queryText2 = CHbSymbianVariant::NewL(value2,
       
   402             CHbSymbianVariant::EDes);
       
   403     CleanupStack::PushL(queryText2);
       
   404 
       
   405     if (value2->Length()!= 0)
       
   406         {
       
   407         mSymbianVariantMap->Add(KQueryText2Key, queryText2);
       
   408         }
       
   409     mSymbianVariantMap->Add(KQueryTextKey, queryText);
       
   410     CleanupStack::Pop(queryText2);
       
   411     CleanupStack::Pop(queryText);
       
   412     CleanupStack::PopAndDestroy(3);
       
   413     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::AddQueryTextParamL" );
       
   414     }
       
   415 
       
   416 void CLpdGlobalPluginDialog::AddRequestorsParamL()
       
   417     {
       
   418     LOCVERIFIERDLGDEBUG( "+CLpdGlobalPluginDialog::AddRequestorsParamL" );
       
   419     CDesC16ArrayFlat* array = new CDesC16ArrayFlat(8);
       
   420     TInt reqCount = iRequestInfo->iRequestors.Count();
       
   421     if (!reqCount)
       
   422         {
       
   423         HBufC* requestor = HbTextResolverSymbian::LoadL(KUnknownRequestor);
       
   424         CleanupStack::PushL(requestor);
       
   425         array->AppendL(requestor->Des());
       
   426         CleanupStack::PopAndDestroy(requestor);
       
   427         }
       
   428     else
       
   429     	{
       
   430     	for (TInt i = 0; i < reqCount; ++i)
       
   431 	        {
       
   432 	        array->AppendL(iRequestInfo->iRequestors[i]->RequestorIdString());
       
   433 	        }
       
   434 	    }
       
   435 
       
   436     TInt count = array->MdcaCount();
       
   437     MDesCArray* marray = static_cast<MDesCArray*> (array);
       
   438     CHbSymbianVariant* requestors = CHbSymbianVariant::NewL(marray,
       
   439             CHbSymbianVariant::EDesArray);
       
   440     mSymbianVariantMap->Add(KRequestorKey, requestors);
       
   441     LOCVERIFIERDLGDEBUG( "-CLpdGlobalPluginDialog::AddRequestorsParamL" );
       
   442     }
       
   443 
       
   444 // End of file
       
   445