controlpanelplugins/themeplugin/src/cpthemechanger_p.cpp
changeset 12 624337f114fe
parent 11 10d0dd0e43f1
child 14 23411a3be0db
child 19 36aa4756ee82
equal deleted inserted replaced
11:10d0dd0e43f1 12:624337f114fe
    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 <HbIcon.h>
    23 #include <QSizeF>
       
    24 #include <hbicon.h>
    24 #include <hbinstance.h>
    25 #include <hbinstance.h>
    25 #include "cpthemeclient_p.h"
    26 #include "cpthemeclient_p.h"
    26 #include "cpthemecommon_p.h"
    27 #include "cpthemecommon_p.h"
    27 #ifdef Q_OS_SYMBIAN
    28 #ifdef Q_OS_SYMBIAN
    28 #include "cpthemeclientsymbian_p.h"
    29 #include "cpthemeclientsymbian_p.h"
    34 #if !defined(Q_OS_SYMBIAN)
    35 #if !defined(Q_OS_SYMBIAN)
    35     #include <stdio.h>
    36     #include <stdio.h>
    36     static const char* KThemePathKey = "HB_THEMES_DIR";
    37     static const char* KThemePathKey = "HB_THEMES_DIR";
    37 #endif
    38 #endif
    38 
    39 
    39     static const char* KDefaultTheme = "hbdefault";
    40     static const QString KDefaultTheme = "hbdefault";
    40     static const char* KSettingsGroup = "hborbit";
       
    41     static const char* KSettingsCategory = "currenttheme";
    41     static const char* KSettingsCategory = "currenttheme";
    42     static const bool KDefaultPreviewAvailable = true;
    42     static const bool KDefaultPreviewAvailable = true;
    43 }
    43 }
    44 
    44 
    45 CpThemeChangerPrivate::CpThemeChangerPrivate(CpThemeChanger* qq):
    45 CpThemeChangerPrivate::CpThemeChangerPrivate(CpThemeChanger* qq):
   103 const QString& CpThemeChangerPrivate::currentThemeName() const
   103 const QString& CpThemeChangerPrivate::currentThemeName() const
   104 {
   104 {
   105     return mCurrentTheme.name.isEmpty() ? KDefaultTheme : mCurrentTheme.name;
   105     return mCurrentTheme.name.isEmpty() ? KDefaultTheme : mCurrentTheme.name;
   106 }
   106 }
   107 
   107 
       
   108 int CpThemeChangerPrivate::indexOf(const CpThemeChanger::ThemeInfo& theme) const
       
   109 {
       
   110     return themeList.indexOf(theme);
       
   111 }
       
   112 
   108 void CpThemeChangerPrivate::updateThemeList(const QString& newThemeName)
   113 void CpThemeChangerPrivate::updateThemeList(const QString& newThemeName)
   109 {
   114 {
   110     if(!themeList.isEmpty()) {
   115     if(!themeList.isEmpty()) {
   111         themeList.clear();
   116         themeList.clear();
   112     }
   117     }
   164                     }
   169                     }
   165                     if(iconPath.isEmpty()){
   170                     if(iconPath.isEmpty()){
   166                         
   171                         
   167                         //if no preview graphics path specified,look for the background graphic.
   172                         //if no preview graphics path specified,look for the background graphic.
   168                         //first look in /scalable folder.  if not there, look in pixmap folder.
   173                         //first look in /scalable folder.  if not there, look in pixmap folder.
   169                         if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
   174                     
       
   175                         //Set thumbnail
       
   176                         if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_thumbnail.svg").exists()){
       
   177                             nameIconPair.icon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_thumbnail.svg");
       
   178                         }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
   170                             nameIconPair.icon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
   179                             nameIconPair.icon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
       
   180                             qreal width = nameIconPair.icon.width();
       
   181                             nameIconPair.icon.setHeight(width);
   171                         } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
   182                         } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
   172                             nameIconPair.icon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png");
   183                             nameIconPair.icon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png");
       
   184                             qreal width = nameIconPair.icon.width();
       
   185                             nameIconPair.icon.setHeight(width);
   173                         } else{
   186                         } else{
   174                             nameIconPair.icon = HbIcon(":/image/themePreview.svg");
   187                             nameIconPair.icon = HbIcon(":/image/themePreview.svg");
   175                         }
   188                         }
   176                     } else {
   189                     } else {
   177                         nameIconPair.icon = HbIcon(fullPathToIcon);
   190                         nameIconPair.icon = HbIcon(fullPathToIcon);
   178                     }
   191                     }
       
   192                     
       
   193                     //set portrait preview
       
   194                     if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_prt.svg").exists()){
       
   195                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_prt.svg");
       
   196                     }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg").exists()){
       
   197                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_prt.svg");
       
   198                     } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png").exists()){
       
   199                         nameIconPair.portraitPreviewIcon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_prt.png");
       
   200                     } else{
       
   201                         nameIconPair.portraitPreviewIcon = HbIcon(":/image/themePreview.svg");
       
   202                     }
       
   203                     
       
   204                     //set landscape preview
       
   205                     if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_theme_preview_lsc.svg").exists()){
       
   206                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_theme_preview_lsc.svg");
       
   207                     }else if(QFileInfo(fullPathToIcon + "/scalable/qtg_graf_screen_bg_lsc.svg").exists()){
       
   208                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToIcon + "/scalable/qtg_graf_screen_bg_lsc.svg");
       
   209                     } else if(QFileInfo(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_lsc.png").exists()){
       
   210                         nameIconPair.landscapePreviewIcon = HbIcon(fullPathToIcon + "/pixmap/qtg_graf_screen_bg_lsc.png");
       
   211                     } else{
       
   212                         nameIconPair.landscapePreviewIcon = HbIcon(":/image/themePreview.svg");
       
   213                     }
       
   214                 
   179                     nameIconPair.name = name;
   215                     nameIconPair.name = name;
       
   216                                         
   180                     themeList.append(nameIconPair);
   217                     themeList.append(nameIconPair);
   181 
   218 
   182                     if (name == mCurrentTheme.name) {
   219                     if (name == mCurrentTheme.name) {
   183                         mCurrentTheme = nameIconPair;
   220                         mCurrentTheme = nameIconPair;
   184                     }
   221                     }
   207     if (mCurrentTheme.name == KDefaultTheme)
   244     if (mCurrentTheme.name == KDefaultTheme)
   208     {
   245     {
   209         mCurrentTheme = def;
   246         mCurrentTheme = def;
   210     }
   247     }
   211 
   248 
   212     // Sort the themes list
       
   213     qSort(themeList.begin(), themeList.end());
       
   214 }
   249 }
   215 
   250 
   216 const QList<CpThemeChanger::ThemeInfo>& CpThemeChangerPrivate::themes() const
   251 const QList<CpThemeChanger::ThemeInfo>& CpThemeChangerPrivate::themes() const
   217 {
   252 {
   218     return themeList;
   253     return themeList;
   314                 break;
   349                 break;
   315 
   350 
   316         case Qt::SizeHintRole:
   351         case Qt::SizeHintRole:
   317                 retVal = mThemeChangerPrivate->themeList.at(index.row()).icon.size();
   352                 retVal = mThemeChangerPrivate->themeList.at(index.row()).icon.size();
   318                 break;
   353                 break;
       
   354         case CpThemeChanger::PortraitPreviewRole:
       
   355                 retVal = mThemeChangerPrivate->themeList.at(index.row()).portraitPreviewIcon;
       
   356                 break;
       
   357         case CpThemeChanger::LandscapePreviewRole:
       
   358                 retVal = mThemeChangerPrivate->themeList.at(index.row()).landscapePreviewIcon;
   319 
   359 
   320             default:
   360             default:
   321                 // do nothing
   361                 // do nothing
   322                 qt_noop();
   362                 qt_noop();
   323         }
   363         }