summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Lancaster <[email protected]>2017-05-15 08:47:23 +0300
committerJasem Mutlaq <[email protected]>2017-05-15 08:47:23 +0300
commit18eef19442d6f4a531db37b7fa830fd122e99635 (patch)
treebb005299da3c6a67ecfb7f7d8994726a345f1a00
parent6eea8fd82d648d9921da9266cbc6169c8164b9a9 (diff)
This patch should both make the dbus commands work in kstars for scripting and also for the scheduler, as well as starting up a dbus server from inside the bundle if none is currently running. This should be combined with changes I made to the OS X build script already to make it all work properly. Hopefully this solves the dbus problems.
-rw-r--r--kstars/kstars.cpp46
-rw-r--r--kstars/tools/scriptbuilder.cpp6
2 files changed, 52 insertions, 0 deletions
diff --git a/kstars/kstars.cpp b/kstars/kstars.cpp
index 54f75e2..aac02a8 100644
--- a/kstars/kstars.cpp
+++ b/kstars/kstars.cpp
@@ -97,6 +97,52 @@ KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
new KstarsAdaptor(this); // NOTE the weird case convention, which cannot be changed as the file is generated by the moc.
+#ifdef Q_OS_OSX
+
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+ QString path=env.value("PATH","");
+ env.insert("PATH","/usr/bin:/usr/local/bin:\"" + QCoreApplication::applicationDirPath() + "\":" + path);
+
+ QProcess dbusCheck;
+ dbusCheck.setProcessEnvironment(env);
+ dbusCheck.start("launchctl list");
+ dbusCheck.waitForFinished();
+ QString output(dbusCheck.readAllStandardOutput());
+
+ QString pluginsDir=QDir(QCoreApplication::applicationDirPath() + "/../PlugIns").absolutePath();
+ QString dbusPlist=pluginsDir + "/dbus/org.freedesktop.dbus-kstars.plist";
+ if(!output.contains("homebrew.mxcl.dbus")&&!output.contains("org.freedesktop.dbus")&&QFileInfo(dbusPlist).exists()){
+ QFile file(dbusPlist);
+ if(file.open(QIODevice::ReadOnly))
+ {
+ QTextStream in(&file);
+ QString pListText=in.readAll();
+ file.close();
+ int programArgsLeft=pListText.indexOf("<key>ProgramArguments</key>");
+ int programArgsRight=pListText.indexOf("</array>" , programArgsLeft) + 8 - programArgsLeft;
+ QString currentProgramArgs=pListText.mid(programArgsLeft,programArgsRight);
+ QString newProgramArguments = "" \
+ "<key>ProgramArguments</key>\n" \
+ " <array>\n" \
+ " <string>" + QCoreApplication::applicationDirPath() + "/dbus-daemon</string>\n" \
+ " <string>--nofork</string>\n" \
+ " <string>--config-file=" + pluginsDir + "/dbus/kstars.conf</string>\n" \
+ " </array>";
+ pListText.replace(currentProgramArgs, newProgramArguments);
+ if(file.open(QIODevice::WriteOnly)){
+ QTextStream stream( &file );
+ stream << pListText;
+ file.close();
+
+ dbusCheck.start("chmod 775 " + dbusPlist);
+ dbusCheck.waitForFinished();
+ dbusCheck.start("launchctl load -w \"" + dbusPlist + "\"");
+ dbusCheck.waitForFinished();
+ }
+ }
+ }
+#endif
+
QDBusConnection::sessionBus().registerObject("/KStars", this);
QDBusConnection::sessionBus().registerService("org.kde.kstars");
diff --git a/kstars/tools/scriptbuilder.cpp b/kstars/tools/scriptbuilder.cpp
index eaef2dc..42cbe8b 100644
--- a/kstars/tools/scriptbuilder.cpp
+++ b/kstars/tools/scriptbuilder.cpp
@@ -991,6 +991,12 @@ void ScriptBuilder::slotRunScript()
#endif
QProcess p;
+#ifdef Q_OS_OSX
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+ QString path=env.value("PATH","");
+ env.insert("PATH","/usr/local/bin:" + QCoreApplication::applicationDirPath() + ":" + path);
+ p.setProcessEnvironment(env);
+#endif
p.start(f.fileName());
if( !p.waitForStarted() )