localconnectivityservice/obexserviceman/utils/src/obexutilslaunchwaiter.cpp
branchRCL_3
changeset 9 87d139e87731
parent 5 11d83199e2d9
child 10 031b9cffe6e4
equal deleted inserted replaced
8:a249528449c3 9:87d139e87731
    84     CMsvStore* store = attachEntry->ReadStoreL();
    84     CMsvStore* store = attachEntry->ReadStoreL();
    85     CleanupStack::PushL(store);  // 2nd push
    85     CleanupStack::PushL(store);  // 2nd push
    86     
    86     
    87     CMsvAttachment* attachInfo = store->AttachmentManagerL().GetAttachmentInfoL(0);
    87     CMsvAttachment* attachInfo = store->AttachmentManagerL().GetAttachmentInfoL(0);
    88     CleanupStack::PushL(attachInfo); // 3rd push
    88     CleanupStack::PushL(attachInfo); // 3rd push
    89     
    89           
    90     TDataType dataType = attachInfo->MimeType();
    90     TDataType dataType = attachInfo->MimeType();
    91   
    91     TFileName filePath;
       
    92     filePath = attachInfo->FilePath();
       
    93     
    92     TInt error = KErrNone;
    94     TInt error = KErrNone;
    93     TBool isCompleteSelf = EFalse;  
    95     TBool isCompleteSelf = EFalse;      
    94     
    96     CEikonEnv* eikEnv = CEikonEnv::Static();
    95     RFile attachFile;        
    97 
    96     TRAP( error, attachFile = store->AttachmentManagerL().GetAttachmentFileL(0));
    98     if ( attachInfo->Type() == CMsvAttachment::EMsvFile )
    97     TFileName fullName;
    99         {
    98     attachFile.FullName(fullName);
   100         RFile attachFile;        
    99     attachFile.Close();
   101         TRAP( error, attachFile = store->AttachmentManagerL().GetAttachmentFileL(0));
   100     
   102         if ( error == KErrNone )
   101     if ( KErrNone == error )
   103             {
   102         {
   104             CleanupClosePushL(attachFile);  // 4th push          
   103         CleanupClosePushL(attachFile);  // 4th push
   105             CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();  // 5th push
   104         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         CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();  // 4th push
   105         TAiwGenericParam paramSave(EGenericParamFileSaved, ETrue);
   122         TAiwGenericParam paramSave(EGenericParamFileSaved, ETrue);
   106         paramList->AppendL( paramSave );
   123         paramList->AppendL( paramSave );
   107 
   124         
   108         if ( CEikonEnv::Static() )
   125         if ( eikEnv )
   109             {
   126             {
   110             // Launches an application in embedded mode
   127             
   111             iDocumentHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );
   128             iDocumentHandler = CDocumentHandler::NewL( eikEnv->Process() );
   112             iDocumentHandler->SetExitObserver( this );
   129             iDocumentHandler->SetExitObserver( this );
   113             RFile64 shareableFile;
   130             RFile64 shareableFile;
   114             TRAP( error, iDocumentHandler->OpenTempFileL(fullName,shareableFile));
   131             TRAP( error, iDocumentHandler->OpenTempFileL(filePath,shareableFile));
   115             if ( error == KErrNone)
   132             if ( error == KErrNone)
   116                 {
   133                 {
   117                 TRAP( error, iDocumentHandler->OpenFileEmbeddedL( shareableFile, dataType, *paramList ));
   134                 TRAP( error, iDocumentHandler->OpenFileEmbeddedL( shareableFile, dataType, *paramList));
   118                 }
   135                 }
   119             shareableFile.Close();
   136             shareableFile.Close();
   120             }
   137             if ( error == KErrNotFound )
   121         
       
   122            
       
   123         if ( error == KErrNotSupported )  
       
   124             // If file is not supported, we open the file manager at file location.
       
   125             {
       
   126             // Launchs file manager at default folder
       
   127             delete iDocumentHandler;
       
   128             iDocumentHandler = NULL;
       
   129                
       
   130             TInt sortMethod = 2;  // 0 = 'By name', 1 = 'By type', 
       
   131                                   // 2 = 'Most recent first' and 3 = 'Largest first'
       
   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                 {
   138                 {
   161                 // Show a confirmation note
   139                 error = KErrNone;
   162                 CAknGlobalNote* note = CAknGlobalNote::NewLC();
   140                 TFileName fileName;
   163                 HBufC* stringholder  = StringLoader::LoadLC( R_BT_SAVED_LINK_UPDATED );
   141                 if (LocateFileL(fileName, filePath))
   164                 note->ShowNoteL(EAknGlobalConfirmationNote, *stringholder);
   142                     {
   165                 CleanupStack::PopAndDestroy(2); //note and stringholder
   143                     // Update the entry
   166                 }            
   144                     TRAP(error, TObexUtilsMessageHandler::UpdateEntryAttachmentL(fileName,aMessage));
   167             }           
   145                     if ( error == KErrNone )
   168         isCompleteSelf = ETrue;
   146                         {
   169         }  // !KErrNone
   147                         // Show a confirmation note
   170 
   148                         CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
   149                         HBufC* stringholder  = StringLoader::LoadLC( R_BT_SAVED_LINK_UPDATED );
       
   150                         note->ShowNoteL(EAknGlobalConfirmationNote, *stringholder);
       
   151                         CleanupStack::PopAndDestroy(2); //note and stringholder
       
   152                         }            
       
   153                     }    
       
   154                 isCompleteSelf = ETrue;
       
   155                 } // KErrNotFound
       
   156             } // eikEnv
       
   157                    
       
   158        		else if ( error == KErrNotSupported )  
       
   159             	{                    
       
   160             	delete iDocumentHandler;
       
   161             	iDocumentHandler = NULL;
       
   162                                    
       
   163             	const TInt sortMethod = 2;  // 0 = 'By name', 1 = 'By type', 
       
   164                                   			// 2 = 'Most recent first' and 3 = 'Largest first'
       
   165             	TRAP (error, TObexUtilsUiLayer::LaunchFileManagerL( filePath, 
       
   166                                                                 sortMethod, 
       
   167                                                                 ETrue )); // ETrue -> launch file manager in embedded mode.
       
   168             	isCompleteSelf = ETrue;
       
   169             	}  // KErrNotSupported
       
   170                 
       
   171         CleanupStack::PopAndDestroy(); // paramList                                     
       
   172         } // EMsvLinkedFile
       
   173     
       
   174     
       
   175     // Set message to READ     
       
   176     TMsvEntry entry = aMessage->Entry();
       
   177     entry.SetUnread( EFalse );
       
   178     aMessage->ChangeL( entry );
       
   179     
   171     User::LeaveIfError ( error );
   180     User::LeaveIfError ( error );
   172     CleanupStack::PopAndDestroy(3); //  attachInfo, store, attachEntry
   181     CleanupStack::PopAndDestroy(3); //  attachInfo, store, attachEntry
       
   182     
       
   183     
   173     
   184     
   174     iObserverRequestStatus = KRequestPending;  // CMsvOperation (observer)
   185     iObserverRequestStatus = KRequestPending;  // CMsvOperation (observer)
   175     iStatus = KRequestPending;  // CMsvOperation
   186     iStatus = KRequestPending;  // CMsvOperation
   176     SetActive();
   187     SetActive();
   177 
   188 
   178     if ( isCompleteSelf )
   189     if ( isCompleteSelf )
   179         {
   190         {
   180         HandleServerAppExit( error );
   191         HandleServerAppExit( error );
   181         }
   192         }
   182     }
   193     }
       
   194 
   183 // -----------------------------------------------------------------------------
   195 // -----------------------------------------------------------------------------
   184 // Destructor
   196 // Destructor
   185 // -----------------------------------------------------------------------------
   197 // -----------------------------------------------------------------------------
   186 CObexUtilsLaunchWaiter::~CObexUtilsLaunchWaiter()
   198 CObexUtilsLaunchWaiter::~CObexUtilsLaunchWaiter()
   187     {
   199     {