webengine/widgetengine/src/WrtPlatform.cpp
changeset 0 dd21522fd290
child 26 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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 the License "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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "WrtPlatform.h"
       
    23 #include <sisregistryentry.h>
       
    24 #include <sisregistrysession.h>
       
    25 #include <sysutil.h> 
       
    26 #include <etel.h>
       
    27 #include <etelmm.h>
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // MACROS
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 const TUid KBrowserAppUid = { 0x10008d39 };
       
    39 _LIT(KNotAvailable, "N/A");
       
    40 _LIT(KPlatformId, "S60");
       
    41 _LIT(KDefManufacturer, "N/A");
       
    42 _LIT(KDefModel, "N/A");
       
    43 _LIT(KDefSerialNumber, "N/A");
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 using namespace KJS;
       
    51 const ClassInfo JSWrtPlatform::info = { "JSWrtPlatform", 0, &WrtPlatformTable, 0 };
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 /*
       
    55 @begin WrtPlatformTable 4
       
    56     id JSWrtPlatform::id DontDelete|ReadOnly
       
    57     romVersion JSWrtPlatform::romVersion DontDelete|ReadOnly
       
    58     packageVersion JSWrtPlatform::packageVersion DontDelete|ReadOnly
       
    59     manufacturer JSWrtPlatform::manufacturer DontDelete|ReadOnly
       
    60     model JSWrtPlatform::model DontDelete|ReadOnly
       
    61 @end
       
    62 */
       
    63 
       
    64 // ============================ MEMBER FUNCTIONS ===============================
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // JSWrtPlatform::JSWrtPlatform
       
    68 // C++ constructor
       
    69 //
       
    70 //
       
    71 // ----------------------------------------------------------------------------
       
    72 JSWrtPlatform::JSWrtPlatform( ExecState* exec )
       
    73     : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), 
       
    74       pltPriv(new WrtPlatformPrivate())
       
    75     {
       
    76     TRAP_IGNORE( pltPriv->m_sisVersion = SISVersionL() );
       
    77     TRAP_IGNORE( GetPhoneInfoL() );
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // JSWrtPlatform::~JSWrtPlatform
       
    82 // Destructor
       
    83 //
       
    84 //
       
    85 // ----------------------------------------------------------------------------
       
    86 JSWrtPlatform::~JSWrtPlatform()
       
    87     {
       
    88     delete pltPriv;
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // JSWrtPlatform::type
       
    93 //
       
    94 //
       
    95 //
       
    96 // ----------------------------------------------------------------------------
       
    97 JSType JSWrtPlatform::type() const 
       
    98 { 
       
    99     return ObjectType; 
       
   100 }
       
   101 
       
   102 // ----------------------------------------------------------------------------
       
   103 // JSWrtPlatform::toString
       
   104 // Returns string representation of the object
       
   105 //
       
   106 //
       
   107 // ----------------------------------------------------------------------------
       
   108 UString JSWrtPlatform::toString(ExecState *exec) const
       
   109     {
       
   110     return "[object JSWrtPlatform]";
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // JSWrtPlatform::getValueProperty
       
   115 //
       
   116 //
       
   117 // ----------------------------------------------------------------------------
       
   118 JSValue* JSWrtPlatform::getValueProperty(ExecState *exec, int token) const
       
   119     {
       
   120     switch( token )
       
   121         {
       
   122         case id: {                
       
   123             TPtrC platformId;
       
   124             platformId.Set( KPlatformId );
       
   125             return jsString( UString((UChar*) platformId.Ptr(), platformId.Length()) );
       
   126         }
       
   127         case romVersion: {                
       
   128             TPtrC versionName;
       
   129             TBuf<KSysUtilVersionTextLength> version;
       
   130             if ( SysUtil::GetSWVersion( version ) == KErrNone )
       
   131                 {
       
   132                 versionName.Set( version );
       
   133                 }
       
   134             else
       
   135                 {
       
   136                 versionName.Set( KNotAvailable );
       
   137                 }
       
   138 
       
   139             return jsString( UString((UChar*) versionName.Ptr(), versionName.Length()) );
       
   140         }
       
   141         case packageVersion: {                
       
   142             return jsString( pltPriv->m_sisVersion );        
       
   143         }
       
   144         case manufacturer: {                
       
   145             return jsString( pltPriv->m_manufacturer );        
       
   146         }
       
   147         case model: {                
       
   148             return jsString( pltPriv->m_model );        
       
   149         }
       
   150 /*        case revision: {                
       
   151             return jsString( pltPriv->m_revision );        
       
   152         }
       
   153           case serialNumber: {                
       
   154             return jsString( pltPriv->m_serialNumber );        
       
   155         }
       
   156 */
       
   157         default:
       
   158             return throwError(exec, GeneralError);
       
   159         }
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // JSWrtPlatform::getOwnPropertySlot
       
   164 //
       
   165 //
       
   166 //
       
   167 // ----------------------------------------------------------------------------
       
   168 bool JSWrtPlatform::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   169 {
       
   170     const HashEntry* entry = Lookup::findEntry(&WrtPlatformTable, propertyName);
       
   171     if (entry)
       
   172         {
       
   173         slot.setStaticEntry(this, entry, staticValueGetter<JSWrtPlatform>);
       
   174         return true;
       
   175         }
       
   176    
       
   177     return JSObject::getOwnPropertySlot(exec, propertyName, slot);
       
   178 }
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // JSWrtPlatform::SISVersionL
       
   182 //
       
   183 //
       
   184 // ----------------------------------------------------------------------------
       
   185 UString JSWrtPlatform::SISVersionL()
       
   186 {
       
   187     Swi::RSisRegistrySession regSession;
       
   188     CleanupClosePushL(regSession);
       
   189     User::LeaveIfError( regSession.Connect() );
       
   190 
       
   191     Swi::RSisRegistryEntry entry;
       
   192     CleanupClosePushL(entry);
       
   193 
       
   194     TPtrC versionName;
       
   195     TInt err = entry.Open( regSession, KBrowserAppUid );
       
   196     if( err == KErrNone )
       
   197         {
       
   198         TVersion version;
       
   199         version = entry.VersionL();
       
   200         versionName.Set( version.Name() );
       
   201         }
       
   202     else
       
   203         {
       
   204         versionName.Set( KNotAvailable );
       
   205         }
       
   206         
       
   207     CleanupStack::PopAndDestroy( &entry );               
       
   208     CleanupStack::PopAndDestroy( &regSession );
       
   209 
       
   210     return UString( (UChar*) versionName.Ptr(), versionName.Length() );
       
   211 }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // JSWrtPlatform::GetPhoneInfoL
       
   215 //
       
   216 //
       
   217 // ----------------------------------------------------------------------------
       
   218 void JSWrtPlatform::GetPhoneInfoL()
       
   219 {
       
   220     TPtrC manufacturer;
       
   221     manufacturer.Set( KDefManufacturer );
       
   222     pltPriv->m_manufacturer = UString( (UChar*) manufacturer.Ptr(), manufacturer.Length() );
       
   223 
       
   224     TPtrC model;
       
   225     model.Set( KDefModel );
       
   226     pltPriv->m_model = UString( (UChar*) model.Ptr(), model.Length() );
       
   227 
       
   228 //    TPtrC revision;
       
   229 //    revision.Set( KDefRevision );
       
   230 //    pltPriv->m_revision = UString( (UChar*) revision.Ptr(), revision.Length() );
       
   231 
       
   232 //    TPtrC serialNumber;
       
   233 //    serialNumber.Set( KDefSerialNumber );
       
   234 //    pltPriv->m_serialNumber = UString( (UChar*) serialNumber.Ptr(), serialNumber.Length() );
       
   235 
       
   236     // Read IMEI on HW, use dummy under WINS
       
   237 #if !defined( __WINS__ )
       
   238     RTelServer server;
       
   239     User::LeaveIfError(server.Connect()); 
       
   240     CleanupClosePushL(server);
       
   241     TInt numPhones;
       
   242     User::LeaveIfError(server.EnumeratePhones(numPhones));
       
   243     if( numPhones > 0 )
       
   244     {
       
   245         RTelServer::TPhoneInfo phoneInfo;
       
   246         User::LeaveIfError(server.GetPhoneInfo(0, phoneInfo)); // Query first phone
       
   247         RMobilePhone phone;
       
   248         User::LeaveIfError(phone.Open(server, phoneInfo.iName));
       
   249         CleanupClosePushL(phone);
       
   250         User::LeaveIfError(phone.Initialise()); 
       
   251         TUint32 identityCaps;
       
   252         phone.GetIdentityCaps( identityCaps );
       
   253         RMobilePhone::TMobilePhoneIdentityV1 id;
       
   254         TRequestStatus status;
       
   255         phone.GetPhoneId( status, id );
       
   256         User::WaitForRequest( status );
       
   257         User::LeaveIfError( status.Int() );
       
   258         if (identityCaps & RMobilePhone::KCapsGetManufacturer)
       
   259             {
       
   260             manufacturer.Set( id.iManufacturer );
       
   261             pltPriv->m_manufacturer = UString( (UChar*) manufacturer.Ptr(), manufacturer.Length() );
       
   262             }
       
   263         if (identityCaps & RMobilePhone::KCapsGetModel)
       
   264             {
       
   265             model.Set( id.iModel );
       
   266             pltPriv->m_model = UString( (UChar*) model.Ptr(), model.Length() );
       
   267             }
       
   268 /*        if (identityCaps & RMobilePhone::KCapsGetRevision)
       
   269             {
       
   270             revision.Set( id.iRevision );
       
   271             pltPriv->m_revision = UString( (UChar*) revision.Ptr(), revision.Length() );
       
   272             }
       
   273         if (identityCaps & RMobilePhone::KCapsGetSerialNumber)
       
   274             {
       
   275             serialNumber.Set( id.iSerialNumber );
       
   276             pltPriv->m_serialNumber = UString( (UChar*) serialNumber.Ptr(), serialNumber.Length() );
       
   277             }
       
   278 */
       
   279         CleanupStack::PopAndDestroy(); // phone
       
   280      }
       
   281      CleanupStack::PopAndDestroy(); // server
       
   282 #else
       
   283 
       
   284 #endif
       
   285 }
       
   286 
       
   287 //END OF FILE
       
   288 
       
   289 
       
   290 
       
   291