examples/ForumNokia/Document_Handler_Example/TestApp/src/TestAppAppui.cpp

00001 /* ====================================================================
00002  * File: TestAppAppUi.cpp
00003  * Created: 28/06/06 by Forum Nokia
00004  * Author:
00005  * Copyright (c):  All rights reserved
00006  * ==================================================================== */
00007 
00008 #include <avkon.hrh>
00009 #include <aknnotewrappers.h>
00010 
00011 #include "TestApp.pan"
00012 #include "TestAppAppUi.h"
00013 #include "TestAppAppView.h"
00014 #include "TestApp.hrh"
00015 
00016 #include <apmstd.h> //TDAtatype, link against: apmime.lib 
00017 #include <DocumentHandler.h>
00018 #include <apgcli.h> //RApaLsSession 
00019 
00020 #ifdef __SERIES60_3X__
00021     _LIT(KTestFile,"c:\\data\\Images\\Pictures\\test.new");
00022 #else
00023     _LIT(KTestFile,"c:\\nokia\\Images\\Pictures\\test.new");
00024 #endif
00025 
00026 #ifdef __SERIES60_3X__
00027     _LIT(KTestFile2,"c:\\data\\Images\\Pictures\\test2.new");
00028 #else
00029     _LIT(KTestFile2,"c:\\nokia\\Images\\Pictures\\test2.new");
00030 #endif
00031 
00032 void CTestAppAppUi::ConstructL()
00033     {
00034     BaseConstructL();
00035 
00036     iAppView = CTestAppAppView::NewL(ClientRect());
00037     iDocHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );                  
00038 
00039     AddToStackL(iAppView);
00040     }
00041 
00042 CTestAppAppUi::CTestAppAppUi()
00043     {
00044     // no implementation required
00045     }
00046 
00047 CTestAppAppUi::~CTestAppAppUi()
00048     {
00049     if (iAppView)
00050         {
00051         RemoveFromStack(iAppView);
00052         delete iAppView;
00053         iAppView = NULL;
00054         }
00055     delete iDocHandler;
00056     }
00057 
00058 // handle any menu commands
00059 void CTestAppAppUi::HandleCommandL(TInt aCommand)
00060     {
00061     switch(aCommand)
00062         {
00063         case EEikCmdExit:
00064         case EAknSoftkeyExit:
00065             Exit();
00066             break;
00067 
00068         case ETestAppCommand1:
00069             {
00070             LaunchFileL(EFalse); //standalone
00071             break;
00072             }
00073 
00074         case ETestAppCommand2:
00075             {
00076             LaunchFileL(ETrue); //embedded
00077             break;
00078             }
00079             break;
00080 
00081         default:
00082             Panic(ETestAppBasicUi);
00083             break;
00084         }
00085     }
00086 
00087 void CTestAppAppUi::LaunchFileL(TBool aEmbedded)
00088     {
00089     TFileName path;
00090     if (iCount++ % 2 == 0)
00091         {        
00092         path = KTestFile;
00093         }
00094     else
00095         {
00096         path = KTestFile2;
00097         }
00098 
00099     TDataType empty = TDataType();
00100   
00101     if( aEmbedded )
00102         {
00103         //Set the exit observer so NotifyExit or in 3rd edition
00104         //HandleServerAppExit will be called
00105         iDocHandler->SetExitObserver(this);   
00106         iDocHandler->OpenFileEmbeddedL(path,empty );             
00107         }        
00108     else
00109         {
00110         iDocHandler->OpenFileL(path,empty );
00111         
00112         //If the standalone handler is already running then update the
00113         //document file
00114         TUid handlerUid;
00115         TInt err = KErrNone;
00116         #ifdef __SERIES60_3X__
00117             err = iDocHandler->HandlerAppUid(handlerUid);
00118         #else
00119             RApaLsSession apaLs;
00120             User::LeaveIfError( apaLs.Connect() );
00121             err = apaLs.AppForDocument(path, handlerUid, empty);  
00122             apaLs.Close();          
00123         #endif
00124         
00125         if( !err )
00126             {
00127             RefreshDocumentFileL(handlerUid, path);
00128             }
00129         else if( err == KNotInitialized )
00130             {
00131             //Handler not initialized
00132             }
00133         else
00134             {
00135             //Some other error
00136             }
00137         
00138         }
00139 
00140     }
00141 
00142 TBool CTestAppAppUi::RefreshDocumentFileL(const TUid& aUid, const TDesC& aFileName )    
00143     {
00144     TApaTaskList taskList(iCoeEnv->WsSession());
00145     TApaTask task = (taskList.FindApp(aUid));
00146 
00147     if (task.Exists())
00148         {
00149         //calls AppUi::OpenFileL, requires SwEvent capability      
00150         User::LeaveIfError(task.SwitchOpenFile(aFileName));
00151         //task.BringToForeground();
00152         return ETrue;
00153         }
00154     return EFalse;    
00155     }    
00156     
00157 void CTestAppAppUi::HandleResourceChangeL(TInt aType)
00158         {
00159         CAknAppUi::HandleResourceChangeL(aType); //call to upper class
00160 
00161     // ADDED FOR SCALABLE UI SUPPORT
00162     // *****************************
00163         //if ( aType == KEikDynamicLayoutVariantSwitch )
00164         //hard coded constant so it can be compiled with first edition
00165         
00166         if ( aType == 0x101F8121 )
00167             {
00168             iAppView->SetRect( ClientRect() );
00169             }
00170         }
00171 
00172 
00173 #ifdef __SERIES60_3X__
00174     void  CTestAppAppUi::HandleServerAppExit (TInt aReason)
00175         {
00176         //Handle the closing of the handler application
00177     MAknServerAppExitObserver::HandleServerAppExit( aReason );          
00178         }
00179 #else
00180     void CTestAppAppUi::NotifyExit(TExitMode aMode)    
00181         {
00182         //Handle the closing of the handler application
00183         //The mode can be set by the handler application by calling
00184         //iDoorObserver->NotifyExit(TExitMode);
00185 
00186         switch (aMode) 
00187             {
00188             
00190             case EKeepChanges:
00191                 {
00192                 //TODO
00193                 }
00194                 break;
00195                 
00198                 case ERevertToSaved:
00199                 {
00200                 //TODO
00201                 }
00202                 break;
00204                 case ENoChanges:
00205                 {
00206                 //TODO
00207                 }
00208                 break;
00210                 case EEmpty:
00211                 {
00212                 //TODO
00213                 }
00214                 break;
00215             default:
00216                 //TODO
00217                 break;
00218             }
00219         }
00220 #endif

Generated by  doxygen 1.6.2