controlpanelplugins/themeplugin/src/cpthemechanger_p.cpp
changeset 19 36aa4756ee82
parent 12 624337f114fe
child 21 2883a5458389
equal deleted inserted replaced
12:624337f114fe 19:36aa4756ee82
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 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 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Private implementation of the theme changer.
       
    15  *
     8  *
    16 */
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  
       
    15  *   
       
    16  */
    17 
    17 
    18 #include "cpthemechanger.h"
    18 #include "cpthemechanger.h"
    19 #include "cpthemechanger_p.h"
    19 #include "cpthemechanger_p.h"
    20 #include <QStringList>
    20 #include <QStringList>
    21 #include <QSettings>
    21 #include <QSettings>
    22 #include <QFileSystemWatcher>
    22 #include <QFileSystemWatcher>
       
    23 #include <QPixmap>
    23 #include <QSizeF>
    24 #include <QSizeF>
    24 #include <hbicon.h>
    25 #include <hbicon.h>
    25 #include <hbinstance.h>
    26 #include <hbinstance.h>
    26 #include "cpthemeclient_p.h"
    27 #include "cpthemeclient_p.h"
    27 #include "cpthemecommon_p.h"
    28 #include "cpthemecommon_p.h"
    35 #if !defined(Q_OS_SYMBIAN)
    36 #if !defined(Q_OS_SYMBIAN)
    36     #include <stdio.h>
    37     #include <stdio.h>
    37     static const char* KThemePathKey = "HB_THEMES_DIR";
    38     static const char* KThemePathKey = "HB_THEMES_DIR";
    38 #endif
    39 #endif
    39 
    40 
    40     static const QString KDefaultTheme = "hbdefault";
    41     static const QString KDefaultTheme = "hbdefault";   
    41     static const char* KSettingsCategory = "currenttheme";
       
    42     static const bool KDefaultPreviewAvailable = true;
       
    43 }
    42 }
    44 
    43 
    45 CpThemeChangerPrivate::CpThemeChangerPrivate(CpThemeChanger* qq):
    44 CpThemeChangerPrivate::CpThemeChangerPrivate(CpThemeChanger* qq):
    46     q_ptr(qq),
    45     q_ptr(qq),
    47     themeClient(CpThemeClient::global()),
    46     themeClient(CpThemeClient::global()),
    74     themeRootPath = "c:\\resource\\hb";
    73     themeRootPath = "c:\\resource\\hb";
    75     themeRootPathPostfix = QString();
    74     themeRootPathPostfix = QString();
    76     #endif
    75     #endif
    77 
    76 
    78     // Get our current state
    77     // Get our current state
    79     QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT));
    78     if (HbInstance::instance()) {
    80     mCurrentTheme.name = settings.value(KSettingsCategory).toString();
    79         HbTheme *hbTheme = HbInstance::instance()->theme();
       
    80         if (hbTheme) {
       
    81             mCurrentTheme.name = hbTheme->name();
       
    82         }
       
    83     }
    81     updateThemeList(mCurrentTheme.name);
    84     updateThemeList(mCurrentTheme.name);
    82 
    85 
    83     // Watch for changes to the theme directory in flash.
    86     // Watch for changes to the theme directory in flash.
    84     // This may change once we start offering a model.
    87     // This may change once we start offering a model.
    85     fileWatcher->addPath(themeRootPath+"/themes/");
    88     fileWatcher->addPath(themeRootPath+"/themes/");
   152                    (iconThemePath.exists("scalable") || iconThemePath.exists("pixmap") )) {
   155                    (iconThemePath.exists("scalable") || iconThemePath.exists("pixmap") )) {
   153                     QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat);
   156                     QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat);
   154                     iniSetting.beginGroup("Icon Theme");
   157                     iniSetting.beginGroup("Icon Theme");
   155                     QString hidden = iniSetting.value("Hidden").toString();
   158                     QString hidden = iniSetting.value("Hidden").toString();
   156                     QString name = iniSetting.value("Name").toString();
   159                     QString name = iniSetting.value("Name").toString();
   157                     QString iconPath = iniSetting.value("PreviewIconPath").toString();
   160                     QString iconPath = iniSetting.value("PreviewThumbnailPath").toString();
       
   161                     QString previewPathPrt = iniSetting.value("PreviewIconPath_prt").toString();
       
   162                     QString previewPathLsc = iniSetting.value("PreviewIconPath_lsc").toString();
   158                     if (name.isEmpty()) {
   163                     if (name.isEmpty()) {
   159                         continue;
   164                         continue;
   160                     }
   165                     }
   161                     if (!KDefaultPreviewAvailable && iconPath.isEmpty())
   166                     
   162                     {
       
   163                         continue;
       
   164                     }
       
   165                     QString fullPathToIcon(iconThemePath.path() + iconPath);
   167                     QString fullPathToIcon(iconThemePath.path() + iconPath);
   166                     // Don't treat this as a theme unless it's got a preview.
   168                     
   167                     if (!QFileInfo(fullPathToIcon).exists() && !KDefaultPreviewAvailable) {
   169                     if(iconPath.isEmpty()|| !QFileInfo(fullPathToIcon).exists()){
   168                         continue;
       
   169                     }
       
   170                     if(iconPath.isEmpty()){
       
   171                         
   170                         
   172                         //if no preview graphics path specified,look for the background graphic.
       
   173                         //first look in /scalable folder.  if not there, look in pixmap folder.
       
   174                     
       
   175                         //Set thumbnail
   171                         //Set thumbnail
   176                         if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_thumbnail.svg").exists()){
   172                         if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_thumbnail.svg").exists()){
   177                             nameIconPair.icon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_thumbnail.svg");
   173                             nameIconPair.icon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_thumbnail.svg");
   178                         }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
   174                         }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
   179                             nameIconPair.icon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
   175                             QPixmap px(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
   180                             qreal width = nameIconPair.icon.width();
   176                             QIcon scaledIcon(px.scaled(QSize(64, 64)));
   181                             nameIconPair.icon.setHeight(width);
   177                             nameIconPair.icon = HbIcon(scaledIcon);
       
   178                             nameIconPair.icon.setIconName(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
       
   179                            
   182                         } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
   180                         } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
   183                             nameIconPair.icon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png");
   181                             QPixmap px(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png");
   184                             qreal width = nameIconPair.icon.width();
   182                             QIcon scaledIcon(px.scaled(QSize(64, 64)));
   185                             nameIconPair.icon.setHeight(width);
   183                             nameIconPair.icon = HbIcon(scaledIcon);
       
   184                             nameIconPair.icon.setIconName(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.png");
       
   185                           
   186                         } else{
   186                         } else{
   187                             nameIconPair.icon = HbIcon(":/image/themePreview.svg");
   187                             nameIconPair.icon = HbIcon(":/image/themePreview.svg");
   188                         }
   188                         }
   189                     } else {
   189                     } else {
   190                         nameIconPair.icon = HbIcon(fullPathToIcon);
   190                         nameIconPair.icon = HbIcon(fullPathToIcon);
   191                     }
   191                     }
   192                     
   192                     
   193                     //set portrait preview
   193                     //Portrait preview
   194                     if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_prt.svg").exists()){
   194                     QString fullPathToPreviewPrt = (iconThemePath.path() + previewPathPrt );
   195                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_prt.svg");
   195                     
   196                     }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
   196                     if(previewPathPrt.isEmpty() || !QFileInfo(fullPathToPreviewPrt).exists()) {
   197                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
   197                     
   198                     } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
   198                         if(QFileInfo(fullPathToPreviewPrt + "/scalable/qtg_graf_theme_preview_prt.svg").exists()){
   199                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png");
   199                             nameIconPair.portraitPreviewIcon = HbIcon(fullPathToPreviewPrt + "/scalable/qtg_graf_theme_preview_prt.svg");
   200                     } else{
   200                         }else if(QFileInfo(fullPathToPreviewPrt + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
   201                         nameIconPair.portraitPreviewIcon = HbIcon(":/image/themePreview.svg");
   201                             nameIconPair.portraitPreviewIcon = HbIcon(fullPathToPreviewPrt + "/scalable/qtg_graf_screen_bg_prt.svg");
   202                     }
   202                         } else if(QFileInfo(fullPathToPreviewPrt + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
   203                     
   203                             nameIconPair.portraitPreviewIcon = HbIcon(fullPathToPreviewPrt + "/pixmap/qtg_graf_screen_bg_prt.png");
   204                     //set landscape preview
   204                         } else{
   205                     if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_lsc.svg").exists()){
   205                             nameIconPair.portraitPreviewIcon = HbIcon(":/image/themePreview.svg");
   206                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_lsc.svg");
   206                         }
   207                     }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_lsc.svg").exists()){
   207                     }
   208                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_lsc.svg");
   208                     else {
   209                     } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_lsc.png").exists()){
   209                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToPreviewPrt);
   210                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_lsc.png");
   210                     }
   211                     } else{
   211                     
   212                         nameIconPair.landscapePreviewIcon = HbIcon(":/image/themePreview.svg");
   212                     //Landscape preview
       
   213                     QString fullPathToPreviewLsc = (iconThemePath.path() + previewPathLsc );
       
   214                                     
       
   215                     if(previewPathLsc.isEmpty() || !QFileInfo(fullPathToPreviewLsc).exists()) {
       
   216                                 
       
   217                         if(QFileInfo(fullPathToPreviewLsc + "/scalable/qtg_graf_theme_preview_lsc.svg").exists()){
       
   218                             nameIconPair.landscapePreviewIcon = HbIcon(fullPathToPreviewLsc + "/scalable/qtg_graf_theme_preview_lsc.svg");
       
   219                         }else if(QFileInfo(fullPathToPreviewLsc + "/scalable/qtg_graf_screen_bg_lsc.svg").exists()){
       
   220                             nameIconPair.landscapePreviewIcon = HbIcon(fullPathToPreviewLsc + "/scalable/qtg_graf_screen_bg_lsc.svg");
       
   221                         } else if(QFileInfo(fullPathToPreviewLsc + "/pixmap/qtg_graf_screen_bg_lsc.png").exists()){
       
   222                             nameIconPair.landscapePreviewIcon = HbIcon(fullPathToPreviewLsc + "/pixmap/qtg_graf_screen_bg_lsc.png");
       
   223                         } else{
       
   224                             nameIconPair.landscapePreviewIcon = HbIcon(":/image/themePreview.svg");
       
   225                         }
       
   226                     }
       
   227                     else {
       
   228                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToPreviewLsc);
   213                     }
   229                     }
   214                 
   230                 
   215                     nameIconPair.name = name;
   231                     nameIconPair.name = name;
   216                                         
   232                                         
   217                     themeList.append(nameIconPair);
   233                     themeList.append(nameIconPair);
   234                     }
   250                     }
   235                 }
   251                 }
   236             }
   252             }
   237         }
   253         }
   238     }
   254     }
   239     // Include default
   255     
   240     CpThemeChanger::ThemeInfo def;
       
   241     def.name = KDefaultTheme;
       
   242     def.icon = HbIcon(":/image/themePreview.svg");
       
   243     themeList.append(def);
       
   244     if (mCurrentTheme.name == KDefaultTheme)
   256     if (mCurrentTheme.name == KDefaultTheme)
   245     {
   257     {
   246         mCurrentTheme = def;
   258         // Include default
       
   259          CpThemeChanger::ThemeInfo def;
       
   260          def.name = KDefaultTheme;
       
   261          def.icon = HbIcon(":/image/themePreview.svg");
       
   262          themeList.append(def);
       
   263   
       
   264          mCurrentTheme = def;
   247     }
   265     }
   248 
   266 
   249 }
   267 }
   250 
   268 
   251 const QList<CpThemeChanger::ThemeInfo>& CpThemeChangerPrivate::themes() const
   269 const QList<CpThemeChanger::ThemeInfo>& CpThemeChangerPrivate::themes() const
   252 {
   270 {
   253     return themeList;
   271    return themeList;
   254 }
   272 }
   255 
   273 
   256 bool CpThemeChangerPrivate::connectToServer()
   274 bool CpThemeChangerPrivate::connectToServer()
   257 {
   275 {
   258     return themeClient->connectToServer();
   276     return themeClient->connectToServer();
   287     }
   305     }
   288 
   306 
   289     if (exists) {
   307     if (exists) {
   290         result = themeClient->changeTheme(newTheme);
   308         result = themeClient->changeTheme(newTheme);
   291 		updateThemeList(newTheme);
   309 		updateThemeList(newTheme);
   292 }
   310     }
   293     return result;
   311     return result;
   294 }
   312 }
   295 
   313 
   296 void CpThemeChangerPrivate::_q_themeDirectoryChanged(const QString&)
   314 void CpThemeChangerPrivate::_q_themeDirectoryChanged(const QString&)
   297 {
   315 {