src/hbutils/theme/hbthemeservices.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    42 #include "hbthemecommon_symbian_p.h"
    42 #include "hbthemecommon_symbian_p.h"
    43 #else
    43 #else
    44 #include "hbthemeclient_p.h"
    44 #include "hbthemeclient_p.h"
    45 #endif
    45 #endif
    46 
    46 
       
    47 #include <QSettings>
       
    48 
    47 /*!
    49 /*!
    48     Sets the active theme that is used with the Hb applications. HbTheme changed() signal will be emitted if theme change is
    50     Sets the active theme that is used with the Hb applications. HbTheme changed() signal will be emitted if theme change is
    49     applied succesfully. In addition to the active theme content loading also the underlying priority themes will be updated
    51     applied succesfully. In addition to the active theme content loading also the underlying priority themes will be updated
    50     during the theme change.
    52     during the theme change.
    51 
    53 
    52     Depending on the platform setTheme functionality might by restricted.
    54     Depending on the platform setTheme functionality might by restricted.
    53     
    55     
    54     \param themePath, absolute path to the folder where themes index.theme file is located.
    56     \param themePath absolute path to the folder where themes index.theme file is located.
    55 */
    57 */
    56 void HbThemeServices::setTheme(const QString &themePath)
    58 void HbThemeServices::setTheme(const QString &themePath)
    57 {
    59 {
    58 #ifdef Q_OS_SYMBIAN
    60 #ifdef Q_OS_SYMBIAN
    59     RProperty themeRequestProp;
    61     RProperty themeRequestProp;
    66     newThemenameChangeRequest.Format(KThemeRequestFormatter, EThemeSelection, &newThemename);
    68     newThemenameChangeRequest.Format(KThemeRequestFormatter, EThemeSelection, &newThemename);
    67     themeRequestProp.Set(newThemenameChangeRequest);
    69     themeRequestProp.Set(newThemenameChangeRequest);
    68     themeRequestProp.Close();
    70     themeRequestProp.Close();
    69 #else
    71 #else
    70     HbThemeClient::global()->setTheme(themePath);
    72     HbThemeClient::global()->setTheme(themePath);
    71 #endif	
    73 #endif  
    72 }
    74 }
    73     
    75     
    74 /*!
    76 /*!
    75     Returns the absolute path to the active theme.
    77     Returns the absolute path to the active theme.
    76 
    78 
    85         path.append("/icons/");
    87         path.append("/icons/");
    86         path.append(info.name);
    88         path.append(info.name);
    87     }
    89     }
    88     return path;
    90     return path;
    89 }
    91 }
       
    92 
       
    93 /*!
       
    94     Returns the list of available themes.
       
    95 
       
    96     \return list of themes. First item of QPair is the unlocalized theme name
       
    97     and the second item is the absolute path to the theme.
       
    98 */
       
    99 const QList<QPair<QString, QString> > HbThemeServices::availableThemes()
       
   100 {
       
   101     QList<QPair<QString, QString> > themes;
       
   102 
       
   103     QStringList rootDirs;
       
   104 #ifdef Q_OS_SYMBIAN
       
   105     QFileInfoList driveList = QDir::drives();
       
   106     QString themesPath = "resource/hb/themes";
       
   107     foreach(const QFileInfo & drive, driveList) {
       
   108         QDir themeFolder(drive.absolutePath() + themesPath);
       
   109         if (themeFolder.exists()) {
       
   110             rootDirs << themeFolder.absolutePath();
       
   111         }
       
   112     }
       
   113 #else
       
   114     QString envDir = QDir::fromNativeSeparators(qgetenv("HB_THEMES_DIR"));
       
   115     if (!envDir.isEmpty())
       
   116         rootDirs << envDir + "/themes";
       
   117 #endif
       
   118 
       
   119     foreach(const QString &rootDir, rootDirs) {
       
   120         QDir root = rootDir;
       
   121         QDir dir = rootDir+"/icons";
       
   122         QStringList themeNamesList = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name);
       
   123         foreach(QString themeName, themeNamesList) {
       
   124             QDir iconThemePath(dir.path()+'/'+themeName);
       
   125             QFile themeIndexFile(root.path()+'/'+themeName+".themeindex");
       
   126             if(themeIndexFile.exists() && iconThemePath.exists("index.theme")) {
       
   127                 QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat);
       
   128                 iniSetting.beginGroup("Icon Theme");
       
   129                 bool hidden = iniSetting.value("Hidden",true).toBool();
       
   130                 QString name = iniSetting.value("Name").toString();
       
   131                 iniSetting.endGroup();
       
   132                 if(!hidden && !name.isEmpty()) {
       
   133                     themes.append(QPair<QString,QString>(name, iconThemePath.absolutePath()));
       
   134                 }
       
   135             }
       
   136         }
       
   137     }
       
   138 
       
   139     return themes;
       
   140 }