localconnectivityservice/obexserviceman/utils/src/obexutilslaunchwaiter.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eikenv.h>
       
    21 #include <DocumentHandler.h>
       
    22 #include <mmsvattachmentmanager.h>
       
    23 #include <msvids.h>
       
    24 #include <bautils.h>
       
    25 #include <AknCommonDialogsDynMem.h>     // for memory and file selection dialogs
       
    26 #include <CommonDialogs.rsg>
       
    27 #include <pathinfo.h>                   // for getting drive root path
       
    28 #include <Obexutils.rsg>
       
    29 #include <AknGlobalNote.h>
       
    30 #include <StringLoader.h>
       
    31 #include <AiwGenericParam.h>
       
    32 #include "obexutilslaunchwaiter.h"
       
    33 #include "obexutilsdebug.h"
       
    34 #include "obexutilsuilayer.h"            // For launching file manager
       
    35 #include "obexutilsmessagehandler.h"            // For updating an entry
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CObexUtilsLaunchWaiter::NewLC
       
    41 // -----------------------------------------------------------------------------
       
    42 CObexUtilsLaunchWaiter* CObexUtilsLaunchWaiter::NewLC( 
       
    43 	CMsvSession& aMsvSession,
       
    44 	CMsvEntry* aMessage,
       
    45     TRequestStatus& aObserverRequestStatus )
       
    46     {
       
    47     CObexUtilsLaunchWaiter* self = new( ELeave )CObexUtilsLaunchWaiter( 
       
    48         aMsvSession,
       
    49         aMessage, 
       
    50         aObserverRequestStatus );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aMessage );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CObexUtilsLaunchWaiter::NewL
       
    58 // -----------------------------------------------------------------------------
       
    59 CObexUtilsLaunchWaiter* CObexUtilsLaunchWaiter::NewL(
       
    60 	CMsvSession& aMsvSession,
       
    61 	CMsvEntry* aMessage,
       
    62     TRequestStatus& aObserverRequestStatus )
       
    63     {
       
    64     CObexUtilsLaunchWaiter* self = CObexUtilsLaunchWaiter::NewLC(
       
    65         aMsvSession,
       
    66         aMessage, 
       
    67         aObserverRequestStatus );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CObexUtilsLaunchWaiter::ConstructL
       
    74 // -----------------------------------------------------------------------------
       
    75 void CObexUtilsLaunchWaiter::ConstructL( CMsvEntry* aMessage )
       
    76     {
       
    77     if (aMessage->Count() < 1)
       
    78         {
       
    79         User::Leave(KErrOverflow);
       
    80         }
       
    81     
       
    82     CMsvEntry* attachEntry = iMsvSession.GetEntryL(((*aMessage)[0]).Id());
       
    83     CleanupStack::PushL(attachEntry);  // 1st push
       
    84     CMsvStore* store = attachEntry->ReadStoreL();
       
    85     CleanupStack::PushL(store);  // 2nd push
       
    86     
       
    87     CMsvAttachment* attachInfo = store->AttachmentManagerL().GetAttachmentInfoL(0);
       
    88     CleanupStack::PushL(attachInfo); // 3rd push
       
    89           
       
    90     TDataType dataType = attachInfo->MimeType();
       
    91     TFileName filePath;
       
    92     filePath = attachInfo->FilePath();
       
    93   
       
    94     TInt error = KErrNone;
       
    95     TBool isCompleteSelf = EFalse;      
       
    96     CEikonEnv* eikEnv = CEikonEnv::Static();
       
    97 
       
    98     if ( attachInfo->Type() == CMsvAttachment::EMsvFile )
       
    99         {
       
   100         RFile attachFile;        
       
   101         TRAP( error, attachFile = store->AttachmentManagerL().GetAttachmentFileL(0));
       
   102         if ( error == KErrNone )
       
   103             {
       
   104             CleanupClosePushL(attachFile);  // 4th push          
       
   105             CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();  // 5th push
       
   106             TAiwGenericParam paramSave(EGenericParamAllowSave, ETrue);
       
   107             paramList->AppendL( paramSave );          
       
   108             
       
   109             if ( eikEnv )
       
   110                 {               
       
   111                 iDocumentHandler = CDocumentHandler::NewL( eikEnv->Process() );
       
   112                 iDocumentHandler->SetExitObserver( this );
       
   113                 TRAP( error, iDocumentHandler->OpenFileEmbeddedL(attachFile, dataType, *paramList));               
       
   114                 }// eikEnv        
       
   115             CleanupStack::PopAndDestroy(2); // paramList, attachFile
       
   116             }
       
   117         }// EMsvFile
       
   118     
       
   119     if ( attachInfo->Type() == CMsvAttachment::EMsvLinkedFile )
       
   120         {     
       
   121         if ( eikEnv )
       
   122             {                        
       
   123             RFs rfs;
       
   124             User::LeaveIfError( rfs.Connect() );
       
   125             if ( BaflUtils::FileExists( rfs, filePath ) )                                 
       
   126                 {
       
   127                 CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();  // 4th push
       
   128                 TAiwGenericParam paramSave(EGenericParamFileSaved, ETrue);
       
   129                 paramList->AppendL( paramSave );
       
   130             
       
   131                 iDocumentHandler = CDocumentHandler::NewL( eikEnv->Process() );
       
   132                 iDocumentHandler->SetExitObserver( this );
       
   133                 
       
   134                 RFile64 shareableFile;
       
   135                 TRAP( error, iDocumentHandler->OpenTempFileL(filePath,shareableFile));
       
   136                 if ( error == KErrNone)
       
   137                     {
       
   138                     TRAP( error, iDocumentHandler->OpenFileEmbeddedL( shareableFile, dataType, *paramList));
       
   139                     }
       
   140                 shareableFile.Close();
       
   141                 CleanupStack::PopAndDestroy(); // paramList 
       
   142                 
       
   143                 if ( error == KErrNotSupported )  
       
   144                     {                                                            
       
   145                     const TInt sortMethod = 2;  // 0 = 'By name', 1 = 'By type', 
       
   146                                                 // 2 = 'Most recent first' and 3 = 'Largest first'
       
   147                     TRAP (error, TObexUtilsUiLayer::LaunchFileManagerL( filePath, 
       
   148                                                                         sortMethod, 
       
   149                                                                         ETrue )); // ETrue -> launch file manager in embedded mode.                    
       
   150                     }  // KErrNotSupported
       
   151                 isCompleteSelf = ETrue;                                         
       
   152                 }            
       
   153             else 
       
   154                 {
       
   155                 error = KErrNone;
       
   156                 TFileName fileName;
       
   157                 if (LocateFileL(fileName, filePath))
       
   158                     {
       
   159                     // Update the entry
       
   160                     TRAP(error, TObexUtilsMessageHandler::UpdateEntryAttachmentL(fileName,aMessage));
       
   161                     if ( error == KErrNone )
       
   162                         {
       
   163                         // Show a confirmation note
       
   164                         CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
   165                         HBufC* stringholder  = StringLoader::LoadLC( R_BT_SAVED_LINK_UPDATED );
       
   166                         note->ShowNoteL(EAknGlobalConfirmationNote, *stringholder);
       
   167                         CleanupStack::PopAndDestroy(2); //note and stringholder
       
   168                         }            
       
   169                     }    
       
   170                 isCompleteSelf = ETrue;
       
   171                 }  
       
   172            
       
   173             rfs.Close();
       
   174             } // eikEnv                                          
       
   175         } // EMsvLinkedFile
       
   176      
       
   177     
       
   178     // Set message to READ     
       
   179     TMsvEntry entry = aMessage->Entry();
       
   180     entry.SetUnread( EFalse );
       
   181     aMessage->ChangeL( entry );
       
   182     
       
   183     User::LeaveIfError ( error );
       
   184     CleanupStack::PopAndDestroy(3); //  attachInfo, store, attachEntry        
       
   185     
       
   186     iObserverRequestStatus = KRequestPending;  // CMsvOperation (observer)
       
   187     iStatus = KRequestPending;  // CMsvOperation
       
   188     SetActive();
       
   189 
       
   190     if ( isCompleteSelf )
       
   191         {
       
   192         HandleServerAppExit( error );
       
   193         }
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // Destructor
       
   198 // -----------------------------------------------------------------------------
       
   199 CObexUtilsLaunchWaiter::~CObexUtilsLaunchWaiter()
       
   200     {
       
   201     Cancel();
       
   202     if (iDocumentHandler)
       
   203         {
       
   204         delete iDocumentHandler;
       
   205         iDocumentHandler = NULL;
       
   206         }
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CObexUtilsLaunchWaiter::RunL
       
   211 // -----------------------------------------------------------------------------
       
   212 void CObexUtilsLaunchWaiter::RunL()
       
   213     {
       
   214     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::RunL()"));
       
   215     
       
   216     TRequestStatus* status = &iObserverRequestStatus;
       
   217     User::RequestComplete( status, KErrNone );
       
   218 
       
   219     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::RunL() completed"));
       
   220     }
       
   221     
       
   222 // -----------------------------------------------------------------------------
       
   223 // CObexUtilsLaunchWaiter::DoCancel
       
   224 // -----------------------------------------------------------------------------
       
   225 void CObexUtilsLaunchWaiter::DoCancel()
       
   226     {
       
   227     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::DoCancel()"));
       
   228    
       
   229     if ( iStatus == KRequestPending )
       
   230         {
       
   231         TRequestStatus* pstat = &iStatus;
       
   232         User::RequestComplete( pstat, KErrCancel );
       
   233         }
       
   234       
       
   235     if( iObserverRequestStatus == KRequestPending )
       
   236         {
       
   237         TRequestStatus* observerStatus = &iObserverRequestStatus;
       
   238         User::RequestComplete( observerStatus, KErrCancel );
       
   239         }
       
   240 
       
   241     
       
   242     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::DoCancel() completed"));
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter
       
   247 // -----------------------------------------------------------------------------
       
   248 CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter( 
       
   249 	CMsvSession& aMsvSession,
       
   250 	CMsvEntry* /*aMessage*/,
       
   251     TRequestStatus& aObserverRequestStatus )
       
   252     :
       
   253     CMsvOperation(aMsvSession, EPriorityStandard, aObserverRequestStatus),
       
   254     iDocumentHandler(NULL)
       
   255     {
       
   256     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter()"));
       
   257 
       
   258     CActiveScheduler::Add( this );
       
   259 
       
   260     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter() completed"));
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CObexUtilsLaunchWaiter::HandleServerAppExit
       
   265 // -----------------------------------------------------------------------------
       
   266 void CObexUtilsLaunchWaiter::HandleServerAppExit(TInt aReason)
       
   267     {
       
   268     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::HandleServerAppExit()"));
       
   269 
       
   270     if( iStatus == KRequestPending )
       
   271         {
       
   272         // Complete self
       
   273         //
       
   274         TRequestStatus* status = &iStatus;
       
   275         User::RequestComplete( status, aReason );
       
   276         }
       
   277 
       
   278 	MAknServerAppExitObserver::HandleServerAppExit( aReason );	
       
   279     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::HandleServerAppExit() completed"));
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CObexUtilsLaunchWaiter::ProgressL
       
   284 // -----------------------------------------------------------------------------
       
   285 const TDesC8& CObexUtilsLaunchWaiter::ProgressL()
       
   286     {
       
   287     return KNullDesC8;
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CObexUtilsLaunchWaiter::LocateFile
       
   292 // -----------------------------------------------------------------------------
       
   293 TBool CObexUtilsLaunchWaiter::LocateFileL(TFileName& aFileName, const TFileName& anOldFileName)
       
   294     {
       
   295     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::LocateFile()"));
       
   296     
       
   297     TBuf<200> buf;
       
   298     TRequestStatus status = KRequestPending;
       
   299     
       
   300     TParse fileParseOld;
       
   301     fileParseOld.Set(anOldFileName, NULL, NULL);
       
   302     TFileName oldName = fileParseOld.NameAndExt();
       
   303             
       
   304     // check old link if the file saved in mmc. If so, check if mmc available. 
       
   305     // if unavailable, show "is File not found as memory card is not present"
       
   306     //
       
   307     TInt err = CheckIfSaveInMMC( anOldFileName );
       
   308     TBool showMMCOut = EFalse;
       
   309     if( err == EDriveF)
       
   310         {
       
   311         if( CheckDriveL(EDriveF) )
       
   312             showMMCOut = ETrue;
       
   313         }
       
   314     else if( err == EDriveE )
       
   315         {
       
   316         if( CheckDriveL(EDriveE) )
       
   317             showMMCOut = ETrue;
       
   318         }
       
   319 
       
   320     TBool answer = EFalse;
       
   321     if( showMMCOut )
       
   322         {
       
   323         answer = TObexUtilsUiLayer::ShowGlobalConfirmationQueryPlainL(R_BT_SAVED_NO_MEMORY_CARD);
       
   324         }
       
   325     else
       
   326         {
       
   327         answer = TObexUtilsUiLayer::ShowGlobalConfirmationQueryPlainL(R_BT_SAVED_SEARCH);
       
   328         }
       
   329    
       
   330     TBool updateLink = EFalse;
       
   331     if ( answer )
       
   332         {
       
   333         updateLink = LaunchFileSelectionDialogL(aFileName, oldName);               
       
   334         }  
       
   335     
       
   336     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::LocateFile() completed"));
       
   337     return updateLink;
       
   338     }
       
   339     
       
   340 // -----------------------------------------------------------------------------
       
   341 // CObexUtilsLaunchWaiter::LaunchFileSelectionDialogL
       
   342 // -----------------------------------------------------------------------------
       
   343 TBool CObexUtilsLaunchWaiter::LaunchFileSelectionDialogL(
       
   344     TFileName& aFileName, 
       
   345     const TFileName& anOldName)
       
   346     {
       
   347     TBuf<200> buf;
       
   348     TParse fileParseNew;
       
   349     TFileName nameNew;
       
   350     TBool updateLink = EFalse;
       
   351    
       
   352     while ( !updateLink ) 
       
   353         {
       
   354         TBool isSelected =  AknCommonDialogsDynMem::RunSelectDlgLD( AknCommonDialogsDynMem::EMemoryTypeMMCExternal|
       
   355                                                                     AknCommonDialogsDynMem::EMemoryTypeMMC|
       
   356                                                                     AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage|
       
   357                                                                     AknCommonDialogsDynMem::EMemoryTypePhone,
       
   358                                                                     aFileName,
       
   359                                                                     R_CFD_DEFAULT_SELECT_MEMORY_SELECTION,
       
   360                                                                     R_CFD_DEFAULT_SELECT_FILE_SELECTION );
       
   361         
       
   362         if ( isSelected )
       
   363             {
       
   364             fileParseNew.Set(aFileName, NULL, NULL);
       
   365             nameNew = fileParseNew.NameAndExt();
       
   366             
       
   367             if ( nameNew.Compare(anOldName)) // names do not match
       
   368                 {
       
   369                 updateLink =  TObexUtilsUiLayer::ShowGlobalConfirmationQueryPlainL(R_BT_SAVED_SEARCH_UPDATE);                        
       
   370                 }
       
   371             else
       
   372                 {
       
   373                 updateLink = ETrue;
       
   374                 }       
       
   375             }
       
   376         else
       
   377             {
       
   378             break;  // Exit from while loop.
       
   379             }
       
   380         }
       
   381   
       
   382     return updateLink;
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CObexUtilsLaunchWaiter::CheckDriveL
       
   387 // -----------------------------------------------------------------------------
       
   388 TInt CObexUtilsLaunchWaiter::CheckDriveL(TDriveNumber aDriveNumber)
       
   389     {
       
   390     RFs rfs;
       
   391     User::LeaveIfError(rfs.Connect());
       
   392     CleanupClosePushL( rfs ) ;
       
   393     TVolumeInfo volumeInfo;
       
   394     TInt err = rfs.Volume(volumeInfo, aDriveNumber);
       
   395     CleanupStack::PopAndDestroy();    // rfs
       
   396     
       
   397     return err;
       
   398     }
       
   399 // -----------------------------------------------------------------------------
       
   400 // CObexUtilsLaunchWaiter::CheckIfSaveInMMC
       
   401 // -----------------------------------------------------------------------------
       
   402 TInt CObexUtilsLaunchWaiter::CheckIfSaveInMMC(const TFileName& aFileName)
       
   403     {
       
   404     if(aFileName.Find(_L("F:")) != KErrNotFound)
       
   405         return EDriveF;
       
   406     if(aFileName.Find(_L("E:")) != KErrNotFound)
       
   407         return EDriveE;
       
   408 
       
   409     return KErrNotFound;
       
   410     }
       
   411 //  End of File