QTfrontend/hwform.cpp
changeset 5238 46ddaf14509d
parent 5222 0922b9d816af
child 5252 ded882439548
equal deleted inserted replaced
5237:963d787a25c2 5238:46ddaf14509d
  1199 
  1199 
  1200     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1200     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1201     ui.pageCampaign->CBSelect->clear();
  1201     ui.pageCampaign->CBSelect->clear();
  1202 
  1202 
  1203     QDir tmpdir;
  1203     QDir tmpdir;
       
  1204     tmpdir.cd(cfgdir->absolutePath());
       
  1205     tmpdir.cd("Data/Missions/Campaign");
       
  1206     tmpdir.setFilter(QDir::Files);
       
  1207     QStringList userentries = tmpdir.entryList(QStringList("*#*.lua"));
       
  1208     //entries.sort();
       
  1209     for(int i = 0; (i < userentries.count()) && (i <= team.CampaignProgress); i++)
       
  1210         ui.pageCampaign->CBSelect->addItem(QString(userentries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(userentries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
       
  1211 
  1204     tmpdir.cd(datadir->absolutePath());
  1212     tmpdir.cd(datadir->absolutePath());
  1205     tmpdir.cd("Missions/Campaign");
  1213     tmpdir.cd("Missions/Campaign");
  1206     tmpdir.setFilter(QDir::Files);
  1214     tmpdir.setFilter(QDir::Files);
  1207     QStringList entries = tmpdir.entryList(QStringList("*#*.lua"));
  1215     QStringList entries = tmpdir.entryList(QStringList("*#*.lua"));
  1208     //entries.sort();
  1216     //entries.sort();
  1209     for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++)
  1217     for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++) {
       
  1218         if (userentries.contains(entries[i])) continue; 
  1210         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
  1219         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
       
  1220     }
  1211 }
  1221 }
  1212 
  1222 
  1213 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1223 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1214 QString HWForm::getDemoArguments()
  1224 QString HWForm::getDemoArguments()
  1215 {
  1225 {
  1238     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1248     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1239     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1249     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1240     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1250     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1241     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1251     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1242     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1252     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1243     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1253     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + cfgdir->absolutePath().replace("/","\\") + "\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1244     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1254     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + cfgdir->absolutePath().replace("/","\\") + "\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1245 #elif defined __APPLE__
  1255 #elif defined __APPLE__
  1246     success = false;
  1256     success = false;
  1247     // TODO; also enable button in pages.cpp and signal in hwform.cpp
  1257     // TODO; also enable button in pages.cpp and signal in hwform.cpp
  1248 #else
  1258 #else
  1249     // this is a little silly due to all the system commands below anyway - just use mkdir -p ?  Does have the advantage of the alert I guess
  1259     // this is a little silly due to all the system commands below anyway - just use mkdir -p ?  Does have the advantage of the alert I guess
  1257     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0;
  1267     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0;
  1258     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
  1268     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
  1259     if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
  1269     if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
  1260     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1270     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1261     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1271     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1262     // hack to add user's settings to hwengine. might be better at this point to read in the file, append it, and write it out to its new home
  1272     // hack to add user's settings to hwengine. might be better at this point to read in the file, append it, and write it out to its new home.  This assumes no spaces in the data dir path
  1263     if (success) success = system(("sed -i 's/^\\(Exec=.*\\)/\\1 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
  1273     if (success) success = system(("sed -i 's/^\\(Exec=.*\\) \\([^ ]* %f\\)/\\1 "+cfgdir->absolutePath().replace(" ","\\\\ ").replace("/","\\/")+" \\2 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
  1264 #endif
  1274 #endif
  1265     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1275     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1266     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1276     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1267 }
  1277 }
  1268 
  1278