[Kstars-devel] [kstars] kstars: Add DBus interface method to set time to the current time.

Akarsh Simha akarsh at kde.org
Tue Jan 12 11:27:38 UTC 2016


Git commit 516f1ccbafa8a7a038d2775231f5d3e78329028e by Akarsh Simha.
Committed on 12/01/2016 at 11:30.
Pushed by asimha into branch 'master'.

Add DBus interface method to set time to the current time.

Adding DBus interface method org.kde.kstars.setTimeToNow which sets
the time to the current time. This allows for syncing of the
simulation clock with the system clock.

Example use-case:

Running the simulation clock continuously takes a lot of CPU, whereas
for many practical purposes, it might suffice to sync the clock every
minute or so automatically. In these cases, one could simply run a
script on a terminal to achieve this:

while true; do
   qdbus org.kde.kstars /KStars org.kde.kstars.setTimeToNow
   sleep 60;
done;

This will ensure that alt-az coordinates are reasonably up-to-date,
eyepiece view is reasonably up-to-date etc. without taking up a lot of
CPU.

CCMAIL: kstars-devel at kde.org

M  +6    -0    kstars/kstars.h
M  +4    -0    kstars/kstarsdbus.cpp
M  +3    -0    kstars/org.kde.kstars.xml

http://commits.kde.org/kstars/516f1ccbafa8a7a038d2775231f5d3e78329028e

diff --git a/kstars/kstars.h b/kstars/kstars.h
index 12a38ad..d25f347 100644
--- a/kstars/kstars.h
+++ b/kstars/kstars.h
@@ -261,6 +261,12 @@ public Q_SLOTS:
      */
     Q_SCRIPTABLE Q_NOREPLY void setLocalTime(int yr, int mth, int day, int hr, int min, int sec);
 
+    /** DBUS interface function.  Set local time and date to present values acc. system clock
+     * @note Just a proxy for slotSetTimeToNow(), but it is better to
+     * keep the DBus interface separate from the internal methods.
+     */
+    Q_SCRIPTABLE Q_NOREPLY void setTimeToNow();
+
     /** DBUS interface function.  Delay further execution of DBUS commands.
      * @param t number of seconds to delay
      */
diff --git a/kstars/kstarsdbus.cpp b/kstars/kstarsdbus.cpp
index a49beaf..6798936 100644
--- a/kstars/kstarsdbus.cpp
+++ b/kstars/kstarsdbus.cpp
@@ -153,6 +153,10 @@ void KStars::setLocalTime(int yr, int mth, int day, int hr, int min, int sec) {
     data()->changeDateTime( data()->geo()->LTtoUT( KStarsDateTime( QDate(yr, mth, day), QTime(hr,min,sec) ) ) );
 }
 
+void KStars::setTimeToNow() {
+    slotSetTimeToNow();
+}
+
 void KStars::waitFor( double sec ) {
     QTime tm;
     tm.start();
diff --git a/kstars/org.kde.kstars.xml b/kstars/org.kde.kstars.xml
index 467569d..9476980 100644
--- a/kstars/org.kde.kstars.xml
+++ b/kstars/org.kde.kstars.xml
@@ -53,6 +53,9 @@
       <arg name="sec" type="i" direction="in"/>
       <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
     </method>
+    <method name="setTimeToNow">
+      <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
+    </method>
     <method name="waitFor">
       <arg name="t" type="d" direction="in"/>
       <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>


More information about the Kstars-devel mailing list