QTfrontend/util/namegen.cpp
branchflibqtfrontend
changeset 8126 5bfa1b2025d6
parent 8103 c247346d296f
parent 8110 9f5fe3fc9d16
equal deleted inserted replaced
8106:861d145b270e 8126:5bfa1b2025d6
   115 QStringList HWNamegen::dictContents(const QString filename)
   115 QStringList HWNamegen::dictContents(const QString filename)
   116 {
   116 {
   117     QStringList list;
   117     QStringList list;
   118 
   118 
   119     // find .txt to load the names from
   119     // find .txt to load the names from
   120     QFile * file = new QFile(QString("physfs://Names/%1.txt").arg(filename));
   120     QFile file(QString("physfs://Names/%1.txt").arg(filename));
   121 
   121 
   122     if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
   122     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
   123     {
   123     {
   124         QTextStream in(file);
   124         QTextStream in(&file);
   125         while (!in.atEnd())
   125         QString line;
   126         {
   126         do
   127             QString line = in.readLine();
   127         {
       
   128             line = in.readLine();
       
   129 
   128             if(!line.isEmpty())
   130             if(!line.isEmpty())
   129                 list.append(line);
   131                 list.append(line);
   130         }
   132         } while (!line.isNull());
   131     }
   133     }
   132 
       
   133     // this QFile isn't needed any further
       
   134     delete file;
       
   135 
   134 
   136     if (list.size() == 0)
   135     if (list.size() == 0)
   137         list.append(filename);
   136         list.append(filename);
   138 
   137 
   139     return list;
   138     return list;
   143 QStringList HWNamegen::dictsForHat(const QString hatname)
   142 QStringList HWNamegen::dictsForHat(const QString hatname)
   144 {
   143 {
   145     QStringList list;
   144     QStringList list;
   146 
   145 
   147     // find .cfg to load the dicts from
   146     // find .cfg to load the dicts from
   148     QFile * file = new QFile(QString("physfs://Names/%1.cfg").arg(hatname));
   147     QFile file(QString("physfs://Names/%1.cfg").arg(hatname));
   149 
   148 
   150     if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
   149     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
   151     {
   150     {
   152         QTextStream in(file);
   151         QTextStream in(&file);
   153         while (!in.atEnd())
   152         QString line;
   154         {
   153         do
   155             QString line = in.readLine();
   154         {
       
   155             line = in.readLine();
       
   156 
   156             if(!line.isEmpty())
   157             if(!line.isEmpty())
   157                 list.append(line);
   158                 list.append(line);
   158         }
   159         } while (!line.isNull());
   159     }
   160     }
   160 
       
   161     // this QFile isn't needed any further
       
   162     delete file;
       
   163 
   161 
   164     if (list.size() == 0)
   162     if (list.size() == 0)
   165         list.append(QString("generic"));
   163         list.append(QString("generic"));
   166 
   164 
   167     return list;
   165     return list;