Add opendesktop association of files for non-windows. NEEDS TESTING.
authornemo
Mon, 01 Nov 2010 17:58:59 -0400
changeset 4084 0d0bf0533eee
parent 4083 830d1f4eb517
child 4085 6bbc5a167a21
Add opendesktop association of files for non-windows. NEEDS TESTING.
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/pages.cpp
--- a/QTfrontend/game.h	Mon Nov 01 17:12:32 2010 -0400
+++ b/QTfrontend/game.h	Mon Nov 01 17:58:59 2010 -0400
@@ -38,6 +38,7 @@
     gsDestroyed = 5
 };
 
+bool checkForDir(const QString & dir);
 
 class HWGame : public TCPBase
 {
--- a/QTfrontend/hwform.cpp	Mon Nov 01 17:12:32 2010 -0400
+++ b/QTfrontend/hwform.cpp	Mon Nov 01 17:58:59 2010 -0400
@@ -141,9 +141,7 @@
     connect(ui.pageOptions->BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(DeleteTeam()));
     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack()));
-#ifdef _WIN32
     connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
-#endif
 
     connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
     connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon()));
@@ -1122,6 +1120,8 @@
 
 void HWForm::AssociateFiles()
 {
+    bool success = true;
+#ifdef _WIN32
     QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
     registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo");
     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
@@ -1131,6 +1131,14 @@
     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\"");
     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\"");
-    QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
+#else
+    if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages");
+    if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/applications");
+    if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0;
+    if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
+    if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
+#endif
+    if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
+    else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
 }
 
--- a/QTfrontend/pages.cpp	Mon Nov 01 17:12:32 2010 -0400
+++ b/QTfrontend/pages.cpp	Mon Nov 01 17:58:59 2010 -0400
@@ -611,12 +611,11 @@
             CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup"));
             MiscLayout->addWidget(CBAutoUpdate, 4, 0, 1, 2);
 #endif
-#ifdef _WIN32
             BtnAssociateFiles = new QPushButton(groupMisc);
             BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions"));
             BtnAssociateFiles->setEnabled(!custom_data && !custom_config);
             MiscLayout->addWidget(BtnAssociateFiles, 4, 0, 1, 2);
-#endif
+
             gbTBLayout->addWidget(groupMisc, 2, 0);
         }