--- /dev/null
+#include "levelpack.h"
+#include <stdio.h>
+// TODO: use QSettings?
+
+LevelPack::LevelPack(const QString &fileName):file(fileName)
+{
+ file.open(QIODevice::ReadOnly|QIODevice::Text);
+ lookSection("[General]");
+ QFileInfo f(file);
+ props["title"]=f.baseName();
+ while(loadPackProperty()){};
+ while(file.canReadLine()){loadLevel();};
+}
+LevelPack::~LevelPack()
+{
+ while(!levels.isEmpty())
+ delete levels.takeFirst();
+}
+QString LevelPack::getLine()
+{
+ QString line;
+ bool empty=true;
+ do {
+ QString lineR(file.readLine());
+ int i=0;
+ int s=lineR.size();
+ empty=true;
+ while(empty && i<s)
+ empty &=lineR.at(i++).isSpace();
+ empty |= lineR.startsWith(';');
+ if(file.error()!=0)
+ printf("Error %d\n",file.error());
+ line=lineR;
+ } while(empty && (file.error()==0) && !file.atEnd());
+ return line;
+}
+bool LevelPack::lookSection(const char *section)
+{
+ QString line(getLine());
+ return line==section;
+}
+QPair<QString,QString> *LevelPack::loadProperty()
+{
+ QString propLine=getLine();
+ if(propLine.startsWith("[") || !propLine.contains('='))
+ {
+ return 0;
+ }
+ return new QPair<QString,QString>(propLine.section('=',0,0),propLine.section('=',1,1).trimmed());
+}
+bool LevelPack::loadPackProperty()
+{
+ QPair<QString,QString> *pair=loadProperty();
+ if(pair)
+ {
+ props[pair->first]=pair->second;
+ delete pair;
+ return true;
+ }
+ return false;
+}
+void LevelPack::loadLevel()
+{
+ QMap<QString,QString> levelInfo;
+ while(QPair<QString,QString> *prop=loadProperty())
+ {
+ levelInfo[prop->first]=prop->second;
+ delete prop;
+ }
+ QString title(levelInfo["title"]);
+ QString board(levelInfo["board"]);
+ QString sol(levelInfo["solution"]);
+ PlayField *level=new PlayField(title,board,sol);
+ levels.append(level);
+}