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