QTfrontend/model/ThemeModel.cpp
changeset 14828 8ed0c3761640
parent 13267 48b23e6f26d9
child 15066 d75ce53d811e
equal deleted inserted replaced
14827:266f973745b8 14828:8ed0c3761640
   122 
   122 
   123     foreach (QString theme, themes)
   123     foreach (QString theme, themes)
   124     {
   124     {
   125         QMap<int, QVariant> dataset;
   125         QMap<int, QVariant> dataset;
   126 
   126 
       
   127         // Ignore directories without theme.cfg
       
   128         QFile themeCfgFile(QString("physfs://Themes/%1/theme.cfg").arg(theme));
       
   129         if (!themeCfgFile.open(QFile::ReadOnly))
       
   130         {
       
   131             continue;
       
   132         }
       
   133 
   127         // themes without icon are supposed to be hidden
   134         // themes without icon are supposed to be hidden
   128         QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme);
   135         QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme);
   129 
       
   130         if (!QFile::exists(iconpath))
   136         if (!QFile::exists(iconpath))
   131         {
   137         {
   132             dataset.insert(IsHiddenRole, true);
   138             dataset.insert(IsHiddenRole, true);
   133         }
   139         }
   134         else
   140         else
   135         {
   141         {
   136             // themes with the key “hidden” in theme.cfg are hidden, too
   142             QTextStream stream(&themeCfgFile);
   137             QFile themeCfgFile(QString("physfs://Themes/%1/theme.cfg").arg(theme));
   143             QString line = stream.readLine();
   138             if (themeCfgFile.open(QFile::ReadOnly))
   144             QString key;
       
   145             while (!line.isNull())
   139             {
   146             {
   140                 QTextStream stream(&themeCfgFile);
   147                 key = QString(line);
   141                 QString line = stream.readLine();
   148                 int equalsPos = line.indexOf('=');
   142                 QString key;
   149                 key.truncate(equalsPos - 1);
   143                 while (!line.isNull())
   150                 key = key.simplified();
       
   151                 if (!line.startsWith(';') && key == "hidden")
   144                 {
   152                 {
   145                     key = QString(line);
   153                     dataset.insert(IsHiddenRole, true);
   146                     int equalsPos = line.indexOf('=');
   154                     break;
   147                     key.truncate(equalsPos - 1);
       
   148                     key = key.simplified();
       
   149                     if (!line.startsWith(';') && key == "hidden")
       
   150                     {
       
   151                         dataset.insert(IsHiddenRole, true);
       
   152                         break;
       
   153                     }
       
   154                     line = stream.readLine();
       
   155                 }
   155                 }
       
   156                 line = stream.readLine();
   156             }
   157             }
       
   158         }
       
   159 
       
   160         // Themes without land textures are considered "background themes"
       
   161         // since they cannot be used for generated maps, but they can be used
       
   162         // for image maps.
       
   163         QString landtexpath = QString("physfs://Themes/%1/LandTex.png").arg(theme);
       
   164         if (!QFile::exists(landtexpath))
       
   165         {
       
   166             dataset.insert(IsBackgroundThemeRole, true);
   157         }
   167         }
   158 
   168 
   159         // detect if theme is dlc
   169         // detect if theme is dlc
   160         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1").arg(theme).toLocal8Bit().data());
   170         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1").arg(theme).toLocal8Bit().data());
   161         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
   171         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
   177             QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
   187             QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
   178             dataset.insert(Qt::DecorationRole, preview);
   188             dataset.insert(Qt::DecorationRole, preview);
   179         }
   189         }
   180 
   190 
   181         m_data.append(dataset);
   191         m_data.append(dataset);
       
   192         themeCfgFile.close();
   182     }
   193     }
   183 }
   194 }