messagingappbase/msgeditor/appuisrc/MsgEditorShutter.cpp
changeset 0 72b543305e3a
child 14 c6838af47512
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005 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 *       CMsgEditorShutter implementation file
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include <aknenv.h>
       
    24 #include <messaginginternalpskeys.h>
       
    25 #include <MuiuMsgEditorLauncher.h>
       
    26 #include "MsgEditorShutter.h"
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 // ---------------------------------------------------------
       
    33 // CMsgEditorShutter::CMsgEditorShutter
       
    34 //
       
    35 // C++ constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 CMsgEditorShutter::CMsgEditorShutter(CMsgEditorDocument& aDoc)
       
    40     : CActive( CActive::EPriorityStandard ),
       
    41     iDoc( aDoc )
       
    42     {
       
    43     CActiveScheduler::Add( this );
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CMsgEditorShutter::ConstructL()
       
    48 //
       
    49 // Symbian OS default constructor can leave.
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 void CMsgEditorShutter::ConstructL()
       
    53     {
       
    54     User::LeaveIfError( iOpenAppProperty.Attach( KPSUidMuiu, KMuiuSysOpenMsgEditors ) );
       
    55     
       
    56     // Complete self
       
    57     TInt openEditors = 0;
       
    58     TInt err = iOpenAppProperty.Get( openEditors );
       
    59     
       
    60     switch ( err )
       
    61         {
       
    62         case KErrPermissionDenied:
       
    63         case KErrArgument:
       
    64             {
       
    65             User::Leave( err );
       
    66             }
       
    67             break;
       
    68         case KErrNotFound:
       
    69             {
       
    70             User::LeaveIfError ( 
       
    71                 RProperty::Define( 
       
    72                     KPSUidMuiu,
       
    73                     KMuiuSysOpenMsgEditors,
       
    74                     RProperty::EInt,
       
    75                     ECapabilityReadDeviceData,
       
    76                     ECapabilityWriteDeviceData,
       
    77                     0 ) );
       
    78             }
       
    79             break;
       
    80         case KErrNone:
       
    81         default:
       
    82             break;
       
    83         }
       
    84     err = iOpenAppStandAloneProperty.Attach(KPSUidMsgEditor,KMuiuStandAloneOpenMsgEditors);
       
    85     TInt newValue = 0; // since only one stand alone editor can be launched
       
    86     err = iOpenAppStandAloneProperty.Get(KPSUidMsgEditor, KMuiuStandAloneOpenMsgEditors, newValue);
       
    87      switch ( err )
       
    88         {
       
    89         case KErrPermissionDenied:
       
    90         case KErrArgument:
       
    91             {
       
    92             User::Leave( err );
       
    93             }
       
    94             break;
       
    95         case KErrNotFound:
       
    96             {
       
    97             User::LeaveIfError ( 
       
    98                 RProperty::Define( 
       
    99                     KPSUidMsgEditor,
       
   100                     KMuiuStandAloneOpenMsgEditors,
       
   101                     RProperty::EInt,
       
   102                     ECapabilityReadDeviceData,
       
   103                     ECapabilityWriteDeviceData,
       
   104                     0 ) );
       
   105             }
       
   106             break;
       
   107         case KErrNone:
       
   108         default:
       
   109             break;
       
   110         }
       
   111     openEditors++;
       
   112     iOpenAppProperty.Set( openEditors );
       
   113     iStatus = KRequestPending;
       
   114     iOpenAppProperty.Subscribe( iStatus );
       
   115     SetActive();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CMsgEditorShutter::NewL
       
   120 //
       
   121 // Two-phased constructor.
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 CMsgEditorShutter* CMsgEditorShutter::NewL(CMsgEditorDocument& aAppUi)
       
   125     {
       
   126     CMsgEditorShutter* self = new ( ELeave ) CMsgEditorShutter(aAppUi);
       
   127     
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL();
       
   130     CleanupStack::Pop( self );
       
   131 
       
   132     return self;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CMsgEditorShutter::~CMsgEditorShutter
       
   137 //
       
   138 // Destructor
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 CMsgEditorShutter::~CMsgEditorShutter()
       
   142     {
       
   143     Cancel();
       
   144     
       
   145     TInt openEditors = 0;
       
   146     iOpenAppProperty.Get( openEditors );
       
   147     
       
   148         // Do not make open editor count negative
       
   149     
       
   150     if ( openEditors > 0 )
       
   151         {
       
   152         openEditors--;    
       
   153         iOpenAppProperty.Set( openEditors );
       
   154         }
       
   155     iOpenAppProperty.Close();
       
   156     iOpenAppStandAloneProperty.Close();
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------
       
   160 // CMsgEditorShutter::DoCancel
       
   161 //
       
   162 // From active object framework
       
   163 // ---------------------------------------------------------
       
   164 //
       
   165 void CMsgEditorShutter::DoCancel()
       
   166     {
       
   167     iOpenAppProperty.Cancel();
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CMsgEditorShutter::RunL
       
   172 //
       
   173 // From active object framework
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 void CMsgEditorShutter::RunL()
       
   177     {
       
   178     TInt openEditors = 0;
       
   179     iOpenAppProperty.Get( openEditors );
       
   180 
       
   181 	TInt launchtype = iDoc.LaunchFlags();
       
   182 
       
   183     TInt StandAloneEditorCnt = 0; // since only one stand alone editor can be launched
       
   184     TInt err = iOpenAppStandAloneProperty.Get(KPSUidMsgEditor, KMuiuStandAloneOpenMsgEditors, StandAloneEditorCnt);
       
   185                  
       
   186     if((launchtype & EMsgLaunchEditorStandAlone ) && StandAloneEditorCnt > 1 )    
       
   187         {
       
   188         StandAloneEditorCnt = 1;
       
   189         err = iOpenAppStandAloneProperty.Set(KPSUidMsgEditor, KMuiuStandAloneOpenMsgEditors, StandAloneEditorCnt);
       
   190          // Run appshutter
       
   191         CAknEnv::RunAppShutter();
       
   192         }
       
   193     else if ( openEditors  )
       
   194         {
       
   195         iStatus = KRequestPending;
       
   196         iOpenAppProperty.Subscribe( iStatus );
       
   197         SetActive();
       
   198         }
       
   199     else
       
   200         {
       
   201         // Run appshutter
       
   202         CAknEnv::RunAppShutter();
       
   203         }
       
   204     }
       
   205 
       
   206 //  End of File