QTfrontend/hwform.cpp
changeset 5213 a86768368309
parent 5205 78138ae93820
child 5222 0922b9d816af
equal deleted inserted replaced
5212:eaffb02f0053 5213:a86768368309
  1208     //entries.sort();
  1208     //entries.sort();
  1209     for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++)
  1209     for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++)
  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"));
  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"));
  1211 }
  1211 }
  1212 
  1212 
       
  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]
       
  1214 QString HWForm::getDemoArguments()
       
  1215 {
       
  1216     QRect resolution = config->vid_Resolution();
       
  1217     return QString(QString::number(resolution.width()) + " "
       
  1218      + QString::number(resolution.height()) + " "
       
  1219      + QString::number(config->bitDepth()) + " " // bpp
       
  1220      + QString::number(config->volume()) + " " // sound volume
       
  1221      + (config->isMusicEnabled() ? "1" : "0") + " "
       
  1222      + (config->isSoundEnabled() ? "1" : "0") + " "
       
  1223      + config->language() + ".txt "
       
  1224      + (config->vid_Fullscreen() ? "1" : "0") + " "
       
  1225      + (config->isShowFPSEnabled() ? "1" : "0") + " "
       
  1226      + (config->isAltDamageEnabled() ? "1" : "0") + " "
       
  1227      + QString::number(config->timerInterval()) + " "
       
  1228      + QString::number(config->translateQuality()));
       
  1229 }
       
  1230 
  1213 void HWForm::AssociateFiles()
  1231 void HWForm::AssociateFiles()
  1214 {
  1232 {
  1215     bool success = true;
  1233     bool success = true;
  1216 #ifdef _WIN32
  1234 #ifdef _WIN32
       
  1235     QString arguments = getDemoArguments();
  1217     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
  1236     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
  1218     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
  1237     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
  1219     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1238     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1220     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1239     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1221     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1240     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1222     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1241     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1223     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1242     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1224     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\"");
  1243     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1225     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\"");
  1244     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1226 #elif defined __APPLE__
  1245 #elif defined __APPLE__
  1227     success = false;
  1246     success = false;
  1228     // TODO; also enable button in pages.cpp and signal in hwform.cpp
  1247     // TODO; also enable button in pages.cpp and signal in hwform.cpp
  1229 #else
  1248 #else
  1230     // 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
  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
       
  1250     QString arguments = getDemoArguments();
  1231     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1251     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1232     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share");
  1252     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share");
  1233     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime");
  1253     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime");
  1234     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages");
  1254     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages");
  1235     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1255     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1241     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-demo")==0;
  1242     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1262     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1243 #endif
  1263 #endif
  1244     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1264     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1245     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1265     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1246 }
  1266 //  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
  1247 
  1267     if (success) success = system(("sed -i 's/^\\(Exec=.*\\)/\\1 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
       
  1268 }
       
  1269