controlpanelplugins/themeplugin/src/cpthemeclientsymbian_p.cpp
changeset 19 36aa4756ee82
parent 11 10d0dd0e43f1
child 21 2883a5458389
equal deleted inserted replaced
12:624337f114fe 19:36aa4756ee82
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0""
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description: 
    14  * Description:  
    15 *
    15  *   
    16 */
    16  */
    17 
       
    18 
    17 
    19 #include "cpthemeclientsymbian_p.h"
    18 #include "cpthemeclientsymbian_p.h"
    20 #include "cpthemesymbiancommon_p.h"
    19 #include "cpthemesymbiancommon_p.h"
       
    20 #include <e32property.h>
    21 
    21 
    22 #include <QFile>
       
    23 #include <QDebug>
       
    24 #include <QTime>
       
    25 
       
    26 const TUint KDefaultMessageSlots = 4;
       
    27 
    22 
    28 /**
    23 /**
    29 * constructor
    24 * constructor
    30 */
    25 */
    31 CpThemeClientPrivate::CpThemeClientPrivate():
    26 CpThemeClientPrivate::CpThemeClientPrivate()
    32     clientConnected(false)
       
    33 {
    27 {
    34 }
    28 }
    35 
    29 
    36 /**
    30 /**
    37 * CpThemeClientPrivate::connectToServer()
    31 * CpThemeClientPrivate::connectToServer()
    38 *
    32 *
    39 * Connects to the server
    33 * Connects to the server
    40 */
    34 */
    41 bool CpThemeClientPrivate::connectToServer()
    35 bool CpThemeClientPrivate::connectToServer()
    42 {
    36 {
    43    
    37     return true;
    44     TInt error; 
       
    45     
       
    46     error = CreateSession(KThemeServerName, Version(), KDefaultMessageSlots);
       
    47     return( clientConnected = (KErrNone == error ) );
       
    48 }
    38 }
    49 
    39 
    50 /**
    40 /**
    51 Indicates a connection to the server
    41 Indicates a connection to the server
    52 */
    42 */
    53 bool CpThemeClientPrivate::isConnected()
    43 bool CpThemeClientPrivate::isConnected()
    54 {
    44 {
    55     return connected;
    45     return true;
    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 }
    46 }
    69 
    47 
    70 /**
    48 /**
    71  * Destructor
    49  * Destructor
    72  */
    50  */
    73 CpThemeClientPrivate::~CpThemeClientPrivate()
    51 CpThemeClientPrivate::~CpThemeClientPrivate()
    74 {
    52 {
    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 }
    53 }
   123 
    54 
   124 /**
    55 /**
   125  * changeTheme
    56  * changeTheme
   126  */
    57  */
   127 bool CpThemeClientPrivate::changeTheme(const QString& aString )
    58 bool CpThemeClientPrivate::changeTheme(const QString& aString )
   128 {
    59 {
   129     TPtrC themeName(reinterpret_cast<const TUint16 *>(aString.constData()));
    60     TInt err = KErrGeneral;
   130     TIpcArgs args(&themeName);
    61     RProperty themeRequestProp;
   131     TInt err = SendReceive(EThemeSelection, args);
    62     
   132     return KErrNone == err;
    63     User::LeaveIfError( themeRequestProp.Attach( KServerUid3, KNewThemeForThemeChanger ) );
       
    64     
       
    65     TBuf<256> newThemenameChangeRequest;
       
    66     _LIT(KThemeRequestFormatter, "%d:%S");
       
    67     TBuf<256> newThemename(aString.utf16());
       
    68     newThemenameChangeRequest.Format( KThemeRequestFormatter, EThemeSelection, &newThemename);
       
    69     err = themeRequestProp.Set(newThemenameChangeRequest);
       
    70     themeRequestProp.Close();
       
    71     return (err == KErrNone);
   133 }
    72 }