omadm/omadmappui/OmaDmCPPlugin/src/OmaDMCPPlugin.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Device updates Ecom plugin Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //System Includes
       
    20 #include <e32std.h>
       
    21 #include <implementationproxy.h>
       
    22 #include <StringLoader.h>
       
    23 #include <bautils.h>
       
    24 #include <AknsUtils.h>
       
    25 #include <gulicon.h>
       
    26 #include <akntitle.h>
       
    27 #include <e32property.h>
       
    28 // Required only for embedded app
       
    29 #include <AknNullService.h>
       
    30 #include <apgtask.h>
       
    31 #include <flogger.h>
       
    32 #include <nsmldmsync.mbg>
       
    33 #include <omadmcppluginresource.rsg>
       
    34 // User includes
       
    35 #include "OmaDMCPPlugin.h"
       
    36 #include "NSmlDMSyncApp.h"
       
    37 #include "nsmldmsyncinternalpskeys.h"
       
    38 #include <gsprivatepluginproviderids.h>
       
    39 
       
    40 _LIT(KOmaDmIconFileName, "Z:\\resource\\apps\\nsmldmsync.mif");
       
    41 _LIT(KOmaDmResFileName,  "Z:\\resource\\OmaDmCPPluginResource.rsc" );
       
    42 
       
    43 // ---------------------------------------------------------------------------------------------
       
    44 // OmaDmCPPlugin::NewLC
       
    45 // returns an object of OmaDmCPPlugin
       
    46 // ---------------------------------------------------------------------------------------------
       
    47 //
       
    48 CGSPluginInterface* COmaDmCPPlugin::NewL()
       
    49 	{
       
    50 	
       
    51 	COmaDmCPPlugin* self = new(ELeave) COmaDmCPPlugin();
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54 	CleanupStack::Pop(self);
       
    55 	return (CGSPluginInterface*) self;
       
    56 	}
       
    57 
       
    58 // ---------------------------------------------------------------------------------------------
       
    59 // OmaDmCPPlugin::Id()
       
    60 // returns the view id
       
    61 // ---------------------------------------------------------------------------------------------
       
    62 //
       
    63 TUid COmaDmCPPlugin::Id() const
       
    64 	{
       
    65       return TUid::Uid( KUidOmaDmCPPluginDll );	
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------------------------------------------
       
    69 // OmaDmCPPlugin::ConstructL
       
    70 // ---------------------------------------------------------------------------------------------
       
    71 //	
       
    72 void COmaDmCPPlugin::ConstructL()
       
    73 	{
       
    74 	BaseConstructL();
       
    75     env = CEikonEnv::Static();
       
    76 
       
    77 	TFileName fileName(KOmaDmResFileName);
       
    78 	
       
    79 	BaflUtils::NearestLanguageFile(env->FsSession(), fileName);
       
    80 
       
    81 	iResId = env->AddResourceFileL(fileName);
       
    82 	}
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------------------------
       
    86 // OmaDmCPPlugin::OmaDmCPPlugin
       
    87 // ---------------------------------------------------------------------------------------------
       
    88 //    
       
    89 COmaDmCPPlugin::COmaDmCPPlugin()
       
    90 	{
       
    91     // Nothing
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------------------------------------------
       
    95 // COmaDmCPPlugin::~COmaDmCPPlugin
       
    96 // ---------------------------------------------------------------------------------------------
       
    97 //
       
    98 COmaDmCPPlugin::~COmaDmCPPlugin()
       
    99 	{
       
   100 		TInt value =0;
       
   101 		TInt r1=RProperty::Get(KPSUidNSmlDMSyncApp,KNSmlDMSyncUiLaunchKey,value);   
       
   102 		if(value ==2 && r1 == KErrNone)
       
   103 		{
       
   104 		 CloseDmUi();
       
   105 		} 
       
   106     if (iResId)
       
   107 	   {
       
   108         env->DeleteResourceFile(iResId);
       
   109 	   }	
       
   110 	if ( iNullService )
       
   111         {
       
   112             delete iNullService;
       
   113             iNullService = NULL;
       
   114         }
       
   115 	}
       
   116 
       
   117 // ---------------------------------------------------------------------------------------------
       
   118 // COmaDmCPPlugin::GetCaptionL
       
   119 // returns the caption to be shown in GS view
       
   120 // ---------------------------------------------------------------------------------------------
       
   121 //
       
   122 void COmaDmCPPlugin::GetCaptionL( TDes& aCaption ) const
       
   123 	{	
       
   124 	StringLoader::Load( aCaption, R_OMADM_CP_TITLE);
       
   125 	}
       
   126 
       
   127 // ---------------------------------------------------------------------------------------------
       
   128 // COmaDmCPPlugin::CreateIconL
       
   129 // Returns the icon to be shown in GS view
       
   130 // ---------------------------------------------------------------------------------------------
       
   131 CGulIcon* COmaDmCPPlugin::CreateIconL( const TUid /*aIconType*/ )
       
   132 	{
       
   133 	CFbsBitmap* bitmap = NULL;
       
   134     CFbsBitmap* mask = NULL;                                               
       
   135  
       
   136     MAknsSkinInstance* instance = AknsUtils::SkinInstance();    
       
   137     AknsUtils::CreateIconL(instance, KAknsIIDQgnPropCpDevUpdate, bitmap, mask,
       
   138     					KOmaDmIconFileName,
       
   139     					EMbmNsmldmsyncQgn_prop_cp_dev_update,
       
   140     				EMbmNsmldmsyncQgn_prop_cp_dev_update_mask);
       
   141     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   142     icon->SetBitmapsOwnedExternally( EFalse );
       
   143     bitmap = NULL;
       
   144     mask = NULL;      
       
   145     return icon;    
       
   146 	}
       
   147 
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // COmaDmCPPlugin::PluginProviderCategory
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 TInt COmaDmCPPlugin::PluginProviderCategory() const
       
   154 	{
       
   155     return KGSPluginProviderInternal;
       
   156 	}
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // COmaDmCPPlugin::ItemType()
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TGSListboxItemTypes COmaDmCPPlugin::ItemType()
       
   163 	{
       
   164     return EGSItemTypeSettingDialog;
       
   165 	}
       
   166 
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // COmaDmCPPlugin::HandleSelection()
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void COmaDmCPPlugin::HandleSelection(
       
   173     const TGSSelectionTypes /*aSelectionType*/ )
       
   174 	{    
       
   175 	TRAP_IGNORE( OpenDmAppL() );    
       
   176 	}
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // COmaDmCPPlugin::OpenDmAppL()
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void COmaDmCPPlugin::OpenDmAppL()
       
   183 	{   
       
   184 	static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
       
   185    	static _LIT_SECURITY_POLICY_C1(KAllowWriteDeviceDataPolicy, ECapabilityWriteDeviceData);
       
   186     TInt r=RProperty::Define(KPSUidNSmlDMSyncApp,KNSmlDMSyncUiLaunchKey,RProperty::EInt,KAllowAllPolicy,KAllowWriteDeviceDataPolicy);
       
   187     TInt value=2;
       
   188 	if ( r!=KErrNone && r!=KErrAlreadyExists )
       
   189        {
       
   190        User::LeaveIfError(r);
       
   191        }    
       
   192        
       
   193     RWsSession ws;
       
   194     User::LeaveIfError( ws.Connect() );
       
   195     CleanupClosePushL( ws );
       
   196     // Find the task with uid
       
   197     TApaTaskList taskList(ws);
       
   198     TApaTask task = taskList.FindApp( KUidSmlSyncApp );
       
   199     
       
   200     if ( task.Exists() )
       
   201         {    	    
       
   202         task.BringToForeground();        
       
   203         }
       
   204     else
       
   205         {
       
   206         // Launch DM application as embedded.        
       
   207         TInt r1=RProperty::Set(KPSUidNSmlDMSyncApp,KNSmlDMSyncUiLaunchKey,value);         
       
   208         iNullService = CAknNullService::NewL( KUidSmlSyncApp, this );        
       
   209         }
       
   210     CleanupStack::PopAndDestroy();  // ws
       
   211     
       
   212 	}
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // COmaDmCPPlugin::DoActivateL
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void COmaDmCPPlugin::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   219                                   TUid /*aCustomMessageId*/,
       
   220                                   const TDesC8& /*aCustomMessage*/ )
       
   221 	{
       
   222     // Nothing
       
   223 	}
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // COmaDmCPPlugin::DoDeactivate
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void COmaDmCPPlugin::DoDeactivate()
       
   230 	{
       
   231     // Closing embedded app
       
   232     if ( iNullService )
       
   233         {
       
   234             delete iNullService;
       
   235             iNullService = NULL;
       
   236         }
       
   237     
       
   238 	}
       
   239 
       
   240 
       
   241 // Constants
       
   242 const TImplementationProxy KImplementationTable[] = 
       
   243 	{
       
   244     IMPLEMENTATION_PROXY_ENTRY( KUidOmaDmCPPluginImpl, COmaDmCPPlugin::NewL ) // used by GS plugin
       
   245 	};
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // ImplementationGroupProxy
       
   249 // Gate/factory function
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(  TInt& aTableCount )
       
   253 	{
       
   254 	aTableCount = sizeof( KImplementationTable ) 
       
   255                 / sizeof( TImplementationProxy );
       
   256 	return KImplementationTable;
       
   257 	}
       
   258 // ---------------------------------------------------------------------------------------------
       
   259 // OmaDmCPPlugin::CloseDmUi
       
   260 // closes DM Ui
       
   261 // ---------------------------------------------------------------------------------------------	
       
   262 void COmaDmCPPlugin:: CloseDmUi()
       
   263 {
       
   264 	  
       
   265     RWsSession ws  = CEikonEnv::Static()->WsSession();
       
   266     TApaTaskList taskList( ws );
       
   267     TApaTask task = taskList.FindApp( KUidSmlSyncApp  );
       
   268       if (task.Exists())
       
   269       {
       
   270     	task.EndTask();
       
   271       }
       
   272 	
       
   273 }	
       
   274 // End of File
       
   275