controlpanelplugins/themeplugin/src/cpthemeclientsymbian_p.cpp
changeset 11 10d0dd0e43f1
child 14 23411a3be0db
child 19 36aa4756ee82
equal deleted inserted replaced
10:0a74be98a8bc 11:10d0dd0e43f1
       
     1 /*
       
     2 * Copyright (c) 2008-2010 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cpthemeclientsymbian_p.h"
       
    20 #include "cpthemesymbiancommon_p.h"
       
    21 
       
    22 #include <QFile>
       
    23 #include <QDebug>
       
    24 #include <QTime>
       
    25 
       
    26 const TUint KDefaultMessageSlots = 4;
       
    27 
       
    28 /**
       
    29 * constructor
       
    30 */
       
    31 CpThemeClientPrivate::CpThemeClientPrivate():
       
    32     clientConnected(false)
       
    33 {
       
    34 }
       
    35 
       
    36 /**
       
    37 * CpThemeClientPrivate::connectToServer()
       
    38 *
       
    39 * Connects to the server
       
    40 */
       
    41 bool CpThemeClientPrivate::connectToServer()
       
    42 {
       
    43    
       
    44     TInt error; 
       
    45     
       
    46     error = CreateSession(KThemeServerName, Version(), KDefaultMessageSlots);
       
    47     return( clientConnected = (KErrNone == error ) );
       
    48 }
       
    49 
       
    50 /**
       
    51 Indicates a connection to the server
       
    52 */
       
    53 bool CpThemeClientPrivate::isConnected()
       
    54 {
       
    55     return connected;
       
    56 }
       
    57 
       
    58 
       
    59 
       
    60 /**
       
    61 Returns the version number
       
    62 */  
       
    63 TVersion CpThemeClientPrivate::Version(void) const
       
    64 {
       
    65     return(TVersion(KThemeServerMajorVersionNumber,
       
    66                     KThemeServerMinorVersionNumber,
       
    67                     KThemeServerBuildVersionNumber));
       
    68 }
       
    69 
       
    70 /**
       
    71  * Destructor
       
    72  */
       
    73 CpThemeClientPrivate::~CpThemeClientPrivate()
       
    74 {
       
    75     RSessionBase::Close();
       
    76 }
       
    77 
       
    78 /**
       
    79  * StartServer
       
    80  */
       
    81 TInt CpThemeClientPrivate::StartServer()
       
    82 {
       
    83     TFindServer findThemeServer(KThemeServerName);
       
    84     TFullName name;
       
    85     if ( KErrNone == findThemeServer.Next( name ) ) {
       
    86         // Server already running
       
    87         return KErrNone;
       
    88     }
       
    89     return CreateServerProcess();
       
    90 }
       
    91 
       
    92 /**
       
    93  * CreateServerProcess
       
    94  */
       
    95 TInt CpThemeClientPrivate::CreateServerProcess()
       
    96 {
       
    97     TInt result;
       
    98     const TUid KServerUid2={0x100039CE};
       
    99     const TUidType serverUid( KNullUid, KServerUid2, KServerUid3 );
       
   100     RProcess server;
       
   101     _LIT(KThemeServerExe,"hbthemeserver.exe");
       
   102     
       
   103     result = server.Create( KThemeServerExe, KNullDesC, EOwnerProcess );
       
   104     
       
   105     if (KErrNone != result) {
       
   106         return  result; 
       
   107     }
       
   108     else {
       
   109         TRequestStatus status;
       
   110         server.Rendezvous(status);
       
   111         if (status!=KRequestPending) {
       
   112             server.Kill(0); // abort startup
       
   113         }
       
   114         else {
       
   115             server.Resume(); // logon OK - start the server
       
   116         }
       
   117         User::WaitForRequest(status);// wait for start or death
       
   118         server.Close();
       
   119         connected == status.Int() == KErrNone ? true : false;
       
   120         return status.Int(); // return the error
       
   121     }
       
   122 }
       
   123 
       
   124 /**
       
   125  * changeTheme
       
   126  */
       
   127 bool CpThemeClientPrivate::changeTheme(const QString& aString )
       
   128 {
       
   129     TPtrC themeName(reinterpret_cast<const TUint16 *>(aString.constData()));
       
   130     TIpcArgs args(&themeName);
       
   131     TInt err = SendReceive(EThemeSelection, args);
       
   132     return KErrNone == err;
       
   133 }