QTfrontend/ui/page/pagetraining.cpp
changeset 6616 f77bb02b669f
parent 6258 ba9defb98a70
child 6699 83dd3447a212
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
   123     QString loc = settings.value("misc/locale", "").toString();
   123     QString loc = settings.value("misc/locale", "").toString();
   124     if (loc.isEmpty())
   124     if (loc.isEmpty())
   125         loc = QLocale::system().name();
   125         loc = QLocale::system().name();
   126 
   126 
   127     QString infoFile = dataMgr.findFileForRead(
   127     QString infoFile = dataMgr.findFileForRead(
   128                             QString("Locale/missions_" + loc + ".txt"));
   128                            QString("Locale/missions_" + loc + ".txt"));
   129 
   129 
   130     // if file is non-existant try with language only
   130     // if file is non-existant try with language only
   131     if (!QFile::exists(infoFile))
   131     if (!QFile::exists(infoFile))
   132         infoFile = dataMgr.findFileForRead(QString(
   132         infoFile = dataMgr.findFileForRead(QString(
   133                 "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt"));
   133                                                "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt"));
   134 
   134 
   135     // fallback if file for current locale is non-existant
   135     // fallback if file for current locale is non-existant
   136     if (!QFile::exists(infoFile))
   136     if (!QFile::exists(infoFile))
   137         infoFile = dataMgr.findFileForRead(QString("Locale/missions_en.txt"));
   137         infoFile = dataMgr.findFileForRead(QString("Locale/missions_en.txt"));
   138 
   138 
   143 
   143 
   144 
   144 
   145     QStringList missionList = dataMgr.entryList(
   145     QStringList missionList = dataMgr.entryList(
   146                                   "Missions/Training",
   146                                   "Missions/Training",
   147                                   QDir::Files, QStringList("*.lua")).
   147                                   QDir::Files, QStringList("*.lua")).
   148                                   replaceInStrings(QRegExp("\\.lua$"), "");
   148                               replaceInStrings(QRegExp("\\.lua$"), "");
   149 
   149 
   150     // scripts to lost - TODO: model?
   150     // scripts to lost - TODO: model?
   151     foreach (const QString & mission, missionList)
   151     foreach (const QString & mission, missionList)
   152     {
   152     {
   153         QListWidgetItem * item = new QListWidgetItem(mission);
   153         QListWidgetItem * item = new QListWidgetItem(mission);
   189 
   189 
   190     if (lstMissions->currentItem())
   190     if (lstMissions->currentItem())
   191     {
   191     {
   192         // TODO also use .pngs in userdata folder
   192         // TODO also use .pngs in userdata folder
   193         QString thumbFile = dataMgr.findFileForRead(
   193         QString thumbFile = dataMgr.findFileForRead(
   194                     "Graphics/Missions/Training/" +
   194                                 "Graphics/Missions/Training/" +
   195                     lstMissions->currentItem()->data(Qt::UserRole).toString() +
   195                                 lstMissions->currentItem()->data(Qt::UserRole).toString() +
   196                     "@2x.png");
   196                                 "@2x.png");
   197 
   197 
   198         if (QFile::exists(thumbFile))
   198         if (QFile::exists(thumbFile))
   199             btnPreview->setIcon(QIcon(thumbFile));
   199             btnPreview->setIcon(QIcon(thumbFile));
   200         else
   200         else
   201             btnPreview->setIcon(QIcon(":/res/Trainings.png"));
   201             btnPreview->setIcon(QIcon(":/res/Trainings.png"));
   202 
   202 
   203         QString realName = lstMissions->currentItem()->data(
   203         QString realName = lstMissions->currentItem()->data(
   204                            Qt::UserRole).toString();
   204                                Qt::UserRole).toString();
   205 
   205 
   206         QString caption = m_info->value(realName + ".name", 
   206         QString caption = m_info->value(realName + ".name",
   207                           lstMissions->currentItem()->text()).toString();
   207                                         lstMissions->currentItem()->text()).toString();
   208 
   208 
   209         QString description = m_info->value(realName + ".desc",
   209         QString description = m_info->value(realName + ".desc",
   210                               tr("No description available")).toString();
   210                                             tr("No description available")).toString();
   211 
   211 
   212         lblCaption->setText("<h2>" + caption +"</h2>");
   212         lblCaption->setText("<h2>" + caption +"</h2>");
   213         lblDescription->setText(description);
   213         lblDescription->setText(description);
   214     }
   214     }
   215     else
   215     else