Derive themes list from list of dirs in Themes folder which have icon.png inside
authorunc0rr
Tue, 21 Jun 2011 22:43:55 +0400
changeset 5276 562070d3f978
parent 5275 91752f716d64
child 5277 09beef0752ab
Derive themes list from list of dirs in Themes folder which have icon.png inside
QTfrontend/main.cpp
share/hedgewars/Data/Themes/themes.cfg
--- a/QTfrontend/main.cpp	Tue Jun 21 16:55:34 2011 +0200
+++ b/QTfrontend/main.cpp	Tue Jun 21 22:43:55 2011 +0400
@@ -384,24 +384,26 @@
         return 1;
     }
 
-    Themes = new QStringList();
-    QFile userthemesfile(cfgdir->absolutePath() + "/Data/Themes/themes.cfg");
-    if (userthemesfile.open(QIODevice::ReadOnly)) {
-        QTextStream stream(&userthemesfile);
-        while (!stream.atEnd()) Themes->append(stream.readLine());
-        userthemesfile.close();
-    }
-    QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
-    QString str;
-    if (themesfile.open(QIODevice::ReadOnly)) {
-        QTextStream stream(&themesfile);
-        while (!stream.atEnd()) {
-            str = stream.readLine();
-            if (!Themes->contains(str)) Themes->append(str);
+    {
+        QDir dir;
+        dir.setPath(cfgdir->absolutePath() + "/Data/Themes");
+        Themes = new QStringList();
+        Themes->append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot));
+
+        dir.setPath(datadir->absolutePath() + "/Themes");
+        Themes->append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot));
+qDebug() << *Themes;
+        for(int i = Themes->size() - 1; i >= 0; --i)
+        {
+            QFile tmpfile;
+            tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(Themes->at(i)));
+            if (!tmpfile.exists())
+            {
+                tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(Themes->at(i)));
+                if(!tmpfile.exists())
+                    Themes->removeAt(i);
+            }
         }
-        themesfile.close();
-    } else {
-        QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
     }
 
     QDir tmpdir;
--- a/share/hedgewars/Data/Themes/themes.cfg	Tue Jun 21 16:55:34 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-Art
-Bamboo
-Bath
-Brick
-Castle
-Cheese
-Christmas
-City
-Compost
-Desert
-EarthRise
-Freeway
-Halloween
-Hell
-Island
-Jungle
-Nature
-Olympics
-Sheep
-Snow
-Stage
-Underwater