controlpanelplugins/themeplugin/src/cpthemechanger.cpp
branchRCL_3
changeset 13 90fe62538f66
equal deleted inserted replaced
12:3fec62e6e7fc 13:90fe62538f66
       
     1 /*
       
     2  * Copyright (c) 2009 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 #include <QString>
       
    18 
       
    19 #include "cpthemechanger.h"
       
    20 #include "cpthemeutil.h"
       
    21 #include "cpthemeinfo.h"
       
    22 
       
    23 #include <hbinstance.h>
       
    24 #include <restricted/hbthemeservices_r.h>
       
    25 
       
    26 /*!
       
    27   \class CpThemeChanger
       
    28 
       
    29   \brief CpThemeChanger provides an interface for changing the current
       
    30   theme.
       
    31   This API is only for use with the control panel and its theme
       
    32   changing plugin.
       
    33 */
       
    34 
       
    35 /*!
       
    36   Constructor.
       
    37 */
       
    38 CpThemeChanger::CpThemeChanger(QObject* p) :
       
    39     QObject(p),
       
    40     mCurrentTheme(0)
       
    41 {
       
    42     if(hbInstance->theme()) {
       
    43         connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(changeFinished()));
       
    44     }
       
    45        
       
    46     setCurrentTheme();
       
    47 }
       
    48 
       
    49 /*!
       
    50     Returns a ThemeInfo object containing the current theme name and
       
    51     corresponding icons.
       
    52 
       
    53     If no repersentative icons exist, the HbIcon returned will be
       
    54     uninitialized.
       
    55 */
       
    56 const CpThemeInfo* CpThemeChanger::currentTheme() const
       
    57 {
       
    58     return mCurrentTheme;
       
    59 }
       
    60 
       
    61 /*!
       
    62  * Private helper function that gets the current theme from hbinstance and s
       
    63  * ets class' current theme.  
       
    64  */
       
    65 void CpThemeChanger::setCurrentTheme()
       
    66 {
       
    67     QString themeName = "";
       
    68     if (HbInstance::instance()) {
       
    69         HbTheme *hbTheme = HbInstance::instance()->theme();
       
    70         if(hbTheme) {
       
    71             themeName = hbTheme->name();
       
    72         }
       
    73          
       
    74     }
       
    75        
       
    76     if(mCurrentTheme && mCurrentTheme->name() == themeName) {
       
    77         return;
       
    78     } else {
       
    79         //buildThemeInfo creates new theme info.
       
    80         CpThemeInfo* tmpTheme = CpThemeUtil::buildThemeInfo(HbThemeServices::themePath(), themeName);
       
    81          
       
    82         //delete old value. set the new value.
       
    83         if(tmpTheme) {
       
    84             if(mCurrentTheme){
       
    85                 delete mCurrentTheme;
       
    86             }
       
    87             mCurrentTheme = tmpTheme;
       
    88         }
       
    89     }
       
    90 }
       
    91 
       
    92 
       
    93 /*!
       
    94  Change a theme. Returns true on success, false otherwise.
       
    95  */
       
    96 bool CpThemeChanger::changeTheme(const CpThemeInfo& newTheme)
       
    97 {
       
    98     bool result = false;
       
    99     // Skip doing this if the request is for the current theme
       
   100     if (newTheme.name().isEmpty() || (mCurrentTheme && newTheme.name() == mCurrentTheme->name())) {
       
   101         return result;
       
   102     }
       
   103 
       
   104     QString themePath = newTheme.itemData();
       
   105     
       
   106     if(!themePath.isEmpty()) {
       
   107         HbThemeServices::setTheme(themePath);
       
   108         result = true;
       
   109     }
       
   110     return result;
       
   111 }
       
   112 
       
   113 /*!
       
   114  Destructor
       
   115  */
       
   116 CpThemeChanger::~CpThemeChanger()
       
   117 {
       
   118     delete mCurrentTheme;
       
   119     mCurrentTheme = 0;
       
   120 }
       
   121 
       
   122 /*!
       
   123  *  Slot to handle notification from theme server that theme change
       
   124  *  is done.  Notify the owner.
       
   125  */
       
   126 void CpThemeChanger::changeFinished()
       
   127 {
       
   128     setCurrentTheme();
       
   129     emit themeChangeFinished();
       
   130 }
       
   131 
       
   132 // End of file
       
   133