controlpanelplugins/themeplugin/src/cpthemechanger.cpp
branchGCC_SURGE
changeset 27 848a3adde87f
parent 25 19394c261aa5
child 26 808caa51b78b
child 31 e79ce701c376
equal deleted inserted replaced
16:8c9427577f2a 27:848a3adde87f
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description:  
    14  * Description:  
    15  *   
    15  *   
    16  */
    16  */
       
    17 #include <QString>
    17 
    18 
    18 #include "cpthemechanger.h"
    19 #include "cpthemechanger.h"
    19 #include "cpthemechanger_p.h"
    20 #include "cpthemeutil.h"
       
    21 #include "cpthemeinfo.h"
       
    22 
       
    23 #include <hbinstance.h>
       
    24 #include <restricted/hbthemeservices_r.h>
    20 
    25 
    21 /*!
    26 /*!
    22   @alpha
       
    23   @hbcore
       
    24   \class CpThemeChanger
    27   \class CpThemeChanger
    25 
    28 
    26   \brief CpThemeChanger provides an interface for changing the current
    29   \brief CpThemeChanger provides an interface for changing the current
    27   theme and enumerating the available themes (e.g., for the UI to provide 
    30   theme.
    28   a list of themes to show).
       
    29 
       
    30   This API is only for use with the control panel and its theme
    31   This API is only for use with the control panel and its theme
    31   changing plugin.
    32   changing plugin.
    32 */
    33 */
    33 
    34 
    34 /*!
    35 /*!
    35   Constructor.
    36   Constructor.
    36 */
    37 */
    37 CpThemeChanger::CpThemeChanger(QObject* p) :
    38 CpThemeChanger::CpThemeChanger(QObject* p) :
    38     QObject(p),
    39     QObject(p),
    39     d_ptr(new CpThemeChangerPrivate(this))
    40     mCurrentTheme(0)
    40 {
    41 {
       
    42     connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(changeFinished()));
       
    43        
       
    44     setCurrentTheme();
    41 }
    45 }
    42 
    46 
    43 /*!
    47 /*!
    44     Provides a list of themes as a const QAbstractItemModel*.
    48     Returns a ThemeInfo object containing the current theme name and
       
    49     corresponding icons.
       
    50 
       
    51     If no repersentative icons exist, the HbIcon returned will be
       
    52     uninitialized.
    45 */
    53 */
    46 QAbstractItemModel& CpThemeChanger::model()
    54 const CpThemeInfo* CpThemeChanger::currentTheme() const
    47 {
    55 {
    48     Q_D(CpThemeChanger);
    56     return mCurrentTheme;
    49    
    57 }
    50     return d->model;
    58 
       
    59 /*!
       
    60  * Private helper function that gets the current theme from hbinstance and s
       
    61  * ets class' current theme.  
       
    62  */
       
    63 void CpThemeChanger::setCurrentTheme()
       
    64 {
       
    65     QString themeName = "";
       
    66     if (HbInstance::instance()) {
       
    67         HbTheme *hbTheme = HbInstance::instance()->theme();
       
    68         if(hbTheme) {
       
    69             themeName = hbTheme->name();
       
    70         }
       
    71          
       
    72     }
       
    73        
       
    74     if(mCurrentTheme && mCurrentTheme->name() == themeName) {
       
    75         return;
       
    76     }
       
    77     else {
       
    78         //buildThemeInfo creates new theme info.
       
    79         CpThemeInfo* tmpTheme = CpThemeUtil::buildThemeInfo(HbThemeServices::themePath(), themeName);
       
    80          
       
    81         //delete old value. set the new value.
       
    82         if(tmpTheme) {
       
    83             if(mCurrentTheme){
       
    84                 delete mCurrentTheme;
       
    85             }
       
    86             mCurrentTheme = tmpTheme;
       
    87         }
       
    88     }
    51 }
    89 }
    52 
    90 
    53 
    91 
    54 /*!
    92 /*!
    55   Creates a connection to the theme server for the purpose of 
       
    56   changing the theme.
       
    57  */
       
    58 bool CpThemeChanger::connectToServer()
       
    59 {
       
    60     Q_D(CpThemeChanger);
       
    61 
       
    62     return d->connectToServer();
       
    63 }
       
    64 
       
    65 /*!
       
    66   Indicates if the client is connected to the theme server.
       
    67 */
       
    68 bool CpThemeChanger::isConnected() const
       
    69 {
       
    70     Q_D(const CpThemeChanger);
       
    71 
       
    72     return d->isConnected();
       
    73 }
       
    74 
       
    75 
       
    76 /*!
       
    77     Returns a ThemeInfo struct containing the current theme name and
       
    78     a repersentative HbIcon.
       
    79 
       
    80     If no repersentative icon exists, the HbIcon returned will be
       
    81     uninitialized.
       
    82 */
       
    83 const CpThemeChanger::ThemeInfo& CpThemeChanger::currentTheme() const
       
    84 {
       
    85     Q_D(const CpThemeChanger);
       
    86 
       
    87     return d->currentTheme();
       
    88 }
       
    89 
       
    90 int CpThemeChanger::indexOf(const ThemeInfo& theme) const
       
    91 {
       
    92     Q_D(const CpThemeChanger);
       
    93     return d->indexOf(theme);
       
    94 }
       
    95 
       
    96 /*!
       
    97  Change a theme. Returns true on success, false otherwise.
    93  Change a theme. Returns true on success, false otherwise.
    98  */
    94  */
    99 bool CpThemeChanger::changeTheme(const QString& newtheme)
    95 bool CpThemeChanger::changeTheme(const QString& newTheme)
   100 {
    96 {
   101     Q_D(CpThemeChanger);
    97     bool result = false;
       
    98     // Skip doing this if the request is for the current theme
       
    99     if (newTheme.isEmpty() || newTheme == mCurrentTheme->name()) {
       
   100         return result;
       
   101     }
   102 
   102 
   103     return d->changeTheme(newtheme);
   103     QString themePath = CpThemeUtil::themePath(newTheme);
       
   104     
       
   105     if(!themePath.isEmpty()) {
       
   106         HbThemeServices::setTheme(themePath);
       
   107         result = true;
       
   108     }
       
   109     return result;
   104 }
   110 }
   105 
   111 
   106 /*!
   112 /*!
   107  Destructor
   113  Destructor
   108  */
   114  */
   109 CpThemeChanger::~CpThemeChanger()
   115 CpThemeChanger::~CpThemeChanger()
   110 {
   116 {
   111     delete d_ptr;
   117     delete mCurrentTheme;
   112     d_ptr = 0;
   118     mCurrentTheme = 0;
   113 }
   119 }
   114 
   120 
   115 #include "moc_cpthemechanger.cpp"
   121 /*!
       
   122  *  Slot to handle notification from theme server that theme change
       
   123  *  is done.  Notify the owner.
       
   124  */
       
   125 void CpThemeChanger::changeFinished()
       
   126 {
       
   127   
       
   128     setCurrentTheme();
       
   129     
       
   130     emit themeChangeFinished();
       
   131 }
   116 
   132 
   117 // End of file
   133 // End of file
   118 
   134