QTfrontend/model/ThemeModel.cpp
branchui-scaling
changeset 15288 c4fd2813b127
parent 15071 d75ce53d811e
equal deleted inserted replaced
13395:0135e64c6c66 15288:c4fd2813b127
   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         QString bordertexpath = QString("physfs://Themes/%1/Border.png").arg(theme);
       
   165         if ((!QFile::exists(landtexpath)) || (!QFile::exists(bordertexpath)))
       
   166         {
       
   167             dataset.insert(IsBackgroundThemeRole, true);
   157         }
   168         }
   158 
   169 
   159         // detect if theme is dlc
   170         // detect if theme is dlc
   160         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1").arg(theme).toLocal8Bit().data());
   171         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1").arg(theme).toLocal8Bit().data());
   161         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
   172         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
   177             QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
   188             QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
   178             dataset.insert(Qt::DecorationRole, preview);
   189             dataset.insert(Qt::DecorationRole, preview);
   179         }
   190         }
   180 
   191 
   181         m_data.append(dataset);
   192         m_data.append(dataset);
       
   193         themeCfgFile.close();
   182     }
   194     }
   183 }
   195 }