src/hbutils/theme/hbthemeservices.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbutils/theme/hbthemeservices.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbutils/theme/hbthemeservices.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -44,6 +44,8 @@
 #include "hbthemeclient_p.h"
 #endif
 
+#include <QSettings>
+
 /*!
     Sets the active theme that is used with the Hb applications. HbTheme changed() signal will be emitted if theme change is
     applied succesfully. In addition to the active theme content loading also the underlying priority themes will be updated
@@ -87,3 +89,52 @@
     }
     return path;
 }
+
+/*!
+    Returns the list of available themes.
+
+    \return list of themes. First item of QPair is the unlocalized theme name
+    and the second item is the absolute path to the theme.
+*/
+const QList<QPair<QString, QString> > HbThemeServices::availableThemes()
+{
+    QList<QPair<QString, QString> > themes;
+
+    QStringList rootDirs;
+#ifdef Q_OS_SYMBIAN
+    QFileInfoList driveList = QDir::drives();
+    QString themesPath = "resource/hb/themes";
+    foreach(const QFileInfo & drive, driveList) {
+        QDir themeFolder(drive.absolutePath() + themesPath);
+        if (themeFolder.exists()) {
+            rootDirs << themeFolder.absolutePath();
+        }
+    }
+#else
+    QString envDir = QDir::fromNativeSeparators(qgetenv("HB_THEMES_DIR"));
+    if (!envDir.isEmpty())
+        rootDirs << envDir + "/themes";
+#endif
+
+    foreach(const QString &rootDir, rootDirs) {
+        QDir root = rootDir;
+        QDir dir = rootDir+"/icons";
+        QStringList themeNamesList = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name);
+        foreach(QString themeName, themeNamesList) {
+            QDir iconThemePath(dir.path()+'/'+themeName);
+            QFile themeIndexFile(root.path()+'/'+themeName+".themeindex");
+            if(themeIndexFile.exists() && iconThemePath.exists("index.theme")) {
+                QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat);
+                iniSetting.beginGroup("Icon Theme");
+                bool hidden = iniSetting.value("Hidden",true).toBool();
+                QString name = iniSetting.value("Name").toString();
+                iniSetting.endGroup();
+                if(!hidden && !name.isEmpty()) {
+                    themes.append(QPair<QString,QString>(name, iconThemePath.absolutePath()));
+                }
+            }
+        }
+    }
+
+    return themes;
+}