[kstars] kstars: Since several people have had problems with the default directories for indiserver, astrometry, xplanet, etc on OS X when they build KStars themselves, I thought I would write some code to fix the problem.

Jasem Mutlaq null at kde.org
Mon Feb 27 07:32:20 UTC 2017


Git commit 090bc4101b8fa0f7cb9029ac288471fc2cf320d5 by Jasem Mutlaq, on behalf of Robert Lancaster.
Committed on 27/02/2017 at 07:29.
Pushed by mutlaqja into branch 'master'.

Since several people have had problems with the default directories for indiserver, astrometry, xplanet, etc on OS X when they build KStars themselves, I thought I would write some code to fix the problem.
Note that the problem has only been experienced by people who build kstars themselves and either don’t have all the internal content in their app or they delete their kstarsrc file without deleting their data directory.
In both of these situations they end up with a problem because the defaults in options are for Linux and are not correct on OS X.  If the user doesn’t run the code that copies the data directory or the user doesn’t toggle the internal checkboxes in the options,
then the Linux defaults are written to the kstarsrc file instead of the defaults for OS X.

So I worked this evening to try to come up with a way that the default paths that do not rely on the internal structure of the app, but instead use the default locations of the external packages on OS X could be written to the user’s kstarsrc file by default.
Note that this change will not affect the majority of users who will probably be installing kstars from the dmg and won’t have a data directory yet, so they will still get everything set to internal which will work just fine for them.
This change should mainly just affect people building kstars themselves from source.  Of course, for those people, they will still need to install all of these items to their proper locations.

CCMAIL:kstars-devel at kde.org

M  +63   -0    kstars/auxiliary/ksutils.cpp
M  +2    -0    kstars/auxiliary/ksutils.h
M  +3    -3    kstars/ekos/align/opsalign.cpp
M  +2    -6    kstars/indi/opsindi.cpp
M  +7    -5    kstars/kstars.kcfg
M  +1    -1    kstars/xplanet/opsxplanet.cpp

https://commits.kde.org/kstars/090bc4101b8fa0f7cb9029ac288471fc2cf320d5

diff --git a/kstars/auxiliary/ksutils.cpp b/kstars/auxiliary/ksutils.cpp
index a347808a3..b9c7cdbdc 100644
--- a/kstars/auxiliary/ksutils.cpp
+++ b/kstars/auxiliary/ksutils.cpp
@@ -631,6 +631,63 @@ QString constGenetiveToAbbrev( const QString &genetive_ ) {
   void Logging::Disabled(QtMsgType, const QMessageLogContext &, const QString &)
   {
   }
+  /**
+    This method provides a centralized location for the default paths to important external files used in the Options
+    on different operating systems.  Note that on OS X, if the user builds the app without indi, astrometry, and xplanet internally
+    then the options below will be used.  If the user drags the app from a dmg and has to install the KStars data directory,
+    then most of these paths will be overwritten since it is preferrred to use the internal versions.
+  **/
+
+  QString getDefaultPath(QString option)
+  {
+      if(option=="indiServer")
+      {
+        #ifdef Q_OS_OSX          
+            return "/usr/local/bin/indiserver";
+        #endif
+            return "/usr/bin/indiserver";
+      }
+      else if (option=="indiDriversDir")
+      {
+        #ifdef Q_OS_OSX
+            return "/usr/local/share/indi";
+        #elif defined(Q_OS_LINUX)
+            return "/usr/share/indi";
+        #else
+          return QStandardPaths::locate(QStandardPaths::GenericDataLocation, "indi", QStandardPaths::LocateDirectory);
+        #endif
+      }
+      else if(option=="AstrometrySolverBinary")
+      {
+        #ifdef Q_OS_OSX
+            return "/usr/local/bin/solve-field";
+        #endif
+          return "/usr/bin/solve-field";
+      }
+      else if(option=="AstrometryWCSInfo")
+      {
+        #ifdef Q_OS_OSX
+            return "/usr/local/bin/wcsinfo";
+        #endif
+            return "/usr/bin/wcsinfo";
+      }
+      else if(option=="AstrometryConfFile")
+      {
+        #ifdef Q_OS_OSX
+            return "/usr/local/etc/astrometry.cfg";
+        #endif
+            return "/etc/astrometry.cfg";
+      }
+      else if(option=="XplanetPath")
+      {
+        #ifdef Q_OS_OSX
+            return "/usr/local/bin/xplanet";
+        #endif
+            return "/usr/bin/xplanet";
+      }
+
+      return QString();
+  }
 
 #ifdef Q_OS_OSX
 bool copyDataFolderFromAppBundleIfNeeded()  //The method returns true if the data directory is good to go.
@@ -647,12 +704,18 @@ bool copyDataFolderFromAppBundleIfNeeded()  //The method returns true if the dat
 
         //This sets some important OS X options.
         Options::setIndiServerIsInternal(true);
+        Options::setIndiServer("*Internal INDI Server*");
         Options::setIndiDriversAreInternal(true);
+        Options::setIndiDriversDir("*Internal INDI Drivers*");
         Options::setAstrometrySolverIsInternal(true);
+        Options::setAstrometrySolverBinary("*Internal Solver*");
         Options::setAstrometryConfFileIsInternal(true);
+        Options::setAstrometryConfFile("*Internal astrometry.cfg*");
         Options::setAstrometryWCSIsInternal(true);
+        Options::setAstrometryWCSInfo("*Internal wcsinfo*");
         Options::setAstrometryUseNoFITS2FITS(false);
         Options::setXplanetIsInternal(true);
+        Options::setXplanetPath("*Internal XPlanet*");
         Options::setRunStartupWizard( false );  //don't run on startup because we are doing it now.
 
 
diff --git a/kstars/auxiliary/ksutils.h b/kstars/auxiliary/ksutils.h
index fdfe78747..9b3c845e7 100644
--- a/kstars/auxiliary/ksutils.h
+++ b/kstars/auxiliary/ksutils.h
@@ -224,6 +224,8 @@ namespace KSUtils {
 
       };
 
+    QString getDefaultPath(QString option);
+
     #ifdef Q_OS_OSX
     bool copyDataFolderFromAppBundleIfNeeded();//The boolean returns true if the data folders are good to go.
     void configureDefaultAstrometry();
diff --git a/kstars/ekos/align/opsalign.cpp b/kstars/ekos/align/opsalign.cpp
index dbb77ce51..7bf725234 100644
--- a/kstars/ekos/align/opsalign.cpp
+++ b/kstars/ekos/align/opsalign.cpp
@@ -67,7 +67,7 @@ void OpsAlign::toggleSolverInternal()
     if(kcfg_AstrometrySolverIsInternal->isChecked())
         kcfg_AstrometrySolverBinary->setText("*Internal Solver*");
     else
-        kcfg_AstrometrySolverBinary->setText("/usr/local/bin/solve-field");
+        kcfg_AstrometrySolverBinary->setText(KSUtils::getDefaultPath("AstrometrySolverBinary"));
 }
 
 void OpsAlign::toggleConfigInternal()
@@ -76,7 +76,7 @@ void OpsAlign::toggleConfigInternal()
     if(kcfg_AstrometryConfFileIsInternal->isChecked())
         kcfg_AstrometryConfFile->setText("*Internal astrometry.cfg*");
     else
-        kcfg_AstrometryConfFile->setText("/etc/astrometry.cfg");
+        kcfg_AstrometryConfFile->setText(KSUtils::getDefaultPath("AstrometryConfFile"));
 }
 
 void OpsAlign::toggleWCSInternal()
@@ -85,7 +85,7 @@ void OpsAlign::toggleWCSInternal()
     if(kcfg_AstrometryWCSIsInternal->isChecked())
         kcfg_AstrometryWCSInfo->setText("*Internal wcsinfo*");
     else
-        kcfg_AstrometryWCSInfo->setText("/usr/local/bin/wcsinfo");
+        kcfg_AstrometryWCSInfo->setText(KSUtils::getDefaultPath("AstrometryWCSInfo"));
 }
 
 void OpsAlign::slotApply()
diff --git a/kstars/indi/opsindi.cpp b/kstars/indi/opsindi.cpp
index f01c1436e..73207534c 100644
--- a/kstars/indi/opsindi.cpp
+++ b/kstars/indi/opsindi.cpp
@@ -82,11 +82,7 @@ void OpsINDI::toggleINDIInternal()
     if(kcfg_indiServerIsInternal->isChecked())
         kcfg_indiServer->setText("*Internal INDI Server*");
     else
-        #ifdef Q_OS_OSX
-        kcfg_indiServer->setText("/usr/local/bin/indiserver");
-        #else
-        kcfg_indiServer->setText("/usr/bin/indiserver");
-        #endif
+        kcfg_indiServer->setText(KSUtils::getDefaultPath("indiServer"));
 }
 
 void OpsINDI::toggleDriversInternal()
@@ -95,7 +91,7 @@ void OpsINDI::toggleDriversInternal()
     if(kcfg_indiDriversAreInternal->isChecked())
         kcfg_indiDriversDir->setText("*Internal INDI Drivers*");
     else
-        kcfg_indiDriversDir->setText("/usr/local/share/indi/");
+        kcfg_indiDriversDir->setText(KSUtils::getDefaultPath("indiDriversDir"));
 }
 
 void OpsINDI::saveFITSDirectory()
diff --git a/kstars/kstars.kcfg b/kstars/kstars.kcfg
index a76f5e96c..911b6fece 100644
--- a/kstars/kstars.kcfg
+++ b/kstars/kstars.kcfg
@@ -2,6 +2,7 @@
 <kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
                           http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
    <kcfgfile name="kstarsrc" />
+   <include>ksutils.h</include>
 
    <group name="GUI">
       <entry name="PositionTimeBox" type="Point">
@@ -182,7 +183,7 @@
       <entry name="indiServer" type="String">
          <label>PATH to indiserver binary</label>
          <whatsthis>PATH to indiserver binary</whatsthis>
-         <default>/usr/bin/indiserver</default>
+         <default code="true">KSUtils::getDefaultPath("indiServer")</default>
       </entry>
       <entry name="indiServerIsInternal" type="Bool">
          <label>Internal or External INDI Server?</label>
@@ -191,6 +192,7 @@
       <entry name="indiDriversDir" type="String">
          <label>PATH to indi drivers directory</label>
          <whatsthis>PATH to indi drivers directory</whatsthis>
+         <default code="true">KSUtils::getDefaultPath("indiDriversDir")</default>
       </entry>
       <entry name="indiDriversAreInternal" type="Bool">
          <label>Internal or External Astrometry Solver?</label>
@@ -978,7 +980,7 @@
       <entry name="XplanetPath" type="String">
          <label>Path to xplanet binary</label>
          <whatsthis>Xplanet binary path</whatsthis>
-         <default></default>
+         <default code="true">KSUtils::getDefaultPath("XplanetPath")</default>
       </entry>
       <entry name="XplanetTitle" type="String">
          <label>Window title</label>
@@ -1637,7 +1639,7 @@
       <entry name="AstrometrySolverBinary" type="String">
          <label>astrometry.net solve-field binary</label>
          <whatsthis>Path to astrometry.net solver location.</whatsthis>
-         <default>/usr/bin/solve-field</default>
+         <default code="true">KSUtils::getDefaultPath("AstrometrySolverBinary")</default>
       </entry>
       <entry name="AstrometrySolverIsInternal" type="Bool">
          <label>Internal or External Astrometry Solver?</label>
@@ -1646,7 +1648,7 @@
       <entry name="AstrometryWCSInfo" type="String">
          <label>astrometry.net wcsinfo binary</label>
          <whatsthis>Path to astrometry.net wcsinfo location.</whatsthis>
-         <default>/usr/bin/wcsinfo</default>
+         <default code="true">KSUtils::getDefaultPath("AstrometryWCSInfo")</default>
       </entry>
       <entry name="AstrometryWCSIsInternal" type="Bool">
          <label>Internal or External wcsinfo?</label>
@@ -1655,7 +1657,7 @@
       <entry name="AstrometryConfFile" type="String">
          <label>astrometry.net configuration file</label>
          <whatsthis>Path to astrometry.net file location.</whatsthis>
-         <default>/etc/astrometry.cfg</default>
+         <default code="true">KSUtils::getDefaultPath("AstrometryConfFile")</default>
       </entry>
       <entry name="AstrometryConfFileIsInternal" type="Bool">
          <label>Internal or External Astrometry.net Conf File?</label>
diff --git a/kstars/xplanet/opsxplanet.cpp b/kstars/xplanet/opsxplanet.cpp
index e56262627..2e7dc3a4c 100644
--- a/kstars/xplanet/opsxplanet.cpp
+++ b/kstars/xplanet/opsxplanet.cpp
@@ -108,7 +108,7 @@ void OpsXplanet::toggleXPlanetInternal()
     if(kcfg_xplanetIsInternal->isChecked())
         kcfg_XplanetPath->setText("*Internal XPlanet*");
     else
-        kcfg_XplanetPath->setText("/usr/local/bin/xplanet");
+        kcfg_XplanetPath->setText(KSUtils::getDefaultPath("XplanetPath"));
 }
 
 void OpsXplanet::slotUpdateWidgets( bool on ) {


More information about the Kstars-devel mailing list