QTfrontend/hwform.cpp
changeset 9219 0a4b6bb69f99
parent 9184 8bf450fe6cc8
child 9235 1c1580c37876
equal deleted inserted replaced
9218:673bf356ad8c 9219:0a4b6bb69f99
   192     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
   192     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
   193     //QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
   193     //QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
   194     //connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   194     //connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   195 #endif
   195 #endif
   196 
   196 
       
   197     previousCampaignName = "";
       
   198     previousTeamName = "";
   197     UpdateTeamsLists();
   199     UpdateTeamsLists();
   198     InitCampaignPage();
   200     InitCampaignPage();
   199     UpdateCampaignPage(0);
   201     UpdateCampaignPage(0);
   200     UpdateWeapons();
   202     UpdateWeapons();
   201 
   203 
   304     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   306     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   305 
   307 
   306     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   308     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   307     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   309     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   308     connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   310     connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   309 
   311     connect(ui.pageCampaign->CBMission, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPageMission(int)));
   310 
   312 
   311     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   313     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   312             ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
   314             ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
   313     connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   315     connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   314             this, SLOT(UpdateWeapons())); // executed second
   316             this, SLOT(UpdateWeapons())); // executed second
  1900     QStringList missionEntries = getCampMissionList(campaignName);
  1902     QStringList missionEntries = getCampMissionList(campaignName);
  1901     QString tName = team.name();
  1903     QString tName = team.name();
  1902     unsigned int n = missionEntries.count();
  1904     unsigned int n = missionEntries.count();
  1903     unsigned int m = getCampProgress(tName, campaignName);
  1905     unsigned int m = getCampProgress(tName, campaignName);
  1904 
  1906 
       
  1907     // if the campaign name changes update the campaignMissionDescriptions list
       
  1908     // this will be used later in UpdateCampaignPageMission() to update
       
  1909     // the mission description in the campaign page
       
  1910     bool updateMissionList = false;
       
  1911     QSettings * m_info;
       
  1912     if(previousCampaignName.compare(campaignName)!=0 ||
       
  1913             previousTeamName.compare(tName) != 0)
       
  1914     {
       
  1915         if (previousTeamName.compare(tName) != 0 &&
       
  1916                 previousTeamName.compare("") != 0)
       
  1917             index = qMin(m + 1, n);
       
  1918         previousCampaignName = campaignName;
       
  1919         previousTeamName = tName;
       
  1920         updateMissionList = true;
       
  1921         // the following code was based on pagetraining.cpp
       
  1922         DataManager & dataMgr = DataManager::instance();
       
  1923         // get locale
       
  1924         QSettings settings(dataMgr.settingsFileName(),
       
  1925                            QSettings::IniFormat);
       
  1926         QString loc = settings.value("misc/locale", "").toString();
       
  1927         if (loc.isEmpty())
       
  1928             loc = QLocale::system().name();
       
  1929         QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
       
  1930         // if file is non-existant try with language only
       
  1931         if (!QFile::exists(campaignDescFile))
       
  1932             campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
       
  1933 
       
  1934         // fallback if file for current locale is non-existant
       
  1935         if (!QFile::exists(campaignDescFile))
       
  1936             campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
       
  1937 
       
  1938         m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this);
       
  1939         m_info->setIniCodec("UTF-8");
       
  1940         campaignMissionDescriptions.clear();
       
  1941         ui.pageCampaign->CBMission->clear();
       
  1942     }
       
  1943 
  1905     for (unsigned int i = qMin(m + 1, n); i > 0; i--)
  1944     for (unsigned int i = qMin(m + 1, n); i > 0; i--)
  1906     {
  1945     {
       
  1946         if(updateMissionList)
       
  1947         {
       
  1948             campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
       
  1949                                             tr("No description available")).toString();
       
  1950         }
  1907         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
  1951         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
       
  1952     }
       
  1953     if(updateMissionList)
       
  1954         delete m_info;
       
  1955 
       
  1956     UpdateCampaignPageMission(index);
       
  1957 }
       
  1958 
       
  1959 void HWForm::UpdateCampaignPageMission(int index)
       
  1960 {
       
  1961     // update thumbnail
       
  1962     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
       
  1963     unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex();
       
  1964     QString image = getCampaignImage(campaignName,mNum);
       
  1965     ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+image)));
       
  1966     // update description
       
  1967     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
       
  1968     // this will cause segfault. This check prevents illegal memory reads
       
  1969     if(index > -1 && index < campaignMissionDescriptions.count()) {
       
  1970         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
       
  1971         ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
  1908     }
  1972     }
  1909 }
  1973 }
  1910 
  1974 
  1911 void HWForm::UpdateCampaignPageProgress(int index)
  1975 void HWForm::UpdateCampaignPageProgress(int index)
  1912 {
  1976 {