localconnectivityservice/obexserviceman/utils/src/obexutilslaunchwaiter.cpp
changeset 0 c3e98f10fcf4
child 1 388a17646e40
equal deleted inserted replaced
-1:000000000000 0:c3e98f10fcf4
       
     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   
       
    92     TInt error = KErrNone;
       
    93     TBool isCompleteSelf = EFalse;  
       
    94     
       
    95     RFile attachFile;
       
    96     TRAP( error, attachFile = store->AttachmentManagerL().GetAttachmentFileL(0));
       
    97     if ( KErrNone == error )
       
    98         {
       
    99         CleanupClosePushL(attachFile);  // 4th push
       
   100         CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();  // 5th push
       
   101         TAiwGenericParam paramSave(EGenericParamFileSaved, ETrue);
       
   102         paramList->AppendL( paramSave );
       
   103 
       
   104         if ( CEikonEnv::Static() )
       
   105             {
       
   106             // Launches an application in embedded mode
       
   107             iDocumentHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );
       
   108             iDocumentHandler->SetExitObserver( this );
       
   109             TRAP( error, iDocumentHandler->OpenFileEmbeddedL( attachFile, dataType, *paramList ));
       
   110             }
       
   111         else
       
   112             {
       
   113             // Launches an application in standalone mode
       
   114             iDocumentHandler = CDocumentHandler::NewL( );
       
   115             // We do not observe exit event when file is launched in standalone mode.            
       
   116             iDocumentHandler->SetExitObserver( NULL );
       
   117             TRAP( error, iDocumentHandler->OpenFileL( attachFile, dataType));
       
   118             }
       
   119             
       
   120         if ( error == KErrNotSupported )  
       
   121             // If file is not supported, we open the file manager at file location.
       
   122             {
       
   123             // Launchs file manager at default folder
       
   124             delete iDocumentHandler;
       
   125             iDocumentHandler = NULL;
       
   126                
       
   127             TInt sortMethod = 2;  // 0 = 'By name', 1 = 'By type', 
       
   128                                   // 2 = 'Most recent first' and 3 = 'Largest first'
       
   129             TFileName fullName;
       
   130             attachFile.FullName(fullName);
       
   131           
       
   132             TRAP (error, TObexUtilsUiLayer::LaunchFileManagerL( fullName, 
       
   133                                                                        sortMethod, 
       
   134                                                                        ETrue )); // ETrue -> launch file manager in embedded mode.
       
   135             isCompleteSelf = ETrue;
       
   136             }  // KErrNotSupported
       
   137         
       
   138         // Set message to READ
       
   139         //
       
   140         TMsvEntry entry = aMessage->Entry();
       
   141         entry.SetUnread( EFalse );
       
   142         aMessage->ChangeL( entry );
       
   143         CleanupStack::PopAndDestroy(2); // paramList, attachFile
       
   144         
       
   145         }   // KErrNone
       
   146     
       
   147     else // Error != KErrNone, broken link found. 
       
   148          // Lets fix it by selecting the right file.
       
   149         {
       
   150         error = KErrNone;
       
   151         TFileName fileName;
       
   152         TFileName oldFileName = attachInfo->FilePath();
       
   153         // select file
       
   154         //
       
   155         if (LocateFileL(fileName, oldFileName))
       
   156             {
       
   157             // Update the entry
       
   158             TRAP(error, TObexUtilsMessageHandler::UpdateEntryAttachmentL(fileName,aMessage));
       
   159             if ( error == KErrNone )
       
   160                 {
       
   161                 // Show a confirmation note
       
   162                 CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
   163                 HBufC* stringholder  = StringLoader::LoadLC( R_BT_SAVED_LINK_UPDATED );
       
   164                 note->ShowNoteL(EAknGlobalConfirmationNote, *stringholder);
       
   165                 CleanupStack::PopAndDestroy(2); //note and stringholder
       
   166                 }            
       
   167             }           
       
   168         isCompleteSelf = ETrue;
       
   169         }  // !KErrNone
       
   170 
       
   171     User::LeaveIfError ( error );
       
   172     CleanupStack::PopAndDestroy(3); //  attachInfo, store, attachEntry
       
   173     
       
   174     iObserverRequestStatus = KRequestPending;  // CMsvOperation (observer)
       
   175     iStatus = KRequestPending;  // CMsvOperation
       
   176     SetActive();
       
   177 
       
   178     if ( isCompleteSelf )
       
   179         {
       
   180         HandleServerAppExit( error );
       
   181         }
       
   182     }
       
   183 // -----------------------------------------------------------------------------
       
   184 // Destructor
       
   185 // -----------------------------------------------------------------------------
       
   186 CObexUtilsLaunchWaiter::~CObexUtilsLaunchWaiter()
       
   187     {
       
   188     Cancel();
       
   189     if (iDocumentHandler)
       
   190         {
       
   191         delete iDocumentHandler;
       
   192         iDocumentHandler = NULL;
       
   193         }
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CObexUtilsLaunchWaiter::RunL
       
   198 // -----------------------------------------------------------------------------
       
   199 void CObexUtilsLaunchWaiter::RunL()
       
   200     {
       
   201     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::RunL()"));
       
   202     
       
   203     TRequestStatus* status = &iObserverRequestStatus;
       
   204     User::RequestComplete( status, KErrNone );
       
   205 
       
   206     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::RunL() completed"));
       
   207     }
       
   208     
       
   209 // -----------------------------------------------------------------------------
       
   210 // CObexUtilsLaunchWaiter::DoCancel
       
   211 // -----------------------------------------------------------------------------
       
   212 void CObexUtilsLaunchWaiter::DoCancel()
       
   213     {
       
   214     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::DoCancel()"));
       
   215    
       
   216     if ( iStatus == KRequestPending )
       
   217         {
       
   218         TRequestStatus* pstat = &iStatus;
       
   219         User::RequestComplete( pstat, KErrCancel );
       
   220         }
       
   221       
       
   222     if( iObserverRequestStatus == KRequestPending )
       
   223         {
       
   224         TRequestStatus* observerStatus = &iObserverRequestStatus;
       
   225         User::RequestComplete( observerStatus, KErrCancel );
       
   226         }
       
   227 
       
   228     
       
   229     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::DoCancel() completed"));
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter
       
   234 // -----------------------------------------------------------------------------
       
   235 CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter( 
       
   236 	CMsvSession& aMsvSession,
       
   237 	CMsvEntry* /*aMessage*/,
       
   238     TRequestStatus& aObserverRequestStatus )
       
   239     :
       
   240     CMsvOperation(aMsvSession, EPriorityStandard, aObserverRequestStatus),
       
   241     iDocumentHandler(NULL)
       
   242     {
       
   243     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter()"));
       
   244 
       
   245     CActiveScheduler::Add( this );
       
   246 
       
   247     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::CObexUtilsLaunchWaiter() completed"));
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CObexUtilsLaunchWaiter::HandleServerAppExit
       
   252 // -----------------------------------------------------------------------------
       
   253 void CObexUtilsLaunchWaiter::HandleServerAppExit(TInt aReason)
       
   254     {
       
   255     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::HandleServerAppExit()"));
       
   256 
       
   257     if( iStatus == KRequestPending )
       
   258         {
       
   259         // Complete self
       
   260         //
       
   261         TRequestStatus* status = &iStatus;
       
   262         User::RequestComplete( status, aReason );
       
   263         }
       
   264 
       
   265 	MAknServerAppExitObserver::HandleServerAppExit( aReason );	
       
   266     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::HandleServerAppExit() completed"));
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CObexUtilsLaunchWaiter::ProgressL
       
   271 // -----------------------------------------------------------------------------
       
   272 const TDesC8& CObexUtilsLaunchWaiter::ProgressL()
       
   273     {
       
   274     return KNullDesC8;
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CObexUtilsLaunchWaiter::LocateFile
       
   279 // -----------------------------------------------------------------------------
       
   280 TBool CObexUtilsLaunchWaiter::LocateFileL(TFileName& aFileName, const TFileName& anOldFileName)
       
   281     {
       
   282     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::LocateFile()"));
       
   283     
       
   284     TBuf<200> buf;
       
   285     TRequestStatus status = KRequestPending;
       
   286     
       
   287     TParse fileParseOld;
       
   288     fileParseOld.Set(anOldFileName, NULL, NULL);
       
   289     TFileName oldName = fileParseOld.NameAndExt();
       
   290             
       
   291     // check old link if the file saved in mmc. If so, check if mmc available. 
       
   292     // if unavailable, show "is File not found as memory card is not present"
       
   293     //
       
   294     TInt err = CheckIfSaveInMMC( anOldFileName );
       
   295     TBool showMMCOut = EFalse;
       
   296     if( err == EDriveF)
       
   297         {
       
   298         if( CheckDriveL(EDriveF) )
       
   299             showMMCOut = ETrue;
       
   300         }
       
   301     else if( err == EDriveE )
       
   302         {
       
   303         if( CheckDriveL(EDriveE) )
       
   304             showMMCOut = ETrue;
       
   305         }
       
   306 
       
   307     TBool answer = EFalse;
       
   308     if( showMMCOut )
       
   309         {
       
   310         answer = TObexUtilsUiLayer::ShowGlobalConfirmationQueryPlainL(R_BT_SAVED_NO_MEMORY_CARD);
       
   311         }
       
   312     else
       
   313         {
       
   314         answer = TObexUtilsUiLayer::ShowGlobalConfirmationQueryPlainL(R_BT_SAVED_SEARCH);
       
   315         }
       
   316    
       
   317     TBool updateLink = EFalse;
       
   318     if ( answer )
       
   319         {
       
   320         updateLink = LaunchFileSelectionDialogL(aFileName, oldName);               
       
   321         }  
       
   322     
       
   323     FLOG(_L("[OBEXUTILS]\t CObexUtilsLaunchWaiter::LocateFile() completed"));
       
   324     return updateLink;
       
   325     }
       
   326     
       
   327 // -----------------------------------------------------------------------------
       
   328 // CObexUtilsLaunchWaiter::LaunchFileSelectionDialogL
       
   329 // -----------------------------------------------------------------------------
       
   330 TBool CObexUtilsLaunchWaiter::LaunchFileSelectionDialogL(
       
   331     TFileName& aFileName, 
       
   332     const TFileName& anOldName)
       
   333     {
       
   334     TBuf<200> buf;
       
   335     TParse fileParseNew;
       
   336     TFileName nameNew;
       
   337     TBool updateLink = EFalse;
       
   338    
       
   339     while ( !updateLink ) 
       
   340         {
       
   341         TBool isSelected =  AknCommonDialogsDynMem::RunSelectDlgLD( AknCommonDialogsDynMem::EMemoryTypeMMCExternal|
       
   342                                                                     AknCommonDialogsDynMem::EMemoryTypeMMC|
       
   343                                                                     AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage|
       
   344                                                                     AknCommonDialogsDynMem::EMemoryTypePhone,
       
   345                                                                     aFileName,
       
   346                                                                     R_CFD_DEFAULT_SELECT_MEMORY_SELECTION,
       
   347                                                                     R_CFD_DEFAULT_SELECT_FILE_SELECTION );
       
   348         
       
   349         if ( isSelected )
       
   350             {
       
   351             fileParseNew.Set(aFileName, NULL, NULL);
       
   352             nameNew = fileParseNew.NameAndExt();
       
   353             
       
   354             if ( nameNew.Compare(anOldName)) // names do not match
       
   355                 {
       
   356                 updateLink =  TObexUtilsUiLayer::ShowGlobalConfirmationQueryPlainL(R_BT_SAVED_SEARCH_UPDATE);                        
       
   357                 }
       
   358             else
       
   359                 {
       
   360                 updateLink = ETrue;
       
   361                 }       
       
   362             }
       
   363         else
       
   364             {
       
   365             break;  // Exit from while loop.
       
   366             }
       
   367         }
       
   368   
       
   369     return updateLink;
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CObexUtilsLaunchWaiter::CheckDriveL
       
   374 // -----------------------------------------------------------------------------
       
   375 TInt CObexUtilsLaunchWaiter::CheckDriveL(TDriveNumber aDriveNumber)
       
   376     {
       
   377     RFs rfs;
       
   378     User::LeaveIfError(rfs.Connect());
       
   379     CleanupClosePushL( rfs ) ;
       
   380     TVolumeInfo volumeInfo;
       
   381     TInt err = rfs.Volume(volumeInfo, aDriveNumber);
       
   382     CleanupStack::PopAndDestroy();    // rfs
       
   383     
       
   384     return err;
       
   385     }
       
   386 // -----------------------------------------------------------------------------
       
   387 // CObexUtilsLaunchWaiter::CheckIfSaveInMMC
       
   388 // -----------------------------------------------------------------------------
       
   389 TInt CObexUtilsLaunchWaiter::CheckIfSaveInMMC(const TFileName& aFileName)
       
   390     {
       
   391     if(aFileName.Find(_L("F:")) != KErrNotFound)
       
   392         return EDriveF;
       
   393     if(aFileName.Find(_L("E:")) != KErrNotFound)
       
   394         return EDriveE;
       
   395 
       
   396     return KErrNotFound;
       
   397     }
       
   398 //  End of File