QTfrontend/hwform.cpp
changeset 5222 0922b9d816af
parent 5213 a86768368309
child 5238 46ddaf14509d
equal deleted inserted replaced
5221:632c42555a01 5222:0922b9d816af
  1229 }
  1229 }
  1230 
  1230 
  1231 void HWForm::AssociateFiles()
  1231 void HWForm::AssociateFiles()
  1232 {
  1232 {
  1233     bool success = true;
  1233     bool success = true;
       
  1234     QString arguments = getDemoArguments();
  1234 #ifdef _WIN32
  1235 #ifdef _WIN32
  1235     QString arguments = getDemoArguments();
       
  1236     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
  1236     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
  1237     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
  1237     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
  1238     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1238     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1239     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"));
  1240     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"));
  1245 #elif defined __APPLE__
  1245 #elif defined __APPLE__
  1246     success = false;
  1246     success = false;
  1247     // 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
  1248 #else
  1248 #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
  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();
       
  1251     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1250     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1252     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share");
  1251     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share");
  1253     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime");
  1252     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime");
  1254     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages");
  1253     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages");
  1255     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1254     if (success) success = checkForDir(QDir::home().absolutePath() + "/.local");
  1258     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0;
  1257     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0;
  1259     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
  1258     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
  1260     if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
  1259     if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
  1261     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1260     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1262     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1261     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
       
  1263     if (success) success = system(("sed -i 's/^\\(Exec=.*\\)/\\1 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
  1263 #endif
  1264 #endif
  1264     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1265     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1265     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1266     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  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
  1267 }
  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 
  1268 }
       
  1269