taskswitcher/taskswitcherui/taskswitcherappecom/src/tsappecom.cpp
changeset 4 4d54b72983ae
child 88 3321d3e205b6
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Taskswitcher application ecom plugin
       
    15  *
       
    16 */
       
    17 
       
    18  
       
    19 #include <e32property.h>
       
    20 #include <apgtask.h>
       
    21 #include <eikenv.h>
       
    22 
       
    23 #include "tsappecomconst.hrh"
       
    24 #include "tsappecom.h"
       
    25 
       
    26 #include "tsappecomlogging.h"
       
    27 
       
    28 // AknCapServer UID, used for P&S category
       
    29 const TUid KTaskswitcherStateCategory = { 0x10207218 };
       
    30 
       
    31 // Taskswitcher UI, used as P&S key
       
    32 const TInt KTaskswitcherStateKey = 0x20016BF0;
       
    33 
       
    34 // Values for Taskswitcher launching P&S
       
    35 const TInt KTaskswitcherBackgroundValue = 1;
       
    36 const TInt KTaskswitcherForegroundValue = KTaskswitcherBackgroundValue << 1;
       
    37 const TInt KTaskswitcherShortAppKeyPressed = KTaskswitcherForegroundValue << 1;
       
    38 const TInt KTaskswitcherLongAppKeyPressed = KTaskswitcherShortAppKeyPressed << 1;
       
    39 
       
    40 // Taskswitcher application UID, for checking if taskswitcher is running
       
    41 const TUid KTaskswitcherAppUidValue = { 0x20016BF0 };
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CTsEcomPlugin::CTsEcomPlugin()
       
    45 // Default constructor for first phase construction.
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CTsEcomPlugin::CTsEcomPlugin()
       
    49     {
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CTsEcomPlugin::NewL()
       
    54 // Standard NewL.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CTsEcomPlugin* CTsEcomPlugin::NewL()
       
    58     {
       
    59     CTsEcomPlugin* self = new ( ELeave ) CTsEcomPlugin;
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CTsEcomPlugin::ConstructL()
       
    68 // 2nd phase construction.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CTsEcomPlugin::ConstructL()
       
    72     {
       
    73     TSLOG_CONTEXT( CTsEcomPlugin::ConstructL, TSLOG_LOCAL );
       
    74     TSLOG_IN();
       
    75     
       
    76     DefineTaskswitcherStateProperty();
       
    77     
       
    78     TSLOG_OUT();
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CTsEcomPlugin::~CTsEcomPlugin()
       
    83 // Destructor.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CTsEcomPlugin::~CTsEcomPlugin()
       
    87     {
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CTsEcomPlugin::Show
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CTsEcomPlugin::Show()
       
    95     {
       
    96     TSLOG_CONTEXT( CTsEcomPlugin::Show, TSLOG_LOCAL );
       
    97     TSLOG_IN();
       
    98     
       
    99     TInt value( 0 );
       
   100     RProperty::Get( KTaskswitcherStateCategory, KTaskswitcherStateKey, value );
       
   101     value &= ~KTaskswitcherBackgroundValue;
       
   102     value |= KTaskswitcherForegroundValue;
       
   103     SetTaskswitcherStateProperty( value );  
       
   104     
       
   105     TSLOG_OUT();    
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CTsEcomPlugin::Dismiss
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CTsEcomPlugin::Dismiss()
       
   113     {
       
   114     TSLOG_CONTEXT( CTsEcomPlugin::Dismiss, TSLOG_LOCAL );
       
   115     TSLOG_IN();
       
   116     
       
   117     TInt value( 0 );
       
   118     RProperty::Get( KTaskswitcherStateCategory, KTaskswitcherStateKey, value );
       
   119     value &= ~KTaskswitcherForegroundValue;
       
   120     value |= KTaskswitcherBackgroundValue;
       
   121     SetTaskswitcherStateProperty( value );  
       
   122     
       
   123     TSLOG_OUT();     
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CTsEcomPlugin::HandleLongAppKeyPress
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CTsEcomPlugin::HandleLongAppKeyPress()
       
   131     {
       
   132     TSLOG_CONTEXT( CTsEcomPlugin::Show, TSLOG_LOCAL );
       
   133     TSLOG_IN();
       
   134     
       
   135     TInt value( 0 );
       
   136     RProperty::Get( KTaskswitcherStateCategory, KTaskswitcherStateKey, value );
       
   137     value &= ~KTaskswitcherShortAppKeyPressed;
       
   138     value |= KTaskswitcherLongAppKeyPressed;
       
   139     SetTaskswitcherStateProperty( value );    
       
   140     
       
   141     TSLOG_OUT();    
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CTsEcomPlugin::HandleShortAppKeyPress
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CTsEcomPlugin::HandleShortAppKeyPress()
       
   149     {
       
   150     TSLOG_CONTEXT( CTsEcomPlugin::Dismiss, TSLOG_LOCAL );
       
   151     TSLOG_IN();
       
   152     
       
   153     TInt value( 0 );
       
   154     RProperty::Get( KTaskswitcherStateCategory, KTaskswitcherStateKey, value );
       
   155     value &= ~KTaskswitcherLongAppKeyPressed;
       
   156     value |= KTaskswitcherShortAppKeyPressed;
       
   157     SetTaskswitcherStateProperty( value ); 
       
   158     
       
   159     TSLOG_OUT();     
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CTsEcomPlugin::IsVisible
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 TBool CTsEcomPlugin::IsVisible()
       
   167     {
       
   168     TSLOG_CONTEXT( CTsEcomPlugin::IsVisible, TSLOG_LOCAL );
       
   169     TSLOG_IN();
       
   170     
       
   171     TInt value( 0 );
       
   172     RProperty::Get( KTaskswitcherStateCategory, KTaskswitcherStateKey, value );
       
   173     if ( value & KTaskswitcherForegroundValue )
       
   174         {
       
   175         TSLOG_OUT();
       
   176         return ETrue;
       
   177         }
       
   178     TSLOG_OUT();
       
   179     return EFalse;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CTsEcomPlugin::IsReady
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 TBool CTsEcomPlugin::IsReady()
       
   187     {
       
   188     TSLOG_CONTEXT( CTsEcomPlugin::IsReady, TSLOG_LOCAL );
       
   189     TSLOG_IN();
       
   190 
       
   191     TBool ret = EFalse;    
       
   192     CEikonEnv* eikonEnv = CEikonEnv::Static();
       
   193     
       
   194     if ( eikonEnv )
       
   195         {
       
   196         TApaTaskList taskList( eikonEnv->WsSession() );
       
   197         TApaTask task = taskList.FindApp( KTaskswitcherAppUidValue ); 
       
   198     
       
   199         if ( task.Exists() )
       
   200             {
       
   201             ret = ETrue;
       
   202             }
       
   203         }
       
   204     
       
   205     TSLOG1_OUT( "IsReady returns: %d", ret );
       
   206     return ret;
       
   207     }
       
   208     
       
   209 // -----------------------------------------------------------------------------
       
   210 // CTsEcomPlugin::SetTaskswitcherStateProperty
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CTsEcomPlugin::SetTaskswitcherStateProperty( TInt aValue )
       
   214     {
       
   215     TSLOG_CONTEXT( CTsEcomPlugin::SetTaskswitcherShowProperty, TSLOG_LOCAL );
       
   216     TSLOG_IN();
       
   217     
       
   218     if ( RProperty::Set( 
       
   219             KTaskswitcherStateCategory, KTaskswitcherStateKey, aValue ) != KErrNone )
       
   220         {
       
   221         DefineTaskswitcherStateProperty();
       
   222         TInt error = 
       
   223             RProperty::Set( KTaskswitcherStateCategory, KTaskswitcherStateKey, aValue );
       
   224         if ( error != KErrNone )
       
   225             {
       
   226             TSLOG1( TSLOG_INFO, "RProperty::Set Error: %d", error ); 
       
   227             }        
       
   228         }
       
   229     
       
   230     TSLOG_OUT();    
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CTsEcomPlugin::DefineTaskswitcherStateProperty
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CTsEcomPlugin::DefineTaskswitcherStateProperty()
       
   238     {
       
   239     TSLOG_CONTEXT( CTsEcomPlugin::DefineTaskswitcherShowProperty, TSLOG_LOCAL );
       
   240     TSLOG_IN();
       
   241     
       
   242     TInt error = RProperty::Define( 
       
   243             KTaskswitcherStateCategory, KTaskswitcherStateKey, RProperty::EInt );
       
   244     if ( error != KErrNone )
       
   245         {
       
   246         TSLOG1( TSLOG_INFO, "RProperty::Define Error: %d", error );
       
   247         }              
       
   248     
       
   249     TSLOG_OUT();
       
   250     }
       
   251 
       
   252 // End of file