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

00001 /*
00002  * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 #include <avkon.hrh>
00030 #include <aknnotewrappers.h>
00031 
00032 #include "TestApp.pan"
00033 #include "TestAppAppUi.h"
00034 #include "TestAppAppView.h"
00035 #include "TestApp.hrh"
00036 
00037 #include <apmstd.h> //TDAtatype, link against: apmime.lib 
00038 #include <DocumentHandler.h>
00039 #include <apgcli.h> //RApaLsSession 
00040 
00041 #ifdef __SERIES60_3X__
00042     _LIT(KTestFile,"c:\\data\\Images\\Pictures\\test.new");
00043 #else
00044     _LIT(KTestFile,"c:\\nokia\\Images\\Pictures\\test.new");
00045 #endif
00046 
00047 #ifdef __SERIES60_3X__
00048     _LIT(KTestFile2,"c:\\data\\Images\\Pictures\\test2.new");
00049 #else
00050     _LIT(KTestFile2,"c:\\nokia\\Images\\Pictures\\test2.new");
00051 #endif
00052 
00053 void CTestAppAppUi::ConstructL()
00054     {
00055     BaseConstructL();
00056 
00057     iAppView = CTestAppAppView::NewL(ClientRect());
00058     iDocHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );                  
00059 
00060     AddToStackL(iAppView);
00061     }
00062 
00063 CTestAppAppUi::CTestAppAppUi()
00064     {
00065     // no implementation required
00066     }
00067 
00068 CTestAppAppUi::~CTestAppAppUi()
00069     {
00070     if (iAppView)
00071         {
00072         RemoveFromStack(iAppView);
00073         delete iAppView;
00074         iAppView = NULL;
00075         }
00076     delete iDocHandler;
00077     }
00078 
00079 // handle any menu commands
00080 void CTestAppAppUi::HandleCommandL(TInt aCommand)
00081     {
00082     switch(aCommand)
00083         {
00084         case EEikCmdExit:
00085         case EAknSoftkeyExit:
00086             Exit();
00087             break;
00088 
00089         case ETestAppCommand1:
00090             {
00091             LaunchFileL(EFalse); //standalone
00092             break;
00093             }
00094 
00095         case ETestAppCommand2:
00096             {
00097             LaunchFileL(ETrue); //embedded
00098             break;
00099             }
00100 
00101         default:
00102             Panic(ETestAppBasicUi);
00103             break;
00104         }
00105     }
00106 
00107 void CTestAppAppUi::LaunchFileL(TBool aEmbedded)
00108     {
00109     TFileName path;
00110     if (iCount++ % 2 == 0)
00111         {        
00112         path = KTestFile;
00113         }
00114     else
00115         {
00116         path = KTestFile2;
00117         }
00118 
00119     TDataType empty = TDataType();
00120   
00121     if( aEmbedded )
00122         {
00123         //Set the exit observer so NotifyExit or in 3rd edition
00124         //HandleServerAppExit will be called
00125         iDocHandler->SetExitObserver(this);   
00126         iDocHandler->OpenFileEmbeddedL(path,empty );             
00127         }        
00128     else
00129         {
00130         iDocHandler->OpenFileL(path,empty );
00131         
00132         //If the standalone handler is already running then update the
00133         //document file
00134         TUid handlerUid;
00135         TInt err = KErrNone;
00136         #ifdef __SERIES60_3X__
00137             err = iDocHandler->HandlerAppUid(handlerUid);
00138         #else
00139             RApaLsSession apaLs;
00140             User::LeaveIfError( apaLs.Connect() );
00141             err = apaLs.AppForDocument(path, handlerUid, empty);  
00142             apaLs.Close();          
00143         #endif
00144         
00145         if( !err )
00146             {
00147             RefreshDocumentFileL(handlerUid, path);
00148             }
00149         else if( err == KNotInitialized )
00150             {
00151             //Handler not initialized
00152             }
00153         else
00154             {
00155             //Some other error
00156             }
00157         
00158         }
00159 
00160     }
00161 
00162 TBool CTestAppAppUi::RefreshDocumentFileL(const TUid& aUid, const TDesC& aFileName )    
00163     {
00164     TApaTaskList taskList(iCoeEnv->WsSession());
00165     TApaTask task = (taskList.FindApp(aUid));
00166 
00167     if (task.Exists())
00168         {
00169         //calls AppUi::OpenFileL, requires SwEvent capability      
00170         User::LeaveIfError(task.SwitchOpenFile(aFileName));
00171         //task.BringToForeground();
00172         return ETrue;
00173         }
00174     return EFalse;    
00175     }    
00176     
00177 void CTestAppAppUi::HandleResourceChangeL(TInt aType)
00178         {
00179         CAknAppUi::HandleResourceChangeL(aType); //call to upper class
00180 
00181     // ADDED FOR SCALABLE UI SUPPORT
00182     // *****************************
00183         //if ( aType == KEikDynamicLayoutVariantSwitch )
00184         //hard coded constant so it can be compiled with first edition
00185         
00186         if ( aType == 0x101F8121 )
00187             {
00188             iAppView->SetRect( ClientRect() );
00189             }
00190         }
00191 
00192 
00193 #ifdef __SERIES60_3X__
00194     void  CTestAppAppUi::HandleServerAppExit (TInt aReason)
00195         {
00196         //Handle the closing of the handler application
00197     MAknServerAppExitObserver::HandleServerAppExit( aReason );          
00198         }
00199 #else
00200     void CTestAppAppUi::NotifyExit(TExitMode aMode)    
00201         {
00202         //Handle the closing of the handler application
00203         //The mode can be set by the handler application by calling
00204         //iDoorObserver->NotifyExit(TExitMode);
00205 
00206         switch (aMode) 
00207             {
00208             
00210             case EKeepChanges:
00211                 {
00212                 //TODO
00213                 }
00214                 break;
00215                 
00218                 case ERevertToSaved:
00219                 {
00220                 //TODO
00221                 }
00222                 break;
00224                 case ENoChanges:
00225                 {
00226                 //TODO
00227                 }
00228                 break;
00230                 case EEmpty:
00231                 {
00232                 //TODO
00233                 }
00234                 break;
00235             default:
00236                 //TODO
00237                 break;
00238             }
00239         }
00240 #endif

Generated by  doxygen 1.6.2