--- a/controlpanelplugins/themeplugin/src/cpthemeutil.cpp Fri Jun 25 17:12:20 2010 +0800
+++ b/controlpanelplugins/themeplugin/src/cpthemeutil.cpp Wed Sep 29 10:09:58 2010 +0800
@@ -26,6 +26,7 @@
#include <hbicon.h>
#include <hbinstance.h>
+#include <restricted/hbthemeservices_r.h>
/*!
* This class provides utility function to get Theme information.
@@ -36,94 +37,23 @@
#include <centralrepository.h>
static const TUid KServerUid3={0x20022E82};
static const TUint32 KDefaultThemeNameKey = 0x2;
- static const TUint32 KDefaultThemeRootPathKey = 0x3;
-
+
#endif
-#if !defined(Q_OS_SYMBIAN)
- #include <stdio.h>
- static const char* KThemePathKey = "HB_THEMES_DIR"; //used for getting default theme.
-#endif
-
-
-#ifdef Q_OS_WIN
- static char* _path = NULL;
- static size_t _size = 0;
- _dupenv_s(&_path, &_size, KThemePathKey);
- static QString themeRootPath = QString(_path);
- static QString themeRootPathPostfix = QString();
- free(_path);
-#elif defined(Q_OS_SYMBIAN)
- static QString themeRootPath = "c:\\resource\\hb";
- static QString themeRootPathPostfix = "resource\\hb";
-#elif defined(Q_OS_MACX)
- static QString themeRootPath = QDir::homePath() + '/' + "Library" + QString("hb");
- static QString themeRootPathPostfix = QString();
-#elif defined(Q_OS_UNIX)
- static QString themeRootPath = QString(getenv(KThemePathKey));
- static QString themeRootPathPostfix = QString();
-#else
- static QString themeRootPath = "c:\\resource\\hb";
- static QString themeRootPathPostfix = QString();
-#endif
//Location of theme preview and background icons.
static const QString KPreviewThumbnailNVG = "/scalable/qtg_graf_theme_preview_thumbnail.nvg";
static const QString KPreviewThumbnailSVG = "/scalable/qtg_graf_theme_preview_thumbnail.svg";
- static const QString KPreviewPrtNVG = "/scalable/qtg_graf_theme_preview_prt.nvg";
- static const QString KPreviewLscNVG = "/scalable/qtg_graf_theme_preview_lsc.nvg";
- static const QString KPreviewPrtSVG = "/scalable/qtg_graf_theme_preview_prt.svg";
- static const QString KPreviewLscSVG = "/scalable/qtg_graf_theme_preview_lsc.svg";
-
static const QString KBackgroundPrtNVG = "/scalable/qtg_graf_screen_bg_prt.nvg";
static const QString KBackgroundLscNVG = "/scalable/qtg_graf_screen_bg_lsc.nvg";
static const QString KBackgroundPrtSVG = "/scalable/qtg_graf_screen_bg_prt.svg";
static const QString KBackgroundLscSVG = "/scalable/qtg_graf_screen_bg_lsc.svg";
- static const QString KBackgroundPrtPNG = "/pixmap/qtg_graf_screen_bg_prt.png";
- static const QString KBackgroundLscPNG = "/pixmap/qtg_graf_screen_bg_lsc.png";
-/*!
- * Returns a list of paths where themes folder reside.
- */
-QStringList CpThemeUtil::themePathList()
-{
- static QStringList themesPathList;
-
- if(themesPathList.isEmpty()) {
-#if defined(Q_OS_SYMBIAN)
- QFileInfoList driveInfoList = QDir::drives();
- foreach (const QFileInfo &driveInfo, driveInfoList) {
- const QString themePath = driveInfo.absolutePath() + themeRootPathPostfix;
- if(QDir(themePath).exists())
- themesPathList << themePath;
- }
-#else
- themesPathList << themeRootPath;
-#endif
- }
- return themesPathList;
-}
-/*!
- * Given the theme name, it returns the absolute path of the theme.
- */
-QString CpThemeUtil::themePath(const QString& themeName)
-{
- QString themePath = "";
- QStringList themesPathList = themePathList();
- foreach (const QString &path, themesPathList) {
- QString tmpPath = path + "/themes/icons/" + themeName;
- if(QDir(tmpPath).exists()) {
- themePath = tmpPath;
- break;
- }
- }
- return themePath;
-}
-
+
/*
* Builds a CpThemeInfo object given theme path and theme name. It creates the name and
* preview icons for the object. Creates a new CpThemeInfo objects. Caller takes ownership.
@@ -134,8 +64,6 @@
CpThemeInfo *themeInfo = new CpThemeInfo();
QString iconPath;
- QString previewPathPrt;
- QString previewPathLsc;
QString name = themeName;
QString hidden = "";
@@ -147,18 +75,18 @@
name = iniSetting.value("Name").toString();
hidden = iniSetting.value("Hidden").toString();
iconPath = iniSetting.value("PreviewThumbnailPath").toString();
- previewPathPrt = iniSetting.value("PreviewIconPath_prt").toString();
- previewPathLsc = iniSetting.value("PreviewIconPath_lsc").toString();
iniSetting.endGroup();
}
if(name.isEmpty() || (hidden == "true") ||( hidden == "")) {
+ delete themeInfo;
return NULL;
}
themeInfo->setName(name);
themeInfo->setItemType(CpThemeInfo::ThemeListItemType_default);
+ themeInfo->setItemData(themePath);
//Get the icons. Logic is as follow:
/* 1. If the icon path is in index.theme and the icon exist, use it.
@@ -167,101 +95,63 @@
* 3. If no icon exist (background or preview),use default theme icon.
*/
if(iconPath.isEmpty() || !QFileInfo(themePath + iconPath).exists()){
- //Set thumbnail
- if(QFileInfo(themePath + KPreviewThumbnailNVG).exists()){
- themeInfo->setIcon(HbIcon(themePath + KPreviewThumbnailNVG));
- }else if(QFileInfo(themePath + KPreviewThumbnailSVG).exists()){
- themeInfo->setIcon(HbIcon(themePath + KPreviewThumbnailSVG));
- }else if(QFileInfo(themePath + KBackgroundPrtNVG).exists()){
- themeInfo->setIcon(HbIcon(themePath + KBackgroundPrtNVG));
- } else if(QFileInfo(themePath + KBackgroundPrtSVG).exists()){
- themeInfo->setIcon(HbIcon(themePath + KBackgroundPrtSVG));
- } else if(QFileInfo(themePath + KBackgroundPrtPNG).exists()){
- themeInfo->setIcon(HbIcon(themePath + KBackgroundPrtPNG));
- }else{
- themeInfo->setIcon(HbIcon(defaultTheme()->icon()));
+ //Set thumbnail
+ HbIcon themeIcon = getPreviewIcon(themePath);
+ if(themeIcon.isNull()){
+ QString defaultThemePath = defaultTheme();
+ if(!defaultThemePath.isEmpty()) {
+ themeIcon = getPreviewIcon(defaultThemePath);
+ }
}
-
+ themeInfo->setIcon(themeIcon);
} else {
themeInfo->setIcon(HbIcon(themePath + iconPath));
}
- //Portrait preview
-
- if(previewPathPrt.isEmpty() || !QFileInfo(themePath + previewPathPrt).exists()) {
-
- if(QFileInfo(themePath + KPreviewPrtNVG).exists()){
- themeInfo->setPortraitPreviewIcon(HbIcon(themePath + KPreviewPrtNVG));
- }else if(QFileInfo(themePath + KPreviewPrtSVG).exists()){
- themeInfo->setPortraitPreviewIcon(HbIcon(themePath + KPreviewPrtSVG));
- }else if(QFileInfo(themePath + KBackgroundPrtNVG).exists()){
- themeInfo->setPortraitPreviewIcon(HbIcon(themePath + KBackgroundPrtNVG));
- } else if(QFileInfo(themePath + KBackgroundPrtSVG).exists()){
- themeInfo->setPortraitPreviewIcon(HbIcon(themePath + KBackgroundPrtSVG));
- } else if(QFileInfo(themePath + KBackgroundPrtPNG).exists()){
- themeInfo->setPortraitPreviewIcon(HbIcon(themePath + KBackgroundPrtPNG));
- } else{
- themeInfo->setPortraitPreviewIcon(HbIcon(defaultTheme()->icon()));
- }
- }
- else {
- themeInfo->setPortraitPreviewIcon(HbIcon(themePath + previewPathPrt));
- }
-
- //Landscape preview
-
- if(previewPathLsc.isEmpty() || !QFileInfo(themePath + previewPathLsc).exists()) {
- if(QFileInfo(themePath + KPreviewLscNVG).exists()){
- themeInfo->setLandscapePreviewIcon(HbIcon(themePath + KPreviewLscNVG));
- }else if(QFileInfo(themePath + KPreviewLscSVG).exists()){
- themeInfo->setLandscapePreviewIcon(HbIcon(themePath + KPreviewLscSVG));
- }else if(QFileInfo(themePath + KBackgroundLscNVG).exists()){
- themeInfo->setLandscapePreviewIcon(HbIcon(themePath + KBackgroundLscNVG));
- } else if(QFileInfo(themePath + KBackgroundLscSVG).exists()){
- themeInfo->setLandscapePreviewIcon(HbIcon(themePath + KBackgroundLscSVG));
- } else if(QFileInfo(themePath + KBackgroundLscPNG).exists()){
- themeInfo->setLandscapePreviewIcon(HbIcon(themePath + KBackgroundLscPNG));
- } else{
- themeInfo->setLandscapePreviewIcon(HbIcon(defaultTheme()->icon()));
- }
- }
- else {
- themeInfo->setLandscapePreviewIcon(HbIcon(themePath + previewPathLsc));
- }
return themeInfo;
}
+/*!
+ * given a path to the theme, returns the preview icon or just a Null icon
+ * if it doesn't exist.
+ */
+HbIcon CpThemeUtil::getPreviewIcon(const QString& themePath)
+{
+ HbIcon themeIcon;
+ if(QFileInfo(themePath + KPreviewThumbnailNVG).exists()){
+ themeIcon = HbIcon(themePath + KPreviewThumbnailNVG);
+ }else if(QFileInfo(themePath + KPreviewThumbnailSVG).exists()){
+ themeIcon = HbIcon(themePath + KPreviewThumbnailSVG);
+ }else if(QFileInfo(themePath + KBackgroundPrtNVG).exists()){
+ themeIcon = HbIcon(themePath + KBackgroundPrtNVG);
+ }else if(QFileInfo(themePath + KBackgroundPrtSVG).exists()){
+ themeIcon = HbIcon(themePath + KBackgroundPrtSVG);
+ }
+ return themeIcon;
+
+}
+
/*! Creates a list of CpThemeInfo objects representing theme information.
- * Caller should take ownership of the list.
+ *
*/
QList<CpThemeInfo> CpThemeUtil::buildThemeList()
{
QList<CpThemeInfo> themeList;
-
- QStringList mThemesPathList = themePathList();
- foreach (const QString &path, mThemesPathList) {
+ QList<QPair<QString, QString> > mThemesPathList = availableThemes();
+ QPair<QString, QString>pair;
+ foreach (pair, mThemesPathList) {
QDir themeDir;
+ QString name = pair.first;
+ QString path = pair.second;
themeDir.setPath( path ) ;
- QStringList iconthemeslist;
- QStringList list = themeDir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name);
CpThemeInfo* themeInfo;
-
- if(list.contains("themes", Qt::CaseSensitive )) {
- QDir root(themeDir.path());
- themeDir.setPath(root.path() + "/themes/icons/") ;
- iconthemeslist = themeDir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name);
- foreach(QString themefolder, iconthemeslist) {
- QDir iconThemePath(root.path() + "/themes/icons/" + themefolder);
- if(iconThemePath.exists("index.theme") &&
- (iconThemePath.exists("scalable") || iconThemePath.exists("pixmap") )) {
-
- themeInfo = buildThemeInfo(iconThemePath.path(), themefolder);
- if(themeInfo && !themeInfo->name().isEmpty()) {
- themeList.append(*themeInfo);
- }
- }
+ if(themeDir.exists("index.theme") &&
+ (themeDir.exists("scalable") || themeDir.exists("pixmap") )) {
+ themeInfo = buildThemeInfo(path, name);
+ if(themeInfo && !themeInfo->name().isEmpty()) {
+ themeList.append(*themeInfo);
}
}
}
@@ -270,15 +160,14 @@
}
/*!
- * Returns the default theme information.
+ * Returns the default theme path.
*/
-CpThemeInfo* CpThemeUtil::defaultTheme()
+QString CpThemeUtil::defaultTheme()
{
//static because default theme doesn't change.
- static CpThemeInfo *defaultTheme = new CpThemeInfo();
- QString defaultThemeName;
- QString defaultThemeRootDir;
- if(defaultTheme->name().isEmpty()) {
+ static QString defaultThemePath("");
+
+ if(defaultThemePath.isEmpty()) {
#ifdef Q_OS_SYMBIAN
@@ -288,24 +177,42 @@
TBuf<256> value;
if (KErrNone == repository->Get((TUint32)KDefaultThemeNameKey, value)) {
QString qvalue((QChar*)value.Ptr(), value.Length());
- defaultThemeName = qvalue.trimmed();
+ defaultThemePath = qvalue.trimmed();
}
value.Zero();
- if (KErrNone == repository->Get((TUint32)KDefaultThemeRootPathKey, value)) {
- QString qvalue((QChar*)value.Ptr(), value.Length());
- defaultThemeRootDir = qvalue.trimmed();
- }
- else {
- defaultThemeRootDir = themePath(defaultThemeName);
- }
- value.Zero();
- delete repository;
+ delete repository;
}
#endif
- defaultTheme = buildThemeInfo(defaultThemeRootDir, defaultThemeName);
-
+
}
- return defaultTheme;
+ return defaultThemePath;
}
+
+const QStringList CpThemeUtil::themeDirectories(const QList<CpThemeInfo>& themeInfoList)
+{
+ QStringList themeDirs;
+
+ foreach(const CpThemeInfo& themeInfo, themeInfoList) {
+ QDir themePath(themeInfo.itemData());
+ QString topDir;
+ if(themePath.cdUp()) {
+ topDir = themePath.path();
+ if(!themeDirs.contains(topDir)) {
+ themeDirs.append(topDir);
+ }
+ }
+ }
+ return themeDirs;
+}
+
+const QList< QPair< QString, QString > > CpThemeUtil::availableThemes( )
+{
+
+ QList<QPair<QString, QString> > result = HbThemeServices::availableThemes();
+ return result;
+
+}
+
+