×
Namespaces

Variants
Actions
(Difference between revisions)

How to change the active theme

From Nokia Developer Wiki
Jump to: navigation, search
lenclud (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetaData)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Symbian C++]][[Category:Themes]][[Category:Code Examples]]
+
{{ArticleMetaData <!-- v1.2 -->
This document will very briefly explain how to change the active theme on a [[S60#S60 Editions|S60 3rd Edition]] device.
+
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20070405
 +
|author= [[User:Ivey]]
 +
}}
 +
[[Category:Symbian C++]][[Category:Themes]][[Category:Code Snippet]]
 +
This document will very briefly explain how to change the active theme on a [[Archived:S60#S60 Editions|S60 3rd Edition]] device. The information in this document is provided as is and the code samples are not meant to be of commercial quality.
  
The information in this document is provided as is and the code samples are not meant to be of commercial quality.
+
Please note that you need to download and install the [http://www.developer.nokia.com/info/sw.nokia.com/id/48a93bd5-028a-4b3e-a0b1-148ff203b2b3/Extensions_plugin_S60_3rd_ed.html Extensions Plug-ins] for your S60 SDKs to gain access to [[API]]s you need. Extensions Plug-ins are available for all S60 3rd Edition and S60 5th Edition SDKs. Fron the Extensions plug-ins you will need ExtendedSkinsAPI and PersonalisationSkinsSettingsAPI.
  
Please note that you need to download and install the [http://www.forum.nokia.com/info/sw.nokia.com/id/48a93bd5-028a-4b3e-a0b1-148ff203b2b3/Extensions_plugin_S60_3rd_ed.html Extensions Plug-ins] for your S60 SDKs to gain access to [[API]]s you need.
+
===Connect to Skin Server===
 
+
Extensions Plug-ins are available for all S60 3rd Edition and S60 5th Edition SDKs.
+
 
+
1. CONNECT TO SKIN SERVER
+
 
<code cpp>#include <AknSSrvClient.h> // aknskinsrv.lib
 
<code cpp>#include <AknSSrvClient.h> // aknskinsrv.lib
 
 
Line 15: Line 33:
 
CleanupClosePushL( skinsSession );</code>
 
CleanupClosePushL( skinsSession );</code>
  
 
+
===Fetch the package ID of the current skin===
2. FETCH THE PACKAGE ID OF THE CURRENT SKIN
+
 
<code cpp>#include <centralrepository.h> // centralrepository.lib
 
<code cpp>#include <centralrepository.h> // centralrepository.lib
 
#include <AknSkinsInternalCRKeys.h>
 
#include <AknSkinsInternalCRKeys.h>
 
…</code>
 
…</code>
  
<code>// iOriginalSkinPid is of type TAknsPkgID
+
<code cpp>// iOriginalSkinPid is of type TAknsPkgID
void CMyThemeManager::StoreCurrentSkinIdL()
+
void CMyThemeManager::GetCurrentSkinIdL()
 
     {
 
     {
 
     TAknsPkgIDBuf pidBuf;             
 
     TAknsPkgIDBuf pidBuf;             
Line 34: Line 51:
 
</code>
 
</code>
  
3. GET A LIST OF INSTALLED SKIN PACKAGES
+
===Get a list of installed skin packages===
  
 
Please see ''aknssrvclient.h'' file for more details on how to work with skins residing on memory card.
 
Please see ''aknssrvclient.h'' file for more details on how to work with skins residing on memory card.
<code>CArrayPtr< CAknsSrvSkinInformationPkg >* skinInfoArray =  
+
<code cpp>CArrayPtr< CAknsSrvSkinInformationPkg >* skinInfoArray =  
 
             skinsSession.EnumerateSkinPackagesL();
 
             skinsSession.EnumerateSkinPackagesL();
 
CleanupStack::PushL( skinInfoArray );</code>
 
CleanupStack::PushL( skinInfoArray );</code>
  
4. GO THROUGH INSTALLED PACKAGES AND SWITCH TO THE FIRST AVAILABLE NEW SKIN
+
===Go through installed packages and switch to the first available new skin===
  
 
<code cpp>TInt retValue( KErrNone );
 
<code cpp>TInt retValue( KErrNone );
Line 62: Line 79:
 
             }             
 
             }             
 
         }</code>
 
         }</code>
5. SAVE THE NEW SKIN PACKAGE ID IN CENTRAL REPOSITORY
+
 
 +
=== Save the new skin package ID in central repository===
 
<code cpp>
 
<code cpp>
 
void CMyThemeManager::SetNewSkinIdL( TAknsPkgID aPkgId )
 
void CMyThemeManager::SetNewSkinIdL( TAknsPkgID aPkgId )
Line 80: Line 98:
 
     }
 
     }
 
</code>
 
</code>
6. FREE ALLOCATED RESOURCES (FROM PARTS 1&3)
+
 
 +
===Free allocated resources===
  
 
<code cpp>skinInfoArray->ResetAndDestroy();         
 
<code cpp>skinInfoArray->ResetAndDestroy();         
Line 86: Line 105:
 
</code>
 
</code>
  
7. NECESSARY CAPABILITIES
+
===Whole Source===
 +
 
 +
<code cpp>
 +
 
 +
#include <AknSSrvClient.h> //aknskinsrv.lib
 +
#include <centralrepository.h> //centralrepository.lib
 +
#include <AknSkinsInternalCRKeys.h>
 +
#include <mmfcontrollerpluginresolver.h> // CleanupResetAndDestroyPushL
 +
 
 +
 
 +
class CMyThemeManager : public CBase, public MAknsSkinChangeObserver
 +
    {
 +
public:
 +
 
 +
    void ChangeSkinL();
 +
 +
private:
 +
 +
    //From MAknsSkinChangeObserver
 +
    virtual void SkinContentChanged();
 +
    virtual void SkinConfigurationChanged(const TAknsSkinStatusConfigurationChangeReason aReason);
 +
    virtual void SkinPackageChanged(const TAknsSkinStatusPackageChangeReason aReason);
 +
    //
 +
    void GetCurrentSkinIdL();
 +
    void SetNewSkinIdL(TAknsPkgID aPkgId);
 +
 +
private:
 +
    TAknsPkgID iOriginalSkinPid;
 +
    };
 +
 
 +
 
 +
/*
 +
* Set the current skin ID into the Central Repository 
 +
*/
 +
void CMyThemeManager::SetNewSkinIdL( TAknsPkgID aPkgId )
 +
    {
 +
    TAknsPkgIDBuf pidBuf;           
 +
    aPkgId.CopyToDes( pidBuf );
 +
    CRepository* repository = CRepository::NewLC(KCRUidPersonalisation);                   
 +
    User::LeaveIfError(repository->Set(KPslnActiveSkinUid, pidBuf));
 +
   
 +
    // KPslnActiveSkinLocation has to be changed also
 +
    // if new skin resides on mmc whereas old one resided in phone mem
 +
    // ...and vice versa
 +
   
 +
    CleanupStack::PopAndDestroy(repository);
 +
    }
 +
 
 +
/*
 +
* Get the current skin ID from the Central Repository
 +
*/
 +
void CMyThemeManager::GetCurrentSkinIdL()
 +
    {
 +
    TAknsPkgIDBuf pidBuf;           
 +
    CRepository* repository = CRepository::NewLC( KCRUidPersonalisation );                   
 +
    User::LeaveIfError(repository->Get(KPslnActiveSkinUid, pidBuf));
 +
    CleanupStack::PopAndDestroy(repository);
 +
    iOriginalSkinPid.SetFromDesL(pidBuf);
 +
    }
 +
 
 +
 
 +
/*
 +
* Change the current skin to the next available skin
 +
*/
 +
void CMyThemeManager::ChangeSkinL()
 +
{
 +
//Connect to the skin server
 +
RAknsSrvSession skinsSession;
 +
User::LeaveIfError( skinsSession.Connect( this ) );
 +
CleanupClosePushL( skinsSession );
 +
 +
//Get the current skin package
 +
GetCurrentSkinIdL();
 +
 +
//Get the list of installed skin packages
 +
CArrayPtr<CAknsSrvSkinInformationPkg>* skinInfoArray =skinsSession.EnumerateSkinPackagesL();
 +
CleanupStack::PushL(skinInfoArray);
 +
CleanupResetAndDestroyPushL(*skinInfoArray);
 +
 +
//Go through installed skin and change it
 +
for (TInt i=0; i < skinInfoArray->Count(); i++ )
 +
{
 +
TAknsPkgID pkgId = skinInfoArray->At( i )->PID();
 +
if ( pkgId != iOriginalSkinPid )
 +
{
 +
//Activate a complete skin package at once.
 +
User::LeaveIfError(skinsSession.SetAllDefinitionSets(pkgId));
 +
SetNewSkinIdL(pkgId);
 +
break; //stop the loop                   
 +
}
 +
}           
 +
 +
//Cleanup everything
 +
CleanupStack::PopAndDestroy(3,&skinsSession); //skinInfoArray, &skinInfoArray
 +
}
 +
 
 +
 +
void CMyThemeManager::SkinContentChanged()
 +
{
 +
//TODO:
 +
}
 +
 
 +
void CMyThemeManager::SkinConfigurationChanged(const TAknsSkinStatusConfigurationChangeReason /*aReason*/)
 +
{
 +
//TODO:
 +
}
 +
 
 +
void CMyThemeManager::SkinPackageChanged(const TAknsSkinStatusPackageChangeReason /*aReason*/)
 +
{
 +
//TODO:
 +
}
 +
 
 +
 
 +
</code>
 +
 
 +
 
 +
===Required capabilities===
 
<code>WriteDeviceData</code>
 
<code>WriteDeviceData</code>
 +
 +
===Related topics===
 +
 +
* [[Extended Skins API]]
 +
* http://www.developer.nokia.com/Community/Discussion/showthread.php?129723-How-to-change-background(skin)-for-status-pane
 +
* http://www.developer.nokia.com/Community/Discussion/showthread.php?132509-Is-it-possible-to-change-theme-programmatically-on-S60-3rd-addition&p=555185
 +
* http://www.developer.nokia.com/Community/Discussion/showthread.php?154995-Change-Skin-Colours-S60-3rd-Ed.
 +
* [[Archived:Changing the skin of the status pane on Symbian]]

Latest revision as of 05:59, 26 July 2012

Article Metadata
Article
Created: ivey (05 Apr 2007)
Last edited: hamishwillee (26 Jul 2012)

This document will very briefly explain how to change the active theme on a S60 3rd Edition device. The information in this document is provided as is and the code samples are not meant to be of commercial quality.

Please note that you need to download and install the Extensions Plug-ins for your S60 SDKs to gain access to APIs you need. Extensions Plug-ins are available for all S60 3rd Edition and S60 5th Edition SDKs. Fron the Extensions plug-ins you will need ExtendedSkinsAPI and PersonalisationSkinsSettingsAPI.

Contents

[edit] Connect to Skin Server

#include <AknSSrvClient.h> // aknskinsrv.lib

RAknsSrvSession skinsSession;
User::LeaveIfError( skinsSession.Connect( this ) );
CleanupClosePushL( skinsSession );

[edit] Fetch the package ID of the current skin

#include <centralrepository.h> // centralrepository.lib
#include <AknSkinsInternalCRKeys.h>
// iOriginalSkinPid is of type TAknsPkgID
void CMyThemeManager::GetCurrentSkinIdL()
{
TAknsPkgIDBuf pidBuf;
CRepository* repository =
CRepository::NewL( KCRUidPersonalisation );
TInt retVal = repository->Get( KPslnActiveSkinUid, pidBuf );
delete repository;
repository = NULL;
iOriginalSkinPid.SetFromDesL( pidBuf );
}

[edit] Get a list of installed skin packages

Please see aknssrvclient.h file for more details on how to work with skins residing on memory card.

CArrayPtr< CAknsSrvSkinInformationPkg >* skinInfoArray = 
skinsSession.EnumerateSkinPackagesL();
CleanupStack::PushL( skinInfoArray );

[edit] Go through installed packages and switch to the first available new skin

TInt retValue( KErrNone );
TInt i( 0 );
if ( skinInfoArray->Count() > 0 )
{
for ( i; i < skinInfoArray->Count(); i++ )
{
TAknsPkgID pkgId = skinInfoArray->At( i )->PID();
if ( pkgId != iOriginalSkinPid )
{
//Activate a complete skin package at once.
retValue = skinsSession.SetAllDefinitionSets( pkgId );
if ( retValue == KErrNone )
{
SetNewSkinIdL( pkgId );
}
break;
}
}
}

[edit] Save the new skin package ID in central repository

void CMyThemeManager::SetNewSkinIdL( TAknsPkgID aPkgId )
{
TAknsPkgIDBuf pidBuf;
aPkgId.CopyToDes( pidBuf );
CRepository* repository =
CRepository::NewL( KCRUidPersonalisation );
TInt retVal = repository->Set( KPslnActiveSkinUid, pidBuf );
 
// KPslnActiveSkinLocation has to be changed also
// if new skin resides on mmc whereas old one resided in phone mem
// ...and vice versa
 
delete repository;
repository = NULL;
}

[edit] Free allocated resources

skinInfoArray->ResetAndDestroy();        
CleanupStack::PopAndDestroy( 2 ); // skinsSession, skinInfoArray

[edit] Whole Source

#include <AknSSrvClient.h>		//aknskinsrv.lib	
#include <centralrepository.h> //centralrepository.lib
#include <AknSkinsInternalCRKeys.h>
#include <mmfcontrollerpluginresolver.h> // CleanupResetAndDestroyPushL
 
 
class CMyThemeManager : public CBase, public MAknsSkinChangeObserver
{
public:
 
void ChangeSkinL();
 
private:
 
//From MAknsSkinChangeObserver
virtual void SkinContentChanged();
virtual void SkinConfigurationChanged(const TAknsSkinStatusConfigurationChangeReason aReason);
virtual void SkinPackageChanged(const TAknsSkinStatusPackageChangeReason aReason);
//
void GetCurrentSkinIdL();
void SetNewSkinIdL(TAknsPkgID aPkgId);
 
private:
TAknsPkgID iOriginalSkinPid;
};
 
 
/*
* Set the current skin ID into the Central Repository
*/

void CMyThemeManager::SetNewSkinIdL( TAknsPkgID aPkgId )
{
TAknsPkgIDBuf pidBuf;
aPkgId.CopyToDes( pidBuf );
CRepository* repository = CRepository::NewLC(KCRUidPersonalisation);
User::LeaveIfError(repository->Set(KPslnActiveSkinUid, pidBuf));
 
// KPslnActiveSkinLocation has to be changed also
// if new skin resides on mmc whereas old one resided in phone mem
// ...and vice versa
 
CleanupStack::PopAndDestroy(repository);
}
 
/*
* Get the current skin ID from the Central Repository
*/

void CMyThemeManager::GetCurrentSkinIdL()
{
TAknsPkgIDBuf pidBuf;
CRepository* repository = CRepository::NewLC( KCRUidPersonalisation );
User::LeaveIfError(repository->Get(KPslnActiveSkinUid, pidBuf));
CleanupStack::PopAndDestroy(repository);
iOriginalSkinPid.SetFromDesL(pidBuf);
}
 
 
/*
* Change the current skin to the next available skin
*/

void CMyThemeManager::ChangeSkinL()
{
//Connect to the skin server
RAknsSrvSession skinsSession;
User::LeaveIfError( skinsSession.Connect( this ) );
CleanupClosePushL( skinsSession );
 
//Get the current skin package
GetCurrentSkinIdL();
 
//Get the list of installed skin packages
CArrayPtr<CAknsSrvSkinInformationPkg>* skinInfoArray =skinsSession.EnumerateSkinPackagesL();
CleanupStack::PushL(skinInfoArray);
CleanupResetAndDestroyPushL(*skinInfoArray);
 
//Go through installed skin and change it
for (TInt i=0; i < skinInfoArray->Count(); i++ )
{
TAknsPkgID pkgId = skinInfoArray->At( i )->PID();
if ( pkgId != iOriginalSkinPid )
{
//Activate a complete skin package at once.
User::LeaveIfError(skinsSession.SetAllDefinitionSets(pkgId));
SetNewSkinIdL(pkgId);
break; //stop the loop
}
}
 
//Cleanup everything
CleanupStack::PopAndDestroy(3,&skinsSession); //skinInfoArray, &skinInfoArray
}
 
 
void CMyThemeManager::SkinContentChanged()
{
//TODO:
}
 
void CMyThemeManager::SkinConfigurationChanged(const TAknsSkinStatusConfigurationChangeReason /*aReason*/)
{
//TODO:
}
 
void CMyThemeManager::SkinPackageChanged(const TAknsSkinStatusPackageChangeReason /*aReason*/)
{
//TODO:
}


[edit] Required capabilities

WriteDeviceData

[edit] Related topics

This page was last modified on 26 July 2012, at 05:59.
103 page views in the last 30 days.
×